xref: /illumos-gate/usr/src/cmd/print/scripts/lpadmin (revision 5c88ba20fc79ecf19255b4a04f03d77630b6d0e7)
17c478bd9Sstevel@tonic-gate#!/bin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
67c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
77c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
87c478bd9Sstevel@tonic-gate# with the License.
97c478bd9Sstevel@tonic-gate#
107c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
117c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
127c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
137c478bd9Sstevel@tonic-gate# and limitations under the License.
147c478bd9Sstevel@tonic-gate#
157c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
167c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
177c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
187c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
197c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
207c478bd9Sstevel@tonic-gate#
217c478bd9Sstevel@tonic-gate# CDDL HEADER END
227c478bd9Sstevel@tonic-gate#
237c478bd9Sstevel@tonic-gate#
24*5c88ba20Swendyp# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gatePATH=/bin:/usr/bin:/usr/sbin export PATH
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gateTEXTDOMAIN="SUNW_OST_OSCMD"
327c478bd9Sstevel@tonic-gateexport TEXTDOMAIN
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gateLPSET=/usr/bin/lpset
357c478bd9Sstevel@tonic-gateLPGET=/usr/bin/lpget
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gateHOST=`/bin/uname -n`
38*5c88ba20SwendypLHOST="localhost"
397c478bd9Sstevel@tonic-gatePID=$$
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gatecmd_name=lpadmin
427c478bd9Sstevel@tonic-gateexit_code=0
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gateusage() {
457c478bd9Sstevel@tonic-gate	gettext "Usage:\n" 1>&2
467c478bd9Sstevel@tonic-gate	gettext "	lpadmin -p (printer) (options)\n" 1>&2
477c478bd9Sstevel@tonic-gate	gettext "	lpadmin -x (dest)\n" 1>&2
487c478bd9Sstevel@tonic-gate	gettext "	lpadmin -d (dest)\n" 1>&2
497c478bd9Sstevel@tonic-gate	gettext "	lpadmin -S print-wheel -A alert-type [ -W minutes ]\n" 1>&2
507c478bd9Sstevel@tonic-gate	gettext "		[ -Q requests ]\n" 1>&2
517c478bd9Sstevel@tonic-gate	gettext "	lpadmin -M -f form-name [ -a [ -o filebreak ]\n" 1>&2
527c478bd9Sstevel@tonic-gate	gettext "		[ -t tray-number ]]\n" 1>&2
537c478bd9Sstevel@tonic-gate	exit 1
547c478bd9Sstevel@tonic-gate}
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate#
577c478bd9Sstevel@tonic-gate# Delete entries in /etc/printers.conf for local printers/classes that no longer
587c478bd9Sstevel@tonic-gate# exist in the /etc/lp database
597c478bd9Sstevel@tonic-gate#
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gatedelete_local() {
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate# Get printer names for each local printer
647c478bd9Sstevel@tonic-gate# grep /etc/printers.conf for each bsdaddr for this server
657c478bd9Sstevel@tonic-gate# get printer name from that line
667c478bd9Sstevel@tonic-gate
67*5c88ba20Swendypfor LINE in `/bin/grep bsdaddr /etc/printers.conf |
68*5c88ba20Swendyp	/bin/egrep -e ${HOST}\|${LHOST}`
697c478bd9Sstevel@tonic-gatedo
70*5c88ba20Swendyp        PRINTER=`echo ${LINE} | /bin/sed -e 's/^:bsdaddr='$LHOST',//' \
71*5c88ba20Swendyp		-e 's/^:bsdaddr='$HOST',//' \
72*5c88ba20Swendyp		-e 's/[,:].*//'`
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate# If there is not an entry for this printer in
757c478bd9Sstevel@tonic-gate#       /etc/lp/printers or /etc/lp/classes
767c478bd9Sstevel@tonic-gate# Then delete the entry for this printer in /etc/printers.conf
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate        if [ ! -d /etc/lp/printers/${PRINTER} -a ! -f /etc/lp/classes/${PRINTER} ] ;
797c478bd9Sstevel@tonic-gate        then
807c478bd9Sstevel@tonic-gate                logger -p lpr.debug -t "lpadmin[${PID}]" \
817c478bd9Sstevel@tonic-gate                         "Removing $PRINTER entry from /etc/printers.conf"
827c478bd9Sstevel@tonic-gate                ${LPSET} -x ${PRINTER}
837c478bd9Sstevel@tonic-gate                status=$?
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate                if [ ${status} -ne 0 ] ; then
867c478bd9Sstevel@tonic-gate                        gettext "Warning: error removing ${PRINTER} " 1>&2
877c478bd9Sstevel@tonic-gate			gettext "entry from /etc/printers.conf\n" 1>&2
887c478bd9Sstevel@tonic-gate                        logger -p lpr.debug -t "lpadmin[${PID}]" \
897c478bd9Sstevel@tonic-gate				"Call to lpset -x $PRINTER exits with ${status}"
907c478bd9Sstevel@tonic-gate			exit_code=1
917c478bd9Sstevel@tonic-gate                fi
927c478bd9Sstevel@tonic-gate        fi
937c478bd9Sstevel@tonic-gatedone
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate#
967c478bd9Sstevel@tonic-gate# shutdown scheduler if there are no local printers
977c478bd9Sstevel@tonic-gate#
987c478bd9Sstevel@tonic-gateCONFIGS=/etc/lp/printers/*/configuration
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gateprinters_configured=`echo $CONFIGS`
1017c478bd9Sstevel@tonic-gateif [ "$printers_configured" = "$CONFIGS" ]; then
1027c478bd9Sstevel@tonic-gate	svcprop -q svc:/application/print/server:default &&
1037c478bd9Sstevel@tonic-gate		svcadm disable svc:/application/print/server:default
1047c478bd9Sstevel@tonic-gatefi
1057c478bd9Sstevel@tonic-gate}
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gatedelete_entries() {
1087c478bd9Sstevel@tonic-gateif [ ! -f /etc/printers.conf ] ; then
1097c478bd9Sstevel@tonic-gate        logger -p lpr.debug -t "lpadmin[${PID}]" \
1107c478bd9Sstevel@tonic-gate		"System error: Cannot access /etc/printers.conf"
1117c478bd9Sstevel@tonic-gate        gettext "lpadmin: System error; Cannot access /etc/printers.conf\n" 1>&2
1127c478bd9Sstevel@tonic-gate        exit 1
1137c478bd9Sstevel@tonic-gatefi
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate# remove _default
1167c478bd9Sstevel@tonic-gate
117*5c88ba20SwendypDEFAULTP=`${LPGET} _default | /bin/grep use | /bin/sed -e 's/[    ]*use=//'`
1187c478bd9Sstevel@tonic-gate${LPGET} -k bsdaddr ${DEFAULTP} >/dev/null 2>&1
1197c478bd9Sstevel@tonic-gatestatus=$?
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gateif [ ${status} -eq 0 ] ; then
1227c478bd9Sstevel@tonic-gate	${LPSET} -x _default
1237c478bd9Sstevel@tonic-gate	status=$?
1247c478bd9Sstevel@tonic-gate	if [ ${status} -ne 0 ] ; then
1257c478bd9Sstevel@tonic-gate		gettext "Warning: error removing _default entry from /etc/printers.conf\n" 1>&2
1267c478bd9Sstevel@tonic-gate		logger -p lpr.debug -t "lpadmin[${PID}]" \
1277c478bd9Sstevel@tonic-gate			"Call to lpset -x _default exits with ${status}"
1287c478bd9Sstevel@tonic-gate		exit_code=1
1297c478bd9Sstevel@tonic-gate	fi
1307c478bd9Sstevel@tonic-gatefi
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate# delete entries in /etc/printers.conf for printers/classes that have
1337c478bd9Sstevel@tonic-gate# been deleted
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gatedelete_local
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate# Delete all the remote printers using bsdaddr
1387c478bd9Sstevel@tonic-gate
139*5c88ba20Swendypfor LINE in `/bin/grep bsdaddr /etc/printers.conf | /bin/egrep -v -e ${HOST}\|${LHOST}`
1407c478bd9Sstevel@tonic-gatedo
141*5c88ba20Swendyp        PRINTER=`echo $LINE | /bin/sed -e 's/^:bsdaddr=[^,]*,//' -e 's/[,:].*//'`
1427c478bd9Sstevel@tonic-gate        ${LPSET} -x $PRINTER
1437c478bd9Sstevel@tonic-gate	status=$?
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate	if [ ${status} -ne 0 ] ; then
1467c478bd9Sstevel@tonic-gate		gettext "Warning: error removing ${PRINTER} entry from /etc/printers.conf\n" 1>&2
1477c478bd9Sstevel@tonic-gate		logger -p lpr.debug -t "lpadmin[${PID}]" \
1487c478bd9Sstevel@tonic-gate			"Call to lpset -x $PRINTER exits with ${status}"
1497c478bd9Sstevel@tonic-gate		exit_code=1
1507c478bd9Sstevel@tonic-gate	fi
1517c478bd9Sstevel@tonic-gatedone
1527c478bd9Sstevel@tonic-gate}
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gateif [ $# -lt 1 ] ; then
1557c478bd9Sstevel@tonic-gate	usage
1567c478bd9Sstevel@tonic-gate	exit 1
1577c478bd9Sstevel@tonic-gatefi
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate# Deal with the -d option independently since getopts does not handle
1607c478bd9Sstevel@tonic-gate# options that may or may not have arguments
1617c478bd9Sstevel@tonic-gate#
1627c478bd9Sstevel@tonic-gatefirst=$1
1637c478bd9Sstevel@tonic-gatesecond=$2
1647c478bd9Sstevel@tonic-gatethird=$3
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gateif [ ${first} = "-d" ] ; then
1677c478bd9Sstevel@tonic-gate	# check that there are no extra arguments
1687c478bd9Sstevel@tonic-gate	if [ -n "${third}" ] ; then
1697c478bd9Sstevel@tonic-gate		usage
1707c478bd9Sstevel@tonic-gate		exit 1
1717c478bd9Sstevel@tonic-gate	fi
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate	# be sure we have lpset and lpget
1757c478bd9Sstevel@tonic-gate	if [ ! -f ${LPSET} -o ! -f ${LPGET} ] ; then
1767c478bd9Sstevel@tonic-gate		gettext "lpadmin: System error; cannot set default printer\n" 1>&2
1777c478bd9Sstevel@tonic-gate		exit 2
1787c478bd9Sstevel@tonic-gate	fi
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate	if [ ! -n "${second}" ] ; then
1817c478bd9Sstevel@tonic-gate		${LPGET} -n system _default >/dev/null 2>&1
1827c478bd9Sstevel@tonic-gate		exit_code=$?
1837c478bd9Sstevel@tonic-gate		if [ ${exit_code} -eq 0 ] ; then
1847c478bd9Sstevel@tonic-gate			# delete _default entry in /etc/printers.conf
1857c478bd9Sstevel@tonic-gate			${LPSET} -n system -x _default
1867c478bd9Sstevel@tonic-gate			exit_code=$?
1877c478bd9Sstevel@tonic-gate			if [ ${exit_code} -ne 0 ] ; then
1887c478bd9Sstevel@tonic-gate				gettext "lpadmin: System error while trying to delete default printer\n" 1>&2
1897c478bd9Sstevel@tonic-gate			fi
1907c478bd9Sstevel@tonic-gate		else
1917c478bd9Sstevel@tonic-gate			# there was no _default, the work is done
1927c478bd9Sstevel@tonic-gate			exit_code=0
1937c478bd9Sstevel@tonic-gate		fi
1947c478bd9Sstevel@tonic-gate	else
1957c478bd9Sstevel@tonic-gate		# add/change  _default entry in /etc/printers.conf
1967c478bd9Sstevel@tonic-gate		${LPGET} -k bsdaddr ${second} >/dev/null 2>&1
1977c478bd9Sstevel@tonic-gate		exit_code=$?
1987c478bd9Sstevel@tonic-gate		if [ $exit_code -eq 0 ] ; then
1997c478bd9Sstevel@tonic-gate			${LPSET} -n system -a use=${second} _default
2007c478bd9Sstevel@tonic-gate			exit_code=$?
2017c478bd9Sstevel@tonic-gate		else
2027c478bd9Sstevel@tonic-gate			echo "${second}: " 1>&2
2037c478bd9Sstevel@tonic-gate			gettext "undefined printer\n" 1>&2
2047c478bd9Sstevel@tonic-gate		fi
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate	fi
2077c478bd9Sstevel@tonic-gate	exit ${exit_code}
2087c478bd9Sstevel@tonic-gatefi
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate#		Strip off legal options
2117c478bd9Sstevel@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
2127c478bd9Sstevel@tonic-gatedo
2137c478bd9Sstevel@tonic-gate	case $arg in
2147c478bd9Sstevel@tonic-gate	D)
2157c478bd9Sstevel@tonic-gate		description="${OPTARG}"
2167c478bd9Sstevel@tonic-gate	;;
2177c478bd9Sstevel@tonic-gate	p)
2187c478bd9Sstevel@tonic-gate		if [ -n "${delete}" ] ; then
2197c478bd9Sstevel@tonic-gate			usage
2207c478bd9Sstevel@tonic-gate		fi
2217c478bd9Sstevel@tonic-gate		printer=${OPTARG}
2227c478bd9Sstevel@tonic-gate	;;
2237c478bd9Sstevel@tonic-gate	s)
2247c478bd9Sstevel@tonic-gate		server=${OPTARG}
2257c478bd9Sstevel@tonic-gate	;;
2267c478bd9Sstevel@tonic-gate	v|U)
2277c478bd9Sstevel@tonic-gate		device=${OPTARG}
228*5c88ba20Swendyp		if [ ! -n "${server}" ] ; then
229*5c88ba20Swendyp			server=${HOST}
230*5c88ba20Swendyp		fi
2317c478bd9Sstevel@tonic-gate	;;
2327c478bd9Sstevel@tonic-gate	x)
2337c478bd9Sstevel@tonic-gate		if [ -n "${printer}" -o -n "${server}" -o \
2347c478bd9Sstevel@tonic-gate		     -n "${device}" -o -n "${description}" ] ; then
2357c478bd9Sstevel@tonic-gate			usage
2367c478bd9Sstevel@tonic-gate		fi
2377c478bd9Sstevel@tonic-gate		delete=${OPTARG}
2387c478bd9Sstevel@tonic-gate		printer=${OPTARG}
2397c478bd9Sstevel@tonic-gate		if [ ${printer} = "all" ] ; then
2407c478bd9Sstevel@tonic-gate			local="true"
2417c478bd9Sstevel@tonic-gate		fi
2427c478bd9Sstevel@tonic-gate	;;
2437c478bd9Sstevel@tonic-gate	S|M|A)
2447c478bd9Sstevel@tonic-gate		local="true"
2457c478bd9Sstevel@tonic-gate	;;
2467c478bd9Sstevel@tonic-gate	c)
2477c478bd9Sstevel@tonic-gate		class=${OPTARG}
2487c478bd9Sstevel@tonic-gate		local="true"
2497c478bd9Sstevel@tonic-gate		if [ ! -f ${LPGET} ] ; then
2507c478bd9Sstevel@tonic-gate			gettext "lpadmin: System error; cannot set class\n " 1>&2
2517c478bd9Sstevel@tonic-gate			exit 2
2527c478bd9Sstevel@tonic-gate		fi
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate		${LPGET} "${class}" > /dev/null 2>&1
2557c478bd9Sstevel@tonic-gate		lpget_class=$?
2567c478bd9Sstevel@tonic-gate		if [ ${lpget_class} -eq 0 -a ! -r /etc/lp/classes/"${class}" ] ; then
2577c478bd9Sstevel@tonic-gate			gettext "lpadmin: ERROR: Can't create class ${class}.\n" 1>&2
2587c478bd9Sstevel@tonic-gate			gettext "           TO FIX: This is an existing printer name;\n" 1>&2
2597c478bd9Sstevel@tonic-gate			gettext "                   choose another name.\n" 1>&2
2607c478bd9Sstevel@tonic-gate			exit 1
2617c478bd9Sstevel@tonic-gate		fi
2627c478bd9Sstevel@tonic-gate	;;
2637c478bd9Sstevel@tonic-gate	r)
2647c478bd9Sstevel@tonic-gate		pconflocalclean="true"
2657c478bd9Sstevel@tonic-gate		local="true"
2667c478bd9Sstevel@tonic-gate	;;
2677c478bd9Sstevel@tonic-gate	esac
2687c478bd9Sstevel@tonic-gatedone
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate#
2717c478bd9Sstevel@tonic-gate# We don't have anything to do; let user know and bail
2727c478bd9Sstevel@tonic-gate#
2737c478bd9Sstevel@tonic-gateif [ ! -n "${printer}" -a ! -n "${delete}" -a ! -n "${local}" ] ; then
2747c478bd9Sstevel@tonic-gate	gettext "lpadmin: ERROR: Nothing to do.\n" 1>&2
2757c478bd9Sstevel@tonic-gate	gettext "        TO FIX: You must give one of these options:\n" 1>&2
2767c478bd9Sstevel@tonic-gate	gettext "		      -p, -d, -x -S\n" 1>&2
2777c478bd9Sstevel@tonic-gate	exit 1
2787c478bd9Sstevel@tonic-gatefi
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate#
2817c478bd9Sstevel@tonic-gate#       Printer does not exist
2827c478bd9Sstevel@tonic-gate#       To be consistent with 2.5, assume adding local printer
2837c478bd9Sstevel@tonic-gate#
2847c478bd9Sstevel@tonic-gateif [ ! -n "${device}" -a ! -n "${server}" -a ! -n "${delete}" \
2857c478bd9Sstevel@tonic-gate					 -a ! -n "${local}" ] ; then
2867c478bd9Sstevel@tonic-gate	${LPGET} "${printer}" > /dev/null 2>&1
2877c478bd9Sstevel@tonic-gate	lpget_stat=$?
2887c478bd9Sstevel@tonic-gate	if [ ${lpget_stat} -ne 0 ] ; then
2897c478bd9Sstevel@tonic-gate		gettext "lpadmin: ERROR: Missing -U or -v option.\n" 1>&2
2907c478bd9Sstevel@tonic-gate		gettext "           TO FIX: Local printers must have\n" 1>&2
2917c478bd9Sstevel@tonic-gate		gettext "                   a port defined (-v option) or\n" 1>&2
2927c478bd9Sstevel@tonic-gate		gettext "                   have dial-out instructions (-U option).\n" 1>&2
2937c478bd9Sstevel@tonic-gate		exit 1
2947c478bd9Sstevel@tonic-gate	fi
2957c478bd9Sstevel@tonic-gatefi
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate#
2987c478bd9Sstevel@tonic-gate#	Do the LP configuration for a local printer served by lpsched
2997c478bd9Sstevel@tonic-gate#
3007c478bd9Sstevel@tonic-gateif [ -f /usr/lib/lp/local/$cmd_name ] ; then
3017c478bd9Sstevel@tonic-gate	if [ -f /etc/lp/printers/${printer}/configuration -o -n "${device}" -o \
3027c478bd9Sstevel@tonic-gate	     -f /etc/lp/classes/${printer} -o -n "${local}" ] ; then
3037c478bd9Sstevel@tonic-gate		# to deal with multi-word arguments
3047c478bd9Sstevel@tonic-gate		CMD="/usr/lib/lp/local/$cmd_name"
3057c478bd9Sstevel@tonic-gate		while [ -n "$*" ] ; do
3067c478bd9Sstevel@tonic-gate			CMD="$CMD \"$1\""
3077c478bd9Sstevel@tonic-gate			shift
3087c478bd9Sstevel@tonic-gate		done
3097c478bd9Sstevel@tonic-gate		case "$CMD" in
3107c478bd9Sstevel@tonic-gate			*\"-D\")
3117c478bd9Sstevel@tonic-gate				CMD="$CMD \"\""
3127c478bd9Sstevel@tonic-gate			;;
3137c478bd9Sstevel@tonic-gate		esac
3147c478bd9Sstevel@tonic-gate		# if adding a printer, make sure scheduler is running
3157c478bd9Sstevel@tonic-gate		if [ -n "${printer}" -a ! -n "${delete}" -a \
3167c478bd9Sstevel@tonic-gate		    ! -p /var/spool/lp/fifos/FIFO ]; then
317*5c88ba20Swendyp			svcadm enable -s svc:/application/print/server:default
3187c478bd9Sstevel@tonic-gate		fi
3197c478bd9Sstevel@tonic-gate		eval $CMD
3207c478bd9Sstevel@tonic-gate		exit_code=$?
3217c478bd9Sstevel@tonic-gate	fi
3227c478bd9Sstevel@tonic-gatefi
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gateif [ $exit_code != 0 ] ; then
3257c478bd9Sstevel@tonic-gate	exit $exit_code
3267c478bd9Sstevel@tonic-gatefi
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate#	split the "server" into printer and server
3307c478bd9Sstevel@tonic-gateif [ -n "${server}" ] ; then
331*5c88ba20Swendyp	if [ `echo ${server} | /bin/grep -c !` = 1 ] ; then
3327c478bd9Sstevel@tonic-gate		rem_printer=`echo ${server} | cut -d! -f2`
3337c478bd9Sstevel@tonic-gate	fi
3347c478bd9Sstevel@tonic-gate	server=`echo ${server} | cut -d! -f1`
3357c478bd9Sstevel@tonic-gatefi
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gateif [ -z "${rem_printer}" ] ; then
3387c478bd9Sstevel@tonic-gate	rem_printer=${printer}
3397c478bd9Sstevel@tonic-gatefi
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate#
3447c478bd9Sstevel@tonic-gate#	Do the Solstice Print Configuration in /etc
3457c478bd9Sstevel@tonic-gate#
3467c478bd9Sstevel@tonic-gateif [ ! -f ${LPSET} -o ! -f ${LPGET} ] ; then
3477c478bd9Sstevel@tonic-gate	exit_code=2
3487c478bd9Sstevel@tonic-gateelse
3497c478bd9Sstevel@tonic-gate	if [ -n "${delete}" ] ; then
3507c478bd9Sstevel@tonic-gate		if [ "${delete}" = "all" ] ; then
3517c478bd9Sstevel@tonic-gate			delete_entries
3527c478bd9Sstevel@tonic-gate   		else
3537c478bd9Sstevel@tonic-gate   			${LPSET} -n system -x ${delete}
3547c478bd9Sstevel@tonic-gate   			exit_code=$?
3557c478bd9Sstevel@tonic-gate			delete_local
3567c478bd9Sstevel@tonic-gate   		fi
3577c478bd9Sstevel@tonic-gate	fi
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate	if [ -n "${printer}" -a -n "${server}" ] ; then
3607c478bd9Sstevel@tonic-gate		${LPSET} -n system \
3617c478bd9Sstevel@tonic-gate			-a "bsdaddr=${server},${rem_printer},Solaris" \
3627c478bd9Sstevel@tonic-gate			${printer}
3637c478bd9Sstevel@tonic-gate		exit_code=$?
3647c478bd9Sstevel@tonic-gate	fi
3657c478bd9Sstevel@tonic-gate	if [ -n "${printer}" -a -n "${description}" ] ; then
3667c478bd9Sstevel@tonic-gate		${LPSET} -n system -a "description=${description}" ${printer}
3677c478bd9Sstevel@tonic-gate		exit_code=$?
3687c478bd9Sstevel@tonic-gate	fi
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate#	Add class for local printers only
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate	if [ -n "${class}" -a -n "${printer}" \
3737c478bd9Sstevel@tonic-gate		-a -f /etc/lp/printers/${printer}/configuration ] ; then
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate		${LPGET} "${class}" > /dev/null 2>&1
3767c478bd9Sstevel@tonic-gate		lpget_class=$?
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate#		If the class doesn't already exist in printers.conf, add it.
3797c478bd9Sstevel@tonic-gate
380*5c88ba20Swendyp		if [ -n "${server}" ] ; then
381*5c88ba20Swendyp			CHOST=$server
382*5c88ba20Swendyp		else
383*5c88ba20Swendyp			CHOST=$HOST
384*5c88ba20Swendyp		fi
3857c478bd9Sstevel@tonic-gate		if [ ${lpget_class} -ne 0 ] ; then
3867c478bd9Sstevel@tonic-gate			${LPSET} -n system \
387*5c88ba20Swendyp				-a "bsdaddr=${CHOST},${class},Solaris" ${class}
3887c478bd9Sstevel@tonic-gate			exit_code=$?
3897c478bd9Sstevel@tonic-gate		fi
3907c478bd9Sstevel@tonic-gate	fi
3917c478bd9Sstevel@tonic-gatefi
3927c478bd9Sstevel@tonic-gate
3937c478bd9Sstevel@tonic-gate# /usr/lib/lp/local/lpadmin has changed the database. This cleans up cruft in the
3947c478bd9Sstevel@tonic-gate# /etc/printers.conf file that refers to deleted objects.
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate	if [ -n "${pconflocalclean}" ] ; then
3977c478bd9Sstevel@tonic-gate		delete_local
3987c478bd9Sstevel@tonic-gate	fi
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gateexit $exit_code
401