10Sstevel@tonic-gate#!/usr/bin/ksh
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*3781Sceastha# Common Development and Distribution License (the "License").
7*3781Sceastha# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
22*3781Sceastha# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*3781Sceastha# Use is subject to license terms.
240Sstevel@tonic-gate#
250Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
260Sstevel@tonic-gate#
270Sstevel@tonic-gate
280Sstevel@tonic-gate#
290Sstevel@tonic-gate# get a list of the Models for this Model from the ppdcache
300Sstevel@tonic-gate#
310Sstevel@tonic-gate
32*3781Sceastha# Input:
33*3781Sceastha#	make model
34*3781Sceastha#	HP OfficeJet 4200
35*3781Sceastha# Output:
36*3781Sceastha#	<label>(<repository letter>): <driver>
37*3781Sceastha#	userlabel(U): Foomatic/hpijs (recommended)
38*3781Sceastha#	SUNWhpijs(S): Foomatic/hpijs (recommended)
39*3781Sceastha
40*3781SceasthaSaveIFS="$IFS"
41*3781SceasthaNoSpaceTabIFS='
42*3781Sceastha'
43*3781SceasthaSEP=": "
44*3781Sceastha
45*3781Sceastha#
46*3781Sceastha# Return cache entries matching the specified make
47*3781Sceastha# and model from the specified cache file.
48*3781Sceastha#
49*3781Sceastha# $1	- Make
50*3781Sceastha# $2	- Model
51*3781Sceastha# $3	- cachefile
52*3781Sceasthappd_make_entries()
53*3781Sceastha{
54*3781Sceastha	for hit in $(/bin/grep "${1}" "${3}" | /bin/grep "${2}")
55*3781Sceastha	do
56*3781Sceastha		echo "${hit#*:*:}"
57*3781Sceastha	done
58*3781Sceastha}
59*3781Sceastha
600Sstevel@tonic-gateif [[ $# -lt 2 ]]; then
610Sstevel@tonic-gate        exit 1
620Sstevel@tonic-gatefi
630Sstevel@tonic-gate
64*3781Sceasthacachefile=/var/lp/ppd/ppdcache
65*3781Sceastha[[ -f $cachefile ]] || exit 1
66*3781Sceasthamake=$1
67*3781Sceasthashift
68*3781Sceasthamodel="$*"
69*3781Sceasthasystem=
70*3781Sceasthavendor=
71*3781Sceasthaadmin=
72*3781Sceasthauser=
730Sstevel@tonic-gate
74*3781Sceastha#
75*3781Sceastha# Ensure each ppdcache entry is processed as a single string
76*3781Sceastha# otherwise it would be split up by spaces.
77*3781Sceastha#
78*3781SceasthaIFS="$NoSpaceTabIFS"
79*3781Sceasthafor pentry in $(ppd_make_entries "${make}" "${model}" "${cachefile}")
80*3781Sceasthado
81*3781Sceastha	IFS="$SaveIFS"
82*3781Sceastha	ppdpath="${pentry##*:}"
83*3781Sceastha	ppdlpath="${ppdpath%/*/*}"
84*3781Sceastha	ppdlabel="${ppdlpath##*/}"
85*3781Sceastha	driver="${pentry%%:*}"
860Sstevel@tonic-gate
87*3781Sceastha	case "${ppdpath}" in
88*3781Sceastha	"/usr/share/ppd/"*)
89*3781Sceastha		system="${system}${ppdlabel}(S)${SEP}${driver}\n"
90*3781Sceastha		;;
91*3781Sceastha	"/opt/share/ppd/"*)
92*3781Sceastha		vendor="${vendor}${ppdlabel}(V)${SEP}${driver}\n"
93*3781Sceastha		;;
94*3781Sceastha	"/usr/local/share/ppd/"*)
95*3781Sceastha		admin="${admin}${ppdlabel}(A)${SEP}${driver}\n"
96*3781Sceastha		;;
97*3781Sceastha	"/var/lp/ppd/"*)
98*3781Sceastha		user="${user}${ppdlabel}(U)${SEP}${driver}\n"
99*3781Sceastha		;;
100*3781Sceastha	esac
101*3781Sceastha	IFS="$NoSpaceTabIFS"
102*3781Sceasthadone
103*3781Sceastha
104*3781SceasthaIFS="$SaveIFS"
105*3781Sceasthaecho "${user}${admin}${vendor}${system}"
106*3781Sceasthaexit 0
107