xref: /titanic_41/usr/src/cmd/print/scripts/getppds (revision 4a6822d07d6d3f9ffe6907ef5f10d11dcadd75c6)
1#!/usr/bin/ksh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23# Use is subject to license terms.
24#
25# ident	"%Z%%M%	%I%	%E% SMI"
26#
27
28#
29# get a list of the Models for this Model from the ppdcache
30#
31
32# Input:
33#	make model
34#	HP OfficeJet 4200
35# Output:
36#	<label>(<repository letter>): <driver>
37#	userlabel(U): Foomatic/hpijs (recommended)
38#	SUNWhpijs(S): Foomatic/hpijs (recommended)
39
40SaveIFS="$IFS"
41NoSpaceTabIFS='
42'
43SEP=": "
44
45#
46# Return cache entries matching the specified make
47# and model from the specified cache file.
48#
49# $1	- Make
50# $2	- Model
51# $3	- cachefile
52ppd_make_entries()
53{
54	for hit in $(/bin/grep "${1}" "${3}" | /bin/grep "${2}")
55	do
56		echo "${hit#*:*:}"
57	done
58}
59
60if [[ $# -lt 2 ]]; then
61        exit 1
62fi
63
64cachefile=/var/lp/ppd/ppdcache
65[[ -f $cachefile ]] || exit 1
66make=$1
67shift
68model="$*"
69system=
70vendor=
71admin=
72user=
73
74#
75# Ensure each ppdcache entry is processed as a single string
76# otherwise it would be split up by spaces.
77#
78IFS="$NoSpaceTabIFS"
79for pentry in $(ppd_make_entries "${make}" "${model}" "${cachefile}")
80do
81	IFS="$SaveIFS"
82	ppdpath="${pentry##*:}"
83	ppdlpath="${ppdpath%/*/*}"
84	ppdlabel="${ppdlpath##*/}"
85	driver="${pentry%%:*}"
86
87	case "${ppdpath}" in
88	"/usr/share/ppd/"*)
89		system="${system}${ppdlabel}(S)${SEP}${driver}\n"
90		;;
91	"/opt/share/ppd/"*)
92		vendor="${vendor}${ppdlabel}(V)${SEP}${driver}\n"
93		;;
94	"/usr/local/share/ppd/"*)
95		admin="${admin}${ppdlabel}(A)${SEP}${driver}\n"
96		;;
97	"/var/lp/ppd/"*)
98		user="${user}${ppdlabel}(U)${SEP}${driver}\n"
99		;;
100	esac
101	IFS="$NoSpaceTabIFS"
102done
103
104IFS="$SaveIFS"
105echo "${user}${admin}${vendor}${system}"
106exit 0
107