xref: /onnv-gate/usr/src/cmd/print/scripts/getppds (revision 7447:e3918cb723cb)
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
63781Sceastha# Common Development and Distribution License (the "License").
73781Sceastha# 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*7447SWendy.Phillips@Sun.COM# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
233781Sceastha# Use is subject to license terms.
240Sstevel@tonic-gate#
250Sstevel@tonic-gate
260Sstevel@tonic-gate#
270Sstevel@tonic-gate# get a list of the Models for this Model from the ppdcache
280Sstevel@tonic-gate#
290Sstevel@tonic-gate
303781Sceastha# Input:
313781Sceastha#	make model
323781Sceastha#	HP OfficeJet 4200
333781Sceastha# Output:
343781Sceastha#	<label>(<repository letter>): <driver>
353781Sceastha#	userlabel(U): Foomatic/hpijs (recommended)
363781Sceastha#	SUNWhpijs(S): Foomatic/hpijs (recommended)
373781Sceastha
383781SceasthaSaveIFS="$IFS"
393781SceasthaNoSpaceTabIFS='
403781Sceastha'
413781SceasthaSEP=": "
423781Sceastha
433781Sceastha#
443781Sceastha# Return cache entries matching the specified make
453781Sceastha# and model from the specified cache file.
463781Sceastha#
473781Sceastha# $1	- Make
483781Sceastha# $2	- Model
493781Sceastha# $3	- cachefile
503781Sceasthappd_make_entries()
513781Sceastha{
52*7447SWendy.Phillips@Sun.COM	for hit in $(/bin/grep "${1}" "${3}" | /bin/grep ":${2}:")
533781Sceastha	do
543781Sceastha		echo "${hit#*:*:}"
553781Sceastha	done
563781Sceastha}
573781Sceastha
580Sstevel@tonic-gateif [[ $# -lt 2 ]]; then
590Sstevel@tonic-gate        exit 1
600Sstevel@tonic-gatefi
610Sstevel@tonic-gate
623781Sceasthacachefile=/var/lp/ppd/ppdcache
633781Sceastha[[ -f $cachefile ]] || exit 1
643781Sceasthamake=$1
653781Sceasthashift
663781Sceasthamodel="$*"
673781Sceasthasystem=
683781Sceasthavendor=
693781Sceasthaadmin=
703781Sceasthauser=
710Sstevel@tonic-gate
723781Sceastha#
733781Sceastha# Ensure each ppdcache entry is processed as a single string
743781Sceastha# otherwise it would be split up by spaces.
753781Sceastha#
763781SceasthaIFS="$NoSpaceTabIFS"
773781Sceasthafor pentry in $(ppd_make_entries "${make}" "${model}" "${cachefile}")
783781Sceasthado
793781Sceastha	IFS="$SaveIFS"
803781Sceastha	ppdpath="${pentry##*:}"
813781Sceastha	ppdlpath="${ppdpath%/*/*}"
823781Sceastha	ppdlabel="${ppdlpath##*/}"
833781Sceastha	driver="${pentry%%:*}"
840Sstevel@tonic-gate
853781Sceastha	case "${ppdpath}" in
863781Sceastha	"/usr/share/ppd/"*)
873781Sceastha		system="${system}${ppdlabel}(S)${SEP}${driver}\n"
883781Sceastha		;;
893781Sceastha	"/opt/share/ppd/"*)
903781Sceastha		vendor="${vendor}${ppdlabel}(V)${SEP}${driver}\n"
913781Sceastha		;;
923781Sceastha	"/usr/local/share/ppd/"*)
933781Sceastha		admin="${admin}${ppdlabel}(A)${SEP}${driver}\n"
943781Sceastha		;;
953781Sceastha	"/var/lp/ppd/"*)
963781Sceastha		user="${user}${ppdlabel}(U)${SEP}${driver}\n"
973781Sceastha		;;
983781Sceastha	esac
993781Sceastha	IFS="$NoSpaceTabIFS"
1003781Sceasthadone
1013781Sceastha
1023781SceasthaIFS="$SaveIFS"
1033781Sceasthaecho "${user}${admin}${vendor}${system}"
1043781Sceasthaexit 0
105