lpadmin revision bcdabfc47e027d458c65d1c456642dd12908e197
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#!/bin/ksh
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico#
134015a2eee98aa663217e87ec879938b5afb27cJazzyNico# CDDL HEADER START
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico# The contents of this file are subject to the terms of the
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Common Development and Distribution License (the "License").
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# You may not use this file except in compliance with the License.
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico#
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# or http://www.opensolaris.org/os/licensing.
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# See the License for the specific language governing permissions
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# and limitations under the License.
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico#
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico# When distributing Covered Code, include this CDDL HEADER in each
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico# If applicable, add the following below this CDDL HEADER, with the
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico# fields enclosed by brackets "[]" replaced with your own identifying
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# information: Portions Copyright [yyyy] [name of copyright owner]
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico#
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# CDDL HEADER END
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Use is subject to license terms.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNicoset -o noclobber
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoPATH=/bin:/usr/bin:/usr/sbin export PATH
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoTEXTDOMAIN="SUNW_OST_OSCMD"
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoexport TEXTDOMAIN
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoPFEXEC=/usr/bin/pfexec
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoLPSET=/usr/bin/lpset
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoLPGET=/usr/bin/lpget
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoLPSTAT=/usr/bin/lpstat
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoLPADMIN=/usr/lib/lp/local/lpadmin
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoLPFILTER=/usr/sbin/lpfilter
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoCOMM=/usr/bin/comm
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoPPDMGR=/usr/sbin/ppdmgr
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoHOST=$(/bin/uname -n)
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoexit_code=0
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
c544ac2705cf516901c8455356d56b52c8615525mfloryanusage() {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico gettext "Usage:\n" 1>&2
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico gettext " lpadmin -p (printer) (options)\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " lpadmin -x (dest)\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " lpadmin -d (dest)\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " lpadmin -S print-wheel -A alert-type [ -W minutes ]\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " [ -Q requests ]\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " lpadmin -M -f form-name [ -a [ -o filebreak ]\n" 1>&2
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico gettext " [ -t tray-number ]]\n" 1>&2
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico exit 1
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# create a filter table for LP service
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNicolp_config_filters() {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ ! -f /etc/lp/filter.table ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico cd /etc/lp/fd ; for filter in *.fd ; do
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico ${PFEXEC} ${LPFILTER} \
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico -f $(/usr/bin/basename $filter .fd) \
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico -F $filter
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico done
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico}
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# enable/disable LP related service(s)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicolp_config_service() { # (enable | disable)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico svcadm ${1} -s svc:/application/print/server:default
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # svcadm ${1} -s svc:/application/print/rfc1179:default
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico # svcadm ${1} -s svc:/application/print/ipp-listener:default
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico}
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# synchronize printers.conf with LP configuration changes
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicolp_config_sync_pconf() { # (pre) (post)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ADDED=$(${COMM} -13 ${1} ${2})
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico REMOVED=$(${COMM} -23 ${1} ${2})
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico lp_server=${server:-${HOST}}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico for DEST in ${ADDED} ; do
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico lp_uri="ipp://${lp_server}/printers/${DEST}"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico lp_bsdaddr="${lp_server},${DEST},Solaris"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ${LPSET} -n system \
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico -a "printer-uri-supported=${lp_uri}" \
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico -a "bsdaddr=${lp_bsdaddr}" \
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ${DEST} 2>/dev/null
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico done
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico for DEST in ${REMOVED} ; do
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ${LPSET} -n system -x ${DEST} 2>/dev/null
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico done
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# Delete all destinations in printers.conf
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicodelete_all() {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico for DEST in $(lpget -n system list | egrep -e '.+:$' | sed -e 's/://')
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico do
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ${LPSET} -n system -x ${DEST}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico status=$?
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico done
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico}
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Call the ppdmgr utility to add a new PPD file to the system.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# $1 - path to PPD file
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# $2 - label name (optional)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoadd_new_ppd_file() {
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico # Add new ppd file and echo full path it was actually saved to
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico ppdmgrcmd="${PFEXEC} ${PPDMGR} -a ${1} -w"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ppderrfile=/tmp/lpadminerror.$$
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ppd_file=$(${ppdmgrcmd} 2>${ppderrfile})
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ppdmgrrc=$?
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ -s "${ppderrfile}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico print -n "lpadmin: " 1>&2
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico cat ${ppderrfile} 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico rm -f ${ppderrfile} >/dev/null 2>&1
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ ${ppdmgrrc} -ne 0 ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico exit 1
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico fi
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico fi
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico rm -f ${ppderrfile} >/dev/null 2>&1
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico#
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# Execution begins here
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# be sure that we can run lpset and lpget
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoif [[ ! -x ${LPSET} || ! -x ${LPGET} ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext "lpadmin: System error; cannot set default printer\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico exit 2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicofi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicoif [[ $# -lt 1 ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico usage
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico exit 1
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicofi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Deal with the -d option independently since getopts does not handle
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# options that may or may not have arguments
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico#
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicoif [[ ${1} = "-d" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ $# -eq 1 ]] ; then # remove the "default"
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico ${LPGET} -n system _default >/dev/null 2>&1
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico exit_code=$?
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ ${exit_code} -eq 0 ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ${LPSET} -n system -x _default
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico exit_code=$?
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico else # no default, nothing to do
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico exit_code=0
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico elif [[ $# -eq 2 ]] ; then # add/change the "default"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ${LPGET} -k bsdaddr ${2} >/dev/null 2>&1
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico exit_code=$?
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ $exit_code -eq 0 ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ${LPSET} -n system -a "use=${2}" _default
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico exit_code=$?
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico else # can't set default to an unconfigured printer
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext "${2}: undefined printer\n" 1>&1
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico else # invalid usage
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico usage
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico exit 1
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico fi
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico exit ${exit_code}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicofi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Strip off legal options
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicowhile getopts "A:ac:D:e:f:F:H:hi:I:lm:Mn:o:p:Q:r:S:s:T:u:U:v:W:x:t:P:" arg
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicodo
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico case $arg in
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico D)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico description="${OPTARG}"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ;;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico n)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ppd_file="${OPTARG}"
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ;;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico p)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ -n "${delete}" ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico usage
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico printer=${OPTARG}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ;;
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico s)
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico server=${OPTARG}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ;;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico v|U)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico device=${OPTARG}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ ! -n "${server}" ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico server=${HOST}
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico fi
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico local="true"
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ;;
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico x)
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ -n "${printer}" || -n "${server}" || \
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico -n "${device}" || -n "${description}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico usage
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico delete=${OPTARG}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico printer=${OPTARG}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ ${printer} = "all" ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico local="true"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico fi
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ;;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico S|M|A)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico local="true"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ;;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico c)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico class=${OPTARG}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico local="true"
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ ! -f ${LPGET} ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico gettext "lpadmin: System error; cannot set class\n " 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico exit 2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ${LPGET} "${class}" > /dev/null 2>&1
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico lpget_class=$?
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ ${lpget_class} -eq 0 && ! -r /etc/lp/classes/"${class}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico gettext "lpadmin: ERROR: Can't create class ${class}.\n" 1>&2
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico gettext " TO FIX: This is an existing printer name;\n" 1>&2
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico gettext " choose another name.\n" 1>&2
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico exit 1
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico fi
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ;;
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico r)
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico local="true"
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ;;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico esac
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicodone
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# We don't have anything to do; let user know and bail
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicoif [[ ! -n "${printer}" && ! -n "${delete}" && ! -n "${local}" ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico gettext "lpadmin: ERROR: Nothing to do.\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " TO FIX: You must give one of these options:\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " -p, -d, -x -S\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico exit 1
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicofi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico#
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# Printer does not exist
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# To be consistent with 2.5, assume adding local printer
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico#
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicoif [[ ! -n "${device}" && ! -n "${server}" && ! -n "${delete}" && \
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ! -n "${local}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ${LPGET} "${printer}" > /dev/null 2>&1
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico lpget_stat=$?
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ ${lpget_stat} -ne 0 ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico gettext "lpadmin: ERROR: Missing -U or -v option.\n" 1>&2
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico gettext " TO FIX: Local printers must have\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " a port defined (-v option) or\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " have dial-out instructions (-U option).\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico exit 1
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicofi
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# process the "server" value
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# It can be a hostname, UUCP form (server!queue), RCMD form(queue@server),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# or in URI form ({scheme}://{endpoint})
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico#
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicocase "${server}" in
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *://*) # URI form
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico uri=${server}
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico rem_printer=$(expr "${server}" : ".*://.*/\([^/]*\)")
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico server=$(expr "${server}" : ".*://\([^/]*\)/.*")
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ;;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *@*) # RCMD form
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico rem_printer=$(expr "${server}" : "\(.*\)@.*")
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico server=$(expr "${server}" : ".*@\(.*\)")
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ;;
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico *!*) # UUCP form
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico rem_printer=$(expr "${server}" : ".*!\(.*\)")
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico server=$(expr "${server}" : "\(.*\)!.*")
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ;;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *) # hostname
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico rem_printer=${printer}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ;;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoesac
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# if there is a "device" or LP configuration, it's local
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoif [[ -n "${device}" || -f /etc/lp/printers/${printer}/configuration || \
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico -f /etc/lp/classes/${printer} ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico local="true"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicofi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Do the LP configuration for a local printer served by lpsched
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicoif [[ -x ${LPADMIN} && -n "${local}" ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico # enumerate LP configured printers before modification
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico PRE=/tmp/lpadmin-pre.$$
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico (/bin/ls /etc/lp/printers 2>/dev/null ; /bin/ls /etc/lp/classes \
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico 2>/dev/null) >${PRE}
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # if there are no printers configured, enable LP service(s)
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico [[ ! -s "${PRE}" ]] && lp_config_service enable
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # add filters to LP service
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico lp_config_filters
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico # add new ppd file to PPD file repositories
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ -n "${ppd_file}" && -x ${PPDMGR} ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico add_new_ppd_file "${ppd_file}"
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # modify LP destination(s)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico CMD="${PFEXEC} ${LPADMIN}"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico while [[ -n "$*" ]] ; do # to deal with multi-word arguments
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico CMD="$CMD \"$1\""
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico # replace the ppd_file originally specified with the -n option
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico # with the one returned from call to ppdmgr
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ "${1}" = "-n" ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico CMD="$CMD \"${ppd_file}\""
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico shift
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico shift
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico done
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico case "$CMD" in
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico *\"-D\")
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico CMD="$CMD \"\""
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ;;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico esac
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # execute the LP lpadmin command
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico eval $CMD
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico exit_code=$?
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # enumerate LP configured printers after modification
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico POST=/tmp/lpadmin-post.$$
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico (/bin/ls /etc/lp/printers 2>/dev/null ; /bin/ls /etc/lp/classes \
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico 2>/dev/null) >${POST}
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico # if there are no destinations, disable the service(s)
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico [[ ! -s "${POST}" ]] && lp_config_service disable
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # sync printers.conf with LP configuration
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico lp_config_sync_pconf "${PRE}" "${POST}"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /bin/rm -f ${PRE} ${POST}
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicofi
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Do any printers.conf configuration that is required
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoif [[ -n "${delete}" ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ "${delete}" = "all" ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico [[ $exit_code -eq 0 ]] && delete_all
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico elif [[ -z "${local}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ${LPSET} -n system -x ${delete}
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico exit_code=$?
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico fi
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoelse
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico if [[ -z "${local}" ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico # if we need a uri, find the "best" one.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ -z "${uri}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico uri="ipp://${server}/printers/${rem_printer}"
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ${LPSTAT} -p ${uri} >/dev/null 2>&1
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ $? -ne 0 ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico uri="lpd://${server}/printers/${rem_printer}#Solaris"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico fi
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # set the bsdaddr
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico bsdaddr="${server},${rem_printer},Solaris"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ -n "${printer}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ${LPSET} -n system \
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico -a "printer-uri-supported=${uri}" \
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico -a "bsdaddr=${bsdaddr}" ${printer}
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico exit_code=$?
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico fi
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico fi
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ -n "${printer}" && -n "${description}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ${LPSET} -n system \
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico -a "description=${description}" ${printer}
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico exit_code=$?
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico fi
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicofi
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# if the "default" doesn't resolve a "bsdaddr", the printer is gone, remove it
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico${LPGET} -n system -k bsdaddr _default >/dev/null 2>&1 ||
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ${LPSET} -n system -x _default >/dev/null 2>&1
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicoexit $exit_code
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico