xref: /onnv-gate/usr/src/cmd/print/scripts/ppdmgr (revision 7447:e3918cb723cb)
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*7447SWendy.Phillips@Sun.COM# Copyright 2008 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	#
3283781Sceastha	tmpgoldencache=$(/bin/mktemp -p "${ppdmgrtmpdir}" \
3293781Sceastha	    tmpgoldencache.XXXXXX 2>/dev/null)
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	#
4433781Sceastha	ucfile=$(/bin/mktemp -p "${ppdmgrtmpdir}" \
4443781Sceastha	    unsortedcache.XXXXXX 2>/dev/null)
4453781Sceastha
4463781Sceastha	#
4473781Sceastha	# Before processing new files, remove any cache entries
4483781Sceastha	# which may be invalid.
4493781Sceastha	#
4503781Sceastha	valid_files=
4513781Sceastha	if [[ -e "${2}" && "${action}" != "${REBUILD}" ]] ; then
4523781Sceastha		valid_files=$(remove_invalid_cache_entries "${2}")
4533781Sceastha		if [[ -n "${valid_files}" ]] ; then
4543781Sceastha			echo "${valid_files}" >>${ucfile}
4553781Sceastha		fi
4563781Sceastha	fi
4573781Sceastha
4583781Sceastha	#
4593781Sceastha	# If there are no valid PPD files in the current cache file,
4603781Sceastha	# and there are no new PPD files to process, the only thing
4613781Sceastha	# left to do is to remove the current cache file.
4623781Sceastha	#
4633781Sceastha	if [[ -z "${valid_files}" && -z "${1}" ]] ; then
4643781Sceastha		/bin/rm -f "${2}" >/dev/null 2>&1
4653781Sceastha		/bin/rm -f "${ucfile}" >/dev/null 2>&1
4663781Sceastha		return 0
4673781Sceastha	fi
4683781Sceastha
4693781Sceastha	#
4703781Sceastha	# For each of the label's PPD files, generate
4713781Sceastha	# a cache file entry and add it to the cache file.
4723781Sceastha	#
4733781Sceastha	vpl_rc=0
4743781Sceastha	vpf_rc=0
4753781Sceastha	vpl_msg=
4763781Sceastha	vpf_msg=
4773781Sceastha	IFS="$NoSpaceTabIFS"
4783781Sceastha	for fname in ${1} ; do
4793781Sceastha		IFS="$SaveIFS"
4803781Sceastha		if [[ -n "${fname}" ]] ; then
4813781Sceastha			verify_ppd_location "${fname}"
4823781Sceastha			vpl_rc=$?
4833781Sceastha			if [[ ${vpl_rc} -ne 0 ]] ; then
4843781Sceastha				vpl_msg="${vpl_msg}\t${fname}\n"
4853781Sceastha			fi
4863781Sceastha
4873781Sceastha			verify_ppd_file "${fname}"
4883781Sceastha			vpf_rc=$?
4893781Sceastha			if [[ ${vpf_rc} -ne 0 ]] ; then
4903781Sceastha				vpf_msg="${vpf_msg}\t${fname}\n"
4913781Sceastha			fi
4923781Sceastha
4933781Sceastha			if [[ ${vpl_rc} -eq 0 && ${vpf_rc} -eq 0 ]] ; then
4943781Sceastha				echo "$(generate_cache_file_entry \
4953781Sceastha				    "${modmanuf}" "${model}" "${nickn}" \
4963781Sceastha				    "${devidmfg}" "${devidmdl}" "${fname}")"
4973781Sceastha			fi
4983781Sceastha		fi
4993781Sceastha		IFS="$NoSpaceTabIFS"
5003781Sceastha	done >>"${ucfile}"
5013781Sceastha	IFS="$SaveIFS"
5023781Sceastha	/bin/sort -u "${ucfile}" >>"${4}" 2>/dev/null
5033781Sceastha	/bin/rm -f "${ucfile}" >/dev/null 2>&1
5043781Sceastha
5053781Sceastha	[[ -n "${vpl_msg}" || -n "${vpf_msg}" ]] || return 0
5063781Sceastha	if [[ -n ${vpl_msg} ]] ; then
5073781Sceastha		gettext "  PPD file(s) not in valid location\n" 2>/dev/null
5083781Sceastha		gettext \
5093781Sceastha	    "  (<repository>/<label>/<manufacturer>/<PPD file>):\n" 2>/dev/null
5103781Sceastha		echo "${vpl_msg}"
5113781Sceastha	fi
5123781Sceastha	if [[ -n ${vpf_msg} ]] ; then
5133781Sceastha		gettext "  invalid PPD file(s):\n" 2>/dev/null
5143781Sceastha		echo "${vpf_msg}"
5153781Sceastha	fi
5163781Sceastha	return 1
5173781Sceastha}
5183781Sceastha
5193781Sceastha#
5203781Sceastha# Update current cache file with candidate cache file if there are
5213781Sceastha# differences.
5223781Sceastha#
5233781Sceastha# $1	- Current cache file
5243781Sceastha# $2	- Candidate cache file to update
5253781Sceastha# $3	- Repository name
5263781Sceastha#
5273781Sceasthaupdate_current_cache_file()
5283781Sceastha{
5293781Sceastha	if debugger "update_current_cache_file" ; then
5303781Sceastha		set -x
5313781Sceastha	fi
5323781Sceastha
5333781Sceastha	if [[ ! -s "${2}" ]] ; then
5343781Sceastha		#
5353781Sceastha		# Candidate cache has zero size (label
5363781Sceastha		# directory with no PPD files under it).
5373781Sceastha		# Delete the empty candidate cache
5383781Sceastha		# file and delete the current cache
5393781Sceastha		# file.
5403781Sceastha		#
5413781Sceastha		/bin/rm -f "${1}" >/dev/null 2>&1
5423781Sceastha		/bin/rm -f "${2}" >/dev/null 2>&1
5433781Sceastha	elif [[ -e "${1}" ]] ; then
5443781Sceastha		#
5453781Sceastha		# If there are differences between the current
5463781Sceastha		# cache file and the newly generated one, then
5473781Sceastha		# replace the current one with the new one, and
5483781Sceastha		# set the flag to update the golden ppdcache
5493781Sceastha		# file.
5503781Sceastha		#
5513781Sceastha		if changes_in_cache "${1}" "${2}" ; then
5523781Sceastha			set_perms ${FILEMODE} ${FILEOWNER} "${2}"
5533781Sceastha			/bin/mv -f "${2}" "${1}" >/dev/null 2>&1
5543781Sceastha		else
5553781Sceastha			/bin/rm -f "${2}" >/dev/null 2>&1
5563781Sceastha		fi
5573781Sceastha	else
5583781Sceastha
5593781Sceastha		#
5603781Sceastha		# There is no current cache file.  Move the candidate
5613781Sceastha		# to the caches directory.
5623781Sceastha		#
5633781Sceastha		set_perms ${FILEMODE} ${FILEOWNER} "${2}"
5643781Sceastha		/bin/mv -f "${2}" "${1}" >/dev/null 2>&1
5653781Sceastha	fi
5663781Sceastha}
5673781Sceastha
5683781Sceastha#
5693781Sceastha# Returns 0 if there are files in $1 with newer timestamp
5703781Sceastha# than $2 or if deletions have occurred under $1,
5713781Sceastha# otherwise returns 1.
5723781Sceastha#
5733781Sceastha# $1	- Full path to the destination label
5743781Sceastha# $2	- Full path to label cache file
5753781Sceastha#
5763781Sceasthachanges_under_label()
5773781Sceastha{
5783781Sceastha	if debugger ; then
5793781Sceastha		set -x
5803781Sceastha	fi
5813781Sceastha
5823781Sceastha	# First check for newer files in the directory
5833781Sceastha	if [[ -e "${2}" && "${action}" != "${REBUILD}" ]] ; then
5843781Sceastha		newfiles=$(/bin/find "${1}" -type f -newer "${2}")
5853781Sceastha	else
5863781Sceastha		newfiles=$(/bin/find "${1}" -type f)
5873781Sceastha	fi
5883781Sceastha	echo "${newfiles}"
5893781Sceastha	[[ -z "${newfiles}" ]] || return 0
5903781Sceastha
5913781Sceastha	#
5923781Sceastha	# Need to detect if PPD files have been deleted by checking
5933781Sceastha	# timestamps on label and manufacturer directories.
5943781Sceastha	#
5953781Sceastha	[[ ! "${1}" -nt "${2}" ]] || return 0
5963781Sceastha	/bin/find "${1}" -type d -newer "${2}" >/dev/null 2>&1 || return 1
5973781Sceastha	return 0
5983781Sceastha}
5993781Sceastha
6003781Sceastha#
6013781Sceastha# If -R was specified, or the timestamp on the specified label's
6023781Sceastha# directory or any of the PPD files under the specified label in
6033781Sceastha# the specified PPD file respository is newer than the cache file
6043781Sceastha# associated with the label, then generate a new sorted cache file.
6053781Sceastha#
6063781Sceastha# The new cache will replace the existing one (if any) only if there
6073781Sceastha# are differences.  Note: if -r was specified, then a new cache file
6083781Sceastha# file will always be installed at
6093781Sceastha#	/var/lp/ppd/caches/<PPD file repository name>-<label name>
6103781Sceastha#
6113781Sceastha# $1	- Full path of the destination PPD file repository
6123781Sceastha# $2	- Destination PPD file repository name
6133781Sceastha# $3	- Destination label name
6143781Sceastha#
6153781Sceasthaupdate_label_cache()
6163781Sceastha{
6173781Sceastha	if debugger ; then
6183781Sceastha		set -x
6193781Sceastha	fi
6203781Sceastha
6213781Sceastha	dstlabelpath="${1}/${3}"
6223781Sceastha	replabelcachepath="${1}/${CACHES}/${3}"
6233781Sceastha	varlabelcachepath="${VARCACHES}/${2}${SEP}${3}"
6243781Sceastha
6253781Sceastha	ulc_rc=0
6263781Sceastha	if [[ -d "${dstlabelpath}" ]] ; then
6273781Sceastha
6283781Sceastha		#
6293781Sceastha		# If the cache doesn't exist for a label,
6303781Sceastha		# or if there were any changes under a label
6313781Sceastha		# (i.e., the timestamp on the label directory or any
6323781Sceastha		# of the PPD files under it is newer than the
6333781Sceastha		# existing cache file), then generate a new cache file.
6343781Sceastha		#
6353781Sceastha		tmpcachepath=$(/bin/mktemp -p "${ppdmgrtmpdir}" \
6363781Sceastha		    tmpcachepath.XXXXXX 2>/dev/null)
637*7447SWendy.Phillips@Sun.COM
638*7447SWendy.Phillips@Sun.COM		# if this is a system repository, check for a prepopulated cache
639*7447SWendy.Phillips@Sun.COM		if [[ "${2}" = "${SYSTEM}" && -e ${FOOCACHEDIR}/${3}.cache ]] ; then
640*7447SWendy.Phillips@Sun.COM			# copy prepopulated cache
641*7447SWendy.Phillips@Sun.COM			/bin/cp -f ${FOOCACHEDIR}/${3}.cache ${tmpcachepath}
642*7447SWendy.Phillips@Sun.COM
643*7447SWendy.Phillips@Sun.COM		else
644*7447SWendy.Phillips@Sun.COM			newfileslist=$(changes_under_label "${dstlabelpath}" \
645*7447SWendy.Phillips@Sun.COM			    "${varlabelcachepath}")
646*7447SWendy.Phillips@Sun.COM			if [[ $? -eq 0 ]] ; then
647*7447SWendy.Phillips@Sun.COM				err_files=$(generate_label_cache_file \
648*7447SWendy.Phillips@Sun.COM				    "${newfileslist}" "${varlabelcachepath}" \
649*7447SWendy.Phillips@Sun.COM				    "${dstlabelpath}" "${tmpcachepath}")
650*7447SWendy.Phillips@Sun.COM				if [[ $? -ne 0 ]] ; then
651*7447SWendy.Phillips@Sun.COM					#
652*7447SWendy.Phillips@Sun.COM					# At least one PPD file was invalid.
653*7447SWendy.Phillips@Sun.COM					# Don't return yet, as the cache info
654*7447SWendy.Phillips@Sun.COM					# for the valid PPD files can still be
655*7447SWendy.Phillips@Sun.COM					# used to generate a cache file.
656*7447SWendy.Phillips@Sun.COM					#
657*7447SWendy.Phillips@Sun.COM					echo "${err_files}"
658*7447SWendy.Phillips@Sun.COM					ulc_rc=1
659*7447SWendy.Phillips@Sun.COM				fi
6603781Sceastha			fi
6613781Sceastha		fi
6623781Sceastha
6633781Sceastha		if [[ -e "${tmpcachepath}" ]] ; then
6643781Sceastha			update_current_cache_file \
6653781Sceastha			    "${varlabelcachepath}" "${tmpcachepath}" "${2}"
6663781Sceastha			/bin/rm -f "${tmpcachepath}" >/dev/null 2>&1
6673781Sceastha		fi
6683781Sceastha	else
6693781Sceastha		#
6703781Sceastha		# If there is a cache file in /var/lp/ppd/caches associated
6713781Sceastha		# with the label which no longer exists, remove it.
6723781Sceastha		#
6733781Sceastha		/bin/rm -f "${varlabelcachepath}" >/dev/null 2>&1
6743781Sceastha	fi
6753781Sceastha	return ${ulc_rc}
6763781Sceastha}
6773781Sceastha
6783781Sceastha#
6793781Sceastha# Returns the alias for the specified real manufacturer's name.
6803781Sceastha#
6813781Sceastha# $1	- Real manufacturer's name
6823781Sceastha# $2	- File containing list of files that have manufacturers aliases
6833781Sceastha#
6843781Sceasthamanuf_name_alias()
6853781Sceastha{
6863781Sceastha	if debugger ; then
6873781Sceastha		set -x
6883781Sceastha	fi
6893781Sceastha
6903781Sceastha	#
6913781Sceastha	# Found a couple of PPD files which had special characters
6923781Sceastha	# in the Manufacturer name (i.e, the following is the Manufacturer
6933781Sceastha	# entry:
6943781Sceastha	#	*Manufacturer:  "Canon Inc. (Kosugi Offic"
6953781Sceastha	# We'll only search the alias file for "Canon Inc."
6963781Sceastha	#
6973781Sceastha	tmpmanuf="${1% *\(*}"
6983781Sceastha
6993781Sceastha	# Search alias files for a match on the real manufacturer name
7003781Sceastha	if [[ -s "${2}" ]] ; then
7013781Sceastha		#
7023781Sceastha		# Check the manufacturer aliases file for case
7033781Sceastha		# insensitive match of the Manufacturer entry
7043781Sceastha		# from the PPD file.  If a match is found,
7053781Sceastha		# then modify the manufacturer entry to
7063781Sceastha		# be that of the specified alias.
7073781Sceastha		#
7083781Sceastha		manufaliases=$(/bin/egrep -i \
7093781Sceastha		    "^${tmpmanuf}:|:${tmpmanuf}:|:${tmpmanuf}$" "${2}")
7103781Sceastha		if [[ -n "${manufaliases}" ]] ; then
7113781Sceastha			echo "${manufaliases%%:*}"
7123781Sceastha			break
7133781Sceastha		else
7143781Sceastha			echo "${tmpmanuf}"
7153781Sceastha		fi
7163781Sceastha	else
7173781Sceastha		echo "${tmpmanuf}"
7183781Sceastha	fi
7193781Sceastha}
7203781Sceastha
7213781Sceastha#
7223781Sceastha# Returns 0 if the extension to the specified PPD file is a known
7233781Sceastha# extension, otherwise returns 1.
7243781Sceastha#
7253781Sceastha# $1	- Full path to PPD file
7263781Sceastha#
7273781Sceastha# Set upon return:
7283781Sceastha#	ppdfileext	- PPD file ext (.ppd or .ppd.gz)
7293781Sceastha#
7303781Sceasthaverify_file_ext()
7313781Sceastha{
7323781Sceastha	if debugger ; then
7333781Sceastha		set -x
7343781Sceastha	fi
7353781Sceastha
7363781Sceastha	if [[ "${1%.gz}".gz = "${1}" ]] ; then
7373781Sceastha		ppdfileext=${GEXT}
7383781Sceastha	elif [[ "${1%.ppd}".ppd = "${1}" ]] ; then
7393781Sceastha		ppdfileext=${PEXT}
7403781Sceastha	else
7413781Sceastha		# invalid PPD file name extension
7423781Sceastha		return 1
7433781Sceastha	fi
7443781Sceastha
7453781Sceastha	return 0
7463781Sceastha}
7473781Sceastha
7483781Sceastha#
7493781Sceastha# Return the lines from the specified PPD file matching the specified
7503781Sceastha# spec items.
7513781Sceastha#
7523781Sceastha# $1	- spec entries from PPD file
7533781Sceastha# $2	- spec item
7543781Sceastha#
7553781Sceastha# $1 example - 1 string with substrings separated by newline:
7563781Sceastha#	*PPD-Adobe: "4.3"
7573781Sceastha#	*Manufacturer: "HP"
7583781Sceastha#	*Product:       "(officejet 4200 series)"
7593781Sceastha#	*ModelName:     "HP OfficeJet 4200"
7603781Sceastha#	*NickName:      "HP OfficeJet 4200 Foomatic/hpijs (recommended)"
7613781Sceastha# $2 example:
7623781Sceastha#	^\*Manufacturer
7633781Sceastha#
7643781Sceasthaspec_entry()
7653781Sceastha{
7663781Sceastha	if debugger ; then
7673781Sceastha		set -x
7683781Sceastha	fi
7693781Sceastha
7703781Sceastha	item=$(echo "${1}" | /bin/grep ${2})
7713781Sceastha	# Remove everything up to and including the first quote
7723781Sceastha	item=${item#*\"}
7733781Sceastha	# Remove the end quote
7743781Sceastha	echo "${item%\"}"
7753781Sceastha}
7763781Sceastha
7773781Sceastha#
7783781Sceastha# Return the lines from the specified PPD file matching the specified
7793781Sceastha# spec items.
7803781Sceastha#
7813781Sceastha# Note: this is similar to spec_entry() except the tokens in the
7823781Sceastha# spec entry are different.
7833781Sceastha#
7843781Sceastha# $1	- spec entries from PPD file
7853781Sceastha# $2	- spec item
7863781Sceastha#
7873781Sceasthadevid_spec_entry()
7883781Sceastha{
7893781Sceastha	if debugger ; then
7903781Sceastha		set -x
7913781Sceastha	fi
7923781Sceastha
7933781Sceastha	item=$(echo "${1}" | /bin/grep ${2})
7943781Sceastha	# Remove everything up to and including the first semi-colon
7953781Sceastha	item=${item#*\:}
7963781Sceastha	# Remove the end quote
7973781Sceastha	echo ${item%\;}
7983781Sceastha
7993781Sceastha}
8003781Sceastha
8013781Sceastha#
8023781Sceastha# Verifies that the specified PPD file
8033781Sceastha#	- has a valid extension
8043781Sceastha#	- has the following required spec file entries:
8053781Sceastha#		*PPD-Adobe: "4.3"
8063781Sceastha#		Manufacturer
8073781Sceastha#		Product
8083781Sceastha#		ModelName
8093781Sceastha#		NickName
8103781Sceastha#
8113781Sceastha# In addition, the manufacture and model from the IEEE1284 device id
8123781Sceastha# information will be gathered here, although it's not an error that
8133781Sceastha# it isn't in the PPD file as many don't contain the IEEE1284 info.
8143781Sceastha#
8153781Sceastha# $1	- Full path to PPD file
8163781Sceastha#
8173781Sceastha# Return codes:
8183781Sceastha#	0	success
8193781Sceastha#	1	invalid PPD file
8203781Sceastha#
8213781Sceasthaverify_ppd_file()
8223781Sceastha{
8233781Sceastha	if debugger ; then
8243781Sceastha		set -x
8253781Sceastha	fi
8263781Sceastha
8273781Sceastha	ADOBESPEC="PPD-Adobe"
8283781Sceastha	MANUF="Manufacturer"
8293781Sceastha	PRODUCT="Product"
8303781Sceastha	MODEL="ModelName"
8313781Sceastha	NICKNAME="NickName"
8323781Sceastha	DEVID="1284DeviceID"
8333781Sceastha
8343781Sceastha	# Verify the PPD file extension
8353781Sceastha	verify_file_ext "${1}" || return 1
8363781Sceastha
8373781Sceastha	# Query for the required spec items
8383781Sceastha	searchentries="^\*${ADOBESPEC}:|^\*${MANUF}:|^\*${PRODUCT}:"
8393781Sceastha	searchentries="${searchentries}|^\*${MODEL}:|^\*${NICKNAME}:"
8403781Sceastha	searchentries="${searchentries}|^\*${DEVID}:"
8413781Sceastha	ppd_info="$(/bin/gzgrep -e "${searchentries}" "${1}")"
8423781Sceastha
8433781Sceastha	#
8443781Sceastha	# Process the query results to verify each of the required spec
8453781Sceastha	# file items appears in the PPD file.
8463781Sceastha	#
8473781Sceastha	for spec_item in ${ADOBESPEC} ${MANUF} ${PRODUCT} ${MODEL} \
8483781Sceastha	    ${NICKNAME} ; do
8493781Sceastha		entry=$(spec_entry "${ppd_info}" "^\*${spec_item}:")
8503781Sceastha		[[ ! -z "${entry}" ]] || return 1
8513781Sceastha		case ${spec_item} in
8523781Sceastha		${MANUF})
8533781Sceastha			realmanuf="${entry}"
8543781Sceastha			;;
8553781Sceastha		${PRODUCT})
8563781Sceastha			product="${entry}"
8573781Sceastha			;;
8583781Sceastha		${MODEL})
8593781Sceastha			model="${entry}"
8603781Sceastha			;;
8613781Sceastha		${NICKNAME})
8623781Sceastha			#
8633781Sceastha			# Remove the model and any commas and spaces
8643781Sceastha			# which appear before the driver
8653781Sceastha			#
8663781Sceastha			nickn="${entry#$model[, ]*}"
8673781Sceastha			;;
8683781Sceastha		esac
8693781Sceastha
8703781Sceastha	done
8713781Sceastha
8723781Sceastha	# Save IEEE1284 device id information
8733781Sceastha	if $(echo "${ppd_info}" | grep "${DEVID}" >/dev/null 2>&1) ; then
8743781Sceastha		DMDL="MDL"
8753781Sceastha		DMFG="MFG"
8763781Sceastha		devid="$(/bin/gzgrep -e "^[ ]*${DMDL}:|^[ ]*${DMFG}:" "${1}")"
8773781Sceastha		devidmdl="$(devid_spec_entry "${devid}" "${DMDL}")"
8783781Sceastha		devidmfg="$(devid_spec_entry "${devid}" "${DMFG}")"
8793781Sceastha	else
8803781Sceastha		devidmdl=
8813781Sceastha		devidmfg=
8823781Sceastha	fi
8833781Sceastha	modmanuf=$(manuf_name_alias "${realmanuf}" ${aliasfile})
8843781Sceastha
8853781Sceastha	return 0
8863781Sceastha}
8873781Sceastha
8883781Sceastha#
8893781Sceastha# generate_cache_file_entry()
8903781Sceastha#
8913781Sceastha# Returns a cache file entry for the specified PPD file.
8923781Sceastha#
8933781Sceastha# $1	- modmanuf
8943781Sceastha# $2	- model
8953781Sceastha# $3	- nickn
8963781Sceastha# $4	- devidmfg
8973781Sceastha# $5	- devidmdl
8983781Sceastha# $6	- Full path to the specified PPD file
8993781Sceastha#
9003781Sceasthagenerate_cache_file_entry()
9013781Sceastha{
9023781Sceastha	if debugger "generate_cache_file_entry" ; then
9033781Sceastha		set -x
9043781Sceastha	fi
9053781Sceastha
9063781Sceastha	echo "${1}":"${2}":"${3}":"${4}":"${5}":"${6}"
9073781Sceastha}
9083781Sceastha
9093781Sceastha#
9103781Sceastha# Expand specified file to the full path.
9113781Sceastha#
9123781Sceastha# $1	- File path to expand
9133781Sceastha#
9143781Sceastha# Return code set to 0 if expanded successfully, otherwise set to 1.
9153781Sceastha#
9163781Sceasthappd_pathname()
9173781Sceastha{
9183781Sceastha	if debugger ; then
9193781Sceastha		set -x
9203781Sceastha	fi
9213781Sceastha
9223781Sceastha	if [[ -f "${1}" && -s "${1}" ]] ; then
9233781Sceastha		(cd "$(/bin/dirname "${1}")" ; \
9243781Sceastha		    echo "$(/bin/pwd)/$(/bin/basename "${1}")") || return 1
9253781Sceastha		return 0
9263781Sceastha	else
9273781Sceastha		return 1
9283781Sceastha	fi
9293781Sceastha}
9303781Sceastha
9313781Sceastha#
9323781Sceastha# Returns the PPD repsitory path associated with the specified
9333781Sceastha# PPD repository name.
9343781Sceastha#
9353781Sceastha# $1	- Repository name
9363781Sceastha#
9373781Sceasthaget_rep_path()
9383781Sceastha{
9393781Sceastha	if debugger ; then
9403781Sceastha		set -x
9413781Sceastha	fi
9423781Sceastha
9433781Sceastha	case ${1} in
9443781Sceastha	${SYSTEM})
9453781Sceastha		echo "${SYSTEMREP}"
9463781Sceastha		;;
9473781Sceastha	${VENDOR})
9483781Sceastha		echo "${VENDORREP}"
9493781Sceastha		;;
9503781Sceastha	${ADMIN})
9513781Sceastha		echo "${ADMINREP}"
9523781Sceastha		;;
9533781Sceastha	${USER})
9543781Sceastha		echo "${USERREP}"
9553781Sceastha		;;
9563781Sceastha	*)
9573781Sceastha		echo "${UNSET}"
9583781Sceastha		;;
9593781Sceastha	esac
9603781Sceastha}
9613781Sceastha
9623781Sceastha#
9633781Sceastha# Returns the PPD respository name from the repository path
9643781Sceastha#
9653781Sceastha# $1	- PPD repository path
9663781Sceastha#
9673781Sceasthaget_rep_name()
9683781Sceastha{
9693781Sceastha	if debugger ; then
9703781Sceastha		set -x
9713781Sceastha	fi
9723781Sceastha
9733781Sceastha	case ${1} in
9743781Sceastha	${SYSTEMREP})
9753781Sceastha		echo "${SYSTEM}"
9763781Sceastha		;;
9773781Sceastha	${VENDORREP})
9783781Sceastha		echo "${VENDOR}"
9793781Sceastha		;;
9803781Sceastha	${ADMINREP})
9813781Sceastha		echo "${ADMIN}"
9823781Sceastha		;;
9833781Sceastha	${USERREP})
9843781Sceastha		echo "${USER}"
9853781Sceastha		;;
9863781Sceastha	"all")
9873781Sceastha		echo "all"
9883781Sceastha		;;
9893781Sceastha	*)
9903781Sceastha		echo "${UNSET}"
9913781Sceastha		;;
9923781Sceastha	esac
9933781Sceastha}
9943781Sceastha
9953781Sceastha#
9963781Sceastha# Returns 0 if a matching label name is found in the specified repository,
9973781Sceastha# otherwise returns 1.
9983781Sceastha#
9993781Sceastha# $1	- repository path
10003781Sceastha# $2	- label name
10013781Sceastha#
10023781Sceasthalabel_path_in_repository()
10033781Sceastha{
10043781Sceastha	if debugger "label_path_in_repository" ; then
10053781Sceastha		set -x
10063781Sceastha	fi
10073781Sceastha
10083781Sceastha	[[ "${1}" != "" && "${2}" != "" ]] || return 1
10093781Sceastha	lpir_rc=1
10103781Sceastha	for repository in ${REPOSITORIES} ; do
10113781Sceastha		if [[ "${repository}" = "${1}" && -d "${1}/${2}" ]] ; then
10123781Sceastha			lpir_rc=0
10133781Sceastha			break
10143781Sceastha		fi
10153781Sceastha	done
10163781Sceastha	return ${lpir_rc}
10173781Sceastha}
10183781Sceastha
10193781Sceastha#
10203781Sceastha# Returns 0 if the source label path is the same
10213781Sceastha# as the destination label path, otherwise returns 1.
10223781Sceastha#
10233781Sceastha# $1	- full path to source PPD file (source label path)
10243781Sceastha# $2	- destination repository path
10253781Sceastha# $3	- destination label name
10263781Sceastha#
10273781Sceasthalabel_path_match()
10283781Sceastha{
10293781Sceastha	if debugger "label_path_match" ; then
10303781Sceastha		set -x
10313781Sceastha	fi
10323781Sceastha
10333781Sceastha	# dest repository not specified
10343781Sceastha	if [[ "${2}" = "${UNSET}" ]] ; then
10353781Sceastha		# dest label not specified
10363781Sceastha		if [[ "${3}" = "${UNSET}" ]] ; then
10373781Sceastha			#
10383781Sceastha			# We've found a match if the label path is in a known
10393781Sceastha			# repository.
10403781Sceastha			#
10413781Sceastha			lpath="${1%/*/*}"
10423781Sceastha			label_path_in_repository \
10433781Sceastha			    "${1%/*/*/*}" "${lpath##*/}" || return 1
10443781Sceastha		else
10453781Sceastha			#
10463781Sceastha			# If the source label path exists in the
10473781Sceastha			# in a known repository, and the destination
10483781Sceastha			# label is the same as the source label,
10493781Sceastha			# then we'll assume the default destination
10503781Sceastha			# repository is the same as the source
10513781Sceastha			# destination repository.
10523781Sceastha			#
10533781Sceastha			[[ "${1%/*/*}" = "${1%/*/*/*}/${3}" ]] || return 1
10543781Sceastha			label_path_in_repository "${1%/*/*/*}" "${3}" || \
10553781Sceastha			    return 1
10563781Sceastha		fi
10573781Sceastha
10583781Sceastha	# dest repository specified, dest label not specified
10593781Sceastha	elif [[ "${3}" = "${UNSET}" ]] ; then
10603781Sceastha		#
10613781Sceastha		# If the destination repository path is the same as the
10623781Sceastha		# source repository, and if the source label exists in the
10633781Sceastha		# destination repository path, then we'll assume the default
10643781Sceastha		# destination label is the same as the source label.
10653781Sceastha		#
10663781Sceastha		[[ "${2}" = "${1%/*/*/*}" ]] || return 1
10673781Sceastha		lpath="${1%/*/*}"
10683781Sceastha		label_path_in_repository "${2}" "${lpath##*/}" || return 1
10693781Sceastha
10703781Sceastha	# dest repository and dest label specified.
10713781Sceastha	else
10723781Sceastha		#
10733781Sceastha		# We've found a match if the destination and label
10743781Sceastha		# match those of the source label path, and the source
10753781Sceastha		# label path is in a known repository.
10763781Sceastha		#
10773781Sceastha		[[ "${1%/*/*}" = "${2}/${3}" ]] || return 1
10783781Sceastha		label_path_in_repository "${2}" "${3}" || return 1
10793781Sceastha	fi
10803781Sceastha	return 0
10813781Sceastha}
10823781Sceastha
10833781Sceastha#
10843781Sceastha# Returns 0 if specified label name is a reserved label, otherwise
10853781Sceastha# returns 1.
10863781Sceastha#
10873781Sceastha# $1	- label name
10883781Sceastha#
10893781Sceasthareserved_label()
10903781Sceastha{
10913781Sceastha	if debugger ; then
10923781Sceastha		set -x
10933781Sceastha	fi
10943781Sceastha
10953781Sceastha	rl_rc=1
10963781Sceastha	for labelname in ${RESERVEDLABELS} ; do
10973781Sceastha		if [[ "${1}" = "${labelname}" ]] ; then
10983781Sceastha			rl_rc=0
10993781Sceastha			break
11003781Sceastha		fi
11013781Sceastha	done
11023781Sceastha	return ${rl_rc}
11033781Sceastha}
11043781Sceastha
11053781Sceastha#
11063781Sceastha# Returns a list of all labels that exist in a repository that are
11073781Sceastha# not reserved labels.
11083781Sceastha#
11093781Sceastha# $1	- Full path of repository
11103781Sceastha# $2	- Repository name
11113781Sceastha#
11123781Sceasthaget_rep_label_list()
11133781Sceastha{
11143781Sceastha	if debugger ; then
11153781Sceastha		set -x
11163781Sceastha	fi
11173781Sceastha
11183781Sceastha	#
11193781Sceastha	# Get a list of all labels that exist in all of the
11203781Sceastha	# PPD file repository.
11213781Sceastha	#
11223781Sceastha	for lname in $(/bin/ls "${1}" 2>/dev/null) ; do
11233781Sceastha		if [[ -d "${1}/${lname}" ]] ; then
11243781Sceastha			if ! reserved_label "${lname}" ; then
11253781Sceastha				echo "${lname} "
11263781Sceastha			fi
11273781Sceastha		fi
11283781Sceastha	done
11293781Sceastha}
11303781Sceastha
11313781Sceastha#
11323781Sceastha# Returns a valid PPD label.
11333781Sceastha#
11343781Sceastha# Verifies the specified PPD label is a valid label.  If the
11353781Sceastha# label is not set, then it is set to a default value.
11363781Sceastha#
11373781Sceastha# Return code set to 0 if the specified PPD label is valid, otherwise 1.
11383781Sceastha#
11393781Sceastha# $1	- PPD label
11403781Sceastha#
11413781Sceasthavalid_specified_label()
11423781Sceastha{
11433781Sceastha	if debugger ; then
11443781Sceastha		set -x
11453781Sceastha	fi
11463781Sceastha
11473781Sceastha	# Verify the specified label
11483781Sceastha	vsl_rc=0
11493781Sceastha	case "${1}" in
11503781Sceastha	"all")
11513781Sceastha		# Reserved label name with -a or -g options
11523781Sceastha		if [[ "${action}" = "${ADD}" || \
11533781Sceastha		    "${action}" = "${GENERATEENTRY}" ]] ; then
11543781Sceastha			print -n "$myprog: " 1>&2
11553781Sceastha			gettext "reserved PPD label name: ${1}\n" 1>&2
11563781Sceastha			vsl_rc=1
11573781Sceastha		else
11583781Sceastha			echo "${1}"
11593781Sceastha		fi
11603781Sceastha		;;
11613781Sceastha
11623781Sceastha	"ppdcache" | "caches" | "manufaliases")
11633781Sceastha		# Reserved label names with any option
11643781Sceastha		print -n "$myprog: " 1>&2
11653781Sceastha		gettext "reserved PPD label name: ${1}\n" 1>&2
11663781Sceastha		vsl_rc=1
11673781Sceastha		;;
11683781Sceastha
11693781Sceastha	"" | "${UNSET}")
11703781Sceastha		# Label name not specified.  Set the default label name.
11713781Sceastha		# For -g and -a, default is "user", otherwise, default
11723781Sceastha		# is "all".
11733781Sceastha		if [[ "${action}" = "${ADD}" || \
11743781Sceastha		    "${action}" = "${GENERATEENTRY}" ]] ; then
11753781Sceastha			echo "${USER}"
11763781Sceastha		else
11773781Sceastha			echo "all"
11783781Sceastha		fi
11793781Sceastha		;;
11803781Sceastha
11813781Sceastha	*)
11823781Sceastha		# label cannot be "." or ".."
11833781Sceastha		if [[ "${1}" = "." || "${1}" = ".." ]] ; then
11843781Sceastha			print -n "$myprog: " 1>&2
11853781Sceastha			gettext "PPD label name cannot be " 1>&2
11863781Sceastha			gettext "\".\" or \"..\"\n" 1>&2
11873781Sceastha			vsl_rc=1
11883781Sceastha		fi
11893781Sceastha
11903781Sceastha		# Label name cannot contain special characters
11913781Sceastha		echo "${1}" | /bin/egrep "${SPECIALCHARS}" >/dev/null
11923781Sceastha		if [[ $? -eq 0 ]] ; then
11933781Sceastha			print -n "$myprog: " 1>&2
11943781Sceastha			gettext "PPD label name contains " 1>&2
11953781Sceastha			gettext "an invalid character: ${1}\n" 1>&2
11963781Sceastha			vsl_rc=1
11973781Sceastha		else
11983781Sceastha			echo "${1}"
11993781Sceastha		fi
12003781Sceastha		;;
12013781Sceastha	esac
12023781Sceastha	return ${vsl_rc}
12033781Sceastha}
12043781Sceastha
12053781Sceastha#
12063781Sceastha# Returns the full path of any variant copy of the source file in
12073781Sceastha# the destination label/repository.
12083781Sceastha#
12093781Sceastha# $1	- Full path to source PPD file
12103781Sceastha# $2	- Full path to destination PPD file
12113781Sceastha#
12123781Sceastha# Return code set to
12133781Sceastha#	0	- Copy doesn't exist
12143781Sceastha#	1	- Duplicate copy exists
12153781Sceastha#	2	- Variant copy exists
12163781Sceastha#
12173781Sceasthavariant_copy()
12183781Sceastha{
12193781Sceastha	if debugger ; then
12203781Sceastha		set -x
12213781Sceastha	fi
12223781Sceastha
12233781Sceastha	#
12243781Sceastha	# First make sure there is not a .ppd and a .ppd.gz version
12253781Sceastha	# of the destination file; users should know not to do this.
12263781Sceastha	#
12273781Sceastha	if [[ -e "${2%.gz}" && -e "${2%.gz}.gz" ]] ; then
12283781Sceastha		/bin/rm -f "${2%.gz}" >/dev/null 2>&1
12293781Sceastha	fi
12303781Sceastha
12313781Sceastha	# Use gzcmp to compare PPD files as it can deal with
12323781Sceastha	# gzipped or regular files.
12333781Sceastha	if $(${GZCMP} "${1}" "${2}"* >/dev/null 2>&1) ; then
12343781Sceastha		echo "${2}"*
12353781Sceastha		return 1
12363781Sceastha	elif [[ -e "${2%.gz}" ]] ; then
12373781Sceastha		echo "${2%.gz}"
12383781Sceastha		return 2
12393781Sceastha	elif [[ -e "${2%.gz}.gz" ]] ; then
12403781Sceastha		echo "${2%.gz}.gz"
12413781Sceastha		return 2
12423781Sceastha	else
12433781Sceastha		#
12443781Sceastha		# A PPD file doesn't exist in the destination
12453781Sceastha		# repository under the destination label.
12463781Sceastha		# Just display the source PPD file, ensuring
12473781Sceastha		# it has a gzip extension as we will always
12483781Sceastha		# try to gzip the copy in the destination.
12493781Sceastha		#
12503781Sceastha		if [[ "${1#*.ppd}" = ".gz" ]] ; then
12513781Sceastha			echo "${2}"
12523781Sceastha		else
12533781Sceastha			echo "${2}.gz"
12543781Sceastha		fi
12553781Sceastha		return 0
12563781Sceastha	fi
12573781Sceastha}
12583781Sceastha
12593781Sceastha#
12603781Sceastha# $1	- Directory mode
12613781Sceastha# $2	- Directory owner (i.e., root:lp)
12623781Sceastha# $3	- Directory to create
12633781Sceastha#
12643781Sceasthamake_dir()
12653781Sceastha{
12663781Sceastha	if debugger "make_dir" ; then
12673781Sceastha		set -x
12683781Sceastha	fi
12693781Sceastha
12703781Sceastha	[[ ! -d "${3}" ]] || return 0
12713781Sceastha	/bin/mkdir "${3}" >/dev/null 2>&1 || return 1
12723781Sceastha	set_perms ${1} ${2} "${3}"
12733781Sceastha	return 0
12743781Sceastha}
12753781Sceastha
12763781Sceastha#
12773781Sceastha# Remove a ppdmgr generated cache (in /var/lp/ppd/cache)
12783781Sceastha# if it doesn't have an associated label in the repository.
12793781Sceastha#
12803781Sceastha# $1	- Full path to label
12813781Sceastha# $2	- Cache name
12823781Sceastha#
12833781Sceastharemove_unassociated_cache()
12843781Sceastha{
12853781Sceastha	if debugger "remove_unassociated_cache" ; then
12863781Sceastha		set -x
12873781Sceastha	fi
12883781Sceastha
12893781Sceastha	if [[ "${1}" != "${UNSET}" ]] ; then
12903781Sceastha		if [[ -n "${1}" && ! -d "${1}" ]] ; then
12913781Sceastha			#
12923781Sceastha			# The label doesn't exist, so delete
12933781Sceastha			# the associated cache file.
12943781Sceastha			#
12953781Sceastha			/bin/rm -f "${VARCACHES}/${2}" >/dev/null 2>&1
12963781Sceastha		fi
12973781Sceastha	fi
12983781Sceastha}
12993781Sceastha
13003781Sceastha#
13013781Sceastha# Sorted copies of cache files for each label in each PPD repository
13023781Sceastha# are maintained in /var/lp/ppd/caches/<PPD respository>-<label>.
13033781Sceastha# This is done so that changes in delivered cache files can be
13043781Sceastha# detected.  If a difference in cache files is detected, or a
13053781Sceastha# cache file is either added or removed, then we know that
13063781Sceastha# the ppdcache file needs to be updated.
13073781Sceastha#
13083781Sceastha# Get a list of all cache files and compare against the list
13093781Sceastha# of labels in all of the PPD file repositories.  They should
13103781Sceastha# be the same.  If there is a label in one of the PPD file
13113781Sceastha# repositories that doesn't have an associated cache file, then
13123781Sceastha# we don't worry about it now, as that will be resolved when
13133781Sceastha# we update the cache for that label.  However, if there is
13143781Sceastha# a cache file associated with a label that no longer exists, then
13153781Sceastha# remove the cache file.
13163781Sceastha#
13173781Sceastha# $1	- Full path to repository (or "all")
13183781Sceastha# $2	- Label name
13193781Sceastha#
13203781Sceasthaupdate_cache()
13213781Sceastha{
13223781Sceastha	if debugger ; then
13233781Sceastha		set -x
13243781Sceastha	fi
13253781Sceastha
13263781Sceastha	#
13273781Sceastha	# Determine which labels in which PPD repository the
13283781Sceastha	# cache file will be updated for.
13293781Sceastha	#
13303781Sceastha	if [[ "${1}" = "all" ]] ; then
13313781Sceastha		rname="${REPOSITORIES}"
13323781Sceastha	else
13333781Sceastha		rname="${1}"
13343781Sceastha	fi
13353781Sceastha
13363781Sceastha	uc_rc=0
13373781Sceastha	for dstreppath in ${rname} ; do
13383781Sceastha		labellist=
13393781Sceastha		if [[ "${2}" = "all" ]] ; then
13403781Sceastha			dstrepname=$(get_rep_name "${dstreppath}")
13413781Sceastha			labellist=$(get_rep_label_list "${dstreppath}" \
13423781Sceastha			    "${dstrepname}")
13433781Sceastha		else
13443781Sceastha
13453781Sceastha			# Ensure the label exists in the PPD file repository.
13463781Sceastha			if [[ -d "${dstreppath}/${2}" ]] ; then
13473781Sceastha				labellist="${2}"
13483781Sceastha			fi
13493781Sceastha		fi
13503781Sceastha
13513781Sceastha		#
13523781Sceastha		# Update the cache for each label in the PPD repository
13533781Sceastha		#
13543781Sceastha		for dstlabel in ${labellist} ; do
13553781Sceastha			ulc_msg=$(update_label_cache "${dstreppath}" \
13563781Sceastha			    "${dstrepname}" "${dstlabel}")
13573781Sceastha			if [[ $? -ne 0 ]] ; then
13583781Sceastha				echo "${ulc_msg}"
13593781Sceastha				uc_rc=1
13603781Sceastha			fi
13613781Sceastha		done
13623781Sceastha	done
13633781Sceastha
13643781Sceastha	# Update the golden cache file.
13653781Sceastha	update_golden_cache
13663781Sceastha	return ${uc_rc}
13673781Sceastha}
13683781Sceastha
13693781Sceastha# $1	- exit status
13703781Sceasthappdmgr_exit()
13713781Sceastha{
13723781Sceastha	if debugger "ppdmgr_exit" ; then
13733781Sceastha		set -x
13743781Sceastha	fi
13753781Sceastha
13763781Sceastha	/bin/rm -rf "${ppdmgrtmpdir}" >/dev/null 2>&1
13773781Sceastha	exit ${1}
13783781Sceastha}
13793781Sceastha
13803781Sceastha
13813781Sceasthausage()
13823781Sceastha{
13833781Sceastha	gettext "usage:\n" 1>&2
13843781Sceastha	print -n "\t$myprog: " 1>&2
13853781Sceastha	gettext "-a <ppd_filename_path> [ -L <label> ]\n" 1>&2
13863781Sceastha	gettext "\t\t[ -R <ppd_repository> ] [-w]\n" 1>&2
13873781Sceastha	print -n "\t$myprog: " 1>&2
13883781Sceastha	gettext "-r [ -L <label> ] [ -R <ppd_repository> ]\n" 1>&2
13893781Sceastha	print -n "\t$myprog: " 1>&2
13903781Sceastha	gettext "-u [ -L <label> ] [ -R <ppd_repository> ]\n" 1>&2
13913781Sceastha
13923781Sceastha	ppdmgr_exit ${FAIL}
13933781Sceastha}
13943781Sceastha
13953781Sceastha##########################################################################
13963781Sceastha# main
13973781Sceastha##########################################################################
13983781Sceastha
13993781Sceasthamyprog=$(/bin/basename $0)
14003781Sceastha
14013781SceasthaSaveIFS="$IFS"
14023781SceasthaNoSpaceTabIFS='
14033781Sceastha'
14043781Sceastha
14053781Sceastha# Updatable PPD repository
14063781SceasthaVARDIR=/var/lp/ppd
14073781Sceastha
14083781Sceastha# Delivered PPD respository
14093781SceasthaSYSTEMREP=/usr/share/ppd
14103781SceasthaADMINREP=/usr/local/share/ppd
14113781SceasthaVENDORREP=/opt/share/ppd
14123781SceasthaUSERREP=${VARDIR}
14133781Sceastha
14143781SceasthaRESERVEDREPS="${SYSTEMREP} ${ADMINREP} ${VENDORREP}"
14153781SceasthaREPOSITORIES="${USERREP} ${RESERVEDREPS}"
14163781SceasthaRESERVEDLABELS="all caches ppdcache manufaliases"
1417*7447SWendy.Phillips@Sun.COM
1418*7447SWendy.Phillips@Sun.COM# Directory where system:SUNWfoomatic is delivered
1419*7447SWendy.Phillips@Sun.COMFOOCACHEDIR=/usr/lib/lp/caches
14203781Sceastha
14213781Sceastha# Deliveries
14223781SceasthaSYSTEM=system
14233781SceasthaVENDOR=vendor
14243781SceasthaADMIN=admin
14253781SceasthaUSER=user
14263781Sceastha
14273781Sceastha# Sytem PPD cache name used by printmgr
14283781SceasthaGOLDCACHE=${USERREP}/ppdcache
14293781Sceastha
14303781Sceastha# Delivered caches directory
14313781SceasthaCACHES=caches
14323781SceasthaMANUFALIASES=manufaliases
14333781Sceastha
14343781Sceastha# Updated caches directory
14353781SceasthaVARCACHES=${VARDIR}/${CACHES}
14363781Sceastha
14373781Sceastha# valid PPD file name extensions
14383781SceasthaPEXT=ppd
14393781SceasthaGEXT=gz
14403781SceasthaFILEEXTS=".${PEXT} .${PEXT}.${GEXT}"
14413781Sceastha
14423781Sceastha# Default modes and owners
14433781SceasthaDIRMODE=755
14443781SceasthaDIROWNER=root:lp
14453781SceasthaADMINOWNER=root:root
14463781SceasthaFILEMODE=444
14473781SceasthaFILEOWNER=root:lp
14483781Sceastha
14493781Sceastha# ppdmgr actions
14503781SceasthaADD=add
14513781SceasthaGENERATEENTRY=generateentry
14523781SceasthaUPDATE=update
14533781SceasthaREBUILD=rebuild
14543781Sceastha
14553781SceasthaSUCCESS=0
14563781SceasthaFAIL=1
14573781SceasthaWARN=2
14583781Sceastha
14593781SceasthaMAXLABELNAME=256
14603781SceasthaGZIP="/bin/gzip -c"
14613781SceasthaGZCMP="/bin/gzcmp -s"
14623781SceasthaCMP="/bin/cmp -s"
14633781SceasthaSPECIALCHARS=":"
14643781SceasthaSEP=":"
14653781Sceastha
14663781Sceasthadebug=0
14673781Sceasthawflag=0
14683781Sceasthastatus=${SUCCESS}
14693781Sceastha
14703781SceasthaUNSET=""
14713781Sceasthappdlabel=${UNSET}
14723781Sceasthappdrepname=${UNSET}
14733781Sceasthappdreppath=${UNSET}
14743781Sceasthamodmanuf=
14753781Sceasthamodel=
14763781Sceasthanickn=
14773781Sceasthadevidmdl=
14783781Sceasthadevidmfg=
14793781Sceastha
14803781Sceasthappdmgrtmpdir=/tmp/ppdmgr.$$
14813781Sceastha/bin/mkdir "${ppdmgrtmpdir}" >/dev/null 2>&1
14823781Sceasthaset_perms ${DIRMODE} ${DIROWNER} "${ppdmgrtmpdir}"
14833781Sceastha
14843781Sceasthaaliasfile=${USERREP}/manufaliases
14853781Sceasthatmpfilepath=
14863781Sceastha
14873781Sceastha
14883781SceasthaOPTS=a:g:L:rR:uwZ
14893781Sceasthawhile getopts "$OPTS" arg ; do
14903781Sceastha	case ${arg} in
14913781Sceastha	a)	# add PPD file
14923781Sceastha		action=${ADD}
14933781Sceastha		origsrcppdpath=${OPTARG}
14943781Sceastha		;;
14953781Sceastha
14963781Sceastha	g)	# create cache entry
14973781Sceastha		action=${GENERATEENTRY}
14983781Sceastha		origsrcppdpath=${OPTARG}
14993781Sceastha		;;
15003781Sceastha
15013781Sceastha	L)	# PPD label name
15023781Sceastha		ppdlabel=${OPTARG}
15033781Sceastha		;;
15043781Sceastha
15053781Sceastha	r)	# rebuild cache
15063781Sceastha		action=${REBUILD}
15073781Sceastha		;;
15083781Sceastha
15093781Sceastha	R)	# PPD file repository to use
15103781Sceastha		ppdrepname=${OPTARG}
15113781Sceastha		;;
15123781Sceastha
15133781Sceastha	u)	# update cache
15143781Sceastha		action=${UPDATE}
15153781Sceastha		;;
15163781Sceastha
15173781Sceastha	w)	# display PPD file path
15183781Sceastha		wflag=1
15193781Sceastha		;;
15203781Sceastha
15213781Sceastha	Z)	# debug
15223781Sceastha		debug=1
15233781Sceastha		;;
15243781Sceastha
15253781Sceastha	?)
15263781Sceastha		usage
15273781Sceastha		;;
15283781Sceastha	esac
15293781Sceasthadone
15303781Sceastha
15313781Sceasthaif debugger "Main" ; then
15323781Sceastha	set -x
15333781Sceasthafi
15343781Sceastha
15353781Sceasthaif [[ $# -lt 1 || -z "${action}" ]] ; then
15363781Sceastha	usage
15373781Sceasthafi
15383781Sceastha
15393781Sceastha# ignore wflag unless specified with -a
15403781Sceasthaif [[ ${wflag} -eq 1 && "${action}" != ${ADD} ]] ; then
15413781Sceastha	wflag=0
15423781Sceasthafi
15433781Sceastha
15443781Sceastha#
15453781Sceastha# Ensure the destination PPD repository directory is set
15463781Sceastha# to match the specified repository.  If the
15473781Sceastha# destination PPD file repository was specified, then
15483781Sceastha# it must be one of the following:
15493781Sceastha# 	"user"
15503781Sceastha#	"admin"
15513781Sceastha#	"vendor"
15523781Sceastha#	"system"
15533781Sceastha#	"all"
15543781Sceastha#
15553781Sceasthacase "${ppdrepname}" in
15563781Sceastha"${SYSTEM}")
15573781Sceastha	ppdreppath="${SYSTEMREP}"
15583781Sceastha	;;
15593781Sceastha"${ADMIN}")
15603781Sceastha	ppdreppath="${ADMINREP}"
15613781Sceastha	;;
15623781Sceastha"${VENDOR}")
15633781Sceastha	ppdreppath="${VENDORREP}"
15643781Sceastha	;;
15653781Sceastha"${USER}")
15663781Sceastha	ppdreppath="${USERREP}"
15673781Sceastha	;;
15683781Sceastha"all")
15693781Sceastha	if [[ "${action}" = "${ADD}" || \
15703781Sceastha	    "${action}" = "${GENERATEENTRY}" ]] ; then
15713781Sceastha		print -n "$myprog: " 1>&2
15723781Sceastha		gettext "reserved PPD repository name: " 1>&2
15733781Sceastha		gettext "${ppdrepname}\n" 1>&2
15743781Sceastha		ppdmgr_exit ${FAIL}
15753781Sceastha	fi
15763781Sceastha	ppdreppath="all"
15773781Sceastha	;;
15783781Sceastha"${UNSET}"|"")
15793781Sceastha	ppdreppath="${UNSET}"
15803781Sceastha	;;
15813781Sceastha
15823781Sceastha*)
15833781Sceastha	print -n "$myprog: " 1>&2
15843781Sceastha	gettext "invalid PPD repository name: ${ppdrepname}\n" 1>&2
15853781Sceastha	ppdmgr_exit ${FAIL}
15863781Sceastha	;;
15873781Sceasthaesac
15883781Sceastha
15893781Sceastha#
15903781Sceastha# When a source PPD file's path is from a known repository, the
15913781Sceastha# destination repository and desination label are assumed to be the
15923781Sceastha# same as the source PPD file's unless a differing repository or label
15933781Sceastha# was specified.
15943781Sceastha#
15953781Sceasthaif [[ "${action}" = "${ADD}" || "${action}" = "${GENERATEENTRY}" ]] ; then
15963781Sceastha
15973781Sceastha	srcppdpath=$(ppd_pathname "${origsrcppdpath}")
15983781Sceastha	ppd_pathname_rc=$?
15993781Sceastha	if [[ ${ppd_pathname_rc} -ne 0 ]] ; then
16003781Sceastha		print -n "$myprog: " 1>&2
16013781Sceastha		gettext "invalid PPD file: ${origsrcppdpath}\n" 1>&2
16023781Sceastha		ppdmgr_exit ${ppd_pathname_rc}
16033781Sceastha	fi
16043781Sceastha
16053781Sceastha	# Path cannot contain special characters
16063781Sceastha	echo "${srcppdpath}" | /bin/egrep  "${SPECIALCHARS}" >/dev/null
16073781Sceastha	if [[ $? -eq 0 ]] ; then
16083781Sceastha		print -n "$myprog: " 1>&2
16093781Sceastha		gettext "PPD path contains " 1>&2
16103781Sceastha		gettext "an invalid character: ${ppd_pathname}\n" 1>&2
16113781Sceastha		ppdmgr_exit ${FAIL}
16123781Sceastha	fi
16133781Sceastha	ppdfname=$(/bin/basename "${origsrcppdpath}")
16143781Sceastha
16153781Sceastha	#
16163781Sceastha	# Check to see if there's any work to be done.  If the source file
16173781Sceastha	# is already in the destination repository under the destination
16183781Sceastha	# label, then there's nothing left to do.  We exit rather than
16193781Sceastha	# going on to do an update on the label in the repository as
16203781Sceastha	# it could possible take a long time to update.  If an add was
16213781Sceastha	# requested, it could have come from an application, so we want
16223781Sceastha	# to return quickly.
16233781Sceastha	#
16243781Sceastha	if label_path_match "${srcppdpath}" "${ppdreppath}" "${ppdlabel}" ; then
16253781Sceastha		if [[ ${wflag} -eq 1 || \
16263781Sceastha		    "${action}" = "${GENERATEENTRY}" ]] ; then
16273781Sceastha			echo "${srcppdpath}"
16283781Sceastha		fi
16293781Sceastha		ppdmgr_exit ${SUCCESS}
16303781Sceastha	fi
16313781Sceasthafi
16323781Sceastha
16333781Sceasthappdlabel=$(valid_specified_label "${ppdlabel}")
16343781Sceasthaif [[ $? -ne 0 ]] ; then
16353781Sceastha	ppdmgr_exit ${FAIL}
16363781Sceasthafi
16373781Sceastha
16383781Sceasthaif [[ "${ppdreppath}" = "${UNSET}" ]] ; then
16393781Sceastha	ppdreppath="${USERREP}"
16403781Sceasthafi
16413781Sceastha
16423781Sceasthadstrepname=$(get_rep_name "${ppdreppath}")
16433781Sceastha
16443781Sceasthacase "${action}" in
16453781Sceastha"${ADD}")
16463781Sceastha	#
16473781Sceastha	# Attempt to add the PPD file to the repository under the
16483781Sceastha	# specified label.  If any errors occur, final_dst_ppd_path
16493781Sceastha	# will contain the error message rather than the path to the
16503781Sceastha	# PPD file.
16513781Sceastha	#
16523781Sceastha	final_dst_ppd_path=$(add_ppd "${srcppdpath}" "${ppdfname}" \
16533781Sceastha	    "${ppdreppath}" "${dstrepname}" "${ppdlabel}")
16543781Sceastha	add_ppd_rc=$?
16553781Sceastha	case ${add_ppd_rc} in
16563781Sceastha	0)	#
16573781Sceastha		# The PPD file was added.  Update the specified
16583781Sceastha		# cache associated with the label if the PPD file
16593781Sceastha		# was added successfully and was not a duplicate.
16603781Sceastha		# Ensure any changes are also reflected in the
16613781Sceastha		# golden cache.
16623781Sceastha		#
16633781Sceastha		add_ppd_msg=$(update_label_cache "${ppdreppath}" \
16643781Sceastha		    "${dstrepname}" "${ppdlabel}")
16653781Sceastha		apm_rc=$?
16663781Sceastha
16673781Sceastha		echo "${add_ppd_msg}" | /bin/grep "${final_dst_ppd_path}"
16683781Sceastha		path_in_msg=$?
16693781Sceastha
16703781Sceastha		#
16713781Sceastha		# Only report cache update errors if the file that was
16723781Sceastha		# added was one that was reported as not being added
16733781Sceastha		# to the cache.  This really should happen as the file
16743781Sceastha		# was verified during the add.
16753781Sceastha		#
16763781Sceastha		if [[ ${apm_rc} -ne 0 && ${path_in_msg} -eq 0 ]] ; then
16773781Sceastha			print -n "$myprog: " 1>&2
16783781Sceastha			gettext "printer information does not reflect " 1>&2
16793781Sceastha			gettext "the\nfollowing PPD file(s):\n" 1>&2
16803781Sceastha			print "${add_ppd_msg}" 1>&2
16813781Sceastha			status=${FAIL}
16823781Sceastha		else
16833781Sceastha			update_golden_cache
16843781Sceastha
16853781Sceastha			#
16863781Sceastha			# Display the full path to the added PPD file,
16873781Sceastha			# if requested (-w).
16883781Sceastha			#
16893781Sceastha			if [[ ${wflag} -eq 1 ]] ; then
16903781Sceastha				print "${final_dst_ppd_path}"
16913781Sceastha			fi
16923781Sceastha		fi
16933781Sceastha		;;
16943781Sceastha
16953781Sceastha	1)	# Duplicate copy exists
16963781Sceastha		if [[ ${wflag} -eq 1 ]] ; then
16973781Sceastha			print "${final_dst_ppd_path}"
16983781Sceastha		fi
16993781Sceastha		;;
17003781Sceastha
17013781Sceastha	2)	# Varying copy exists
17023781Sceastha		print -n "$myprog: " 1>&2
17033781Sceastha		gettext "differing variant of source PPD file " 1>&2
17043781Sceastha		gettext "already exists at\n" 1>&2
17053781Sceastha		gettext "${final_dst_ppd_path}\n" 1>&2
17063781Sceastha		status=${FAIL}
17073781Sceastha		;;
17083781Sceastha	*)	# The PPD file was not added as a problem occurred.
17093781Sceastha		# Display the error message.
17103781Sceastha		print -n "$myprog: " 1>&2
17113781Sceastha		print "${final_dst_ppd_path}" 1>&2
17123781Sceastha		status=${FAIL}
17133781Sceastha		;;
17143781Sceastha
17153781Sceastha	esac
17163781Sceastha	;;
17173781Sceastha
17183781Sceastha"${GENERATEENTRY}")
17193781Sceastha	#
17203781Sceastha	# Create a cache file entry for the specified PPD file and
17213781Sceastha	# display it on standard out.
17223781Sceastha	#
17233781Sceastha	verify_ppd_file "${srcppdpath}"
17243781Sceastha	if [[ $? -eq 0 ]] ; then
17253781Sceastha		dstdir="${ppdreppath}/${ppdlabel}/${modmanuf}"
17263781Sceastha		final_dst_path="${dstdir}/$(/bin/basename ${srcppdpath})"
17273781Sceastha		verify_ppd_location "${final_dst_path}"
17283781Sceastha		if [[ $? -eq 0 ]] ; then
17293781Sceastha			# Generate the cache file entry
17303781Sceastha			print "$(generate_cache_file_entry "${modmanuf}" \
17313781Sceastha			    "${model}" "${nickn}" "${devidmfg}" "${devidmdl}" \
17323781Sceastha			    "${final_dst_path}")"
17333781Sceastha		else
17343781Sceastha			print -n "$myprog: " 1>&2
17353781Sceastha			gettext "PPD file not in valid location\n" 1>&2
17363781Sceastha			gettext \
17373781Sceastha	    "(<repository>/<label>/<manufacturer>/<PPD file>):\n\t${1}\n" 1>&2
17383781Sceastha			status=${FAIL}
17393781Sceastha		fi
17403781Sceastha
17413781Sceastha	else
17423781Sceastha		print -n "$myprog: " 1>&2
17433781Sceastha		gettext "invalid PPD file: ${1}\n" 1>&2
17443781Sceastha		status=${FAIL}
17453781Sceastha	fi
17463781Sceastha	;;
17473781Sceastha
17483781Sceastha"${REBUILD}" | "${UPDATE}")
17493781Sceastha	update_msg=$(update_cache "${ppdreppath}" "${ppdlabel}")
17503781Sceastha	if [[ $? -ne 0 ]] ; then
17513781Sceastha		print -n "$myprog: " 1>&2
17523781Sceastha		gettext "printer information does not reflect " 1>&2
17533781Sceastha		gettext "the\nfollowing PPD file(s):\n" 1>&2
17543781Sceastha		print "${update_msg}" 1>&2
17553781Sceastha		status=${WARN}
17563781Sceastha	fi
17573781Sceastha	;;
17583781Sceastha
17593781Sceastha*)
17603781Sceastha	usage
17613781Sceastha	;;
17623781Sceasthaesac
17633781Sceastha
17643781Sceasthappdmgr_exit ${status}
1765