xref: /titanic_53/usr/src/cmd/print/scripts/getppds (revision c81d47afd05baeb768e2f032636019b717899efd)
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
6*c81d47afSceastha# Common Development and Distribution License (the "License").
7*c81d47afSceastha# 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*c81d47afSceastha# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*c81d47afSceastha# Use is subject to license terms.
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate# get a list of the Models for this Model from the ppdcache
307c478bd9Sstevel@tonic-gate#
317c478bd9Sstevel@tonic-gate
32*c81d47afSceastha# Input:
33*c81d47afSceastha#	make model
34*c81d47afSceastha#	HP OfficeJet 4200
35*c81d47afSceastha# Output:
36*c81d47afSceastha#	<label>(<repository letter>): <driver>
37*c81d47afSceastha#	userlabel(U): Foomatic/hpijs (recommended)
38*c81d47afSceastha#	SUNWhpijs(S): Foomatic/hpijs (recommended)
39*c81d47afSceastha
40*c81d47afSceasthaSaveIFS="$IFS"
41*c81d47afSceasthaNoSpaceTabIFS='
42*c81d47afSceastha'
43*c81d47afSceasthaSEP=": "
44*c81d47afSceastha
45*c81d47afSceastha#
46*c81d47afSceastha# Return cache entries matching the specified make
47*c81d47afSceastha# and model from the specified cache file.
48*c81d47afSceastha#
49*c81d47afSceastha# $1	- Make
50*c81d47afSceastha# $2	- Model
51*c81d47afSceastha# $3	- cachefile
52*c81d47afSceasthappd_make_entries()
53*c81d47afSceastha{
54*c81d47afSceastha	for hit in $(/bin/grep "${1}" "${3}" | /bin/grep "${2}")
55*c81d47afSceastha	do
56*c81d47afSceastha		echo "${hit#*:*:}"
57*c81d47afSceastha	done
58*c81d47afSceastha}
59*c81d47afSceastha
607c478bd9Sstevel@tonic-gateif [[ $# -lt 2 ]]; then
617c478bd9Sstevel@tonic-gate        exit 1
627c478bd9Sstevel@tonic-gatefi
637c478bd9Sstevel@tonic-gate
64*c81d47afSceasthacachefile=/var/lp/ppd/ppdcache
65*c81d47afSceastha[[ -f $cachefile ]] || exit 1
66*c81d47afSceasthamake=$1
677c478bd9Sstevel@tonic-gateshift
68*c81d47afSceasthamodel="$*"
69*c81d47afSceasthasystem=
70*c81d47afSceasthavendor=
71*c81d47afSceasthaadmin=
72*c81d47afSceasthauser=
737c478bd9Sstevel@tonic-gate
74*c81d47afSceastha#
75*c81d47afSceastha# Ensure each ppdcache entry is processed as a single string
76*c81d47afSceastha# otherwise it would be split up by spaces.
77*c81d47afSceastha#
78*c81d47afSceasthaIFS="$NoSpaceTabIFS"
79*c81d47afSceasthafor pentry in $(ppd_make_entries "${make}" "${model}" "${cachefile}")
80*c81d47afSceasthado
81*c81d47afSceastha	IFS="$SaveIFS"
82*c81d47afSceastha	ppdpath="${pentry##*:}"
83*c81d47afSceastha	ppdlpath="${ppdpath%/*/*}"
84*c81d47afSceastha	ppdlabel="${ppdlpath##*/}"
85*c81d47afSceastha	driver="${pentry%%:*}"
867c478bd9Sstevel@tonic-gate
87*c81d47afSceastha	case "${ppdpath}" in
88*c81d47afSceastha	"/usr/share/ppd/"*)
89*c81d47afSceastha		system="${system}${ppdlabel}(S)${SEP}${driver}\n"
90*c81d47afSceastha		;;
91*c81d47afSceastha	"/opt/share/ppd/"*)
92*c81d47afSceastha		vendor="${vendor}${ppdlabel}(V)${SEP}${driver}\n"
93*c81d47afSceastha		;;
94*c81d47afSceastha	"/usr/local/share/ppd/"*)
95*c81d47afSceastha		admin="${admin}${ppdlabel}(A)${SEP}${driver}\n"
96*c81d47afSceastha		;;
97*c81d47afSceastha	"/var/lp/ppd/"*)
98*c81d47afSceastha		user="${user}${ppdlabel}(U)${SEP}${driver}\n"
99*c81d47afSceastha		;;
100*c81d47afSceastha	esac
101*c81d47afSceastha	IFS="$NoSpaceTabIFS"
102*c81d47afSceasthadone
103*c81d47afSceastha
104*c81d47afSceasthaIFS="$SaveIFS"
105*c81d47afSceasthaecho "${user}${admin}${vendor}${system}"
1067c478bd9Sstevel@tonic-gateexit 0
107