8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / print / scripts / ppdfilename2mmp
blob1d24c0af994224d33034c157b06084c8451b156e
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 2007 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
25 # ident "%Z%%M% %I% %E% SMI"
29 # Get the make/model/nickname as well as the repository/label from ppdfilename
32 # Input
33 # ppdfilename
34 # /var/lp/ppd/user/HP/foo.ppd.gz
35 # Output
36 # make
37 # model
38 # label(repository letter): driver
40 # Lexmark
41 # IBM Page Printer 3112
42 # foomatic(L): Foomatic/hpijs
45 if [[ $# -lt 1 ]]; then
46 exit 1
49 cachefile=/var/lp/ppd/ppdcache
50 [[ -f $cachefile ]] || exit 1
52 cacheentry=$(/bin/grep "$1" $cachefile)
53 [[ -n "$cacheentry" ]] || exit 1
56 # Retrieve the manufacturer (make)
57 # Use only the first word in manufacturer entry
59 manuf=$(echo "$cacheentry" |
60 nawk '{FS=":"; print $1}' |
61 nawk '{print $1}')
63 # Retrieve the model
64 model=$(echo "$cacheentry" | nawk '{FS=":"; print $2}')
66 # Retrieve the driver
67 driver=$(echo "$cacheentry" | nawk '{FS=":"; print $3}')
70 # Retrieve the PPD path. Parse the PPD path to get the
71 # label path and to figure out the repository letter
72 # associated with the label path. Note:
73 # the PPD file name is the 6th colon separated entry
74 # in the cache entry. This is may need to be modified if the
75 # format changes.
77 ppdpath=$(echo "$cacheentry" | /bin/nawk '{FS=":"; print $6}' )
78 manupath=$(/bin/dirname "$ppdpath")
79 labelpath=$(/bin/dirname "$manupath")
81 case "$labelpath" in
82 /usr/share/ppd/*)
83 repltr=S
85 /opt/share/ppd/*)
86 repltr=V
88 /usr/local/share/ppd/*)
89 repltr=A
91 /var/lp/ppd/*)
92 repltr=U
94 esac
96 [[ -n "${repltr}" ]] || exit 1
97 echo "${manuf}\n${model}"
98 echo "$(/bin/basename "$labelpath")(${repltr}): $driver"
100 exit 0