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
26 #
27 # Get the make/model/nickname as well as the repository/label from ppdfilename
28 #
29
30 # Input
31 # ppdfilename
32 # /var/lp/ppd/user/HP/foo.ppd.gz
33 # Output
34 # make
35 # model
36 # label(repository letter): driver
37 #
38 # Lexmark
39 # IBM Page Printer 3112
40 # foomatic(L): Foomatic/hpijs
41 #
42
43 if [[ $# -lt 1 ]]; then
44 exit 1
45 fi
46
47 cachefile=/var/lp/ppd/ppdcache
48 [[ -f $cachefile ]] || exit 1
49
50 cacheentry=$(/bin/grep "$1" $cachefile)
51 [[ -n "$cacheentry" ]] || exit 1
52
53 #
54 # Retrieve the manufacturer (make)
55 # Use only the first word in manufacturer entry
56 #
57 manuf=$(echo "$cacheentry" |
58 /usr/xpg4/bin/awk '{FS=":"; print $1}' |
59 /usr/xpg4/bin/awk '{print $1}')
60
61 # Retrieve the model
62 model=$(echo "$cacheentry" | /usr/xpg4/bin/awk '{FS=":"; print $2}')
63
64 # Retrieve the driver
65 driver=$(echo "$cacheentry" | /usr/xpg4/bin/awk '{FS=":"; print $3}')
66
67 #
68 # Retrieve the PPD path. Parse the PPD path to get the
69 # label path and to figure out the repository letter
70 # associated with the label path. Note:
71 # the PPD file name is the 6th colon separated entry
72 # in the cache entry. This is may need to be modified if the
73 # format changes.
74 #
75 ppdpath=$(echo "$cacheentry" | /usr/xpg4/bin/awk '{FS=":"; print $6}' )
76 manupath=$(/bin/dirname "$ppdpath")
77 labelpath=$(/bin/dirname "$manupath")
78
79 case "$labelpath" in
80 /usr/share/ppd/*)
81 repltr=S
82 ;;
83 /opt/share/ppd/*)
84 repltr=V
85 ;;
86 /usr/local/share/ppd/*)
87 repltr=A
88 ;;
89 /var/lp/ppd/*)
90 repltr=U
91 ;;
92 esac
93
94 [[ -n "${repltr}" ]] || exit 1
95 echo "${manuf}\n${model}"
96 echo "$(/bin/basename "$labelpath")(${repltr}): $driver"
97
98 exit 0