xref: /titanic_44/usr/src/cmd/print/scripts/getppds (revision 70fa9386ff0a83ccf99d2d3ac2198d2ed51bf748)
17c478bd9Sstevel@tonic-gate#!/usr/bin/ksh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6c81d47afSceastha# Common Development and Distribution License (the "License").
7c81d47afSceastha# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
22*70fa9386SWendy Phillips# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23c81d47afSceastha# Use is subject to license terms.
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate# get a list of the Models for this Model from the ppdcache
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate
30c81d47afSceastha# Input:
31c81d47afSceastha#	make model
32c81d47afSceastha#	HP OfficeJet 4200
33c81d47afSceastha# Output:
34c81d47afSceastha#	<label>(<repository letter>): <driver>
35c81d47afSceastha#	userlabel(U): Foomatic/hpijs (recommended)
36c81d47afSceastha#	SUNWhpijs(S): Foomatic/hpijs (recommended)
37c81d47afSceastha
38c81d47afSceasthaSaveIFS="$IFS"
39c81d47afSceasthaNoSpaceTabIFS='
40c81d47afSceastha'
41c81d47afSceasthaSEP=": "
42c81d47afSceastha
43c81d47afSceastha#
44c81d47afSceastha# Return cache entries matching the specified make
45c81d47afSceastha# and model from the specified cache file.
46c81d47afSceastha#
47c81d47afSceastha# $1	- Make
48c81d47afSceastha# $2	- Model
49c81d47afSceastha# $3	- cachefile
50c81d47afSceasthappd_make_entries()
51c81d47afSceastha{
52*70fa9386SWendy Phillips	for hit in $(/bin/grep "${1}" "${3}" | /bin/grep ":${2}:")
53c81d47afSceastha	do
54c81d47afSceastha		echo "${hit#*:*:}"
55c81d47afSceastha	done
56c81d47afSceastha}
57c81d47afSceastha
587c478bd9Sstevel@tonic-gateif [[ $# -lt 2 ]]; then
597c478bd9Sstevel@tonic-gate        exit 1
607c478bd9Sstevel@tonic-gatefi
617c478bd9Sstevel@tonic-gate
62c81d47afSceasthacachefile=/var/lp/ppd/ppdcache
63c81d47afSceastha[[ -f $cachefile ]] || exit 1
64c81d47afSceasthamake=$1
657c478bd9Sstevel@tonic-gateshift
66c81d47afSceasthamodel="$*"
67c81d47afSceasthasystem=
68c81d47afSceasthavendor=
69c81d47afSceasthaadmin=
70c81d47afSceasthauser=
717c478bd9Sstevel@tonic-gate
72c81d47afSceastha#
73c81d47afSceastha# Ensure each ppdcache entry is processed as a single string
74c81d47afSceastha# otherwise it would be split up by spaces.
75c81d47afSceastha#
76c81d47afSceasthaIFS="$NoSpaceTabIFS"
77c81d47afSceasthafor pentry in $(ppd_make_entries "${make}" "${model}" "${cachefile}")
78c81d47afSceasthado
79c81d47afSceastha	IFS="$SaveIFS"
80c81d47afSceastha	ppdpath="${pentry##*:}"
81c81d47afSceastha	ppdlpath="${ppdpath%/*/*}"
82c81d47afSceastha	ppdlabel="${ppdlpath##*/}"
83c81d47afSceastha	driver="${pentry%%:*}"
847c478bd9Sstevel@tonic-gate
85c81d47afSceastha	case "${ppdpath}" in
86c81d47afSceastha	"/usr/share/ppd/"*)
87c81d47afSceastha		system="${system}${ppdlabel}(S)${SEP}${driver}\n"
88c81d47afSceastha		;;
89c81d47afSceastha	"/opt/share/ppd/"*)
90c81d47afSceastha		vendor="${vendor}${ppdlabel}(V)${SEP}${driver}\n"
91c81d47afSceastha		;;
92c81d47afSceastha	"/usr/local/share/ppd/"*)
93c81d47afSceastha		admin="${admin}${ppdlabel}(A)${SEP}${driver}\n"
94c81d47afSceastha		;;
95c81d47afSceastha	"/var/lp/ppd/"*)
96c81d47afSceastha		user="${user}${ppdlabel}(U)${SEP}${driver}\n"
97c81d47afSceastha		;;
98c81d47afSceastha	esac
99c81d47afSceastha	IFS="$NoSpaceTabIFS"
100c81d47afSceasthadone
101c81d47afSceastha
102c81d47afSceasthaIFS="$SaveIFS"
103c81d47afSceasthaecho "${user}${admin}${vendor}${system}"
1047c478bd9Sstevel@tonic-gateexit 0
105