xref: /titanic_44/usr/src/cmd/print/scripts/ppdfilename2mmp (revision 24da5b34f49324ed742a340010ed5bd3d4e06625)
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 the make/model/nickname as well as the repository/label from ppdfilename
30#
31
32# Input
33#	ppdfilename
34#	/var/lp/ppd/user/HP/foo.ppd.gz
35# Output
36#	make
37#	model
38#	label(repository letter): driver
39#
40#	Lexmark
41#	IBM Page Printer 3112
42#	foomatic(L): Foomatic/hpijs
43#
44
45if [[ $# -lt 1 ]]; then
46        exit 1
47fi
48
49cachefile=/var/lp/ppd/ppdcache
50[[ -f $cachefile ]] || exit 1
51
52cacheentry=$(/bin/grep "$1" $cachefile)
53[[ -n "$cacheentry" ]] || exit 1
54
55#
56# Retrieve the manufacturer (make)
57# Use only the first word in manufacturer entry
58#
59manuf=$(echo "$cacheentry" |
60nawk '{FS=":"; print $1}' |
61nawk '{print $1}')
62
63# Retrieve the model
64model=$(echo "$cacheentry" | nawk '{FS=":"; print $2}')
65
66# Retrieve the driver
67driver=$(echo "$cacheentry" | nawk '{FS=":"; print $3}')
68
69#
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.
76#
77ppdpath=$(echo "$cacheentry" | /bin/nawk '{FS=":"; print $6}' )
78manupath=$(/bin/dirname "$ppdpath")
79labelpath=$(/bin/dirname "$manupath")
80
81case "$labelpath" in
82/usr/share/ppd/*)
83	repltr=S
84		;;
85/opt/share/ppd/*)
86	repltr=V
87	;;
88/usr/local/share/ppd/*)
89	repltr=A
90	;;
91/var/lp/ppd/*)
92	repltr=U
93	;;
94esac
95
96[[ -n "${repltr}" ]] || exit 1
97echo "${manuf}\n${model}"
98echo "$(/bin/basename "$labelpath")(${repltr}): $driver"
99
100exit 0
101