c81d47afd05baeb768e2f032636019b717899efdceastha# CDDL HEADER START
c81d47afd05baeb768e2f032636019b717899efdceastha# The contents of this file are subject to the terms of the
c81d47afd05baeb768e2f032636019b717899efdceastha# Common Development and Distribution License (the "License").
c81d47afd05baeb768e2f032636019b717899efdceastha# You may not use this file except in compliance with the License.
c81d47afd05baeb768e2f032636019b717899efdceastha# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c81d47afd05baeb768e2f032636019b717899efdceastha# See the License for the specific language governing permissions
c81d47afd05baeb768e2f032636019b717899efdceastha# and limitations under the License.
c81d47afd05baeb768e2f032636019b717899efdceastha# When distributing Covered Code, include this CDDL HEADER in each
c81d47afd05baeb768e2f032636019b717899efdceastha# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c81d47afd05baeb768e2f032636019b717899efdceastha# If applicable, add the following below this CDDL HEADER, with the
c81d47afd05baeb768e2f032636019b717899efdceastha# fields enclosed by brackets "[]" replaced with your own identifying
c81d47afd05baeb768e2f032636019b717899efdceastha# information: Portions Copyright [yyyy] [name of copyright owner]
c81d47afd05baeb768e2f032636019b717899efdceastha# CDDL HEADER END
4fb0018bf832424363cfcc05b23323c48ab7a076Sumanth Naropanth# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
c81d47afd05baeb768e2f032636019b717899efdceastha# Use is subject to license terms.
c81d47afd05baeb768e2f032636019b717899efdceastha# Description: Script to generate the Solaris printmgr 'ppdcache' file from the
c81d47afd05baeb768e2f032636019b717899efdceastha# ppd files installed in the given ppd database directory
c81d47afd05baeb768e2f032636019b717899efdceastha# ppdmgr -a <ppd_filename_path> [ -L <label> ] [-w]
c81d47afd05baeb768e2f032636019b717899efdceastha# ppdmgr -g <ppd_filename_path> [ -L <label> ] [ -R <ppd_repository> ]
c81d47afd05baeb768e2f032636019b717899efdceastha# ppdmgr -r [ -L <label> ] [ -R <ppd_repository> ]
c81d47afd05baeb768e2f032636019b717899efdceastha# ppdmgr -u [ -L <label> ] [ -R <ppd_repository> ]
c81d47afd05baeb768e2f032636019b717899efdceastha# -a <ppd_filename_path> - Add a new PPD file to the specified
c81d47afd05baeb768e2f032636019b717899efdceastha# label in the "user" repository, and
c81d47afd05baeb768e2f032636019b717899efdceastha# updates to the "user" repository
c81d47afd05baeb768e2f032636019b717899efdceastha# in the ppdcache.
c81d47afd05baeb768e2f032636019b717899efdceastha# -g <ppd_filename_path> - Generate a cache file entry
c81d47afd05baeb768e2f032636019b717899efdceastha# for the specified PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# on standard out.
c81d47afd05baeb768e2f032636019b717899efdceastha# -L <label> - Label name. <label>
c81d47afd05baeb768e2f032636019b717899efdceastha# can be any characters from the
c81d47afd05baeb768e2f032636019b717899efdceastha# portable character set, however
c81d47afd05baeb768e2f032636019b717899efdceastha# may not contain a semi-colon (':').
c81d47afd05baeb768e2f032636019b717899efdceastha# The following are the defaults
c81d47afd05baeb768e2f032636019b717899efdceastha# for <label> for each option:
c81d47afd05baeb768e2f032636019b717899efdceastha# OPTION DEFAULT LABEL
c81d47afd05baeb768e2f032636019b717899efdceastha# ------ -------------
c81d47afd05baeb768e2f032636019b717899efdceastha# -a <label> from <ppd_filename_path>
c81d47afd05baeb768e2f032636019b717899efdceastha# if <ppd_filename_path>
c81d47afd05baeb768e2f032636019b717899efdceastha# is from a known repository,
c81d47afd05baeb768e2f032636019b717899efdceastha# otherwise defaults to "user".
c81d47afd05baeb768e2f032636019b717899efdceastha# -g <label> from <ppd_filename_path>
c81d47afd05baeb768e2f032636019b717899efdceastha# if <ppd_filename_path>
c81d47afd05baeb768e2f032636019b717899efdceastha# is from a known repository,
c81d47afd05baeb768e2f032636019b717899efdceastha# otherwise defaults to "user".
c81d47afd05baeb768e2f032636019b717899efdceastha# The following are reserved labels:
c81d47afd05baeb768e2f032636019b717899efdceastha# caches - may never be specified
c81d47afd05baeb768e2f032636019b717899efdceastha# ppdcache - may never be specified
c81d47afd05baeb768e2f032636019b717899efdceastha# manufaliases - may never be specified
c81d47afd05baeb768e2f032636019b717899efdceastha# all - applies specified
c81d47afd05baeb768e2f032636019b717899efdceastha# action to all labels
c81d47afd05baeb768e2f032636019b717899efdceastha# in a repository.
c81d47afd05baeb768e2f032636019b717899efdceastha# Can only be specified
c81d47afd05baeb768e2f032636019b717899efdceastha# with -r or -u.
c81d47afd05baeb768e2f032636019b717899efdceastha# SUNW* - anything starting with
c81d47afd05baeb768e2f032636019b717899efdceastha# SUNW is reserved for
c81d47afd05baeb768e2f032636019b717899efdceastha# use by Sun, but not
c81d47afd05baeb768e2f032636019b717899efdceastha# prohibited.
c81d47afd05baeb768e2f032636019b717899efdceastha# -r - Rebuild the cache information for the
c81d47afd05baeb768e2f032636019b717899efdceastha# specified label in the specified
c81d47afd05baeb768e2f032636019b717899efdceastha# repository. Similar to -u, however,
c81d47afd05baeb768e2f032636019b717899efdceastha# the cache file is removed to force an
c81d47afd05baeb768e2f032636019b717899efdceastha# update to the ppdcache.
c81d47afd05baeb768e2f032636019b717899efdceastha# -R <ppd_repository> - PPD repository name.
c81d47afd05baeb768e2f032636019b717899efdceastha# Defaults to "user".
c81d47afd05baeb768e2f032636019b717899efdceastha# The following are the possible
c81d47afd05baeb768e2f032636019b717899efdceastha# values for <ppd_repository> and
c81d47afd05baeb768e2f032636019b717899efdceastha# location in the system:
c81d47afd05baeb768e2f032636019b717899efdceastha# REP LOCATION
c81d47afd05baeb768e2f032636019b717899efdceastha# --- --------
c81d47afd05baeb768e2f032636019b717899efdceastha# all all repositories
c81d47afd05baeb768e2f032636019b717899efdceastha# Note: When specified with the -a option
c81d47afd05baeb768e2f032636019b717899efdceastha# only "user" and "admin" are valid.
c81d47afd05baeb768e2f032636019b717899efdceastha# "vendor", "system", and "all" will be
c81d47afd05baeb768e2f032636019b717899efdceastha# considered reserved.
c81d47afd05baeb768e2f032636019b717899efdceastha# -u - Update the PPD cache information
c81d47afd05baeb768e2f032636019b717899efdceastha# for the specified label in the specified
c81d47afd05baeb768e2f032636019b717899efdceastha# repository if needed. If the cache
c81d47afd05baeb768e2f032636019b717899efdceastha# update was required, then the updated
c81d47afd05baeb768e2f032636019b717899efdceastha# cache information is reflected in
c81d47afd05baeb768e2f032636019b717899efdceastha# the ppdcache.
c81d47afd05baeb768e2f032636019b717899efdceastha# -w - Display full path of where the
c81d47afd05baeb768e2f032636019b717899efdceastha# ppd file is located on the system.
c81d47afd05baeb768e2f032636019b717899efdceastha# Only valid with -a, otherwise the
c81d47afd05baeb768e2f032636019b717899efdceastha# option is ignored.
c81d47afd05baeb768e2f032636019b717899efdceastha# If -a, -g, -r, or -u are specified on the command line, only the last action
c81d47afd05baeb768e2f032636019b717899efdceastha# specified will be performed.
c81d47afd05baeb768e2f032636019b717899efdceastha# Cache file entry format:
c81d47afd05baeb768e2f032636019b717899efdceastha# <ModifiedManufacturerName>:<Model>:<NickName>:<1284DeviceIDManufacturer>:<1284DeviceIDModel>:<FullPPDFilePath>
c81d47afd05baeb768e2f032636019b717899efdceastha# HP:HP DeskJet 450:Foomatic/hpijs (recommended):dj450:hp:/usr/share/ppd/HP/HP-DeskJet_450-hpijs.ppd.gz
c81d47afd05baeb768e2f032636019b717899efdceastha# Generates debug output for calling routine.
c81d47afd05baeb768e2f032636019b717899efdceastha# If calling routine's name is passed in, then
c81d47afd05baeb768e2f032636019b717899efdceastha# will also generate the name of the calling routine.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Name of calling routine
c81d47afd05baeb768e2f032636019b717899efdceastha [[ ${debug} -eq 1 ]] || return 1
c81d47afd05baeb768e2f032636019b717899efdceastha# Set the ownership and permissions on a file.
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Owner:Group
c81d47afd05baeb768e2f032636019b717899efdceastha# $3 - Full path to file
c81d47afd05baeb768e2f032636019b717899efdceastha# Create administrator repository directories, /usr/local/share/ppd,
c81d47afd05baeb768e2f032636019b717899efdceastha# if needed. This is a special case a Solaris doesn't deliver
c81d47afd05baeb768e2f032636019b717899efdceastha# /usr/local/share and it has different permissions than the
c81d47afd05baeb768e2f032636019b717899efdceastha# user repository.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - destination repository name
c81d47afd05baeb768e2f032636019b717899efdceastha # Only create administrator repository directories, if needed.
c81d47afd05baeb768e2f032636019b717899efdceastha make_dir ${DIRMODE} ${ADMINOWNER} "${admpar}" || return 1
c81d47afd05baeb768e2f032636019b717899efdceastha make_dir ${DIRMODE} ${ADMINOWNER} ${ADMINREP} || return 1
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns full path to PPD file that was added to the system.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path to source PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - PPD file name
c81d47afd05baeb768e2f032636019b717899efdceastha# $3 - Full path to repository
c81d47afd05baeb768e2f032636019b717899efdceastha# $4 - Repository name
c81d47afd05baeb768e2f032636019b717899efdceastha# $5 - Label name
c81d47afd05baeb768e2f032636019b717899efdceastha# Return codes:
c81d47afd05baeb768e2f032636019b717899efdceastha# 0 - File successfully added
c81d47afd05baeb768e2f032636019b717899efdceastha# 2 - Duplicate file already exists
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ $? -ne 0 ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha # If a version (either compressed or not compressed) of the PPD
c81d47afd05baeb768e2f032636019b717899efdceastha # file exists in the destination in the label/repository,
c81d47afd05baeb768e2f032636019b717899efdceastha dst_copy_path=$(variant_copy "${1}" "${dstpath}" "${6}" "${ppdfname}")
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ ${ap_rc} -ne 0 ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha # Can only add a PPD file to the "user" or "admin" repository.
c81d47afd05baeb768e2f032636019b717899efdceastha # Note: this check is here instead of at the top of this
c81d47afd05baeb768e2f032636019b717899efdceastha # function as we don't want to cause an error if a user
c81d47afd05baeb768e2f032636019b717899efdceastha # specifies the same repository and label as a the specified
c81d47afd05baeb768e2f032636019b717899efdceastha # ppd file and the repository of the specified ppd file
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ "${4}" != "${USER}" && "${4}" != "${ADMIN}" ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "invalid PPD file repository name: ${4}" 2>/dev/null
c81d47afd05baeb768e2f032636019b717899efdceastha if ! create_adminrep_dirs ${4} ${DIRMODE} ${ADMINOWNER} || \
c81d47afd05baeb768e2f032636019b717899efdceastha ! make_dir ${DIRMODE} ${DIROWNER} "${dstlabelpath}" || \
c81d47afd05baeb768e2f032636019b717899efdceastha ! make_dir ${DIRMODE} ${DIROWNER} "${dstmanufpath}" ; then
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "unable to create destination directories" 2>/dev/null
c81d47afd05baeb768e2f032636019b717899efdceastha # Copy source PPD file, and compress if needed, to destination
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ $? -eq 1 ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha /bin/cp -f "${1}" "${dst_copy_path}" >/dev/null 2>&1
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ $? -ne 0 ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha set_perms ${FILEMODE} ${FILEOWNER} "${dst_copy_path}"
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns 0 if the cache needs to be modified, otherwise
c81d47afd05baeb768e2f032636019b717899efdceastha# returns 1.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path to cache
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Full path to cache replacement candidate
c81d47afd05baeb768e2f032636019b717899efdceastha# Generate a new golden cache file (/var/lp/ppd/ppdcache), by
c81d47afd05baeb768e2f032636019b717899efdceastha# concatenating and sorting all existing cache files in /var/lp/ppd/caches.
c81d47afd05baeb768e2f032636019b717899efdceastha# If there are difference between the newly generated golden cache file and
c81d47afd05baeb768e2f032636019b717899efdceastha# the existing one (if it exists) then the newly generated one replaces the
c81d47afd05baeb768e2f032636019b717899efdceastha # Remove any cache files that don't have an associated
c81d47afd05baeb768e2f032636019b717899efdceastha for cname in $(/bin/ls ${VARCACHES} 2>/dev/null) ; do
4fb0018bf832424363cfcc05b23323c48ab7a076Sumanth Naropanth tmpgoldencache=$ppdmgrtmpdir/tmpgoldencache
c81d47afd05baeb768e2f032636019b717899efdceastha /bin/sort "${VARCACHES}"/* >>"${tmpgoldencache}" 2>/dev/null
c81d47afd05baeb768e2f032636019b717899efdceastha # Use the newly generated "temporary" golden cache file if there
c81d47afd05baeb768e2f032636019b717899efdceastha # differences between the current and newly generated ppdcache
c81d47afd05baeb768e2f032636019b717899efdceastha changes_in_cache "${GOLDCACHE}" "${tmpgoldencache}" ; then
c81d47afd05baeb768e2f032636019b717899efdceastha set_perms ${FILEMODE} ${FILEOWNER} "${tmpgoldencache}"
c81d47afd05baeb768e2f032636019b717899efdceastha # There wasn't an existing ppdcache. Install the newly
c81d47afd05baeb768e2f032636019b717899efdceastha set_perms ${FILEMODE} ${FILEOWNER} "${tmpgoldencache}"
c81d47afd05baeb768e2f032636019b717899efdceastha /bin/mv -f "${tmpgoldencache}" "${GOLDCACHE}" >/dev/null 2>&1
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns a list of PPD files that exist.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path to cache file
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns 0 if the path to the PPD is as follows:
c81d47afd05baeb768e2f032636019b717899efdceastha# <PPD file repository>/<label>/<manufacturer>/<PPD file>
c81d47afd05baeb768e2f032636019b717899efdceastha# otherwise, returns 1
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 Full path to PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha # Strip off what should be <label>/<manufacturer>/<PPD file>
c81d47afd05baeb768e2f032636019b717899efdceastha # and verify the PPD file repository matches one of the
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ "${repository}" = "${ppd_file_repository}" ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha# Generate, and sort, cache entries for each PPD files in the specified
c81d47afd05baeb768e2f032636019b717899efdceastha# list to the specified file.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - List of full paths to PPD files
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Full path to current cache file
c81d47afd05baeb768e2f032636019b717899efdceastha# $3 - Full path to label
c81d47afd05baeb768e2f032636019b717899efdceastha# $4 - Full path to new cache file to generate
c81d47afd05baeb768e2f032636019b717899efdceastha# Return code:
c81d47afd05baeb768e2f032636019b717899efdceastha# 1 unsuccessful
c81d47afd05baeb768e2f032636019b717899efdceastha # Generate a cache file containing cache entries for
c81d47afd05baeb768e2f032636019b717899efdceastha # Before processing new files, remove any cache entries
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ -e "${2}" && "${action}" != "${REBUILD}" ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha # If there are no valid PPD files in the current cache file,
c81d47afd05baeb768e2f032636019b717899efdceastha # and there are no new PPD files to process, the only thing
c81d47afd05baeb768e2f032636019b717899efdceastha for fname in ${1} ; do
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ ${vpl_rc} -ne 0 ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ ${vpf_rc} -ne 0 ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha [[ -n "${vpl_msg}" || -n "${vpf_msg}" ]] || return 0
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ -n ${vpl_msg} ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha gettext " PPD file(s) not in valid location\n" 2>/dev/null
c81d47afd05baeb768e2f032636019b717899efdceastha " (<repository>/<label>/<manufacturer>/<PPD file>):\n" 2>/dev/null
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ -n ${vpf_msg} ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha# Update current cache file with candidate cache file if there are
c81d47afd05baeb768e2f032636019b717899efdceastha# differences.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Current cache file
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Candidate cache file to update
c81d47afd05baeb768e2f032636019b717899efdceastha# $3 - Repository name
c81d47afd05baeb768e2f032636019b717899efdceastha # There is no current cache file. Move the candidate
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns 0 if there are files in $1 with newer timestamp
c81d47afd05baeb768e2f032636019b717899efdceastha# than $2 or if deletions have occurred under $1,
c81d47afd05baeb768e2f032636019b717899efdceastha# otherwise returns 1.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path to the destination label
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Full path to label cache file
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ -e "${2}" && "${action}" != "${REBUILD}" ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha # Need to detect if PPD files have been deleted by checking
c81d47afd05baeb768e2f032636019b717899efdceastha /bin/find "${1}" -type d -newer "${2}" >/dev/null 2>&1 || return 1
c81d47afd05baeb768e2f032636019b717899efdceastha# If -R was specified, or the timestamp on the specified label's
c81d47afd05baeb768e2f032636019b717899efdceastha# directory or any of the PPD files under the specified label in
c81d47afd05baeb768e2f032636019b717899efdceastha# the specified PPD file respository is newer than the cache file
c81d47afd05baeb768e2f032636019b717899efdceastha# associated with the label, then generate a new sorted cache file.
c81d47afd05baeb768e2f032636019b717899efdceastha# The new cache will replace the existing one (if any) only if there
c81d47afd05baeb768e2f032636019b717899efdceastha# are differences. Note: if -r was specified, then a new cache file
c81d47afd05baeb768e2f032636019b717899efdceastha# file will always be installed at
c81d47afd05baeb768e2f032636019b717899efdceastha# /var/lp/ppd/caches/<PPD file repository name>-<label name>
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path of the destination PPD file repository
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Destination PPD file repository name
c81d47afd05baeb768e2f032636019b717899efdceastha# $3 - Destination label name
c81d47afd05baeb768e2f032636019b717899efdceastha # (i.e., the timestamp on the label directory or any
c81d47afd05baeb768e2f032636019b717899efdceastha # existing cache file), then generate a new cache file.
70fa9386ff0a83ccf99d2d3ac2198d2ed51bf748Wendy Phillips # if this is a system repository, check for a prepopulated cache
70fa9386ff0a83ccf99d2d3ac2198d2ed51bf748Wendy Phillips if [[ "${2}" = "${SYSTEM}" && -e ${FOOCACHEDIR}/${3}.cache ]] ; then
70fa9386ff0a83ccf99d2d3ac2198d2ed51bf748Wendy Phillips /bin/cp -f ${FOOCACHEDIR}/${3}.cache ${tmpcachepath}
70fa9386ff0a83ccf99d2d3ac2198d2ed51bf748Wendy Phillips newfileslist=$(changes_under_label "${dstlabelpath}" \
70fa9386ff0a83ccf99d2d3ac2198d2ed51bf748Wendy Phillips if [[ $? -eq 0 ]] ; then
70fa9386ff0a83ccf99d2d3ac2198d2ed51bf748Wendy Phillips if [[ $? -ne 0 ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha # If there is a cache file in /var/lp/ppd/caches associated
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns the alias for the specified real manufacturer's name.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Real manufacturer's name
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - File containing list of files that have manufacturers aliases
c81d47afd05baeb768e2f032636019b717899efdceastha # Found a couple of PPD files which had special characters
c81d47afd05baeb768e2f032636019b717899efdceastha # in the Manufacturer name (i.e, the following is the Manufacturer
c81d47afd05baeb768e2f032636019b717899efdceastha # Search alias files for a match on the real manufacturer name
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns 0 if the extension to the specified PPD file is a known
c81d47afd05baeb768e2f032636019b717899efdceastha# extension, otherwise returns 1.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path to PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# Set upon return:
c81d47afd05baeb768e2f032636019b717899efdceastha# ppdfileext - PPD file ext (.ppd or .ppd.gz)
c81d47afd05baeb768e2f032636019b717899efdceastha# Return the lines from the specified PPD file matching the specified
c81d47afd05baeb768e2f032636019b717899efdceastha# spec items.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - spec entries from PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - spec item
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 example - 1 string with substrings separated by newline:
c81d47afd05baeb768e2f032636019b717899efdceastha# *PPD-Adobe: "4.3"
c81d47afd05baeb768e2f032636019b717899efdceastha# *Manufacturer: "HP"
c81d47afd05baeb768e2f032636019b717899efdceastha# *Product: "(officejet 4200 series)"
c81d47afd05baeb768e2f032636019b717899efdceastha# *ModelName: "HP OfficeJet 4200"
c81d47afd05baeb768e2f032636019b717899efdceastha# *NickName: "HP OfficeJet 4200 Foomatic/hpijs (recommended)"
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 example:
c81d47afd05baeb768e2f032636019b717899efdceastha# ^\*Manufacturer
c81d47afd05baeb768e2f032636019b717899efdceastha # Remove everything up to and including the first quote
c81d47afd05baeb768e2f032636019b717899efdceastha# Return the lines from the specified PPD file matching the specified
c81d47afd05baeb768e2f032636019b717899efdceastha# spec items.
c81d47afd05baeb768e2f032636019b717899efdceastha# Note: this is similar to spec_entry() except the tokens in the
c81d47afd05baeb768e2f032636019b717899efdceastha# spec entry are different.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - spec entries from PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - spec item
c81d47afd05baeb768e2f032636019b717899efdceastha # Remove everything up to and including the first semi-colon
c81d47afd05baeb768e2f032636019b717899efdceastha# Verifies that the specified PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# - has a valid extension
c81d47afd05baeb768e2f032636019b717899efdceastha# - has the following required spec file entries:
c81d47afd05baeb768e2f032636019b717899efdceastha# *PPD-Adobe: "4.3"
c81d47afd05baeb768e2f032636019b717899efdceastha# Manufacturer
c81d47afd05baeb768e2f032636019b717899efdceastha# In addition, the manufacture and model from the IEEE1284 device id
c81d47afd05baeb768e2f032636019b717899efdceastha# information will be gathered here, although it's not an error that
c81d47afd05baeb768e2f032636019b717899efdceastha# it isn't in the PPD file as many don't contain the IEEE1284 info.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path to PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# Return codes:
c81d47afd05baeb768e2f032636019b717899efdceastha# 1 invalid PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha searchentries="^\*${ADOBESPEC}:|^\*${MANUF}:|^\*${PRODUCT}:"
c81d47afd05baeb768e2f032636019b717899efdceastha searchentries="${searchentries}|^\*${MODEL}:|^\*${NICKNAME}:"
c81d47afd05baeb768e2f032636019b717899efdceastha ppd_info="$(/bin/gzgrep -e "${searchentries}" "${1}")"
c81d47afd05baeb768e2f032636019b717899efdceastha # Process the query results to verify each of the required spec
c81d47afd05baeb768e2f032636019b717899efdceastha for spec_item in ${ADOBESPEC} ${MANUF} ${PRODUCT} ${MODEL} \
c81d47afd05baeb768e2f032636019b717899efdceastha entry=$(spec_entry "${ppd_info}" "^\*${spec_item}:")
c81d47afd05baeb768e2f032636019b717899efdceastha if $(echo "${ppd_info}" | grep "${DEVID}" >/dev/null 2>&1) ; then
c81d47afd05baeb768e2f032636019b717899efdceastha devid="$(/bin/gzgrep -e "^[ ]*${DMDL}:|^[ ]*${DMFG}:" "${1}")"
c81d47afd05baeb768e2f032636019b717899efdceastha modmanuf=$(manuf_name_alias "${realmanuf}" ${aliasfile})
c81d47afd05baeb768e2f032636019b717899efdceastha# generate_cache_file_entry()
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns a cache file entry for the specified PPD file.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - modmanuf
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - model
c81d47afd05baeb768e2f032636019b717899efdceastha# $3 - nickn
c81d47afd05baeb768e2f032636019b717899efdceastha# $4 - devidmfg
c81d47afd05baeb768e2f032636019b717899efdceastha# $5 - devidmdl
c81d47afd05baeb768e2f032636019b717899efdceastha# $6 - Full path to the specified PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# Expand specified file to the full path.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - File path to expand
c81d47afd05baeb768e2f032636019b717899efdceastha# Return code set to 0 if expanded successfully, otherwise set to 1.
c81d47afd05baeb768e2f032636019b717899efdceastha echo "$(/bin/pwd)/$(/bin/basename "${1}")") || return 1
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns the PPD repsitory path associated with the specified
c81d47afd05baeb768e2f032636019b717899efdceastha# PPD repository name.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Repository name
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns the PPD respository name from the repository path
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - PPD repository path
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns 0 if a matching label name is found in the specified repository,
c81d47afd05baeb768e2f032636019b717899efdceastha# otherwise returns 1.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - repository path
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - label name
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ "${repository}" = "${1}" && -d "${1}/${2}" ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns 0 if the source label path is the same
c81d47afd05baeb768e2f032636019b717899efdceastha# as the destination label path, otherwise returns 1.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - full path to source PPD file (source label path)
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - destination repository path
c81d47afd05baeb768e2f032636019b717899efdceastha# $3 - destination label name
c81d47afd05baeb768e2f032636019b717899efdceastha # We've found a match if the label path is in a known
c81d47afd05baeb768e2f032636019b717899efdceastha # dest repository specified, dest label not specified
c81d47afd05baeb768e2f032636019b717899efdceastha # If the destination repository path is the same as the
c81d47afd05baeb768e2f032636019b717899efdceastha # source repository, and if the source label exists in the
c81d47afd05baeb768e2f032636019b717899efdceastha # destination repository path, then we'll assume the default
c81d47afd05baeb768e2f032636019b717899efdceastha # destination label is the same as the source label.
c81d47afd05baeb768e2f032636019b717899efdceastha label_path_in_repository "${2}" "${lpath##*/}" || return 1
c81d47afd05baeb768e2f032636019b717899efdceastha # match those of the source label path, and the source
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns 0 if specified label name is a reserved label, otherwise
c81d47afd05baeb768e2f032636019b717899efdceastha# returns 1.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - label name
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns a list of all labels that exist in a repository that are
c81d47afd05baeb768e2f032636019b717899efdceastha# not reserved labels.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path of repository
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Repository name
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns a valid PPD label.
c81d47afd05baeb768e2f032636019b717899efdceastha# Verifies the specified PPD label is a valid label. If the
c81d47afd05baeb768e2f032636019b717899efdceastha# label is not set, then it is set to a default value.
c81d47afd05baeb768e2f032636019b717899efdceastha# Return code set to 0 if the specified PPD label is valid, otherwise 1.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - PPD label
c81d47afd05baeb768e2f032636019b717899efdceastha # Label name not specified. Set the default label name.
c81d47afd05baeb768e2f032636019b717899efdceastha # For -g and -a, default is "user", otherwise, default
c81d47afd05baeb768e2f032636019b717899efdceastha echo "${1}" | /bin/egrep "${SPECIALCHARS}" >/dev/null
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ $? -eq 0 ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha# Returns the full path of any variant copy of the source file in
c81d47afd05baeb768e2f032636019b717899efdceastha# the destination label/repository.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path to source PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Full path to destination PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# Return code set to
c81d47afd05baeb768e2f032636019b717899efdceastha# 0 - Copy doesn't exist
c81d47afd05baeb768e2f032636019b717899efdceastha# 1 - Duplicate copy exists
c81d47afd05baeb768e2f032636019b717899efdceastha# 2 - Variant copy exists
c81d47afd05baeb768e2f032636019b717899efdceastha # First make sure there is not a .ppd and a .ppd.gz version
c81d47afd05baeb768e2f032636019b717899efdceastha # of the destination file; users should know not to do this.
c81d47afd05baeb768e2f032636019b717899efdceastha # Use gzcmp to compare PPD files as it can deal with
c81d47afd05baeb768e2f032636019b717899efdceastha if $(${GZCMP} "${1}" "${2}"* >/dev/null 2>&1) ; then
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Directory mode
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Directory owner (i.e., root:lp)
c81d47afd05baeb768e2f032636019b717899efdceastha# $3 - Directory to create
c81d47afd05baeb768e2f032636019b717899efdceastha# Remove a ppdmgr generated cache (in /var/lp/ppd/cache)
c81d47afd05baeb768e2f032636019b717899efdceastha# if it doesn't have an associated label in the repository.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path to label
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Cache name
c81d47afd05baeb768e2f032636019b717899efdceastha# Sorted copies of cache files for each label in each PPD repository
c81d47afd05baeb768e2f032636019b717899efdceastha# are maintained in /var/lp/ppd/caches/<PPD respository>-<label>.
c81d47afd05baeb768e2f032636019b717899efdceastha# This is done so that changes in delivered cache files can be
c81d47afd05baeb768e2f032636019b717899efdceastha# detected. If a difference in cache files is detected, or a
c81d47afd05baeb768e2f032636019b717899efdceastha# cache file is either added or removed, then we know that
c81d47afd05baeb768e2f032636019b717899efdceastha# the ppdcache file needs to be updated.
c81d47afd05baeb768e2f032636019b717899efdceastha# Get a list of all cache files and compare against the list
c81d47afd05baeb768e2f032636019b717899efdceastha# of labels in all of the PPD file repositories. They should
c81d47afd05baeb768e2f032636019b717899efdceastha# be the same. If there is a label in one of the PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha# repositories that doesn't have an associated cache file, then
c81d47afd05baeb768e2f032636019b717899efdceastha# we don't worry about it now, as that will be resolved when
c81d47afd05baeb768e2f032636019b717899efdceastha# we update the cache for that label. However, if there is
c81d47afd05baeb768e2f032636019b717899efdceastha# a cache file associated with a label that no longer exists, then
c81d47afd05baeb768e2f032636019b717899efdceastha# remove the cache file.
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - Full path to repository (or "all")
c81d47afd05baeb768e2f032636019b717899efdceastha# $2 - Label name
c81d47afd05baeb768e2f032636019b717899efdceastha # Determine which labels in which PPD repository the
c81d47afd05baeb768e2f032636019b717899efdceastha # Ensure the label exists in the PPD file repository.
c81d47afd05baeb768e2f032636019b717899efdceastha # Update the cache for each label in the PPD repository
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ $? -ne 0 ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha# $1 - exit status
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "-a <ppd_filename_path> [ -L <label> ]\n" 1>&2
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "-r [ -L <label> ] [ -R <ppd_repository> ]\n" 1>&2
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "-u [ -L <label> ] [ -R <ppd_repository> ]\n" 1>&2
c81d47afd05baeb768e2f032636019b717899efdceastha##########################################################################
c81d47afd05baeb768e2f032636019b717899efdceastha##########################################################################
c81d47afd05baeb768e2f032636019b717899efdceastha# Updatable PPD repository
c81d47afd05baeb768e2f032636019b717899efdceastha# Delivered PPD respository
70fa9386ff0a83ccf99d2d3ac2198d2ed51bf748Wendy Phillips# Directory where system:SUNWfoomatic is delivered
c81d47afd05baeb768e2f032636019b717899efdceastha# Deliveries
c81d47afd05baeb768e2f032636019b717899efdceastha# Sytem PPD cache name used by printmgr
c81d47afd05baeb768e2f032636019b717899efdceastha# Delivered caches directory
c81d47afd05baeb768e2f032636019b717899efdceastha# Updated caches directory
c81d47afd05baeb768e2f032636019b717899efdceastha# valid PPD file name extensions
c81d47afd05baeb768e2f032636019b717899efdceastha# Default modes and owners
c81d47afd05baeb768e2f032636019b717899efdceastha# ppdmgr actions
4fb0018bf832424363cfcc05b23323c48ab7a076Sumanth Naropanthppdmgrtmpdir=$(/usr/bin/mktemp -t -d ppdmgr.XXXXXX)
4fb0018bf832424363cfcc05b23323c48ab7a076Sumanth Naropanthif [ -z "$ppdmgrtmpdir" ] ; then
4fb0018bf832424363cfcc05b23323c48ab7a076Sumanth Naropanth gettext "Fatal error: could not create temporary directory\n" 1>&2
c81d47afd05baeb768e2f032636019b717899efdceastha a) # add PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha g) # create cache entry
c81d47afd05baeb768e2f032636019b717899efdceastha L) # PPD label name
c81d47afd05baeb768e2f032636019b717899efdceastha r) # rebuild cache
c81d47afd05baeb768e2f032636019b717899efdceastha R) # PPD file repository to use
c81d47afd05baeb768e2f032636019b717899efdceastha u) # update cache
c81d47afd05baeb768e2f032636019b717899efdceastha w) # display PPD file path
c81d47afd05baeb768e2f032636019b717899efdceastha# ignore wflag unless specified with -a
c81d47afd05baeb768e2f032636019b717899efdceasthaif [[ ${wflag} -eq 1 && "${action}" != ${ADD} ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha# Ensure the destination PPD repository directory is set
c81d47afd05baeb768e2f032636019b717899efdceastha# to match the specified repository. If the
c81d47afd05baeb768e2f032636019b717899efdceastha# destination PPD file repository was specified, then
c81d47afd05baeb768e2f032636019b717899efdceastha# it must be one of the following:
c81d47afd05baeb768e2f032636019b717899efdceastha"${SYSTEM}")
c81d47afd05baeb768e2f032636019b717899efdceastha"${VENDOR}")
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "invalid PPD repository name: ${ppdrepname}\n" 1>&2
c81d47afd05baeb768e2f032636019b717899efdceastha# When a source PPD file's path is from a known repository, the
c81d47afd05baeb768e2f032636019b717899efdceastha# destination repository and desination label are assumed to be the
c81d47afd05baeb768e2f032636019b717899efdceastha# same as the source PPD file's unless a differing repository or label
c81d47afd05baeb768e2f032636019b717899efdceastha# was specified.
c81d47afd05baeb768e2f032636019b717899efdceasthaif [[ "${action}" = "${ADD}" || "${action}" = "${GENERATEENTRY}" ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "invalid PPD file: ${origsrcppdpath}\n" 1>&2
c81d47afd05baeb768e2f032636019b717899efdceastha # Path cannot contain special characters
c81d47afd05baeb768e2f032636019b717899efdceastha echo "${srcppdpath}" | /bin/egrep "${SPECIALCHARS}" >/dev/null
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "an invalid character: ${ppd_pathname}\n" 1>&2
c81d47afd05baeb768e2f032636019b717899efdceastha # Check to see if there's any work to be done. If the source file
c81d47afd05baeb768e2f032636019b717899efdceastha # is already in the destination repository under the destination
c81d47afd05baeb768e2f032636019b717899efdceastha # label, then there's nothing left to do. We exit rather than
c81d47afd05baeb768e2f032636019b717899efdceastha # going on to do an update on the label in the repository as
c81d47afd05baeb768e2f032636019b717899efdceastha # it could possible take a long time to update. If an add was
c81d47afd05baeb768e2f032636019b717899efdceastha # requested, it could have come from an application, so we want
c81d47afd05baeb768e2f032636019b717899efdceastha # to return quickly.
c81d47afd05baeb768e2f032636019b717899efdceastha if label_path_match "${srcppdpath}" "${ppdreppath}" "${ppdlabel}" ; then
c81d47afd05baeb768e2f032636019b717899efdceastha echo "${srcppdpath}"
c81d47afd05baeb768e2f032636019b717899efdceastha # Attempt to add the PPD file to the repository under the
c81d47afd05baeb768e2f032636019b717899efdceastha # specified label. If any errors occur, final_dst_ppd_path
c81d47afd05baeb768e2f032636019b717899efdceastha # will contain the error message rather than the path to the
c81d47afd05baeb768e2f032636019b717899efdceastha # PPD file.
c81d47afd05baeb768e2f032636019b717899efdceastha final_dst_ppd_path=$(add_ppd "${srcppdpath}" "${ppdfname}" \
c81d47afd05baeb768e2f032636019b717899efdceastha # The PPD file was added. Update the specified
c81d47afd05baeb768e2f032636019b717899efdceastha # cache associated with the label if the PPD file
c81d47afd05baeb768e2f032636019b717899efdceastha # was added successfully and was not a duplicate.
c81d47afd05baeb768e2f032636019b717899efdceastha # Ensure any changes are also reflected in the
c81d47afd05baeb768e2f032636019b717899efdceastha # golden cache.
c81d47afd05baeb768e2f032636019b717899efdceastha echo "${add_ppd_msg}" | /bin/grep "${final_dst_ppd_path}"
c81d47afd05baeb768e2f032636019b717899efdceastha # Only report cache update errors if the file that was
c81d47afd05baeb768e2f032636019b717899efdceastha # added was one that was reported as not being added
c81d47afd05baeb768e2f032636019b717899efdceastha # to the cache. This really should happen as the file
c81d47afd05baeb768e2f032636019b717899efdceastha # was verified during the add.
c81d47afd05baeb768e2f032636019b717899efdceastha if [[ ${apm_rc} -ne 0 && ${path_in_msg} -eq 0 ]] ; then
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "printer information does not reflect " 1>&2
c81d47afd05baeb768e2f032636019b717899efdceastha # Display the full path to the added PPD file,
c81d47afd05baeb768e2f032636019b717899efdceastha # if requested (-w).
c81d47afd05baeb768e2f032636019b717899efdceastha print "${final_dst_ppd_path}"
c81d47afd05baeb768e2f032636019b717899efdceastha print "${final_dst_ppd_path}"
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "differing variant of source PPD file " 1>&2
c81d47afd05baeb768e2f032636019b717899efdceastha *) # The PPD file was not added as a problem occurred.
c81d47afd05baeb768e2f032636019b717899efdceastha # Display the error message.
c81d47afd05baeb768e2f032636019b717899efdceastha"${GENERATEENTRY}")
c81d47afd05baeb768e2f032636019b717899efdceastha # Create a cache file entry for the specified PPD file and
c81d47afd05baeb768e2f032636019b717899efdceastha # display it on standard out.
c81d47afd05baeb768e2f032636019b717899efdceastha final_dst_path="${dstdir}/$(/bin/basename ${srcppdpath})"
c81d47afd05baeb768e2f032636019b717899efdceastha # Generate the cache file entry
c81d47afd05baeb768e2f032636019b717899efdceastha "(<repository>/<label>/<manufacturer>/<PPD file>):\n\t${1}\n" 1>&2
c81d47afd05baeb768e2f032636019b717899efdceastha update_msg=$(update_cache "${ppdreppath}" "${ppdlabel}")
c81d47afd05baeb768e2f032636019b717899efdceastha gettext "printer information does not reflect " 1>&2