xref: /onnv-gate/usr/src/cmd/print/scripts/lpadmin (revision 2264:b2b9267d002d)
10Sstevel@tonic-gate#!/bin/sh
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*2264Sjacobs# Common Development and Distribution License (the "License").
7*2264Sjacobs# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
220Sstevel@tonic-gate#
23*2264Sjacobs# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate# Use is subject to license terms.
250Sstevel@tonic-gate#
260Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate#
280Sstevel@tonic-gatePATH=/bin:/usr/bin:/usr/sbin export PATH
290Sstevel@tonic-gate
300Sstevel@tonic-gateTEXTDOMAIN="SUNW_OST_OSCMD"
310Sstevel@tonic-gateexport TEXTDOMAIN
320Sstevel@tonic-gate
330Sstevel@tonic-gateLPSET=/usr/bin/lpset
340Sstevel@tonic-gateLPGET=/usr/bin/lpget
350Sstevel@tonic-gate
360Sstevel@tonic-gateHOST=`/bin/uname -n`
37831SwendypLHOST="localhost"
380Sstevel@tonic-gatePID=$$
390Sstevel@tonic-gate
400Sstevel@tonic-gatecmd_name=lpadmin
410Sstevel@tonic-gateexit_code=0
420Sstevel@tonic-gate
430Sstevel@tonic-gateusage() {
440Sstevel@tonic-gate	gettext "Usage:\n" 1>&2
450Sstevel@tonic-gate	gettext "	lpadmin -p (printer) (options)\n" 1>&2
460Sstevel@tonic-gate	gettext "	lpadmin -x (dest)\n" 1>&2
470Sstevel@tonic-gate	gettext "	lpadmin -d (dest)\n" 1>&2
480Sstevel@tonic-gate	gettext "	lpadmin -S print-wheel -A alert-type [ -W minutes ]\n" 1>&2
490Sstevel@tonic-gate	gettext "		[ -Q requests ]\n" 1>&2
500Sstevel@tonic-gate	gettext "	lpadmin -M -f form-name [ -a [ -o filebreak ]\n" 1>&2
510Sstevel@tonic-gate	gettext "		[ -t tray-number ]]\n" 1>&2
520Sstevel@tonic-gate	exit 1
530Sstevel@tonic-gate}
540Sstevel@tonic-gate
550Sstevel@tonic-gate#
560Sstevel@tonic-gate# Delete entries in /etc/printers.conf for local printers/classes that no longer
570Sstevel@tonic-gate# exist in the /etc/lp database
580Sstevel@tonic-gate#
590Sstevel@tonic-gate
600Sstevel@tonic-gatedelete_local() {
610Sstevel@tonic-gate
620Sstevel@tonic-gate# Get printer names for each local printer
630Sstevel@tonic-gate# grep /etc/printers.conf for each bsdaddr for this server
640Sstevel@tonic-gate# get printer name from that line
650Sstevel@tonic-gate
66831Swendypfor LINE in `/bin/grep bsdaddr /etc/printers.conf |
67831Swendyp	/bin/egrep -e ${HOST}\|${LHOST}`
680Sstevel@tonic-gatedo
69831Swendyp        PRINTER=`echo ${LINE} | /bin/sed -e 's/^:bsdaddr='$LHOST',//' \
70831Swendyp		-e 's/^:bsdaddr='$HOST',//' \
71831Swendyp		-e 's/[,:].*//'`
720Sstevel@tonic-gate
730Sstevel@tonic-gate# If there is not an entry for this printer in
740Sstevel@tonic-gate#       /etc/lp/printers or /etc/lp/classes
750Sstevel@tonic-gate# Then delete the entry for this printer in /etc/printers.conf
760Sstevel@tonic-gate
770Sstevel@tonic-gate        if [ ! -d /etc/lp/printers/${PRINTER} -a ! -f /etc/lp/classes/${PRINTER} ] ;
780Sstevel@tonic-gate        then
790Sstevel@tonic-gate                logger -p lpr.debug -t "lpadmin[${PID}]" \
800Sstevel@tonic-gate                         "Removing $PRINTER entry from /etc/printers.conf"
810Sstevel@tonic-gate                ${LPSET} -x ${PRINTER}
820Sstevel@tonic-gate                status=$?
830Sstevel@tonic-gate
840Sstevel@tonic-gate                if [ ${status} -ne 0 ] ; then
850Sstevel@tonic-gate                        gettext "Warning: error removing ${PRINTER} " 1>&2
860Sstevel@tonic-gate			gettext "entry from /etc/printers.conf\n" 1>&2
870Sstevel@tonic-gate                        logger -p lpr.debug -t "lpadmin[${PID}]" \
880Sstevel@tonic-gate				"Call to lpset -x $PRINTER exits with ${status}"
890Sstevel@tonic-gate			exit_code=1
900Sstevel@tonic-gate                fi
910Sstevel@tonic-gate        fi
920Sstevel@tonic-gatedone
930Sstevel@tonic-gate
940Sstevel@tonic-gate#
950Sstevel@tonic-gate# shutdown scheduler if there are no local printers
960Sstevel@tonic-gate#
970Sstevel@tonic-gateCONFIGS=/etc/lp/printers/*/configuration
980Sstevel@tonic-gate
990Sstevel@tonic-gateprinters_configured=`echo $CONFIGS`
1000Sstevel@tonic-gateif [ "$printers_configured" = "$CONFIGS" ]; then
1010Sstevel@tonic-gate	svcprop -q svc:/application/print/server:default &&
1020Sstevel@tonic-gate		svcadm disable svc:/application/print/server:default
1030Sstevel@tonic-gatefi
1040Sstevel@tonic-gate}
1050Sstevel@tonic-gate
1060Sstevel@tonic-gatedelete_entries() {
1070Sstevel@tonic-gateif [ ! -f /etc/printers.conf ] ; then
1080Sstevel@tonic-gate        logger -p lpr.debug -t "lpadmin[${PID}]" \
1090Sstevel@tonic-gate		"System error: Cannot access /etc/printers.conf"
1100Sstevel@tonic-gate        gettext "lpadmin: System error; Cannot access /etc/printers.conf\n" 1>&2
1110Sstevel@tonic-gate        exit 1
1120Sstevel@tonic-gatefi
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate# remove _default
1150Sstevel@tonic-gate
116831SwendypDEFAULTP=`${LPGET} _default | /bin/grep use | /bin/sed -e 's/[    ]*use=//'`
1170Sstevel@tonic-gate${LPGET} -k bsdaddr ${DEFAULTP} >/dev/null 2>&1
1180Sstevel@tonic-gatestatus=$?
1190Sstevel@tonic-gate
1200Sstevel@tonic-gateif [ ${status} -eq 0 ] ; then
1210Sstevel@tonic-gate	${LPSET} -x _default
1220Sstevel@tonic-gate	status=$?
1230Sstevel@tonic-gate	if [ ${status} -ne 0 ] ; then
1240Sstevel@tonic-gate		gettext "Warning: error removing _default entry from /etc/printers.conf\n" 1>&2
1250Sstevel@tonic-gate		logger -p lpr.debug -t "lpadmin[${PID}]" \
1260Sstevel@tonic-gate			"Call to lpset -x _default exits with ${status}"
1270Sstevel@tonic-gate		exit_code=1
1280Sstevel@tonic-gate	fi
1290Sstevel@tonic-gatefi
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate# delete entries in /etc/printers.conf for printers/classes that have
1320Sstevel@tonic-gate# been deleted
1330Sstevel@tonic-gate
1340Sstevel@tonic-gatedelete_local
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate# Delete all the remote printers using bsdaddr
1370Sstevel@tonic-gate
138831Swendypfor LINE in `/bin/grep bsdaddr /etc/printers.conf | /bin/egrep -v -e ${HOST}\|${LHOST}`
1390Sstevel@tonic-gatedo
140831Swendyp        PRINTER=`echo $LINE | /bin/sed -e 's/^:bsdaddr=[^,]*,//' -e 's/[,:].*//'`
1410Sstevel@tonic-gate        ${LPSET} -x $PRINTER
1420Sstevel@tonic-gate	status=$?
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate	if [ ${status} -ne 0 ] ; then
1450Sstevel@tonic-gate		gettext "Warning: error removing ${PRINTER} entry from /etc/printers.conf\n" 1>&2
1460Sstevel@tonic-gate		logger -p lpr.debug -t "lpadmin[${PID}]" \
1470Sstevel@tonic-gate			"Call to lpset -x $PRINTER exits with ${status}"
1480Sstevel@tonic-gate		exit_code=1
1490Sstevel@tonic-gate	fi
1500Sstevel@tonic-gatedone
1510Sstevel@tonic-gate}
1520Sstevel@tonic-gate
1530Sstevel@tonic-gateif [ $# -lt 1 ] ; then
1540Sstevel@tonic-gate	usage
1550Sstevel@tonic-gate	exit 1
1560Sstevel@tonic-gatefi
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate# Deal with the -d option independently since getopts does not handle
1590Sstevel@tonic-gate# options that may or may not have arguments
1600Sstevel@tonic-gate#
1610Sstevel@tonic-gatefirst=$1
1620Sstevel@tonic-gatesecond=$2
1630Sstevel@tonic-gatethird=$3
1640Sstevel@tonic-gate
1650Sstevel@tonic-gateif [ ${first} = "-d" ] ; then
1660Sstevel@tonic-gate	# check that there are no extra arguments
1670Sstevel@tonic-gate	if [ -n "${third}" ] ; then
1680Sstevel@tonic-gate		usage
1690Sstevel@tonic-gate		exit 1
1700Sstevel@tonic-gate	fi
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate	# be sure we have lpset and lpget
1740Sstevel@tonic-gate	if [ ! -f ${LPSET} -o ! -f ${LPGET} ] ; then
1750Sstevel@tonic-gate		gettext "lpadmin: System error; cannot set default printer\n" 1>&2
1760Sstevel@tonic-gate		exit 2
1770Sstevel@tonic-gate	fi
1780Sstevel@tonic-gate
1790Sstevel@tonic-gate	if [ ! -n "${second}" ] ; then
1800Sstevel@tonic-gate		${LPGET} -n system _default >/dev/null 2>&1
1810Sstevel@tonic-gate		exit_code=$?
1820Sstevel@tonic-gate		if [ ${exit_code} -eq 0 ] ; then
1830Sstevel@tonic-gate			# delete _default entry in /etc/printers.conf
1840Sstevel@tonic-gate			${LPSET} -n system -x _default
1850Sstevel@tonic-gate			exit_code=$?
1860Sstevel@tonic-gate			if [ ${exit_code} -ne 0 ] ; then
1870Sstevel@tonic-gate				gettext "lpadmin: System error while trying to delete default printer\n" 1>&2
1880Sstevel@tonic-gate			fi
1890Sstevel@tonic-gate		else
1900Sstevel@tonic-gate			# there was no _default, the work is done
1910Sstevel@tonic-gate			exit_code=0
1920Sstevel@tonic-gate		fi
1930Sstevel@tonic-gate	else
1940Sstevel@tonic-gate		# add/change  _default entry in /etc/printers.conf
1950Sstevel@tonic-gate		${LPGET} -k bsdaddr ${second} >/dev/null 2>&1
1960Sstevel@tonic-gate		exit_code=$?
1970Sstevel@tonic-gate		if [ $exit_code -eq 0 ] ; then
1980Sstevel@tonic-gate			${LPSET} -n system -a use=${second} _default
1990Sstevel@tonic-gate			exit_code=$?
2000Sstevel@tonic-gate		else
2010Sstevel@tonic-gate			echo "${second}: " 1>&2
2020Sstevel@tonic-gate			gettext "undefined printer\n" 1>&2
2030Sstevel@tonic-gate		fi
2040Sstevel@tonic-gate
2050Sstevel@tonic-gate	fi
2060Sstevel@tonic-gate	exit ${exit_code}
2070Sstevel@tonic-gatefi
2080Sstevel@tonic-gate
2090Sstevel@tonic-gate#		Strip off legal options
2100Sstevel@tonic-gatewhile 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
2110Sstevel@tonic-gatedo
2120Sstevel@tonic-gate	case $arg in
2130Sstevel@tonic-gate	D)
2140Sstevel@tonic-gate		description="${OPTARG}"
2150Sstevel@tonic-gate	;;
2160Sstevel@tonic-gate	p)
2170Sstevel@tonic-gate		if [ -n "${delete}" ] ; then
2180Sstevel@tonic-gate			usage
2190Sstevel@tonic-gate		fi
2200Sstevel@tonic-gate		printer=${OPTARG}
2210Sstevel@tonic-gate	;;
2220Sstevel@tonic-gate	s)
2230Sstevel@tonic-gate		server=${OPTARG}
2240Sstevel@tonic-gate	;;
2250Sstevel@tonic-gate	v|U)
2260Sstevel@tonic-gate		device=${OPTARG}
227831Swendyp		if [ ! -n "${server}" ] ; then
228831Swendyp			server=${HOST}
229831Swendyp		fi
2300Sstevel@tonic-gate	;;
2310Sstevel@tonic-gate	x)
2320Sstevel@tonic-gate		if [ -n "${printer}" -o -n "${server}" -o \
2330Sstevel@tonic-gate		     -n "${device}" -o -n "${description}" ] ; then
2340Sstevel@tonic-gate			usage
2350Sstevel@tonic-gate		fi
2360Sstevel@tonic-gate		delete=${OPTARG}
2370Sstevel@tonic-gate		printer=${OPTARG}
2380Sstevel@tonic-gate		if [ ${printer} = "all" ] ; then
2390Sstevel@tonic-gate			local="true"
2400Sstevel@tonic-gate		fi
2410Sstevel@tonic-gate	;;
2420Sstevel@tonic-gate	S|M|A)
2430Sstevel@tonic-gate		local="true"
2440Sstevel@tonic-gate	;;
2450Sstevel@tonic-gate	c)
2460Sstevel@tonic-gate		class=${OPTARG}
2470Sstevel@tonic-gate		local="true"
2480Sstevel@tonic-gate		if [ ! -f ${LPGET} ] ; then
2490Sstevel@tonic-gate			gettext "lpadmin: System error; cannot set class\n " 1>&2
2500Sstevel@tonic-gate			exit 2
2510Sstevel@tonic-gate		fi
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate		${LPGET} "${class}" > /dev/null 2>&1
2540Sstevel@tonic-gate		lpget_class=$?
2550Sstevel@tonic-gate		if [ ${lpget_class} -eq 0 -a ! -r /etc/lp/classes/"${class}" ] ; then
2560Sstevel@tonic-gate			gettext "lpadmin: ERROR: Can't create class ${class}.\n" 1>&2
2570Sstevel@tonic-gate			gettext "           TO FIX: This is an existing printer name;\n" 1>&2
2580Sstevel@tonic-gate			gettext "                   choose another name.\n" 1>&2
2590Sstevel@tonic-gate			exit 1
2600Sstevel@tonic-gate		fi
2610Sstevel@tonic-gate	;;
2620Sstevel@tonic-gate	r)
2630Sstevel@tonic-gate		pconflocalclean="true"
2640Sstevel@tonic-gate		local="true"
2650Sstevel@tonic-gate	;;
2660Sstevel@tonic-gate	esac
2670Sstevel@tonic-gatedone
2680Sstevel@tonic-gate
2690Sstevel@tonic-gate#
2700Sstevel@tonic-gate# We don't have anything to do; let user know and bail
2710Sstevel@tonic-gate#
2720Sstevel@tonic-gateif [ ! -n "${printer}" -a ! -n "${delete}" -a ! -n "${local}" ] ; then
2730Sstevel@tonic-gate	gettext "lpadmin: ERROR: Nothing to do.\n" 1>&2
2740Sstevel@tonic-gate	gettext "        TO FIX: You must give one of these options:\n" 1>&2
2750Sstevel@tonic-gate	gettext "		      -p, -d, -x -S\n" 1>&2
2760Sstevel@tonic-gate	exit 1
2770Sstevel@tonic-gatefi
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate#
2800Sstevel@tonic-gate#       Printer does not exist
2810Sstevel@tonic-gate#       To be consistent with 2.5, assume adding local printer
2820Sstevel@tonic-gate#
2830Sstevel@tonic-gateif [ ! -n "${device}" -a ! -n "${server}" -a ! -n "${delete}" \
2840Sstevel@tonic-gate					 -a ! -n "${local}" ] ; then
2850Sstevel@tonic-gate	${LPGET} "${printer}" > /dev/null 2>&1
2860Sstevel@tonic-gate	lpget_stat=$?
2870Sstevel@tonic-gate	if [ ${lpget_stat} -ne 0 ] ; then
2880Sstevel@tonic-gate		gettext "lpadmin: ERROR: Missing -U or -v option.\n" 1>&2
2890Sstevel@tonic-gate		gettext "           TO FIX: Local printers must have\n" 1>&2
2900Sstevel@tonic-gate		gettext "                   a port defined (-v option) or\n" 1>&2
2910Sstevel@tonic-gate		gettext "                   have dial-out instructions (-U option).\n" 1>&2
2920Sstevel@tonic-gate		exit 1
2930Sstevel@tonic-gate	fi
2940Sstevel@tonic-gatefi
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate#
2970Sstevel@tonic-gate#	Do the LP configuration for a local printer served by lpsched
2980Sstevel@tonic-gate#
2990Sstevel@tonic-gateif [ -f /usr/lib/lp/local/$cmd_name ] ; then
3000Sstevel@tonic-gate	if [ -f /etc/lp/printers/${printer}/configuration -o -n "${device}" -o \
3010Sstevel@tonic-gate	     -f /etc/lp/classes/${printer} -o -n "${local}" ] ; then
3020Sstevel@tonic-gate		# to deal with multi-word arguments
3030Sstevel@tonic-gate		CMD="/usr/lib/lp/local/$cmd_name"
3040Sstevel@tonic-gate		while [ -n "$*" ] ; do
3050Sstevel@tonic-gate			CMD="$CMD \"$1\""
3060Sstevel@tonic-gate			shift
3070Sstevel@tonic-gate		done
3080Sstevel@tonic-gate		case "$CMD" in
3090Sstevel@tonic-gate			*\"-D\")
3100Sstevel@tonic-gate				CMD="$CMD \"\""
3110Sstevel@tonic-gate			;;
3120Sstevel@tonic-gate		esac
3130Sstevel@tonic-gate		# if adding a printer, make sure scheduler is running
3140Sstevel@tonic-gate		if [ -n "${printer}" -a ! -n "${delete}" -a \
3150Sstevel@tonic-gate		    ! -p /var/spool/lp/fifos/FIFO ]; then
316831Swendyp			svcadm enable -s svc:/application/print/server:default
3170Sstevel@tonic-gate		fi
3180Sstevel@tonic-gate		eval $CMD
3190Sstevel@tonic-gate		exit_code=$?
320*2264Sjacobs		# add filters to the print server
321*2264Sjacobs		if [ ! -f /etc/lp/filter.table ] ; then
322*2264Sjacobs			cd /etc/lp/fd ; for filter in *.fd ; do
323*2264Sjacobs				/usr/sbin/lpfilter \
324*2264Sjacobs					-f `/usr/bin/basename $filter .fd` \
325*2264Sjacobs					-F $filter
326*2264Sjacobs			done
327*2264Sjacobs		fi
3280Sstevel@tonic-gate	fi
3290Sstevel@tonic-gatefi
3300Sstevel@tonic-gate
3310Sstevel@tonic-gateif [ $exit_code != 0 ] ; then
3320Sstevel@tonic-gate	exit $exit_code
3330Sstevel@tonic-gatefi
3340Sstevel@tonic-gate
335*2264Sjacobs#	process the "server" value
336*2264Sjacobs#	It can be a hostname, UUCP form (server!queue), RCMD form(queue@server),
337*2264Sjacobs#	or in URI form ({scheme}://{endpoint})
338*2264Sjacobs#
339*2264Sjacobscase "${server}" in
340*2264Sjacobs	*://*)	# URI form
341*2264Sjacobs		uri=${server}
342*2264Sjacobs		rem_printer=`expr "${server}" : ".*://.*/\([^/]*\)"`
343*2264Sjacobs		server=`expr "${server}" : ".*://\([^/]*\)/.*"`
344*2264Sjacobs		;;
345*2264Sjacobs	*@*)	# RCMD form
346*2264Sjacobs		rem_printer=`expr "${server}" : "\(.*\)@.*"`
347*2264Sjacobs		server=`expr "${server}" : ".*@\(.*\)"`
348*2264Sjacobs		;;
349*2264Sjacobs	*!*)	# UUCP form
350*2264Sjacobs		rem_printer=`expr "${server}" : ".*!\(.*\)"`
351*2264Sjacobs		server=`expr "${server}" : "\(.*\)!.*"`
352*2264Sjacobs		;;
353*2264Sjacobs	*)	# hostname
354*2264Sjacobs		rem_printer=${printer}
355*2264Sjacobs		;;
356*2264Sjacobsesac
357*2264Sjacobs# default URI form is "lpd" form
3580Sstevel@tonic-gateif [ -n "${server}" ] ; then
359*2264Sjacobs	uri=${uri:-"lpd://${server}/printers/${rem_printer}#Solaris"}
360*2264Sjacobs	bsdaddr="${server},${rem_printer},Solaris"
3610Sstevel@tonic-gatefi
3620Sstevel@tonic-gate
3630Sstevel@tonic-gate#
3640Sstevel@tonic-gate#	Do the Solstice Print Configuration in /etc
3650Sstevel@tonic-gate#
3660Sstevel@tonic-gateif [ ! -f ${LPSET} -o ! -f ${LPGET} ] ; then
3670Sstevel@tonic-gate	exit_code=2
3680Sstevel@tonic-gateelse
3690Sstevel@tonic-gate	if [ -n "${delete}" ] ; then
3700Sstevel@tonic-gate		if [ "${delete}" = "all" ] ; then
3710Sstevel@tonic-gate			delete_entries
3720Sstevel@tonic-gate   		else
3730Sstevel@tonic-gate   			${LPSET} -n system -x ${delete}
3740Sstevel@tonic-gate   			exit_code=$?
3750Sstevel@tonic-gate			delete_local
3760Sstevel@tonic-gate   		fi
3770Sstevel@tonic-gate	fi
3780Sstevel@tonic-gate
379*2264Sjacobs	if [ -n "${printer}" -a -n "${uri}" ] ; then
380*2264Sjacobs		${LPSET} -n system -a "printer-uri-supported=${uri}" ${printer}
381*2264Sjacobs		exit_code=$?
382*2264Sjacobs	fi
383*2264Sjacobs	if [ -n "${printer}" -a -n "${bsdaddr}" ] ; then
384*2264Sjacobs		${LPSET} -n system -a "bsdaddr=${bsdaddr}" ${printer}
3850Sstevel@tonic-gate		exit_code=$?
3860Sstevel@tonic-gate	fi
3870Sstevel@tonic-gate	if [ -n "${printer}" -a -n "${description}" ] ; then
3880Sstevel@tonic-gate		${LPSET} -n system -a "description=${description}" ${printer}
3890Sstevel@tonic-gate		exit_code=$?
3900Sstevel@tonic-gate	fi
3910Sstevel@tonic-gate
3920Sstevel@tonic-gate#	Add class for local printers only
3930Sstevel@tonic-gate
3940Sstevel@tonic-gate	if [ -n "${class}" -a -n "${printer}" \
3950Sstevel@tonic-gate		-a -f /etc/lp/printers/${printer}/configuration ] ; then
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate		${LPGET} "${class}" > /dev/null 2>&1
3980Sstevel@tonic-gate		lpget_class=$?
3990Sstevel@tonic-gate
4000Sstevel@tonic-gate#		If the class doesn't already exist in printers.conf, add it.
4010Sstevel@tonic-gate
402*2264Sjacobs		server=${server:-$HOST}
403*2264Sjacobs		uri="lpd://${server}/printers/${class}#Solaris"
404*2264Sjacobs		bsdaddr="${server},${class},Solaris"
4050Sstevel@tonic-gate		if [ ${lpget_class} -ne 0 ] ; then
4060Sstevel@tonic-gate			${LPSET} -n system \
407*2264Sjacobs				-a "printer-uri-supported=${uri}" \
408*2264Sjacobs				-a "bsdaddr=${bsdaddr}" \
409*2264Sjacobs				${class}
4100Sstevel@tonic-gate			exit_code=$?
4110Sstevel@tonic-gate		fi
4120Sstevel@tonic-gate	fi
4130Sstevel@tonic-gatefi
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate# /usr/lib/lp/local/lpadmin has changed the database. This cleans up cruft in the
4160Sstevel@tonic-gate# /etc/printers.conf file that refers to deleted objects.
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate	if [ -n "${pconflocalclean}" ] ; then
4190Sstevel@tonic-gate		delete_local
4200Sstevel@tonic-gate	fi
4210Sstevel@tonic-gate
4220Sstevel@tonic-gateexit $exit_code
423