8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / print / scripts / getppds
blobde91dadef43160937089eb1635017eba1633e2a6
1 #!/usr/bin/ksh
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
22 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
27 # get a list of the Models for this Model from the ppdcache
30 # Input:
31 # make model
32 # HP OfficeJet 4200
33 # Output:
34 # <label>(<repository letter>): <driver>
35 # userlabel(U): Foomatic/hpijs (recommended)
36 # SUNWhpijs(S): Foomatic/hpijs (recommended)
38 SaveIFS="$IFS"
39 NoSpaceTabIFS='
41 SEP=": "
44 # Return cache entries matching the specified make
45 # and model from the specified cache file.
47 # $1 - Make
48 # $2 - Model
49 # $3 - cachefile
50 ppd_make_entries()
52 for hit in $(/bin/grep "${1}" "${3}" | /bin/grep ":${2}:")
54 echo "${hit#*:*:}"
55 done
58 if [[ $# -lt 2 ]]; then
59 exit 1
62 cachefile=/var/lp/ppd/ppdcache
63 [[ -f $cachefile ]] || exit 1
64 make=$1
65 shift
66 model="$*"
67 system=
68 vendor=
69 admin=
70 user=
73 # Ensure each ppdcache entry is processed as a single string
74 # otherwise it would be split up by spaces.
76 IFS="$NoSpaceTabIFS"
77 for pentry in $(ppd_make_entries "${make}" "${model}" "${cachefile}")
79 IFS="$SaveIFS"
80 ppdpath="${pentry##*:}"
81 ppdlpath="${ppdpath%/*/*}"
82 ppdlabel="${ppdlpath##*/}"
83 driver="${pentry%%:*}"
85 case "${ppdpath}" in
86 "/usr/share/ppd/"*)
87 system="${system}${ppdlabel}(S)${SEP}${driver}\n"
89 "/opt/share/ppd/"*)
90 vendor="${vendor}${ppdlabel}(V)${SEP}${driver}\n"
92 "/usr/local/share/ppd/"*)
93 admin="${admin}${ppdlabel}(A)${SEP}${driver}\n"
95 "/var/lp/ppd/"*)
96 user="${user}${ppdlabel}(U)${SEP}${driver}\n"
98 esac
99 IFS="$NoSpaceTabIFS"
100 done
102 IFS="$SaveIFS"
103 echo "${user}${admin}${vendor}${system}"
104 exit 0