13781Sceastha#!/bin/ksh 23781Sceastha# 33781Sceastha# CDDL HEADER START 43781Sceastha# 53781Sceastha# The contents of this file are subject to the terms of the 63781Sceastha# Common Development and Distribution License (the "License"). 73781Sceastha# You may not use this file except in compliance with the License. 83781Sceastha# 93781Sceastha# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 103781Sceastha# or http://www.opensolaris.org/os/licensing. 113781Sceastha# See the License for the specific language governing permissions 123781Sceastha# and limitations under the License. 133781Sceastha# 143781Sceastha# When distributing Covered Code, include this CDDL HEADER in each 153781Sceastha# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 163781Sceastha# If applicable, add the following below this CDDL HEADER, with the 173781Sceastha# fields enclosed by brackets "[]" replaced with your own identifying 183781Sceastha# information: Portions Copyright [yyyy] [name of copyright owner] 193781Sceastha# 203781Sceastha# CDDL HEADER END 213781Sceastha# 22*8532SSumanth.Naropanth@Sun.COM# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 233781Sceastha# Use is subject to license terms. 243781Sceastha# 253781Sceastha 263781Sceastha# 273781Sceastha# Description: Script to generate the Solaris printmgr 'ppdcache' file from the 283781Sceastha# ppd files installed in the given ppd database directory 293781Sceastha# 303781Sceastha# ppdmgr -a <ppd_filename_path> [ -L <label> ] [-w] 313781Sceastha# ppdmgr -g <ppd_filename_path> [ -L <label> ] [ -R <ppd_repository> ] 323781Sceastha# ppdmgr -r [ -L <label> ] [ -R <ppd_repository> ] 333781Sceastha# ppdmgr -u [ -L <label> ] [ -R <ppd_repository> ] 343781Sceastha# 353781Sceastha# Options: 363781Sceastha# -a <ppd_filename_path> - Add a new PPD file to the specified 373781Sceastha# label in the "user" repository, and 383781Sceastha# updates to the "user" repository 393781Sceastha# in the ppdcache. 403781Sceastha# -g <ppd_filename_path> - Generate a cache file entry 413781Sceastha# for the specified PPD file 423781Sceastha# on standard out. 433781Sceastha# -L <label> - Label name. <label> 443781Sceastha# can be any characters from the 453781Sceastha# portable character set, however 463781Sceastha# may not contain a semi-colon (':'). 473781Sceastha# The following are the defaults 483781Sceastha# for <label> for each option: 493781Sceastha# OPTION DEFAULT LABEL 503781Sceastha# ------ ------------- 513781Sceastha# -a <label> from <ppd_filename_path> 523781Sceastha# if <ppd_filename_path> 533781Sceastha# is from a known repository, 543781Sceastha# otherwise defaults to "user". 553781Sceastha# -g <label> from <ppd_filename_path> 563781Sceastha# if <ppd_filename_path> 573781Sceastha# is from a known repository, 583781Sceastha# otherwise defaults to "user". 593781Sceastha# -r all 603781Sceastha# -u all 613781Sceastha# The following are reserved labels: 623781Sceastha# caches - may never be specified 633781Sceastha# ppdcache - may never be specified 643781Sceastha# manufaliases - may never be specified 653781Sceastha# all - applies specified 663781Sceastha# action to all labels 673781Sceastha# in a repository. 683781Sceastha# Can only be specified 693781Sceastha# with -r or -u. 703781Sceastha# SUNW* - anything starting with 713781Sceastha# SUNW is reserved for 723781Sceastha# use by Sun, but not 733781Sceastha# prohibited. 743781Sceastha# -r - Rebuild the cache information for the 753781Sceastha# specified label in the specified 763781Sceastha# repository. Similar to -u, however, 773781Sceastha# the cache file is removed to force an 783781Sceastha# update to the ppdcache. 793781Sceastha# -R <ppd_repository> - PPD repository name. 803781Sceastha# Defaults to "user". 813781Sceastha# The following are the possible 823781Sceastha# values for <ppd_repository> and 833781Sceastha# location in the system: 843781Sceastha# REP LOCATION 853781Sceastha# --- -------- 863781Sceastha# user /var/lp/ppd 873781Sceastha# admin /usr/local/share/ppd 883781Sceastha# vendor /opt/share/ppd 893781Sceastha# system /usr/share/ppd 903781Sceastha# all all repositories 913781Sceastha# 923781Sceastha# Note: When specified with the -a option 933781Sceastha# only "user" and "admin" are valid. 943781Sceastha# "vendor", "system", and "all" will be 953781Sceastha# considered reserved. 963781Sceastha# -u - Update the PPD cache information 973781Sceastha# for the specified label in the specified 983781Sceastha# repository if needed. If the cache 993781Sceastha# update was required, then the updated 1003781Sceastha# cache information is reflected in 1013781Sceastha# the ppdcache. 1023781Sceastha# -w - Display full path of where the 1033781Sceastha# ppd file is located on the system. 1043781Sceastha# Only valid with -a, otherwise the 1053781Sceastha# option is ignored. 1063781Sceastha# 1073781Sceastha# If -a, -g, -r, or -u are specified on the command line, only the last action 1083781Sceastha# specified will be performed. 1093781Sceastha# 1103781Sceastha# Cache file entry format: 1113781Sceastha# <ModifiedManufacturerName>:<Model>:<NickName>:<1284DeviceIDManufacturer>:<1284DeviceIDModel>:<FullPPDFilePath> 1123781Sceastha# HP:HP DeskJet 450:Foomatic/hpijs (recommended):dj450:hp:/usr/share/ppd/HP/HP-DeskJet_450-hpijs.ppd.gz 1133781Sceastha# 1143781Sceastha 1153781SceasthaPATH=/bin:/usr/bin:/usr/sbin export PATH 1163781Sceasthaset -o noclobber 1173781Sceastha 1183781SceasthaTEXTDOMAIN="SUNW_OST_OSCMD" 1193781Sceasthaexport TEXTDOMAIN 1203781Sceastha 1213781Sceastha# 1223781Sceastha# Generates debug output for calling routine. 1233781Sceastha# If calling routine's name is passed in, then 1243781Sceastha# will also generate the name of the calling routine. 1253781Sceastha# 1263781Sceastha# $1 - Name of calling routine 1273781Sceasthadebugger() 1283781Sceastha{ 1293781Sceastha [[ ${debug} -eq 1 ]] || return 1 1303781Sceastha if [[ -n "${1}" ]] ; then 1313781Sceastha echo "In ${1}..." 1>&2 1323781Sceastha fi 1333781Sceastha return 0 1343781Sceastha} 1353781Sceastha 1363781Sceastha# 1373781Sceastha# Set the ownership and permissions on a file. 1383781Sceastha# 1393781Sceastha# $1 - Mode 1403781Sceastha# $2 - Owner:Group 1413781Sceastha# $3 - Full path to file 1423781Sceastha# 1433781Sceasthaset_perms() 1443781Sceastha{ 1453781Sceastha /bin/chmod -f ${1} "${3}" >/dev/null 2>&1 1463781Sceastha /bin/chown -f ${2} "${3}" >/dev/null 2>&1 1473781Sceastha} 1483781Sceastha 1493781Sceastha# 1503781Sceastha# Create administrator repository directories, /usr/local/share/ppd, 1513781Sceastha# if needed. This is a special case a Solaris doesn't deliver 1523781Sceastha# /usr/local/share and it has different permissions than the 1533781Sceastha# user repository. 1543781Sceastha# 1553781Sceastha# $1 - destination repository name 1563781Sceastha# 1573781Sceasthacreate_adminrep_dirs() 1583781Sceastha{ 1593781Sceastha if debugger "check_adminrep_dirs" ; then 1603781Sceastha set -x 1613781Sceastha fi 1623781Sceastha 1633781Sceastha # Only create administrator repository directories, if needed. 1643781Sceastha [[ "${1}" = "${ADMIN}" ]] || return 0 1653781Sceastha 1663781Sceastha # Check /usr/local/share/ppd 1673781Sceastha [[ ! -d "${ADMINREP}" ]] || return 0 1683781Sceastha 1693781Sceastha # Check /usr/local/share 1703781Sceastha admpar=$(/bin/dirname "${ADMINREP}") 1713781Sceastha if [[ ! -d "${admpar}" ]] ; then 1723781Sceastha 1733781Sceastha # Check /usr/local 1743781Sceastha admppar=$(/bin/dirname "${admpar}") 1753781Sceastha if [[ ! -d "${admppar}" ]] ; then 1763781Sceastha make_dir ${DIRMODE} ${ADMINOWNER} "${admppar}" || \ 1773781Sceastha return 1 1783781Sceastha fi 1793781Sceastha make_dir ${DIRMODE} ${ADMINOWNER} "${admpar}" || return 1 1803781Sceastha fi 1813781Sceastha make_dir ${DIRMODE} ${ADMINOWNER} ${ADMINREP} || return 1 1823781Sceastha return 0 1833781Sceastha} 1843781Sceastha 1853781Sceastha# 1863781Sceastha# Returns full path to PPD file that was added to the system. 1873781Sceastha# 1883781Sceastha# $1 - Full path to source PPD file 1893781Sceastha# $2 - PPD file name 1903781Sceastha# $3 - Full path to repository 1913781Sceastha# $4 - Repository name 1923781Sceastha# $5 - Label name 1933781Sceastha# 1943781Sceastha# Return codes: 1953781Sceastha# 0 - File successfully added 1963781Sceastha# 1 - Error 1973781Sceastha# 2 - Duplicate file already exists 1983781Sceastha# 1993781Sceasthaadd_ppd() 2003781Sceastha{ 2013781Sceastha if debugger ; then 2023781Sceastha set -x 2033781Sceastha fi 2043781Sceastha 2053781Sceastha verify_ppd_file "${1}" 2063781Sceastha if [[ $? -ne 0 ]] ; then 2073781Sceastha gettext "invalid PPD file: ${1}" 2>/dev/null 2083781Sceastha return 3 2093781Sceastha fi 2103781Sceastha 2113781Sceastha # The destination path can now be set 2123781Sceastha dstlabelpath="${3}/${5}" 2133781Sceastha dstmanufpath="${dstlabelpath}/${modmanuf}" 2143781Sceastha dstpath="${dstmanufpath}/${2}" 2153781Sceastha 2163781Sceastha # 2173781Sceastha # If a version (either compressed or not compressed) of the PPD 2183781Sceastha # file exists in the destination in the label/repository, 2193781Sceastha # then just return as there no work to be done. 2203781Sceastha dst_copy_path=$(variant_copy "${1}" "${dstpath}" "${6}" "${ppdfname}") 2213781Sceastha ap_rc=$? 2223781Sceastha if [[ ${ap_rc} -ne 0 ]] ; then 2233781Sceastha echo "${dst_copy_path}" 2243781Sceastha return ${ap_rc} 2253781Sceastha fi 2263781Sceastha 2273781Sceastha # 2283781Sceastha # Can only add a PPD file to the "user" or "admin" repository. 2293781Sceastha # Note: this check is here instead of at the top of this 2303781Sceastha # function as we don't want to cause an error if a user 2313781Sceastha # specifies the same repository and label as a the specified 2323781Sceastha # ppd file and the repository of the specified ppd file 2333781Sceastha # exists in a known repository. 2343781Sceastha # 2353781Sceastha if [[ "${4}" != "${USER}" && "${4}" != "${ADMIN}" ]] ; then 2363781Sceastha gettext "invalid PPD file repository name: ${4}" 2>/dev/null 2373781Sceastha return 3 2383781Sceastha fi 2393781Sceastha 2403781Sceastha # Ensure destination directories exist 2413781Sceastha if ! create_adminrep_dirs ${4} ${DIRMODE} ${ADMINOWNER} || \ 2423781Sceastha ! make_dir ${DIRMODE} ${DIROWNER} "${3}" || \ 2433781Sceastha ! make_dir ${DIRMODE} ${DIROWNER} "${dstlabelpath}" || \ 2443781Sceastha ! make_dir ${DIRMODE} ${DIROWNER} "${dstmanufpath}" ; then 2453781Sceastha gettext "unable to create destination directories" 2>/dev/null 2463781Sceastha return 3 2473781Sceastha fi 2483781Sceastha 2493781Sceastha # Copy source PPD file, and compress if needed, to destination 2503781Sceastha if [[ "${ppdfileext}" = "${PEXT}" ]] ; then 2513781Sceastha ${GZIP} "${1}" >"${dst_copy_path}" 2>/dev/null 2523781Sceastha if [[ $? -eq 1 ]] ; then 2533781Sceastha gettext "unable to copy PPD file " 2>/dev/null 2543781Sceastha gettext "to destination" 2>/dev/null 2553781Sceastha return 3 2563781Sceastha fi 2573781Sceastha else 2583781Sceastha /bin/cp -f "${1}" "${dst_copy_path}" >/dev/null 2>&1 2593781Sceastha if [[ $? -ne 0 ]] ; then 2603781Sceastha gettext "unable to copy PPD file " 2>/dev/null 2613781Sceastha gettext "to destination" 2>/dev/null 2623781Sceastha return 3 2633781Sceastha fi 2643781Sceastha fi 2653781Sceastha set_perms ${FILEMODE} ${FILEOWNER} "${dst_copy_path}" 2663781Sceastha 2673781Sceastha echo "${dst_copy_path}" 2683781Sceastha 2693781Sceastha return 0 2703781Sceastha} 2713781Sceastha 2723781Sceastha# 2733781Sceastha# Returns 0 if the cache needs to be modified, otherwise 2743781Sceastha# returns 1. 2753781Sceastha# 2763781Sceastha# $1 - Full path to cache 2773781Sceastha# $2 - Full path to cache replacement candidate 2783781Sceastha# 2793781Sceasthachanges_in_cache() 2803781Sceastha{ 2813781Sceastha if debugger "changes_in_cache" ; then 2823781Sceastha set -x 2833781Sceastha fi 2843781Sceastha 2853781Sceastha if [[ "${action}" = "${REBUILD}" ]] ; then 2863781Sceastha return 0 2873781Sceastha fi 2883781Sceastha [[ "${2}" -nt "${1}" ]] || return 1 2893781Sceastha if $(${CMP} "${1}" "${2}" >/dev/null 2>&1) ; then 2903781Sceastha # No differences. Just update timestamp 2913781Sceastha /bin/touch -r "${2}" "${1}" >/dev/null 2>&1 2923781Sceastha return 1 2933781Sceastha else 2943781Sceastha return 0 2953781Sceastha fi 2963781Sceastha} 2973781Sceastha 2983781Sceastha# 2993781Sceastha# Generate a new golden cache file (/var/lp/ppd/ppdcache), by 3003781Sceastha# concatenating and sorting all existing cache files in /var/lp/ppd/caches. 3013781Sceastha# 3023781Sceastha# If there are difference between the newly generated golden cache file and 3033781Sceastha# the existing one (if it exists) then the newly generated one replaces the 3043781Sceastha# existing one at /var/lp/ppd/ppdcache. 3053781Sceastha# 3063781Sceasthaupdate_golden_cache() 3073781Sceastha{ 3083781Sceastha 3093781Sceastha if debugger "update_golden_cache" ; then 3103781Sceastha set -x 3113781Sceastha fi 3123781Sceastha 3133781Sceastha # 3143781Sceastha # Remove any cache files that don't have an associated 3153781Sceastha # label. 3163781Sceastha # 3173781Sceastha for cname in $(/bin/ls ${VARCACHES} 2>/dev/null) ; do 3183781Sceastha repname="${cname%%:*}" 3193781Sceastha cfile="${cname#*:}" 3203781Sceastha checkdir="$(get_rep_path ${repname})/${cfile}" 3213781Sceastha remove_unassociated_cache "${checkdir}" "${cname}" 3223781Sceastha done 3233781Sceastha 3243781Sceastha # 3253781Sceastha # Combine the contents of all cache files into a 3263781Sceastha # temporary golden cache file. 3273781Sceastha # 328*8532SSumanth.Naropanth@Sun.COM tmpgoldencache=$ppdmgrtmpdir/tmpgoldencache 329*8532SSumanth.Naropanth@Sun.COM 3303781Sceastha /bin/sort "${VARCACHES}"/* >>"${tmpgoldencache}" 2>/dev/null 3313781Sceastha 3323781Sceastha if [[ ! -s "${tmpgoldencache}" ]] ; then 3333781Sceastha # No cache files. Remove golden cache. 3343781Sceastha /bin/rm -f "${GOLDCACHE}" >/dev/null 2>&1 3353781Sceastha /bin/rm -f "${tmpgoldencache}" >/dev/null 2>&1 3363781Sceastha elif [[ -e "${GOLDCACHE}" ]] ; then 3373781Sceastha # 3383781Sceastha # Use the newly generated "temporary" golden cache file if there 3393781Sceastha # differences between the current and newly generated ppdcache 3403781Sceastha # or if a rebuild is being performed. 3413781Sceastha # 3423781Sceastha if [[ "${VARCACHES}" -nt "${GOLDCACHE}" ]] || \ 3433781Sceastha changes_in_cache "${GOLDCACHE}" "${tmpgoldencache}" ; then 3443781Sceastha set_perms ${FILEMODE} ${FILEOWNER} "${tmpgoldencache}" 3453781Sceastha /bin/mv -f "${tmpgoldencache}" \ 3463781Sceastha "${GOLDCACHE}" >/dev/null 2>&1 3473781Sceastha else 3483781Sceastha /bin/rm -f "${tmpgoldencache}" >/dev/null 2>&1 3493781Sceastha fi 3503781Sceastha else 3513781Sceastha # There wasn't an existing ppdcache. Install the newly 3523781Sceastha # generated ppdcache file to the golden ppdcache. 3533781Sceastha set_perms ${FILEMODE} ${FILEOWNER} "${tmpgoldencache}" 3543781Sceastha /bin/mv -f "${tmpgoldencache}" "${GOLDCACHE}" >/dev/null 2>&1 3553781Sceastha fi 3563781Sceastha} 3573781Sceastha 3583781Sceastha# 3593781Sceastha# Returns a list of PPD files that exist. 3603781Sceastha# 3613781Sceastha# $1 - Full path to cache file 3623781Sceastha# 3633781Sceastharemove_invalid_cache_entries() 3643781Sceastha{ 3653781Sceastha if debugger ; then 3663781Sceastha set -x 3673781Sceastha fi 3683781Sceastha 3693781Sceastha [[ -s "${1}" ]] || return 3703781Sceastha 3713781Sceastha IFS="$NoSpaceTabIFS" 3723781Sceastha for centry in $(/bin/cat "${1}" 2>/dev/null) ; do 3733781Sceastha IFS="$SaveIFS" 3743781Sceastha # 3753781Sceastha # Keep the entry from the ppd cache if it still 3763781Sceastha # exists and there haven't been any modifications 3773781Sceastha # since the last update to the cache. 3783781Sceastha # 3793781Sceastha if [[ -n "${centry}" ]] ; then 3803781Sceastha ppdfile="${centry##*:}" 3813781Sceastha if [[ -n "${ppdfile}" && -e "${ppdfile}" && 3823781Sceastha "${1}" -nt "${ppdfile}" ]] ; then 3833781Sceastha echo "${centry}" 3843781Sceastha fi 3853781Sceastha fi 3863781Sceastha IFS="$NoSpaceTabIFS" 3873781Sceastha done 3883781Sceastha IFS="$SaveIFS" 3893781Sceastha} 3903781Sceastha 3913781Sceastha# 3923781Sceastha# Returns 0 if the path to the PPD is as follows: 3933781Sceastha# <PPD file repository>/<label>/<manufacturer>/<PPD file> 3943781Sceastha# otherwise, returns 1 3953781Sceastha# 3963781Sceastha# $1 Full path to PPD file 3973781Sceastha# 3983781Sceasthaverify_ppd_location() 3993781Sceastha{ 4003781Sceastha if debugger ; then 4013781Sceastha set -x 4023781Sceastha fi 4033781Sceastha 4043781Sceastha # 4053781Sceastha # Strip off what should be <label>/<manufacturer>/<PPD file> 4063781Sceastha # and verify the PPD file repository matches one of the 4073781Sceastha # known PPD file repositories. 4083781Sceastha # 4093781Sceastha ppd_file_repository=${1%/*/*/*} 4103781Sceastha found=1 4113781Sceastha for repository in ${REPOSITORIES} ; do 4123781Sceastha if [[ "${repository}" = "${ppd_file_repository}" ]] ; then 4133781Sceastha found=0 4143781Sceastha break 4153781Sceastha fi 4163781Sceastha done 4173781Sceastha return ${found} 4183781Sceastha} 4193781Sceastha 4203781Sceastha# 4213781Sceastha# Generate, and sort, cache entries for each PPD files in the specified 4223781Sceastha# list to the specified file. 4233781Sceastha# 4243781Sceastha# $1 - List of full paths to PPD files 4253781Sceastha# $2 - Full path to current cache file 4263781Sceastha# $3 - Full path to label 4273781Sceastha# $4 - Full path to new cache file to generate 4283781Sceastha# 4293781Sceastha# Return code: 4303781Sceastha# 0 success 4313781Sceastha# 1 unsuccessful 4323781Sceastha# 4333781Sceasthagenerate_label_cache_file() 4343781Sceastha{ 4353781Sceastha if debugger ; then 4363781Sceastha set -x 4373781Sceastha fi 4383781Sceastha 4393781Sceastha # 4403781Sceastha # Generate a cache file containing cache entries for 4413781Sceastha # all files in the label. 4423781Sceastha # 443*8532SSumanth.Naropanth@Sun.COM ucfile=$ppdmgrtmpdir/unsortedcache 4443781Sceastha 4453781Sceastha # 4463781Sceastha # Before processing new files, remove any cache entries 4473781Sceastha # which may be invalid. 4483781Sceastha # 4493781Sceastha valid_files= 4503781Sceastha if [[ -e "${2}" && "${action}" != "${REBUILD}" ]] ; then 4513781Sceastha valid_files=$(remove_invalid_cache_entries "${2}") 4523781Sceastha if [[ -n "${valid_files}" ]] ; then 4533781Sceastha echo "${valid_files}" >>${ucfile} 4543781Sceastha fi 4553781Sceastha fi 4563781Sceastha 4573781Sceastha # 4583781Sceastha # If there are no valid PPD files in the current cache file, 4593781Sceastha # and there are no new PPD files to process, the only thing 4603781Sceastha # left to do is to remove the current cache file. 4613781Sceastha # 4623781Sceastha if [[ -z "${valid_files}" && -z "${1}" ]] ; then 4633781Sceastha /bin/rm -f "${2}" >/dev/null 2>&1 4643781Sceastha /bin/rm -f "${ucfile}" >/dev/null 2>&1 4653781Sceastha return 0 4663781Sceastha fi 4673781Sceastha 4683781Sceastha # 4693781Sceastha # For each of the label's PPD files, generate 4703781Sceastha # a cache file entry and add it to the cache file. 4713781Sceastha # 4723781Sceastha vpl_rc=0 4733781Sceastha vpf_rc=0 4743781Sceastha vpl_msg= 4753781Sceastha vpf_msg= 4763781Sceastha IFS="$NoSpaceTabIFS" 4773781Sceastha for fname in ${1} ; do 4783781Sceastha IFS="$SaveIFS" 4793781Sceastha if [[ -n "${fname}" ]] ; then 4803781Sceastha verify_ppd_location "${fname}" 4813781Sceastha vpl_rc=$? 4823781Sceastha if [[ ${vpl_rc} -ne 0 ]] ; then 4833781Sceastha vpl_msg="${vpl_msg}\t${fname}\n" 4843781Sceastha fi 4853781Sceastha 4863781Sceastha verify_ppd_file "${fname}" 4873781Sceastha vpf_rc=$? 4883781Sceastha if [[ ${vpf_rc} -ne 0 ]] ; then 4893781Sceastha vpf_msg="${vpf_msg}\t${fname}\n" 4903781Sceastha fi 4913781Sceastha 4923781Sceastha if [[ ${vpl_rc} -eq 0 && ${vpf_rc} -eq 0 ]] ; then 4933781Sceastha echo "$(generate_cache_file_entry \ 4943781Sceastha "${modmanuf}" "${model}" "${nickn}" \ 4953781Sceastha "${devidmfg}" "${devidmdl}" "${fname}")" 4963781Sceastha fi 4973781Sceastha fi 4983781Sceastha IFS="$NoSpaceTabIFS" 4993781Sceastha done >>"${ucfile}" 5003781Sceastha IFS="$SaveIFS" 5013781Sceastha /bin/sort -u "${ucfile}" >>"${4}" 2>/dev/null 5023781Sceastha /bin/rm -f "${ucfile}" >/dev/null 2>&1 5033781Sceastha 5043781Sceastha [[ -n "${vpl_msg}" || -n "${vpf_msg}" ]] || return 0 5053781Sceastha if [[ -n ${vpl_msg} ]] ; then 5063781Sceastha gettext " PPD file(s) not in valid location\n" 2>/dev/null 5073781Sceastha gettext \ 5083781Sceastha " (<repository>/<label>/<manufacturer>/<PPD file>):\n" 2>/dev/null 5093781Sceastha echo "${vpl_msg}" 5103781Sceastha fi 5113781Sceastha if [[ -n ${vpf_msg} ]] ; then 5123781Sceastha gettext " invalid PPD file(s):\n" 2>/dev/null 5133781Sceastha echo "${vpf_msg}" 5143781Sceastha fi 5153781Sceastha return 1 5163781Sceastha} 5173781Sceastha 5183781Sceastha# 5193781Sceastha# Update current cache file with candidate cache file if there are 5203781Sceastha# differences. 5213781Sceastha# 5223781Sceastha# $1 - Current cache file 5233781Sceastha# $2 - Candidate cache file to update 5243781Sceastha# $3 - Repository name 5253781Sceastha# 5263781Sceasthaupdate_current_cache_file() 5273781Sceastha{ 5283781Sceastha if debugger "update_current_cache_file" ; then 5293781Sceastha set -x 5303781Sceastha fi 5313781Sceastha 5323781Sceastha if [[ ! -s "${2}" ]] ; then 5333781Sceastha # 5343781Sceastha # Candidate cache has zero size (label 5353781Sceastha # directory with no PPD files under it). 5363781Sceastha # Delete the empty candidate cache 5373781Sceastha # file and delete the current cache 5383781Sceastha # file. 5393781Sceastha # 5403781Sceastha /bin/rm -f "${1}" >/dev/null 2>&1 5413781Sceastha /bin/rm -f "${2}" >/dev/null 2>&1 5423781Sceastha elif [[ -e "${1}" ]] ; then 5433781Sceastha # 5443781Sceastha # If there are differences between the current 5453781Sceastha # cache file and the newly generated one, then 5463781Sceastha # replace the current one with the new one, and 5473781Sceastha # set the flag to update the golden ppdcache 5483781Sceastha # file. 5493781Sceastha # 5503781Sceastha if changes_in_cache "${1}" "${2}" ; then 5513781Sceastha set_perms ${FILEMODE} ${FILEOWNER} "${2}" 5523781Sceastha /bin/mv -f "${2}" "${1}" >/dev/null 2>&1 5533781Sceastha else 5543781Sceastha /bin/rm -f "${2}" >/dev/null 2>&1 5553781Sceastha fi 5563781Sceastha else 5573781Sceastha 5583781Sceastha # 5593781Sceastha # There is no current cache file. Move the candidate 5603781Sceastha # to the caches directory. 5613781Sceastha # 5623781Sceastha set_perms ${FILEMODE} ${FILEOWNER} "${2}" 5633781Sceastha /bin/mv -f "${2}" "${1}" >/dev/null 2>&1 5643781Sceastha fi 5653781Sceastha} 5663781Sceastha 5673781Sceastha# 5683781Sceastha# Returns 0 if there are files in $1 with newer timestamp 5693781Sceastha# than $2 or if deletions have occurred under $1, 5703781Sceastha# otherwise returns 1. 5713781Sceastha# 5723781Sceastha# $1 - Full path to the destination label 5733781Sceastha# $2 - Full path to label cache file 5743781Sceastha# 5753781Sceasthachanges_under_label() 5763781Sceastha{ 5773781Sceastha if debugger ; then 5783781Sceastha set -x 5793781Sceastha fi 5803781Sceastha 5813781Sceastha # First check for newer files in the directory 5823781Sceastha if [[ -e "${2}" && "${action}" != "${REBUILD}" ]] ; then 5833781Sceastha newfiles=$(/bin/find "${1}" -type f -newer "${2}") 5843781Sceastha else 5853781Sceastha newfiles=$(/bin/find "${1}" -type f) 5863781Sceastha fi 5873781Sceastha echo "${newfiles}" 5883781Sceastha [[ -z "${newfiles}" ]] || return 0 5893781Sceastha 5903781Sceastha # 5913781Sceastha # Need to detect if PPD files have been deleted by checking 5923781Sceastha # timestamps on label and manufacturer directories. 5933781Sceastha # 5943781Sceastha [[ ! "${1}" -nt "${2}" ]] || return 0 5953781Sceastha /bin/find "${1}" -type d -newer "${2}" >/dev/null 2>&1 || return 1 5963781Sceastha return 0 5973781Sceastha} 5983781Sceastha 5993781Sceastha# 6003781Sceastha# If -R was specified, or the timestamp on the specified label's 6013781Sceastha# directory or any of the PPD files under the specified label in 6023781Sceastha# the specified PPD file respository is newer than the cache file 6033781Sceastha# associated with the label, then generate a new sorted cache file. 6043781Sceastha# 6053781Sceastha# The new cache will replace the existing one (if any) only if there 6063781Sceastha# are differences. Note: if -r was specified, then a new cache file 6073781Sceastha# file will always be installed at 6083781Sceastha# /var/lp/ppd/caches/<PPD file repository name>-<label name> 6093781Sceastha# 6103781Sceastha# $1 - Full path of the destination PPD file repository 6113781Sceastha# $2 - Destination PPD file repository name 6123781Sceastha# $3 - Destination label name 6133781Sceastha# 6143781Sceasthaupdate_label_cache() 6153781Sceastha{ 6163781Sceastha if debugger ; then 6173781Sceastha set -x 6183781Sceastha fi 6193781Sceastha 6203781Sceastha dstlabelpath="${1}/${3}" 6213781Sceastha replabelcachepath="${1}/${CACHES}/${3}" 6223781Sceastha varlabelcachepath="${VARCACHES}/${2}${SEP}${3}" 6233781Sceastha 6243781Sceastha ulc_rc=0 6253781Sceastha if [[ -d "${dstlabelpath}" ]] ; then 6263781Sceastha 6273781Sceastha # 6283781Sceastha # If the cache doesn't exist for a label, 6293781Sceastha # or if there were any changes under a label 6303781Sceastha # (i.e., the timestamp on the label directory or any 6313781Sceastha # of the PPD files under it is newer than the 6323781Sceastha # existing cache file), then generate a new cache file. 6333781Sceastha # 634*8532SSumanth.Naropanth@Sun.COM tmpcachepath=$ppdmgrtmpdir/tmpcachepath 6357447SWendy.Phillips@Sun.COM 6367447SWendy.Phillips@Sun.COM # if this is a system repository, check for a prepopulated cache 6377447SWendy.Phillips@Sun.COM if [[ "${2}" = "${SYSTEM}" && -e ${FOOCACHEDIR}/${3}.cache ]] ; then 6387447SWendy.Phillips@Sun.COM # copy prepopulated cache 6397447SWendy.Phillips@Sun.COM /bin/cp -f ${FOOCACHEDIR}/${3}.cache ${tmpcachepath} 6407447SWendy.Phillips@Sun.COM 6417447SWendy.Phillips@Sun.COM else 6427447SWendy.Phillips@Sun.COM newfileslist=$(changes_under_label "${dstlabelpath}" \ 6437447SWendy.Phillips@Sun.COM "${varlabelcachepath}") 6447447SWendy.Phillips@Sun.COM if [[ $? -eq 0 ]] ; then 6457447SWendy.Phillips@Sun.COM err_files=$(generate_label_cache_file \ 6467447SWendy.Phillips@Sun.COM "${newfileslist}" "${varlabelcachepath}" \ 6477447SWendy.Phillips@Sun.COM "${dstlabelpath}" "${tmpcachepath}") 6487447SWendy.Phillips@Sun.COM if [[ $? -ne 0 ]] ; then 6497447SWendy.Phillips@Sun.COM # 6507447SWendy.Phillips@Sun.COM # At least one PPD file was invalid. 6517447SWendy.Phillips@Sun.COM # Don't return yet, as the cache info 6527447SWendy.Phillips@Sun.COM # for the valid PPD files can still be 6537447SWendy.Phillips@Sun.COM # used to generate a cache file. 6547447SWendy.Phillips@Sun.COM # 6557447SWendy.Phillips@Sun.COM echo "${err_files}" 6567447SWendy.Phillips@Sun.COM ulc_rc=1 6577447SWendy.Phillips@Sun.COM fi 6583781Sceastha fi 6593781Sceastha fi 6603781Sceastha 6613781Sceastha if [[ -e "${tmpcachepath}" ]] ; then 6623781Sceastha update_current_cache_file \ 6633781Sceastha "${varlabelcachepath}" "${tmpcachepath}" "${2}" 6643781Sceastha /bin/rm -f "${tmpcachepath}" >/dev/null 2>&1 6653781Sceastha fi 6663781Sceastha else 6673781Sceastha # 6683781Sceastha # If there is a cache file in /var/lp/ppd/caches associated 6693781Sceastha # with the label which no longer exists, remove it. 6703781Sceastha # 6713781Sceastha /bin/rm -f "${varlabelcachepath}" >/dev/null 2>&1 6723781Sceastha fi 6733781Sceastha return ${ulc_rc} 6743781Sceastha} 6753781Sceastha 6763781Sceastha# 6773781Sceastha# Returns the alias for the specified real manufacturer's name. 6783781Sceastha# 6793781Sceastha# $1 - Real manufacturer's name 6803781Sceastha# $2 - File containing list of files that have manufacturers aliases 6813781Sceastha# 6823781Sceasthamanuf_name_alias() 6833781Sceastha{ 6843781Sceastha if debugger ; then 6853781Sceastha set -x 6863781Sceastha fi 6873781Sceastha 6883781Sceastha # 6893781Sceastha # Found a couple of PPD files which had special characters 6903781Sceastha # in the Manufacturer name (i.e, the following is the Manufacturer 6913781Sceastha # entry: 6923781Sceastha # *Manufacturer: "Canon Inc. (Kosugi Offic" 6933781Sceastha # We'll only search the alias file for "Canon Inc." 6943781Sceastha # 6953781Sceastha tmpmanuf="${1% *\(*}" 6963781Sceastha 6973781Sceastha # Search alias files for a match on the real manufacturer name 6983781Sceastha if [[ -s "${2}" ]] ; then 6993781Sceastha # 7003781Sceastha # Check the manufacturer aliases file for case 7013781Sceastha # insensitive match of the Manufacturer entry 7023781Sceastha # from the PPD file. If a match is found, 7033781Sceastha # then modify the manufacturer entry to 7043781Sceastha # be that of the specified alias. 7053781Sceastha # 7063781Sceastha manufaliases=$(/bin/egrep -i \ 7073781Sceastha "^${tmpmanuf}:|:${tmpmanuf}:|:${tmpmanuf}$" "${2}") 7083781Sceastha if [[ -n "${manufaliases}" ]] ; then 7093781Sceastha echo "${manufaliases%%:*}" 7103781Sceastha break 7113781Sceastha else 7123781Sceastha echo "${tmpmanuf}" 7133781Sceastha fi 7143781Sceastha else 7153781Sceastha echo "${tmpmanuf}" 7163781Sceastha fi 7173781Sceastha} 7183781Sceastha 7193781Sceastha# 7203781Sceastha# Returns 0 if the extension to the specified PPD file is a known 7213781Sceastha# extension, otherwise returns 1. 7223781Sceastha# 7233781Sceastha# $1 - Full path to PPD file 7243781Sceastha# 7253781Sceastha# Set upon return: 7263781Sceastha# ppdfileext - PPD file ext (.ppd or .ppd.gz) 7273781Sceastha# 7283781Sceasthaverify_file_ext() 7293781Sceastha{ 7303781Sceastha if debugger ; then 7313781Sceastha set -x 7323781Sceastha fi 7333781Sceastha 7343781Sceastha if [[ "${1%.gz}".gz = "${1}" ]] ; then 7353781Sceastha ppdfileext=${GEXT} 7363781Sceastha elif [[ "${1%.ppd}".ppd = "${1}" ]] ; then 7373781Sceastha ppdfileext=${PEXT} 7383781Sceastha else 7393781Sceastha # invalid PPD file name extension 7403781Sceastha return 1 7413781Sceastha fi 7423781Sceastha 7433781Sceastha return 0 7443781Sceastha} 7453781Sceastha 7463781Sceastha# 7473781Sceastha# Return the lines from the specified PPD file matching the specified 7483781Sceastha# spec items. 7493781Sceastha# 7503781Sceastha# $1 - spec entries from PPD file 7513781Sceastha# $2 - spec item 7523781Sceastha# 7533781Sceastha# $1 example - 1 string with substrings separated by newline: 7543781Sceastha# *PPD-Adobe: "4.3" 7553781Sceastha# *Manufacturer: "HP" 7563781Sceastha# *Product: "(officejet 4200 series)" 7573781Sceastha# *ModelName: "HP OfficeJet 4200" 7583781Sceastha# *NickName: "HP OfficeJet 4200 Foomatic/hpijs (recommended)" 7593781Sceastha# $2 example: 7603781Sceastha# ^\*Manufacturer 7613781Sceastha# 7623781Sceasthaspec_entry() 7633781Sceastha{ 7643781Sceastha if debugger ; then 7653781Sceastha set -x 7663781Sceastha fi 7673781Sceastha 7683781Sceastha item=$(echo "${1}" | /bin/grep ${2}) 7693781Sceastha # Remove everything up to and including the first quote 7703781Sceastha item=${item#*\"} 7713781Sceastha # Remove the end quote 7723781Sceastha echo "${item%\"}" 7733781Sceastha} 7743781Sceastha 7753781Sceastha# 7763781Sceastha# Return the lines from the specified PPD file matching the specified 7773781Sceastha# spec items. 7783781Sceastha# 7793781Sceastha# Note: this is similar to spec_entry() except the tokens in the 7803781Sceastha# spec entry are different. 7813781Sceastha# 7823781Sceastha# $1 - spec entries from PPD file 7833781Sceastha# $2 - spec item 7843781Sceastha# 7853781Sceasthadevid_spec_entry() 7863781Sceastha{ 7873781Sceastha if debugger ; then 7883781Sceastha set -x 7893781Sceastha fi 7903781Sceastha 7913781Sceastha item=$(echo "${1}" | /bin/grep ${2}) 7923781Sceastha # Remove everything up to and including the first semi-colon 7933781Sceastha item=${item#*\:} 7943781Sceastha # Remove the end quote 7953781Sceastha echo ${item%\;} 7963781Sceastha 7973781Sceastha} 7983781Sceastha 7993781Sceastha# 8003781Sceastha# Verifies that the specified PPD file 8013781Sceastha# - has a valid extension 8023781Sceastha# - has the following required spec file entries: 8033781Sceastha# *PPD-Adobe: "4.3" 8043781Sceastha# Manufacturer 8053781Sceastha# Product 8063781Sceastha# ModelName 8073781Sceastha# NickName 8083781Sceastha# 8093781Sceastha# In addition, the manufacture and model from the IEEE1284 device id 8103781Sceastha# information will be gathered here, although it's not an error that 8113781Sceastha# it isn't in the PPD file as many don't contain the IEEE1284 info. 8123781Sceastha# 8133781Sceastha# $1 - Full path to PPD file 8143781Sceastha# 8153781Sceastha# Return codes: 8163781Sceastha# 0 success 8173781Sceastha# 1 invalid PPD file 8183781Sceastha# 8193781Sceasthaverify_ppd_file() 8203781Sceastha{ 8213781Sceastha if debugger ; then 8223781Sceastha set -x 8233781Sceastha fi 8243781Sceastha 8253781Sceastha ADOBESPEC="PPD-Adobe" 8263781Sceastha MANUF="Manufacturer" 8273781Sceastha PRODUCT="Product" 8283781Sceastha MODEL="ModelName" 8293781Sceastha NICKNAME="NickName" 8303781Sceastha DEVID="1284DeviceID" 8313781Sceastha 8323781Sceastha # Verify the PPD file extension 8333781Sceastha verify_file_ext "${1}" || return 1 8343781Sceastha 8353781Sceastha # Query for the required spec items 8363781Sceastha searchentries="^\*${ADOBESPEC}:|^\*${MANUF}:|^\*${PRODUCT}:" 8373781Sceastha searchentries="${searchentries}|^\*${MODEL}:|^\*${NICKNAME}:" 8383781Sceastha searchentries="${searchentries}|^\*${DEVID}:" 8393781Sceastha ppd_info="$(/bin/gzgrep -e "${searchentries}" "${1}")" 8403781Sceastha 8413781Sceastha # 8423781Sceastha # Process the query results to verify each of the required spec 8433781Sceastha # file items appears in the PPD file. 8443781Sceastha # 8453781Sceastha for spec_item in ${ADOBESPEC} ${MANUF} ${PRODUCT} ${MODEL} \ 8463781Sceastha ${NICKNAME} ; do 8473781Sceastha entry=$(spec_entry "${ppd_info}" "^\*${spec_item}:") 8483781Sceastha [[ ! -z "${entry}" ]] || return 1 8493781Sceastha case ${spec_item} in 8503781Sceastha ${MANUF}) 8513781Sceastha realmanuf="${entry}" 8523781Sceastha ;; 8533781Sceastha ${PRODUCT}) 8543781Sceastha product="${entry}" 8553781Sceastha ;; 8563781Sceastha ${MODEL}) 8573781Sceastha model="${entry}" 8583781Sceastha ;; 8593781Sceastha ${NICKNAME}) 8603781Sceastha # 8613781Sceastha # Remove the model and any commas and spaces 8623781Sceastha # which appear before the driver 8633781Sceastha # 8643781Sceastha nickn="${entry#$model[, ]*}" 8653781Sceastha ;; 8663781Sceastha esac 8673781Sceastha 8683781Sceastha done 8693781Sceastha 8703781Sceastha # Save IEEE1284 device id information 8713781Sceastha if $(echo "${ppd_info}" | grep "${DEVID}" >/dev/null 2>&1) ; then 8723781Sceastha DMDL="MDL" 8733781Sceastha DMFG="MFG" 8743781Sceastha devid="$(/bin/gzgrep -e "^[ ]*${DMDL}:|^[ ]*${DMFG}:" "${1}")" 8753781Sceastha devidmdl="$(devid_spec_entry "${devid}" "${DMDL}")" 8763781Sceastha devidmfg="$(devid_spec_entry "${devid}" "${DMFG}")" 8773781Sceastha else 8783781Sceastha devidmdl= 8793781Sceastha devidmfg= 8803781Sceastha fi 8813781Sceastha modmanuf=$(manuf_name_alias "${realmanuf}" ${aliasfile}) 8823781Sceastha 8833781Sceastha return 0 8843781Sceastha} 8853781Sceastha 8863781Sceastha# 8873781Sceastha# generate_cache_file_entry() 8883781Sceastha# 8893781Sceastha# Returns a cache file entry for the specified PPD file. 8903781Sceastha# 8913781Sceastha# $1 - modmanuf 8923781Sceastha# $2 - model 8933781Sceastha# $3 - nickn 8943781Sceastha# $4 - devidmfg 8953781Sceastha# $5 - devidmdl 8963781Sceastha# $6 - Full path to the specified PPD file 8973781Sceastha# 8983781Sceasthagenerate_cache_file_entry() 8993781Sceastha{ 9003781Sceastha if debugger "generate_cache_file_entry" ; then 9013781Sceastha set -x 9023781Sceastha fi 9033781Sceastha 9043781Sceastha echo "${1}":"${2}":"${3}":"${4}":"${5}":"${6}" 9053781Sceastha} 9063781Sceastha 9073781Sceastha# 9083781Sceastha# Expand specified file to the full path. 9093781Sceastha# 9103781Sceastha# $1 - File path to expand 9113781Sceastha# 9123781Sceastha# Return code set to 0 if expanded successfully, otherwise set to 1. 9133781Sceastha# 9143781Sceasthappd_pathname() 9153781Sceastha{ 9163781Sceastha if debugger ; then 9173781Sceastha set -x 9183781Sceastha fi 9193781Sceastha 9203781Sceastha if [[ -f "${1}" && -s "${1}" ]] ; then 9213781Sceastha (cd "$(/bin/dirname "${1}")" ; \ 9223781Sceastha echo "$(/bin/pwd)/$(/bin/basename "${1}")") || return 1 9233781Sceastha return 0 9243781Sceastha else 9253781Sceastha return 1 9263781Sceastha fi 9273781Sceastha} 9283781Sceastha 9293781Sceastha# 9303781Sceastha# Returns the PPD repsitory path associated with the specified 9313781Sceastha# PPD repository name. 9323781Sceastha# 9333781Sceastha# $1 - Repository name 9343781Sceastha# 9353781Sceasthaget_rep_path() 9363781Sceastha{ 9373781Sceastha if debugger ; then 9383781Sceastha set -x 9393781Sceastha fi 9403781Sceastha 9413781Sceastha case ${1} in 9423781Sceastha ${SYSTEM}) 9433781Sceastha echo "${SYSTEMREP}" 9443781Sceastha ;; 9453781Sceastha ${VENDOR}) 9463781Sceastha echo "${VENDORREP}" 9473781Sceastha ;; 9483781Sceastha ${ADMIN}) 9493781Sceastha echo "${ADMINREP}" 9503781Sceastha ;; 9513781Sceastha ${USER}) 9523781Sceastha echo "${USERREP}" 9533781Sceastha ;; 9543781Sceastha *) 9553781Sceastha echo "${UNSET}" 9563781Sceastha ;; 9573781Sceastha esac 9583781Sceastha} 9593781Sceastha 9603781Sceastha# 9613781Sceastha# Returns the PPD respository name from the repository path 9623781Sceastha# 9633781Sceastha# $1 - PPD repository path 9643781Sceastha# 9653781Sceasthaget_rep_name() 9663781Sceastha{ 9673781Sceastha if debugger ; then 9683781Sceastha set -x 9693781Sceastha fi 9703781Sceastha 9713781Sceastha case ${1} in 9723781Sceastha ${SYSTEMREP}) 9733781Sceastha echo "${SYSTEM}" 9743781Sceastha ;; 9753781Sceastha ${VENDORREP}) 9763781Sceastha echo "${VENDOR}" 9773781Sceastha ;; 9783781Sceastha ${ADMINREP}) 9793781Sceastha echo "${ADMIN}" 9803781Sceastha ;; 9813781Sceastha ${USERREP}) 9823781Sceastha echo "${USER}" 9833781Sceastha ;; 9843781Sceastha "all") 9853781Sceastha echo "all" 9863781Sceastha ;; 9873781Sceastha *) 9883781Sceastha echo "${UNSET}" 9893781Sceastha ;; 9903781Sceastha esac 9913781Sceastha} 9923781Sceastha 9933781Sceastha# 9943781Sceastha# Returns 0 if a matching label name is found in the specified repository, 9953781Sceastha# otherwise returns 1. 9963781Sceastha# 9973781Sceastha# $1 - repository path 9983781Sceastha# $2 - label name 9993781Sceastha# 10003781Sceasthalabel_path_in_repository() 10013781Sceastha{ 10023781Sceastha if debugger "label_path_in_repository" ; then 10033781Sceastha set -x 10043781Sceastha fi 10053781Sceastha 10063781Sceastha [[ "${1}" != "" && "${2}" != "" ]] || return 1 10073781Sceastha lpir_rc=1 10083781Sceastha for repository in ${REPOSITORIES} ; do 10093781Sceastha if [[ "${repository}" = "${1}" && -d "${1}/${2}" ]] ; then 10103781Sceastha lpir_rc=0 10113781Sceastha break 10123781Sceastha fi 10133781Sceastha done 10143781Sceastha return ${lpir_rc} 10153781Sceastha} 10163781Sceastha 10173781Sceastha# 10183781Sceastha# Returns 0 if the source label path is the same 10193781Sceastha# as the destination label path, otherwise returns 1. 10203781Sceastha# 10213781Sceastha# $1 - full path to source PPD file (source label path) 10223781Sceastha# $2 - destination repository path 10233781Sceastha# $3 - destination label name 10243781Sceastha# 10253781Sceasthalabel_path_match() 10263781Sceastha{ 10273781Sceastha if debugger "label_path_match" ; then 10283781Sceastha set -x 10293781Sceastha fi 10303781Sceastha 10313781Sceastha # dest repository not specified 10323781Sceastha if [[ "${2}" = "${UNSET}" ]] ; then 10333781Sceastha # dest label not specified 10343781Sceastha if [[ "${3}" = "${UNSET}" ]] ; then 10353781Sceastha # 10363781Sceastha # We've found a match if the label path is in a known 10373781Sceastha # repository. 10383781Sceastha # 10393781Sceastha lpath="${1%/*/*}" 10403781Sceastha label_path_in_repository \ 10413781Sceastha "${1%/*/*/*}" "${lpath##*/}" || return 1 10423781Sceastha else 10433781Sceastha # 10443781Sceastha # If the source label path exists in the 10453781Sceastha # in a known repository, and the destination 10463781Sceastha # label is the same as the source label, 10473781Sceastha # then we'll assume the default destination 10483781Sceastha # repository is the same as the source 10493781Sceastha # destination repository. 10503781Sceastha # 10513781Sceastha [[ "${1%/*/*}" = "${1%/*/*/*}/${3}" ]] || return 1 10523781Sceastha label_path_in_repository "${1%/*/*/*}" "${3}" || \ 10533781Sceastha return 1 10543781Sceastha fi 10553781Sceastha 10563781Sceastha # dest repository specified, dest label not specified 10573781Sceastha elif [[ "${3}" = "${UNSET}" ]] ; then 10583781Sceastha # 10593781Sceastha # If the destination repository path is the same as the 10603781Sceastha # source repository, and if the source label exists in the 10613781Sceastha # destination repository path, then we'll assume the default 10623781Sceastha # destination label is the same as the source label. 10633781Sceastha # 10643781Sceastha [[ "${2}" = "${1%/*/*/*}" ]] || return 1 10653781Sceastha lpath="${1%/*/*}" 10663781Sceastha label_path_in_repository "${2}" "${lpath##*/}" || return 1 10673781Sceastha 10683781Sceastha # dest repository and dest label specified. 10693781Sceastha else 10703781Sceastha # 10713781Sceastha # We've found a match if the destination and label 10723781Sceastha # match those of the source label path, and the source 10733781Sceastha # label path is in a known repository. 10743781Sceastha # 10753781Sceastha [[ "${1%/*/*}" = "${2}/${3}" ]] || return 1 10763781Sceastha label_path_in_repository "${2}" "${3}" || return 1 10773781Sceastha fi 10783781Sceastha return 0 10793781Sceastha} 10803781Sceastha 10813781Sceastha# 10823781Sceastha# Returns 0 if specified label name is a reserved label, otherwise 10833781Sceastha# returns 1. 10843781Sceastha# 10853781Sceastha# $1 - label name 10863781Sceastha# 10873781Sceasthareserved_label() 10883781Sceastha{ 10893781Sceastha if debugger ; then 10903781Sceastha set -x 10913781Sceastha fi 10923781Sceastha 10933781Sceastha rl_rc=1 10943781Sceastha for labelname in ${RESERVEDLABELS} ; do 10953781Sceastha if [[ "${1}" = "${labelname}" ]] ; then 10963781Sceastha rl_rc=0 10973781Sceastha break 10983781Sceastha fi 10993781Sceastha done 11003781Sceastha return ${rl_rc} 11013781Sceastha} 11023781Sceastha 11033781Sceastha# 11043781Sceastha# Returns a list of all labels that exist in a repository that are 11053781Sceastha# not reserved labels. 11063781Sceastha# 11073781Sceastha# $1 - Full path of repository 11083781Sceastha# $2 - Repository name 11093781Sceastha# 11103781Sceasthaget_rep_label_list() 11113781Sceastha{ 11123781Sceastha if debugger ; then 11133781Sceastha set -x 11143781Sceastha fi 11153781Sceastha 11163781Sceastha # 11173781Sceastha # Get a list of all labels that exist in all of the 11183781Sceastha # PPD file repository. 11193781Sceastha # 11203781Sceastha for lname in $(/bin/ls "${1}" 2>/dev/null) ; do 11213781Sceastha if [[ -d "${1}/${lname}" ]] ; then 11223781Sceastha if ! reserved_label "${lname}" ; then 11233781Sceastha echo "${lname} " 11243781Sceastha fi 11253781Sceastha fi 11263781Sceastha done 11273781Sceastha} 11283781Sceastha 11293781Sceastha# 11303781Sceastha# Returns a valid PPD label. 11313781Sceastha# 11323781Sceastha# Verifies the specified PPD label is a valid label. If the 11333781Sceastha# label is not set, then it is set to a default value. 11343781Sceastha# 11353781Sceastha# Return code set to 0 if the specified PPD label is valid, otherwise 1. 11363781Sceastha# 11373781Sceastha# $1 - PPD label 11383781Sceastha# 11393781Sceasthavalid_specified_label() 11403781Sceastha{ 11413781Sceastha if debugger ; then 11423781Sceastha set -x 11433781Sceastha fi 11443781Sceastha 11453781Sceastha # Verify the specified label 11463781Sceastha vsl_rc=0 11473781Sceastha case "${1}" in 11483781Sceastha "all") 11493781Sceastha # Reserved label name with -a or -g options 11503781Sceastha if [[ "${action}" = "${ADD}" || \ 11513781Sceastha "${action}" = "${GENERATEENTRY}" ]] ; then 11523781Sceastha print -n "$myprog: " 1>&2 11533781Sceastha gettext "reserved PPD label name: ${1}\n" 1>&2 11543781Sceastha vsl_rc=1 11553781Sceastha else 11563781Sceastha echo "${1}" 11573781Sceastha fi 11583781Sceastha ;; 11593781Sceastha 11603781Sceastha "ppdcache" | "caches" | "manufaliases") 11613781Sceastha # Reserved label names with any option 11623781Sceastha print -n "$myprog: " 1>&2 11633781Sceastha gettext "reserved PPD label name: ${1}\n" 1>&2 11643781Sceastha vsl_rc=1 11653781Sceastha ;; 11663781Sceastha 11673781Sceastha "" | "${UNSET}") 11683781Sceastha # Label name not specified. Set the default label name. 11693781Sceastha # For -g and -a, default is "user", otherwise, default 11703781Sceastha # is "all". 11713781Sceastha if [[ "${action}" = "${ADD}" || \ 11723781Sceastha "${action}" = "${GENERATEENTRY}" ]] ; then 11733781Sceastha echo "${USER}" 11743781Sceastha else 11753781Sceastha echo "all" 11763781Sceastha fi 11773781Sceastha ;; 11783781Sceastha 11793781Sceastha *) 11803781Sceastha # label cannot be "." or ".." 11813781Sceastha if [[ "${1}" = "." || "${1}" = ".." ]] ; then 11823781Sceastha print -n "$myprog: " 1>&2 11833781Sceastha gettext "PPD label name cannot be " 1>&2 11843781Sceastha gettext "\".\" or \"..\"\n" 1>&2 11853781Sceastha vsl_rc=1 11863781Sceastha fi 11873781Sceastha 11883781Sceastha # Label name cannot contain special characters 11893781Sceastha echo "${1}" | /bin/egrep "${SPECIALCHARS}" >/dev/null 11903781Sceastha if [[ $? -eq 0 ]] ; then 11913781Sceastha print -n "$myprog: " 1>&2 11923781Sceastha gettext "PPD label name contains " 1>&2 11933781Sceastha gettext "an invalid character: ${1}\n" 1>&2 11943781Sceastha vsl_rc=1 11953781Sceastha else 11963781Sceastha echo "${1}" 11973781Sceastha fi 11983781Sceastha ;; 11993781Sceastha esac 12003781Sceastha return ${vsl_rc} 12013781Sceastha} 12023781Sceastha 12033781Sceastha# 12043781Sceastha# Returns the full path of any variant copy of the source file in 12053781Sceastha# the destination label/repository. 12063781Sceastha# 12073781Sceastha# $1 - Full path to source PPD file 12083781Sceastha# $2 - Full path to destination PPD file 12093781Sceastha# 12103781Sceastha# Return code set to 12113781Sceastha# 0 - Copy doesn't exist 12123781Sceastha# 1 - Duplicate copy exists 12133781Sceastha# 2 - Variant copy exists 12143781Sceastha# 12153781Sceasthavariant_copy() 12163781Sceastha{ 12173781Sceastha if debugger ; then 12183781Sceastha set -x 12193781Sceastha fi 12203781Sceastha 12213781Sceastha # 12223781Sceastha # First make sure there is not a .ppd and a .ppd.gz version 12233781Sceastha # of the destination file; users should know not to do this. 12243781Sceastha # 12253781Sceastha if [[ -e "${2%.gz}" && -e "${2%.gz}.gz" ]] ; then 12263781Sceastha /bin/rm -f "${2%.gz}" >/dev/null 2>&1 12273781Sceastha fi 12283781Sceastha 12293781Sceastha # Use gzcmp to compare PPD files as it can deal with 12303781Sceastha # gzipped or regular files. 12313781Sceastha if $(${GZCMP} "${1}" "${2}"* >/dev/null 2>&1) ; then 12323781Sceastha echo "${2}"* 12333781Sceastha return 1 12343781Sceastha elif [[ -e "${2%.gz}" ]] ; then 12353781Sceastha echo "${2%.gz}" 12363781Sceastha return 2 12373781Sceastha elif [[ -e "${2%.gz}.gz" ]] ; then 12383781Sceastha echo "${2%.gz}.gz" 12393781Sceastha return 2 12403781Sceastha else 12413781Sceastha # 12423781Sceastha # A PPD file doesn't exist in the destination 12433781Sceastha # repository under the destination label. 12443781Sceastha # Just display the source PPD file, ensuring 12453781Sceastha # it has a gzip extension as we will always 12463781Sceastha # try to gzip the copy in the destination. 12473781Sceastha # 12483781Sceastha if [[ "${1#*.ppd}" = ".gz" ]] ; then 12493781Sceastha echo "${2}" 12503781Sceastha else 12513781Sceastha echo "${2}.gz" 12523781Sceastha fi 12533781Sceastha return 0 12543781Sceastha fi 12553781Sceastha} 12563781Sceastha 12573781Sceastha# 12583781Sceastha# $1 - Directory mode 12593781Sceastha# $2 - Directory owner (i.e., root:lp) 12603781Sceastha# $3 - Directory to create 12613781Sceastha# 12623781Sceasthamake_dir() 12633781Sceastha{ 12643781Sceastha if debugger "make_dir" ; then 12653781Sceastha set -x 12663781Sceastha fi 12673781Sceastha 12683781Sceastha [[ ! -d "${3}" ]] || return 0 12693781Sceastha /bin/mkdir "${3}" >/dev/null 2>&1 || return 1 12703781Sceastha set_perms ${1} ${2} "${3}" 12713781Sceastha return 0 12723781Sceastha} 12733781Sceastha 12743781Sceastha# 12753781Sceastha# Remove a ppdmgr generated cache (in /var/lp/ppd/cache) 12763781Sceastha# if it doesn't have an associated label in the repository. 12773781Sceastha# 12783781Sceastha# $1 - Full path to label 12793781Sceastha# $2 - Cache name 12803781Sceastha# 12813781Sceastharemove_unassociated_cache() 12823781Sceastha{ 12833781Sceastha if debugger "remove_unassociated_cache" ; then 12843781Sceastha set -x 12853781Sceastha fi 12863781Sceastha 12873781Sceastha if [[ "${1}" != "${UNSET}" ]] ; then 12883781Sceastha if [[ -n "${1}" && ! -d "${1}" ]] ; then 12893781Sceastha # 12903781Sceastha # The label doesn't exist, so delete 12913781Sceastha # the associated cache file. 12923781Sceastha # 12933781Sceastha /bin/rm -f "${VARCACHES}/${2}" >/dev/null 2>&1 12943781Sceastha fi 12953781Sceastha fi 12963781Sceastha} 12973781Sceastha 12983781Sceastha# 12993781Sceastha# Sorted copies of cache files for each label in each PPD repository 13003781Sceastha# are maintained in /var/lp/ppd/caches/<PPD respository>-<label>. 13013781Sceastha# This is done so that changes in delivered cache files can be 13023781Sceastha# detected. If a difference in cache files is detected, or a 13033781Sceastha# cache file is either added or removed, then we know that 13043781Sceastha# the ppdcache file needs to be updated. 13053781Sceastha# 13063781Sceastha# Get a list of all cache files and compare against the list 13073781Sceastha# of labels in all of the PPD file repositories. They should 13083781Sceastha# be the same. If there is a label in one of the PPD file 13093781Sceastha# repositories that doesn't have an associated cache file, then 13103781Sceastha# we don't worry about it now, as that will be resolved when 13113781Sceastha# we update the cache for that label. However, if there is 13123781Sceastha# a cache file associated with a label that no longer exists, then 13133781Sceastha# remove the cache file. 13143781Sceastha# 13153781Sceastha# $1 - Full path to repository (or "all") 13163781Sceastha# $2 - Label name 13173781Sceastha# 13183781Sceasthaupdate_cache() 13193781Sceastha{ 13203781Sceastha if debugger ; then 13213781Sceastha set -x 13223781Sceastha fi 13233781Sceastha 13243781Sceastha # 13253781Sceastha # Determine which labels in which PPD repository the 13263781Sceastha # cache file will be updated for. 13273781Sceastha # 13283781Sceastha if [[ "${1}" = "all" ]] ; then 13293781Sceastha rname="${REPOSITORIES}" 13303781Sceastha else 13313781Sceastha rname="${1}" 13323781Sceastha fi 13333781Sceastha 13343781Sceastha uc_rc=0 13353781Sceastha for dstreppath in ${rname} ; do 13363781Sceastha labellist= 13373781Sceastha if [[ "${2}" = "all" ]] ; then 13383781Sceastha dstrepname=$(get_rep_name "${dstreppath}") 13393781Sceastha labellist=$(get_rep_label_list "${dstreppath}" \ 13403781Sceastha "${dstrepname}") 13413781Sceastha else 13423781Sceastha 13433781Sceastha # Ensure the label exists in the PPD file repository. 13443781Sceastha if [[ -d "${dstreppath}/${2}" ]] ; then 13453781Sceastha labellist="${2}" 13463781Sceastha fi 13473781Sceastha fi 13483781Sceastha 13493781Sceastha # 13503781Sceastha # Update the cache for each label in the PPD repository 13513781Sceastha # 13523781Sceastha for dstlabel in ${labellist} ; do 13533781Sceastha ulc_msg=$(update_label_cache "${dstreppath}" \ 13543781Sceastha "${dstrepname}" "${dstlabel}") 13553781Sceastha if [[ $? -ne 0 ]] ; then 13563781Sceastha echo "${ulc_msg}" 13573781Sceastha uc_rc=1 13583781Sceastha fi 13593781Sceastha done 13603781Sceastha done 13613781Sceastha 13623781Sceastha # Update the golden cache file. 13633781Sceastha update_golden_cache 13643781Sceastha return ${uc_rc} 13653781Sceastha} 13663781Sceastha 13673781Sceastha# $1 - exit status 13683781Sceasthappdmgr_exit() 13693781Sceastha{ 13703781Sceastha if debugger "ppdmgr_exit" ; then 13713781Sceastha set -x 13723781Sceastha fi 13733781Sceastha 13743781Sceastha /bin/rm -rf "${ppdmgrtmpdir}" >/dev/null 2>&1 13753781Sceastha exit ${1} 13763781Sceastha} 13773781Sceastha 13783781Sceastha 13793781Sceasthausage() 13803781Sceastha{ 13813781Sceastha gettext "usage:\n" 1>&2 13823781Sceastha print -n "\t$myprog: " 1>&2 13833781Sceastha gettext "-a <ppd_filename_path> [ -L <label> ]\n" 1>&2 13843781Sceastha gettext "\t\t[ -R <ppd_repository> ] [-w]\n" 1>&2 13853781Sceastha print -n "\t$myprog: " 1>&2 13863781Sceastha gettext "-r [ -L <label> ] [ -R <ppd_repository> ]\n" 1>&2 13873781Sceastha print -n "\t$myprog: " 1>&2 13883781Sceastha gettext "-u [ -L <label> ] [ -R <ppd_repository> ]\n" 1>&2 13893781Sceastha 13903781Sceastha ppdmgr_exit ${FAIL} 13913781Sceastha} 13923781Sceastha 13933781Sceastha########################################################################## 13943781Sceastha# main 13953781Sceastha########################################################################## 13963781Sceastha 13973781Sceasthamyprog=$(/bin/basename $0) 13983781Sceastha 13993781SceasthaSaveIFS="$IFS" 14003781SceasthaNoSpaceTabIFS=' 14013781Sceastha' 14023781Sceastha 14033781Sceastha# Updatable PPD repository 14043781SceasthaVARDIR=/var/lp/ppd 14053781Sceastha 14063781Sceastha# Delivered PPD respository 14073781SceasthaSYSTEMREP=/usr/share/ppd 14083781SceasthaADMINREP=/usr/local/share/ppd 14093781SceasthaVENDORREP=/opt/share/ppd 14103781SceasthaUSERREP=${VARDIR} 14113781Sceastha 14123781SceasthaRESERVEDREPS="${SYSTEMREP} ${ADMINREP} ${VENDORREP}" 14133781SceasthaREPOSITORIES="${USERREP} ${RESERVEDREPS}" 14143781SceasthaRESERVEDLABELS="all caches ppdcache manufaliases" 14157447SWendy.Phillips@Sun.COM 14167447SWendy.Phillips@Sun.COM# Directory where system:SUNWfoomatic is delivered 14177447SWendy.Phillips@Sun.COMFOOCACHEDIR=/usr/lib/lp/caches 14183781Sceastha 14193781Sceastha# Deliveries 14203781SceasthaSYSTEM=system 14213781SceasthaVENDOR=vendor 14223781SceasthaADMIN=admin 14233781SceasthaUSER=user 14243781Sceastha 14253781Sceastha# Sytem PPD cache name used by printmgr 14263781SceasthaGOLDCACHE=${USERREP}/ppdcache 14273781Sceastha 14283781Sceastha# Delivered caches directory 14293781SceasthaCACHES=caches 14303781SceasthaMANUFALIASES=manufaliases 14313781Sceastha 14323781Sceastha# Updated caches directory 14333781SceasthaVARCACHES=${VARDIR}/${CACHES} 14343781Sceastha 14353781Sceastha# valid PPD file name extensions 14363781SceasthaPEXT=ppd 14373781SceasthaGEXT=gz 14383781SceasthaFILEEXTS=".${PEXT} .${PEXT}.${GEXT}" 14393781Sceastha 14403781Sceastha# Default modes and owners 14413781SceasthaDIRMODE=755 14423781SceasthaDIROWNER=root:lp 14433781SceasthaADMINOWNER=root:root 14443781SceasthaFILEMODE=444 14453781SceasthaFILEOWNER=root:lp 14463781Sceastha 14473781Sceastha# ppdmgr actions 14483781SceasthaADD=add 14493781SceasthaGENERATEENTRY=generateentry 14503781SceasthaUPDATE=update 14513781SceasthaREBUILD=rebuild 14523781Sceastha 14533781SceasthaSUCCESS=0 14543781SceasthaFAIL=1 14553781SceasthaWARN=2 14563781Sceastha 14573781SceasthaMAXLABELNAME=256 14583781SceasthaGZIP="/bin/gzip -c" 14593781SceasthaGZCMP="/bin/gzcmp -s" 14603781SceasthaCMP="/bin/cmp -s" 14613781SceasthaSPECIALCHARS=":" 14623781SceasthaSEP=":" 14633781Sceastha 14643781Sceasthadebug=0 14653781Sceasthawflag=0 14663781Sceasthastatus=${SUCCESS} 14673781Sceastha 14683781SceasthaUNSET="" 14693781Sceasthappdlabel=${UNSET} 14703781Sceasthappdrepname=${UNSET} 14713781Sceasthappdreppath=${UNSET} 14723781Sceasthamodmanuf= 14733781Sceasthamodel= 14743781Sceasthanickn= 14753781Sceasthadevidmdl= 14763781Sceasthadevidmfg= 14773781Sceastha 1478*8532SSumanth.Naropanth@Sun.COMppdmgrtmpdir=$(/usr/bin/mktemp -t -d ppdmgr.XXXXXX) 1479*8532SSumanth.Naropanth@Sun.COMif [ -z "$ppdmgrtmpdir" ] ; then 1480*8532SSumanth.Naropanth@Sun.COM print -n "$myprog: " 1>&2 1481*8532SSumanth.Naropanth@Sun.COM gettext "Fatal error: could not create temporary directory\n" 1>&2 1482*8532SSumanth.Naropanth@Sun.COM exit 1 1483*8532SSumanth.Naropanth@Sun.COMfi 14843781Sceastha 14853781Sceasthaaliasfile=${USERREP}/manufaliases 14863781Sceasthatmpfilepath= 14873781Sceastha 14883781Sceastha 14893781SceasthaOPTS=a:g:L:rR:uwZ 14903781Sceasthawhile getopts "$OPTS" arg ; do 14913781Sceastha case ${arg} in 14923781Sceastha a) # add PPD file 14933781Sceastha action=${ADD} 14943781Sceastha origsrcppdpath=${OPTARG} 14953781Sceastha ;; 14963781Sceastha 14973781Sceastha g) # create cache entry 14983781Sceastha action=${GENERATEENTRY} 14993781Sceastha origsrcppdpath=${OPTARG} 15003781Sceastha ;; 15013781Sceastha 15023781Sceastha L) # PPD label name 15033781Sceastha ppdlabel=${OPTARG} 15043781Sceastha ;; 15053781Sceastha 15063781Sceastha r) # rebuild cache 15073781Sceastha action=${REBUILD} 15083781Sceastha ;; 15093781Sceastha 15103781Sceastha R) # PPD file repository to use 15113781Sceastha ppdrepname=${OPTARG} 15123781Sceastha ;; 15133781Sceastha 15143781Sceastha u) # update cache 15153781Sceastha action=${UPDATE} 15163781Sceastha ;; 15173781Sceastha 15183781Sceastha w) # display PPD file path 15193781Sceastha wflag=1 15203781Sceastha ;; 15213781Sceastha 15223781Sceastha Z) # debug 15233781Sceastha debug=1 15243781Sceastha ;; 15253781Sceastha 15263781Sceastha ?) 15273781Sceastha usage 15283781Sceastha ;; 15293781Sceastha esac 15303781Sceasthadone 15313781Sceastha 15323781Sceasthaif debugger "Main" ; then 15333781Sceastha set -x 15343781Sceasthafi 15353781Sceastha 15363781Sceasthaif [[ $# -lt 1 || -z "${action}" ]] ; then 15373781Sceastha usage 15383781Sceasthafi 15393781Sceastha 15403781Sceastha# ignore wflag unless specified with -a 15413781Sceasthaif [[ ${wflag} -eq 1 && "${action}" != ${ADD} ]] ; then 15423781Sceastha wflag=0 15433781Sceasthafi 15443781Sceastha 15453781Sceastha# 15463781Sceastha# Ensure the destination PPD repository directory is set 15473781Sceastha# to match the specified repository. If the 15483781Sceastha# destination PPD file repository was specified, then 15493781Sceastha# it must be one of the following: 15503781Sceastha# "user" 15513781Sceastha# "admin" 15523781Sceastha# "vendor" 15533781Sceastha# "system" 15543781Sceastha# "all" 15553781Sceastha# 15563781Sceasthacase "${ppdrepname}" in 15573781Sceastha"${SYSTEM}") 15583781Sceastha ppdreppath="${SYSTEMREP}" 15593781Sceastha ;; 15603781Sceastha"${ADMIN}") 15613781Sceastha ppdreppath="${ADMINREP}" 15623781Sceastha ;; 15633781Sceastha"${VENDOR}") 15643781Sceastha ppdreppath="${VENDORREP}" 15653781Sceastha ;; 15663781Sceastha"${USER}") 15673781Sceastha ppdreppath="${USERREP}" 15683781Sceastha ;; 15693781Sceastha"all") 15703781Sceastha if [[ "${action}" = "${ADD}" || \ 15713781Sceastha "${action}" = "${GENERATEENTRY}" ]] ; then 15723781Sceastha print -n "$myprog: " 1>&2 15733781Sceastha gettext "reserved PPD repository name: " 1>&2 15743781Sceastha gettext "${ppdrepname}\n" 1>&2 15753781Sceastha ppdmgr_exit ${FAIL} 15763781Sceastha fi 15773781Sceastha ppdreppath="all" 15783781Sceastha ;; 15793781Sceastha"${UNSET}"|"") 15803781Sceastha ppdreppath="${UNSET}" 15813781Sceastha ;; 15823781Sceastha 15833781Sceastha*) 15843781Sceastha print -n "$myprog: " 1>&2 15853781Sceastha gettext "invalid PPD repository name: ${ppdrepname}\n" 1>&2 15863781Sceastha ppdmgr_exit ${FAIL} 15873781Sceastha ;; 15883781Sceasthaesac 15893781Sceastha 15903781Sceastha# 15913781Sceastha# When a source PPD file's path is from a known repository, the 15923781Sceastha# destination repository and desination label are assumed to be the 15933781Sceastha# same as the source PPD file's unless a differing repository or label 15943781Sceastha# was specified. 15953781Sceastha# 15963781Sceasthaif [[ "${action}" = "${ADD}" || "${action}" = "${GENERATEENTRY}" ]] ; then 15973781Sceastha 15983781Sceastha srcppdpath=$(ppd_pathname "${origsrcppdpath}") 15993781Sceastha ppd_pathname_rc=$? 16003781Sceastha if [[ ${ppd_pathname_rc} -ne 0 ]] ; then 16013781Sceastha print -n "$myprog: " 1>&2 16023781Sceastha gettext "invalid PPD file: ${origsrcppdpath}\n" 1>&2 16033781Sceastha ppdmgr_exit ${ppd_pathname_rc} 16043781Sceastha fi 16053781Sceastha 16063781Sceastha # Path cannot contain special characters 16073781Sceastha echo "${srcppdpath}" | /bin/egrep "${SPECIALCHARS}" >/dev/null 16083781Sceastha if [[ $? -eq 0 ]] ; then 16093781Sceastha print -n "$myprog: " 1>&2 16103781Sceastha gettext "PPD path contains " 1>&2 16113781Sceastha gettext "an invalid character: ${ppd_pathname}\n" 1>&2 16123781Sceastha ppdmgr_exit ${FAIL} 16133781Sceastha fi 16143781Sceastha ppdfname=$(/bin/basename "${origsrcppdpath}") 16153781Sceastha 16163781Sceastha # 16173781Sceastha # Check to see if there's any work to be done. If the source file 16183781Sceastha # is already in the destination repository under the destination 16193781Sceastha # label, then there's nothing left to do. We exit rather than 16203781Sceastha # going on to do an update on the label in the repository as 16213781Sceastha # it could possible take a long time to update. If an add was 16223781Sceastha # requested, it could have come from an application, so we want 16233781Sceastha # to return quickly. 16243781Sceastha # 16253781Sceastha if label_path_match "${srcppdpath}" "${ppdreppath}" "${ppdlabel}" ; then 16263781Sceastha if [[ ${wflag} -eq 1 || \ 16273781Sceastha "${action}" = "${GENERATEENTRY}" ]] ; then 16283781Sceastha echo "${srcppdpath}" 16293781Sceastha fi 16303781Sceastha ppdmgr_exit ${SUCCESS} 16313781Sceastha fi 16323781Sceasthafi 16333781Sceastha 16343781Sceasthappdlabel=$(valid_specified_label "${ppdlabel}") 16353781Sceasthaif [[ $? -ne 0 ]] ; then 16363781Sceastha ppdmgr_exit ${FAIL} 16373781Sceasthafi 16383781Sceastha 16393781Sceasthaif [[ "${ppdreppath}" = "${UNSET}" ]] ; then 16403781Sceastha ppdreppath="${USERREP}" 16413781Sceasthafi 16423781Sceastha 16433781Sceasthadstrepname=$(get_rep_name "${ppdreppath}") 16443781Sceastha 16453781Sceasthacase "${action}" in 16463781Sceastha"${ADD}") 16473781Sceastha # 16483781Sceastha # Attempt to add the PPD file to the repository under the 16493781Sceastha # specified label. If any errors occur, final_dst_ppd_path 16503781Sceastha # will contain the error message rather than the path to the 16513781Sceastha # PPD file. 16523781Sceastha # 16533781Sceastha final_dst_ppd_path=$(add_ppd "${srcppdpath}" "${ppdfname}" \ 16543781Sceastha "${ppdreppath}" "${dstrepname}" "${ppdlabel}") 16553781Sceastha add_ppd_rc=$? 16563781Sceastha case ${add_ppd_rc} in 16573781Sceastha 0) # 16583781Sceastha # The PPD file was added. Update the specified 16593781Sceastha # cache associated with the label if the PPD file 16603781Sceastha # was added successfully and was not a duplicate. 16613781Sceastha # Ensure any changes are also reflected in the 16623781Sceastha # golden cache. 16633781Sceastha # 16643781Sceastha add_ppd_msg=$(update_label_cache "${ppdreppath}" \ 16653781Sceastha "${dstrepname}" "${ppdlabel}") 16663781Sceastha apm_rc=$? 16673781Sceastha 16683781Sceastha echo "${add_ppd_msg}" | /bin/grep "${final_dst_ppd_path}" 16693781Sceastha path_in_msg=$? 16703781Sceastha 16713781Sceastha # 16723781Sceastha # Only report cache update errors if the file that was 16733781Sceastha # added was one that was reported as not being added 16743781Sceastha # to the cache. This really should happen as the file 16753781Sceastha # was verified during the add. 16763781Sceastha # 16773781Sceastha if [[ ${apm_rc} -ne 0 && ${path_in_msg} -eq 0 ]] ; then 16783781Sceastha print -n "$myprog: " 1>&2 16793781Sceastha gettext "printer information does not reflect " 1>&2 16803781Sceastha gettext "the\nfollowing PPD file(s):\n" 1>&2 16813781Sceastha print "${add_ppd_msg}" 1>&2 16823781Sceastha status=${FAIL} 16833781Sceastha else 16843781Sceastha update_golden_cache 16853781Sceastha 16863781Sceastha # 16873781Sceastha # Display the full path to the added PPD file, 16883781Sceastha # if requested (-w). 16893781Sceastha # 16903781Sceastha if [[ ${wflag} -eq 1 ]] ; then 16913781Sceastha print "${final_dst_ppd_path}" 16923781Sceastha fi 16933781Sceastha fi 16943781Sceastha ;; 16953781Sceastha 16963781Sceastha 1) # Duplicate copy exists 16973781Sceastha if [[ ${wflag} -eq 1 ]] ; then 16983781Sceastha print "${final_dst_ppd_path}" 16993781Sceastha fi 17003781Sceastha ;; 17013781Sceastha 17023781Sceastha 2) # Varying copy exists 17033781Sceastha print -n "$myprog: " 1>&2 17043781Sceastha gettext "differing variant of source PPD file " 1>&2 17053781Sceastha gettext "already exists at\n" 1>&2 17063781Sceastha gettext "${final_dst_ppd_path}\n" 1>&2 17073781Sceastha status=${FAIL} 17083781Sceastha ;; 17093781Sceastha *) # The PPD file was not added as a problem occurred. 17103781Sceastha # Display the error message. 17113781Sceastha print -n "$myprog: " 1>&2 17123781Sceastha print "${final_dst_ppd_path}" 1>&2 17133781Sceastha status=${FAIL} 17143781Sceastha ;; 17153781Sceastha 17163781Sceastha esac 17173781Sceastha ;; 17183781Sceastha 17193781Sceastha"${GENERATEENTRY}") 17203781Sceastha # 17213781Sceastha # Create a cache file entry for the specified PPD file and 17223781Sceastha # display it on standard out. 17233781Sceastha # 17243781Sceastha verify_ppd_file "${srcppdpath}" 17253781Sceastha if [[ $? -eq 0 ]] ; then 17263781Sceastha dstdir="${ppdreppath}/${ppdlabel}/${modmanuf}" 17273781Sceastha final_dst_path="${dstdir}/$(/bin/basename ${srcppdpath})" 17283781Sceastha verify_ppd_location "${final_dst_path}" 17293781Sceastha if [[ $? -eq 0 ]] ; then 17303781Sceastha # Generate the cache file entry 17313781Sceastha print "$(generate_cache_file_entry "${modmanuf}" \ 17323781Sceastha "${model}" "${nickn}" "${devidmfg}" "${devidmdl}" \ 17333781Sceastha "${final_dst_path}")" 17343781Sceastha else 17353781Sceastha print -n "$myprog: " 1>&2 17363781Sceastha gettext "PPD file not in valid location\n" 1>&2 17373781Sceastha gettext \ 17383781Sceastha "(<repository>/<label>/<manufacturer>/<PPD file>):\n\t${1}\n" 1>&2 17393781Sceastha status=${FAIL} 17403781Sceastha fi 17413781Sceastha 17423781Sceastha else 17433781Sceastha print -n "$myprog: " 1>&2 17443781Sceastha gettext "invalid PPD file: ${1}\n" 1>&2 17453781Sceastha status=${FAIL} 17463781Sceastha fi 17473781Sceastha ;; 17483781Sceastha 17493781Sceastha"${REBUILD}" | "${UPDATE}") 17503781Sceastha update_msg=$(update_cache "${ppdreppath}" "${ppdlabel}") 17513781Sceastha if [[ $? -ne 0 ]] ; then 17523781Sceastha print -n "$myprog: " 1>&2 17533781Sceastha gettext "printer information does not reflect " 1>&2 17543781Sceastha gettext "the\nfollowing PPD file(s):\n" 1>&2 17553781Sceastha print "${update_msg}" 1>&2 17563781Sceastha status=${WARN} 17573781Sceastha fi 17583781Sceastha ;; 17593781Sceastha 17603781Sceastha*) 17613781Sceastha usage 17623781Sceastha ;; 17633781Sceasthaesac 17643781Sceastha 17653781Sceasthappdmgr_exit ${status} 1766