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 2008 Sun Microsystems, Inc. All rights reserved. 23# Use is subject to license terms. 24# 25 26# 27# get a list of the Models for this Model from the ppdcache 28# 29 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) 37 38SaveIFS="$IFS" 39NoSpaceTabIFS=' 40' 41SEP=": " 42 43# 44# Return cache entries matching the specified make 45# and model from the specified cache file. 46# 47# $1 - Make 48# $2 - Model 49# $3 - cachefile 50ppd_make_entries() 51{ 52 for hit in $(/bin/grep "${1}" "${3}" | /bin/grep ":${2}:") 53 do 54 echo "${hit#*:*:}" 55 done 56} 57 58if [[ $# -lt 2 ]]; then 59 exit 1 60fi 61 62cachefile=/var/lp/ppd/ppdcache 63[[ -f $cachefile ]] || exit 1 64make=$1 65shift 66model="$*" 67system= 68vendor= 69admin= 70user= 71 72# 73# Ensure each ppdcache entry is processed as a single string 74# otherwise it would be split up by spaces. 75# 76IFS="$NoSpaceTabIFS" 77for pentry in $(ppd_make_entries "${make}" "${model}" "${cachefile}") 78do 79 IFS="$SaveIFS" 80 ppdpath="${pentry##*:}" 81 ppdlpath="${ppdpath%/*/*}" 82 ppdlabel="${ppdlpath##*/}" 83 driver="${pentry%%:*}" 84 85 case "${ppdpath}" in 86 "/usr/share/ppd/"*) 87 system="${system}${ppdlabel}(S)${SEP}${driver}\n" 88 ;; 89 "/opt/share/ppd/"*) 90 vendor="${vendor}${ppdlabel}(V)${SEP}${driver}\n" 91 ;; 92 "/usr/local/share/ppd/"*) 93 admin="${admin}${ppdlabel}(A)${SEP}${driver}\n" 94 ;; 95 "/var/lp/ppd/"*) 96 user="${user}${ppdlabel}(U)${SEP}${driver}\n" 97 ;; 98 esac 99 IFS="$NoSpaceTabIFS" 100done 101 102IFS="$SaveIFS" 103echo "${user}${admin}${vendor}${system}" 104exit 0 105