xref: /titanic_50/usr/src/cmd/print/scripts/lpadmin (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate#!/bin/sh
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate#
24*7c478bd9Sstevel@tonic-gate# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
25*7c478bd9Sstevel@tonic-gate# Use is subject to license terms.
26*7c478bd9Sstevel@tonic-gate#
27*7c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate#
29*7c478bd9Sstevel@tonic-gatePATH=/bin:/usr/bin:/usr/sbin export PATH
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gateTEXTDOMAIN="SUNW_OST_OSCMD"
32*7c478bd9Sstevel@tonic-gateexport TEXTDOMAIN
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gateLPSET=/usr/bin/lpset
35*7c478bd9Sstevel@tonic-gateLPGET=/usr/bin/lpget
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gateHOST=`/bin/uname -n`
38*7c478bd9Sstevel@tonic-gatePID=$$
39*7c478bd9Sstevel@tonic-gate
40*7c478bd9Sstevel@tonic-gatecmd_name=lpadmin
41*7c478bd9Sstevel@tonic-gateexit_code=0
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gateusage() {
44*7c478bd9Sstevel@tonic-gate	gettext "Usage:\n" 1>&2
45*7c478bd9Sstevel@tonic-gate	gettext "	lpadmin -p (printer) (options)\n" 1>&2
46*7c478bd9Sstevel@tonic-gate	gettext "	lpadmin -x (dest)\n" 1>&2
47*7c478bd9Sstevel@tonic-gate	gettext "	lpadmin -d (dest)\n" 1>&2
48*7c478bd9Sstevel@tonic-gate	gettext "	lpadmin -S print-wheel -A alert-type [ -W minutes ]\n" 1>&2
49*7c478bd9Sstevel@tonic-gate	gettext "		[ -Q requests ]\n" 1>&2
50*7c478bd9Sstevel@tonic-gate	gettext "	lpadmin -M -f form-name [ -a [ -o filebreak ]\n" 1>&2
51*7c478bd9Sstevel@tonic-gate	gettext "		[ -t tray-number ]]\n" 1>&2
52*7c478bd9Sstevel@tonic-gate	exit 1
53*7c478bd9Sstevel@tonic-gate}
54*7c478bd9Sstevel@tonic-gate
55*7c478bd9Sstevel@tonic-gate#
56*7c478bd9Sstevel@tonic-gate# Delete entries in /etc/printers.conf for local printers/classes that no longer
57*7c478bd9Sstevel@tonic-gate# exist in the /etc/lp database
58*7c478bd9Sstevel@tonic-gate#
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gatedelete_local() {
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate# Get printer names for each local printer
63*7c478bd9Sstevel@tonic-gate# grep /etc/printers.conf for each bsdaddr for this server
64*7c478bd9Sstevel@tonic-gate# get printer name from that line
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gatefor LINE in `grep bsdaddr=${HOST}, /etc/printers.conf`
67*7c478bd9Sstevel@tonic-gatedo
68*7c478bd9Sstevel@tonic-gate        PRINTER=`echo ${LINE} | sed -e 's/^:bsdaddr='$HOST',//' -e 's/[,:].*//'`
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate# If there is not an entry for this printer in
71*7c478bd9Sstevel@tonic-gate#       /etc/lp/printers or /etc/lp/classes
72*7c478bd9Sstevel@tonic-gate# Then delete the entry for this printer in /etc/printers.conf
73*7c478bd9Sstevel@tonic-gate
74*7c478bd9Sstevel@tonic-gate        if [ ! -d /etc/lp/printers/${PRINTER} -a ! -f /etc/lp/classes/${PRINTER} ] ;
75*7c478bd9Sstevel@tonic-gate        then
76*7c478bd9Sstevel@tonic-gate                logger -p lpr.debug -t "lpadmin[${PID}]" \
77*7c478bd9Sstevel@tonic-gate                         "Removing $PRINTER entry from /etc/printers.conf"
78*7c478bd9Sstevel@tonic-gate                ${LPSET} -x ${PRINTER}
79*7c478bd9Sstevel@tonic-gate                status=$?
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate                if [ ${status} -ne 0 ] ; then
82*7c478bd9Sstevel@tonic-gate                        gettext "Warning: error removing ${PRINTER} " 1>&2
83*7c478bd9Sstevel@tonic-gate			gettext "entry from /etc/printers.conf\n" 1>&2
84*7c478bd9Sstevel@tonic-gate                        logger -p lpr.debug -t "lpadmin[${PID}]" \
85*7c478bd9Sstevel@tonic-gate				"Call to lpset -x $PRINTER exits with ${status}"
86*7c478bd9Sstevel@tonic-gate			exit_code=1
87*7c478bd9Sstevel@tonic-gate                fi
88*7c478bd9Sstevel@tonic-gate        fi
89*7c478bd9Sstevel@tonic-gatedone
90*7c478bd9Sstevel@tonic-gate
91*7c478bd9Sstevel@tonic-gate#
92*7c478bd9Sstevel@tonic-gate# shutdown scheduler if there are no local printers
93*7c478bd9Sstevel@tonic-gate#
94*7c478bd9Sstevel@tonic-gateCONFIGS=/etc/lp/printers/*/configuration
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gateprinters_configured=`echo $CONFIGS`
97*7c478bd9Sstevel@tonic-gateif [ "$printers_configured" = "$CONFIGS" ]; then
98*7c478bd9Sstevel@tonic-gate	svcprop -q svc:/application/print/server:default &&
99*7c478bd9Sstevel@tonic-gate		svcadm disable svc:/application/print/server:default
100*7c478bd9Sstevel@tonic-gatefi
101*7c478bd9Sstevel@tonic-gate}
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gatedelete_entries() {
104*7c478bd9Sstevel@tonic-gateif [ ! -f /etc/printers.conf ] ; then
105*7c478bd9Sstevel@tonic-gate        logger -p lpr.debug -t "lpadmin[${PID}]" \
106*7c478bd9Sstevel@tonic-gate		"System error: Cannot access /etc/printers.conf"
107*7c478bd9Sstevel@tonic-gate        gettext "lpadmin: System error; Cannot access /etc/printers.conf\n" 1>&2
108*7c478bd9Sstevel@tonic-gate        exit 1
109*7c478bd9Sstevel@tonic-gatefi
110*7c478bd9Sstevel@tonic-gate
111*7c478bd9Sstevel@tonic-gate# remove _default
112*7c478bd9Sstevel@tonic-gate
113*7c478bd9Sstevel@tonic-gateDEFAULTP=`${LPGET} _default | grep use | sed -e 's/[    ]*use=//'`
114*7c478bd9Sstevel@tonic-gate${LPGET} -k bsdaddr ${DEFAULTP} >/dev/null 2>&1
115*7c478bd9Sstevel@tonic-gatestatus=$?
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gateif [ ${status} -eq 0 ] ; then
118*7c478bd9Sstevel@tonic-gate	${LPSET} -x _default
119*7c478bd9Sstevel@tonic-gate	status=$?
120*7c478bd9Sstevel@tonic-gate	if [ ${status} -ne 0 ] ; then
121*7c478bd9Sstevel@tonic-gate		gettext "Warning: error removing _default entry from /etc/printers.conf\n" 1>&2
122*7c478bd9Sstevel@tonic-gate		logger -p lpr.debug -t "lpadmin[${PID}]" \
123*7c478bd9Sstevel@tonic-gate			"Call to lpset -x _default exits with ${status}"
124*7c478bd9Sstevel@tonic-gate		exit_code=1
125*7c478bd9Sstevel@tonic-gate	fi
126*7c478bd9Sstevel@tonic-gatefi
127*7c478bd9Sstevel@tonic-gate
128*7c478bd9Sstevel@tonic-gate# delete entries in /etc/printers.conf for printers/classes that have
129*7c478bd9Sstevel@tonic-gate# been deleted
130*7c478bd9Sstevel@tonic-gate
131*7c478bd9Sstevel@tonic-gatedelete_local
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate# Delete all the remote printers using bsdaddr
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gatefor LINE in `grep bsdaddr /etc/printers.conf | grep -v ${HOST}`
136*7c478bd9Sstevel@tonic-gatedo
137*7c478bd9Sstevel@tonic-gate        PRINTER=`echo $LINE | sed -e 's/^:bsdaddr=[^,]*,//' -e 's/[,:].*//'`
138*7c478bd9Sstevel@tonic-gate        ${LPSET} -x $PRINTER
139*7c478bd9Sstevel@tonic-gate	status=$?
140*7c478bd9Sstevel@tonic-gate
141*7c478bd9Sstevel@tonic-gate	if [ ${status} -ne 0 ] ; then
142*7c478bd9Sstevel@tonic-gate		gettext "Warning: error removing ${PRINTER} entry from /etc/printers.conf\n" 1>&2
143*7c478bd9Sstevel@tonic-gate		logger -p lpr.debug -t "lpadmin[${PID}]" \
144*7c478bd9Sstevel@tonic-gate			"Call to lpset -x $PRINTER exits with ${status}"
145*7c478bd9Sstevel@tonic-gate		exit_code=1
146*7c478bd9Sstevel@tonic-gate	fi
147*7c478bd9Sstevel@tonic-gatedone
148*7c478bd9Sstevel@tonic-gate}
149*7c478bd9Sstevel@tonic-gate
150*7c478bd9Sstevel@tonic-gateif [ $# -lt 1 ] ; then
151*7c478bd9Sstevel@tonic-gate	usage
152*7c478bd9Sstevel@tonic-gate	exit 1
153*7c478bd9Sstevel@tonic-gatefi
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate# Deal with the -d option independently since getopts does not handle
156*7c478bd9Sstevel@tonic-gate# options that may or may not have arguments
157*7c478bd9Sstevel@tonic-gate#
158*7c478bd9Sstevel@tonic-gatefirst=$1
159*7c478bd9Sstevel@tonic-gatesecond=$2
160*7c478bd9Sstevel@tonic-gatethird=$3
161*7c478bd9Sstevel@tonic-gate
162*7c478bd9Sstevel@tonic-gateif [ ${first} = "-d" ] ; then
163*7c478bd9Sstevel@tonic-gate	# check that there are no extra arguments
164*7c478bd9Sstevel@tonic-gate	if [ -n "${third}" ] ; then
165*7c478bd9Sstevel@tonic-gate		usage
166*7c478bd9Sstevel@tonic-gate		exit 1
167*7c478bd9Sstevel@tonic-gate	fi
168*7c478bd9Sstevel@tonic-gate
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate	# be sure we have lpset and lpget
171*7c478bd9Sstevel@tonic-gate	if [ ! -f ${LPSET} -o ! -f ${LPGET} ] ; then
172*7c478bd9Sstevel@tonic-gate		gettext "lpadmin: System error; cannot set default printer\n" 1>&2
173*7c478bd9Sstevel@tonic-gate		exit 2
174*7c478bd9Sstevel@tonic-gate	fi
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gate	if [ ! -n "${second}" ] ; then
177*7c478bd9Sstevel@tonic-gate		${LPGET} -n system _default >/dev/null 2>&1
178*7c478bd9Sstevel@tonic-gate		exit_code=$?
179*7c478bd9Sstevel@tonic-gate		if [ ${exit_code} -eq 0 ] ; then
180*7c478bd9Sstevel@tonic-gate			# delete _default entry in /etc/printers.conf
181*7c478bd9Sstevel@tonic-gate			${LPSET} -n system -x _default
182*7c478bd9Sstevel@tonic-gate			exit_code=$?
183*7c478bd9Sstevel@tonic-gate			if [ ${exit_code} -ne 0 ] ; then
184*7c478bd9Sstevel@tonic-gate				gettext "lpadmin: System error while trying to delete default printer\n" 1>&2
185*7c478bd9Sstevel@tonic-gate			fi
186*7c478bd9Sstevel@tonic-gate		else
187*7c478bd9Sstevel@tonic-gate			# there was no _default, the work is done
188*7c478bd9Sstevel@tonic-gate			exit_code=0
189*7c478bd9Sstevel@tonic-gate		fi
190*7c478bd9Sstevel@tonic-gate	else
191*7c478bd9Sstevel@tonic-gate		# add/change  _default entry in /etc/printers.conf
192*7c478bd9Sstevel@tonic-gate		${LPGET} -k bsdaddr ${second} >/dev/null 2>&1
193*7c478bd9Sstevel@tonic-gate		exit_code=$?
194*7c478bd9Sstevel@tonic-gate		if [ $exit_code -eq 0 ] ; then
195*7c478bd9Sstevel@tonic-gate			${LPSET} -n system -a use=${second} _default
196*7c478bd9Sstevel@tonic-gate			exit_code=$?
197*7c478bd9Sstevel@tonic-gate		else
198*7c478bd9Sstevel@tonic-gate			echo "${second}: " 1>&2
199*7c478bd9Sstevel@tonic-gate			gettext "undefined printer\n" 1>&2
200*7c478bd9Sstevel@tonic-gate		fi
201*7c478bd9Sstevel@tonic-gate
202*7c478bd9Sstevel@tonic-gate	fi
203*7c478bd9Sstevel@tonic-gate	exit ${exit_code}
204*7c478bd9Sstevel@tonic-gatefi
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate#		Strip off legal options
207*7c478bd9Sstevel@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
208*7c478bd9Sstevel@tonic-gatedo
209*7c478bd9Sstevel@tonic-gate	case $arg in
210*7c478bd9Sstevel@tonic-gate	D)
211*7c478bd9Sstevel@tonic-gate		description="${OPTARG}"
212*7c478bd9Sstevel@tonic-gate	;;
213*7c478bd9Sstevel@tonic-gate	p)
214*7c478bd9Sstevel@tonic-gate		if [ -n "${delete}" ] ; then
215*7c478bd9Sstevel@tonic-gate			usage
216*7c478bd9Sstevel@tonic-gate		fi
217*7c478bd9Sstevel@tonic-gate		printer=${OPTARG}
218*7c478bd9Sstevel@tonic-gate	;;
219*7c478bd9Sstevel@tonic-gate	s)
220*7c478bd9Sstevel@tonic-gate		server=${OPTARG}
221*7c478bd9Sstevel@tonic-gate	;;
222*7c478bd9Sstevel@tonic-gate	v|U)
223*7c478bd9Sstevel@tonic-gate		device=${OPTARG}
224*7c478bd9Sstevel@tonic-gate		server=`uname -n`
225*7c478bd9Sstevel@tonic-gate	;;
226*7c478bd9Sstevel@tonic-gate	x)
227*7c478bd9Sstevel@tonic-gate		if [ -n "${printer}" -o -n "${server}" -o \
228*7c478bd9Sstevel@tonic-gate		     -n "${device}" -o -n "${description}" ] ; then
229*7c478bd9Sstevel@tonic-gate			usage
230*7c478bd9Sstevel@tonic-gate		fi
231*7c478bd9Sstevel@tonic-gate		delete=${OPTARG}
232*7c478bd9Sstevel@tonic-gate		printer=${OPTARG}
233*7c478bd9Sstevel@tonic-gate		if [ ${printer} = "all" ] ; then
234*7c478bd9Sstevel@tonic-gate			local="true"
235*7c478bd9Sstevel@tonic-gate		fi
236*7c478bd9Sstevel@tonic-gate	;;
237*7c478bd9Sstevel@tonic-gate	S|M|A)
238*7c478bd9Sstevel@tonic-gate		local="true"
239*7c478bd9Sstevel@tonic-gate	;;
240*7c478bd9Sstevel@tonic-gate	c)
241*7c478bd9Sstevel@tonic-gate		class=${OPTARG}
242*7c478bd9Sstevel@tonic-gate		local="true"
243*7c478bd9Sstevel@tonic-gate		if [ ! -f ${LPGET} ] ; then
244*7c478bd9Sstevel@tonic-gate			gettext "lpadmin: System error; cannot set class\n " 1>&2
245*7c478bd9Sstevel@tonic-gate			exit 2
246*7c478bd9Sstevel@tonic-gate		fi
247*7c478bd9Sstevel@tonic-gate
248*7c478bd9Sstevel@tonic-gate		${LPGET} "${class}" > /dev/null 2>&1
249*7c478bd9Sstevel@tonic-gate		lpget_class=$?
250*7c478bd9Sstevel@tonic-gate		if [ ${lpget_class} -eq 0 -a ! -r /etc/lp/classes/"${class}" ] ; then
251*7c478bd9Sstevel@tonic-gate			gettext "lpadmin: ERROR: Can't create class ${class}.\n" 1>&2
252*7c478bd9Sstevel@tonic-gate			gettext "           TO FIX: This is an existing printer name;\n" 1>&2
253*7c478bd9Sstevel@tonic-gate			gettext "                   choose another name.\n" 1>&2
254*7c478bd9Sstevel@tonic-gate			exit 1
255*7c478bd9Sstevel@tonic-gate		fi
256*7c478bd9Sstevel@tonic-gate	;;
257*7c478bd9Sstevel@tonic-gate	r)
258*7c478bd9Sstevel@tonic-gate		pconflocalclean="true"
259*7c478bd9Sstevel@tonic-gate		local="true"
260*7c478bd9Sstevel@tonic-gate	;;
261*7c478bd9Sstevel@tonic-gate	esac
262*7c478bd9Sstevel@tonic-gatedone
263*7c478bd9Sstevel@tonic-gate
264*7c478bd9Sstevel@tonic-gate#
265*7c478bd9Sstevel@tonic-gate# We don't have anything to do; let user know and bail
266*7c478bd9Sstevel@tonic-gate#
267*7c478bd9Sstevel@tonic-gateif [ ! -n "${printer}" -a ! -n "${delete}" -a ! -n "${local}" ] ; then
268*7c478bd9Sstevel@tonic-gate	gettext "lpadmin: ERROR: Nothing to do.\n" 1>&2
269*7c478bd9Sstevel@tonic-gate	gettext "        TO FIX: You must give one of these options:\n" 1>&2
270*7c478bd9Sstevel@tonic-gate	gettext "		      -p, -d, -x -S\n" 1>&2
271*7c478bd9Sstevel@tonic-gate	exit 1
272*7c478bd9Sstevel@tonic-gatefi
273*7c478bd9Sstevel@tonic-gate
274*7c478bd9Sstevel@tonic-gate#
275*7c478bd9Sstevel@tonic-gate#       Printer does not exist
276*7c478bd9Sstevel@tonic-gate#       To be consistent with 2.5, assume adding local printer
277*7c478bd9Sstevel@tonic-gate#
278*7c478bd9Sstevel@tonic-gateif [ ! -n "${device}" -a ! -n "${server}" -a ! -n "${delete}" \
279*7c478bd9Sstevel@tonic-gate					 -a ! -n "${local}" ] ; then
280*7c478bd9Sstevel@tonic-gate	${LPGET} "${printer}" > /dev/null 2>&1
281*7c478bd9Sstevel@tonic-gate	lpget_stat=$?
282*7c478bd9Sstevel@tonic-gate	if [ ${lpget_stat} -ne 0 ] ; then
283*7c478bd9Sstevel@tonic-gate		gettext "lpadmin: ERROR: Missing -U or -v option.\n" 1>&2
284*7c478bd9Sstevel@tonic-gate		gettext "           TO FIX: Local printers must have\n" 1>&2
285*7c478bd9Sstevel@tonic-gate		gettext "                   a port defined (-v option) or\n" 1>&2
286*7c478bd9Sstevel@tonic-gate		gettext "                   have dial-out instructions (-U option).\n" 1>&2
287*7c478bd9Sstevel@tonic-gate		exit 1
288*7c478bd9Sstevel@tonic-gate	fi
289*7c478bd9Sstevel@tonic-gatefi
290*7c478bd9Sstevel@tonic-gate
291*7c478bd9Sstevel@tonic-gate#
292*7c478bd9Sstevel@tonic-gate#	Do the LP configuration for a local printer served by lpsched
293*7c478bd9Sstevel@tonic-gate#
294*7c478bd9Sstevel@tonic-gateif [ -f /usr/lib/lp/local/$cmd_name ] ; then
295*7c478bd9Sstevel@tonic-gate	if [ -f /etc/lp/printers/${printer}/configuration -o -n "${device}" -o \
296*7c478bd9Sstevel@tonic-gate	     -f /etc/lp/classes/${printer} -o -n "${local}" ] ; then
297*7c478bd9Sstevel@tonic-gate		# to deal with multi-word arguments
298*7c478bd9Sstevel@tonic-gate		CMD="/usr/lib/lp/local/$cmd_name"
299*7c478bd9Sstevel@tonic-gate		while [ -n "$*" ] ; do
300*7c478bd9Sstevel@tonic-gate			CMD="$CMD \"$1\""
301*7c478bd9Sstevel@tonic-gate			shift
302*7c478bd9Sstevel@tonic-gate		done
303*7c478bd9Sstevel@tonic-gate		case "$CMD" in
304*7c478bd9Sstevel@tonic-gate			*\"-D\")
305*7c478bd9Sstevel@tonic-gate				CMD="$CMD \"\""
306*7c478bd9Sstevel@tonic-gate			;;
307*7c478bd9Sstevel@tonic-gate		esac
308*7c478bd9Sstevel@tonic-gate		# if adding a printer, make sure scheduler is running
309*7c478bd9Sstevel@tonic-gate		if [ -n "${printer}" -a ! -n "${delete}" -a \
310*7c478bd9Sstevel@tonic-gate		    ! -p /var/spool/lp/fifos/FIFO ]; then
311*7c478bd9Sstevel@tonic-gate			svcadm enable svc:/application/print/server:default
312*7c478bd9Sstevel@tonic-gate		fi
313*7c478bd9Sstevel@tonic-gate		eval $CMD
314*7c478bd9Sstevel@tonic-gate		exit_code=$?
315*7c478bd9Sstevel@tonic-gate	fi
316*7c478bd9Sstevel@tonic-gatefi
317*7c478bd9Sstevel@tonic-gate
318*7c478bd9Sstevel@tonic-gateif [ $exit_code != 0 ] ; then
319*7c478bd9Sstevel@tonic-gate	exit $exit_code
320*7c478bd9Sstevel@tonic-gatefi
321*7c478bd9Sstevel@tonic-gate
322*7c478bd9Sstevel@tonic-gate
323*7c478bd9Sstevel@tonic-gate#	split the "server" into printer and server
324*7c478bd9Sstevel@tonic-gateif [ -n "${server}" ] ; then
325*7c478bd9Sstevel@tonic-gate	if [ `echo ${server} | grep -c !` = 1 ] ; then
326*7c478bd9Sstevel@tonic-gate		rem_printer=`echo ${server} | cut -d! -f2`
327*7c478bd9Sstevel@tonic-gate	fi
328*7c478bd9Sstevel@tonic-gate	server=`echo ${server} | cut -d! -f1`
329*7c478bd9Sstevel@tonic-gatefi
330*7c478bd9Sstevel@tonic-gate
331*7c478bd9Sstevel@tonic-gateif [ -z "${rem_printer}" ] ; then
332*7c478bd9Sstevel@tonic-gate	rem_printer=${printer}
333*7c478bd9Sstevel@tonic-gatefi
334*7c478bd9Sstevel@tonic-gate
335*7c478bd9Sstevel@tonic-gate
336*7c478bd9Sstevel@tonic-gate
337*7c478bd9Sstevel@tonic-gate#
338*7c478bd9Sstevel@tonic-gate#	Do the Solstice Print Configuration in /etc
339*7c478bd9Sstevel@tonic-gate#
340*7c478bd9Sstevel@tonic-gateif [ ! -f ${LPSET} -o ! -f ${LPGET} ] ; then
341*7c478bd9Sstevel@tonic-gate	exit_code=2
342*7c478bd9Sstevel@tonic-gateelse
343*7c478bd9Sstevel@tonic-gate	if [ -n "${delete}" ] ; then
344*7c478bd9Sstevel@tonic-gate		if [ "${delete}" = "all" ] ; then
345*7c478bd9Sstevel@tonic-gate			delete_entries
346*7c478bd9Sstevel@tonic-gate   		else
347*7c478bd9Sstevel@tonic-gate   			${LPSET} -n system -x ${delete}
348*7c478bd9Sstevel@tonic-gate   			exit_code=$?
349*7c478bd9Sstevel@tonic-gate			delete_local
350*7c478bd9Sstevel@tonic-gate   		fi
351*7c478bd9Sstevel@tonic-gate	fi
352*7c478bd9Sstevel@tonic-gate
353*7c478bd9Sstevel@tonic-gate	if [ -n "${printer}" -a -n "${server}" ] ; then
354*7c478bd9Sstevel@tonic-gate		${LPSET} -n system \
355*7c478bd9Sstevel@tonic-gate			-a "bsdaddr=${server},${rem_printer},Solaris" \
356*7c478bd9Sstevel@tonic-gate			${printer}
357*7c478bd9Sstevel@tonic-gate		exit_code=$?
358*7c478bd9Sstevel@tonic-gate	fi
359*7c478bd9Sstevel@tonic-gate	if [ -n "${printer}" -a -n "${description}" ] ; then
360*7c478bd9Sstevel@tonic-gate		${LPSET} -n system -a "description=${description}" ${printer}
361*7c478bd9Sstevel@tonic-gate		exit_code=$?
362*7c478bd9Sstevel@tonic-gate	fi
363*7c478bd9Sstevel@tonic-gate
364*7c478bd9Sstevel@tonic-gate#	Add class for local printers only
365*7c478bd9Sstevel@tonic-gate
366*7c478bd9Sstevel@tonic-gate	if [ -n "${class}" -a -n "${printer}" \
367*7c478bd9Sstevel@tonic-gate		-a -f /etc/lp/printers/${printer}/configuration ] ; then
368*7c478bd9Sstevel@tonic-gate
369*7c478bd9Sstevel@tonic-gate		${LPGET} "${class}" > /dev/null 2>&1
370*7c478bd9Sstevel@tonic-gate		lpget_class=$?
371*7c478bd9Sstevel@tonic-gate
372*7c478bd9Sstevel@tonic-gate#		If the class doesn't already exist in printers.conf, add it.
373*7c478bd9Sstevel@tonic-gate
374*7c478bd9Sstevel@tonic-gate		if [ ${lpget_class} -ne 0 ] ; then
375*7c478bd9Sstevel@tonic-gate			this_server=`uname -n`
376*7c478bd9Sstevel@tonic-gate			${LPSET} -n system \
377*7c478bd9Sstevel@tonic-gate				-a "bsdaddr=${this_server},${class},Solaris" ${class}
378*7c478bd9Sstevel@tonic-gate			exit_code=$?
379*7c478bd9Sstevel@tonic-gate		fi
380*7c478bd9Sstevel@tonic-gate	fi
381*7c478bd9Sstevel@tonic-gatefi
382*7c478bd9Sstevel@tonic-gate
383*7c478bd9Sstevel@tonic-gate# /usr/lib/lp/local/lpadmin has changed the database. This cleans up cruft in the
384*7c478bd9Sstevel@tonic-gate# /etc/printers.conf file that refers to deleted objects.
385*7c478bd9Sstevel@tonic-gate
386*7c478bd9Sstevel@tonic-gate	if [ -n "${pconflocalclean}" ] ; then
387*7c478bd9Sstevel@tonic-gate		delete_local
388*7c478bd9Sstevel@tonic-gate	fi
389*7c478bd9Sstevel@tonic-gate
390*7c478bd9Sstevel@tonic-gateexit $exit_code
391