3
# $Id: add_netatalk_printer,v 1.6 2001/10/06 12:27:38 srittau Exp $
5
# A lovely script to add netatalk printers
7
#ident "@(#)netatalk 0.5 99/06/22 job@uchicago.edu" /* Netatalk 1.4*/
9
# This File is released under the Perl Artistic Licence.
10
# See http://www.perl.org for details
12
# Or you can use it under the licence that accompanies Netatalk 1.3 =)
14
# This file is maintained by Job Bogan <job@uchicago.edu>
15
# Please contact me at this address for bug reports, problems, etc.
16
# Please do not bother the netatalk maintainers with problems from
21
# Exit Codes ... 1 for missed path or user input
22
# 2 for an aborted run (by not saying yes to a 'are you sure?'
23
# 3 for failed lpadmin commands
24
# 4 for possible security problem
26
# make base name for temp files.
28
TMP_STUFF="/tmp/`basename $0`.$$"
31
mkdir -m 700 ${TMP_STUFF} || exit 4
32
trap 'rm -f $TMP_STUFF > /dev/null 2>&1' 0
35
# grab the pathname the script was called w/
36
# if it was run by ./add... then make the path == `pwd`
40
if [ "$RUNHOME" = "." ]; then
44
# allow for the env NETATALKHOME to override the guessed one from above
46
NETATALKHOME=${NETATALKHOME:-$RUNHOME}
49
PATH=/bin:${PATH}:${NETATALKHOME}/bin:${NETATALKHOME}/etc:${NETATALKHOME}/etc/filters:/usr/lib:/usr/sbin
51
if [ ! -x ${NETATALKHOME}/bin/pap ]; then
52
echo "OOPS: I don't see ${NETATALKHOME}/bin/pap ,"
53
echo ' Check that it is executable or set ${NETATALKHOME}'
54
echo ' so i can find pap at ${NETATALKHOME}/bin/pap'
55
echo '[We are guessing the location of the binary from the'
56
echo 'path that was used to run this script or $NETATALKHOME]'
60
# get the user to tell us where to look for things, and list things there.
63
echo "Enter Appletalk zone [default: local]: \c"
68
echo "Looking for LaserWriters in Zone ${ZONE} ..."
69
${NETATALKHOME}/bin/nbplkup ":LaserWriter@${ZONE}"
72
echo "Enter AppleTalk printer name: \c"
76
if [ "$DEST" = "" ]; then
77
echo "OOPS: you need to tell me a printer name"
81
echo "checking nbplkup ${DEST}:LaserWriter@${ZONE}"
83
TestDEST=`${NETATALKHOME}/bin/nbplkup "${DEST}:LaserWriter@${ZONE}"`
87
if [ "${TestDEST}" = "" ]; then
88
echo "I don't see that printer on the network. You may have entered an incorrect"
89
echo "printer name - if so, exit and restart."
90
echo "[You should only enter the printer name, not the :LaserWriter portion]"
96
NBPNAME="${DEST}@${ZONE}"
101
# scrunch all of the whitespace and / out of the appletalk name and suggest
102
# that as the unix name
104
SUGGEST=`echo "$DEST" | cut -d: -f1 | sed 's/ //g' | sed 's#/##g` ; export SUGGEST
106
# truncate the suggested name to 14 chars to conform to lp specs.
108
SUGGEST1=`expr ${SUGGEST} : '\(..............\)'`
109
SUGGEST=${SUGGEST1:-$SUGGEST}
111
echo "Enter Unix printer name - [default: ${SUGGEST}] : \c"
114
if [ "${UNIXPRINT}" = "" ]; then
115
UNIXPRINT="${SUGGEST}"
120
# Here we check for legal names again. >14 chars
123
UNIXPRINT1=`expr "${UNIXPRINT}" : '\(..............\)'`
125
# if UNIXPRINT is shorter than 14chars, UNIXPRINT1 ends up null ("")
126
# if UNIXPRINT was longer, then we get a 14char version of it. bleah.
128
if [ "${UNIXPRINT1}" = "" ]; then
129
UNIXPRINT1="${UNIXPRINT}"
131
#if [ "${UNIXPRINT1}" != "${UNIXPRINT}" ]; then
132
echo "Oops, that name was too long... Truncating to 14 chars."
133
echo "setting printer name to '${UNIXPRINT}'"
134
UNIXPRINT="${UNIXPRINT1}"
137
echo "Enter a description for this printer. [The Appletalk name will"
138
echo "be included by default, and must be included for the printing"
139
echo "filters to work.] : \c"
142
DESC="${DESC} [${NBPNAME}]"
145
echo "Do you want all print jobs to print out in reversed page order?"
146
echo "This is usually only desired if this printer stacks jobs"
147
echo "face up in the output bin. [N/y] \c"
149
case ${REV} in [Yy]*) REV="Netatalk-R" ;;
154
if lpstat -p ${UNIXPRINT} >/dev/null 2>&1 ; then
156
echo "OOPS: There already exists a printer named '${UNIXPRINT}'"
157
echo " here are the comments from /etc/lp/printers/${UNIXPRINT}/comment"
158
cat /etc/lp/printers/${UNIXPRINT}/comment
160
echo "Do you still want to do this? This will flush "
161
echo "all pending jobs! [Y/n]? \c"
163
case ${DOTHIS} in [Yy]*) ;;
167
echo "Rejecting all new jobs for ${UNIXPRINT}"
168
reject -r "Making ${UNIXPRINT} a netatalk printer" ${UNIXPRINT}
169
echo "Disabling and Flushing the ${UNIXPRINT} queue"
170
disable -c -r "Making ${UNIXPRINT} a netatalk printer" ${UNIXPRINT}
174
# Check if we need to do silly tricks to share the printer... only on 5.5.1 or older
177
if [ "`uname -r`" -lt "5.6" ]; then
179
echo "Do you want to share this printer with other machines [Y/n]?\c"
182
echo "You're running SunOS 5.6 or higher... skipping 'sacadm' and 'pmadm'"
185
if nistest printers.org_dir; then
186
echo "Do you want to add this printer to your NIS printer map? [y/N]"
187
echo "(You will need to share this printer with other machines)"
189
case ${NIS} in [Yy]*) ADD_NIS=1 ;;
194
echo "Do you want to save the error messages from pap in"
195
echo "'/var/spool/lp/tmp/Netatalk/${UNIXPRINT}' [y/N]"
196
echo "(If you answer N, error messages will go to /dev/null.)"
198
case ${SAVEerr} in [Yy]*) SAVEerr=1 ;;
202
echo "Making ${UNIXPRINT} print to ${DEST} via netatalk"
204
if [ "${SAVEerr}" = "" ]; then
207
LOCKS=/var/spool/lp/tmp/Netatalk
208
if [ ! -d ${LOCKS} ]; then
209
mkdir -m 0771 ${LOCKS}
213
LOCKDEV=${LOCKS}/${UNIXPRINT}
215
chown lp:lp ${LOCKDEV}
221
if [ ! -r /etc/lp/filter.table ]; then
222
echo "Setting up the existing print filters..."
223
for i in `ls /etc/lp/fd | sed 's/.fd$//'`; do
224
lpfilter -f ${i} -F/etc/lp/fd/${i}.fd
227
if lpfilter -f netatalk -l > /dev/null 2>&1 ; then
228
echo 'Looks like you have a Netatalk printer filter defined. Good!'
230
echo "Humm... You need a Netatalk printer filter..."
231
echo "... making you one ..."
232
cat > /etc/lp/fd/netatalk.fd << EOF
233
#ident "@(#)netatalk.fd 0.2 97/09/04 job@uchicago.edu" /* Netatalk 1.4 */
235
Input types: postscript
237
Printer types: Netatalk
240
Command: ${NETATALKHOME}/etc/filters/ifpap 2>&1 > /dev/null
242
chown lp:lp /etc/lp/fd/netatalk.fd
243
chmod 664 /etc/lp/fd/netatalk.fd
244
lpfilter -f netatalk -F /etc/lp/fd/netatalk.fd
247
if lpfilter -f netatalk-r -l 2>&1 > /dev/null ; then
248
echo 'Looks like you have a Reverse Netatalk printer filter defined. Good!'
250
echo "Humm... You need a Reverse Netatalk printer filter..."
251
echo "... making you one ..."
252
cat > /etc/lp/fd/netatalk-r.fd << EOF
253
#ident "@(#)netatalk-r.fd 0.2 97/09/04 job@uchicago.edu" /* Netatalk 1.4 */
255
Input types: postscript
257
Printer types: Netatalk-R
260
Command: "/usr/lib/lp/postscript/postreverse | ${NETATALKHOME}/etc/filters/ifpap 2>&1 >/dev/null"
262
chown lp:lp /etc/lp/fd/netatalk-r.fd
263
chmod 664 /etc/lp/fd/netatalk-r.fd
264
lpfilter -f netatalk-r -F /etc/lp/fd/netatalk-r.fd
267
if [ ! -r /usr/share/lib/terminfo/N/Netatalk ]; then
268
echo "Making a Terminfo entry for Netatalk printers"
269
cat > ${TMP_STUFF}/terminfo << EOF
272
cpi=null, csnm=^D, lpi=null, scs=^D, slines=^D, u9=^D,
274
tic ${TMP_STUFF}/terminfo
275
chown bin:bin /usr/share/lib/terminfo/N/Netatalk
276
chmod 644 /usr/share/lib/terminfo/N/Netatalk
279
if [ ! -r /usr/share/lib/terminfo/N/Netatalk-R ]; then
280
echo "Making a Terminfo entry for Reversed Netatalk printers"
281
cat > ${TMP_STUFF}/terminfoR << EOF
284
cpi=null, csnm=^D, lpi=null, scs=^D, slines=^D, u9=^D,
286
tic "${TMP_STUFF}/terminfoR"
287
chown bin:bin /usr/share/lib/terminfo/N/Netatalk-R
288
chmod 644 /usr/share/lib/terminfo/N/Netatalk-R
292
# this is old cruft... we should not have done this in the 1st place.
293
# we need to edit the template interface file to point to the local netatalk bins
294
#cat ${RUNHOME}/etc/netatalk.template | sed "s#DEFAULT_NETATALK_HOME#${RUNHOME}#g" \
295
# > "/etc/lp/interfaces/${UNIXPRINT}"
296
#chown lp:lp /etc/lp/interfaces/${UNIXPRINT}
297
#chmod 0775 /etc/lp/interfaces/${UNIXPRINT}
298
# below is the correct way.
301
echo "Setting up ${UNIXPRINT} ... Edit options later as you see fit."
302
lpadmin -p ${UNIXPRINT} -D "${DESC}" -T ${REV} \
303
-i ${RUNHOME}/netatalk.template -I PS -v ${LOCKDEV} -A none || exit 3
304
accept ${UNIXPRINT} || exit 3
305
enable ${UNIXPRINT} || exit 3
307
case ${SHARE} in [Nn]*) exit; ;;
311
echo "Setting up network sharing for ${UNIXPRINT}"
313
# from p925 in the Solaris Administration Guide, Vol. II (2.5)
316
if sacadm -l -p tcp > /dev/null; then
317
echo "already running a tcp listener"
319
echo "Defining tcp listener ..."
320
sacadm -a -p tcp -t listen -c "/usr/lib/saf/listen tcp" \
321
-v `nlsadmin -V` -n 999
324
# this is extra, but a good idea...
326
LPD_ADDR="\\x`lpsystem -A`" ; export LPD_ADDR
327
ADDR_0=`echo $LPD_ADDR | sed -e 's/\\x00020203/\\x00020ACE/g'`; export ADDR_0
329
if pmadm -l -p tcp -s 0 > /dev/null; then
330
echo "<0> service is already defined."
332
echo "Defining <0>/tcp service ..."
333
pmadm -a -p tcp -s 0 -i root \
334
-m `nlsadmin -c /usr/lib/saf/nlps_server -A ${ADDR_0}` \
338
# again from the solaris book noted above.
340
if pmadm -l -p tcp -s lp > /dev/null; then
341
echo "<lp> service is already defined."
343
echo "Defining <lp>/tcp service ..."
344
pmadm -a -p tcp -s lp -i root \
345
-m `nlsadmin -o /var/spool/lp/fifos/listenS5` \
349
if pmadm -l -p tcp -s lpd > /dev/null; then
350
echo "<lpd> service is already defined."
352
echo "Defining <lpd>/tcp service ..."
353
pmadm -a -p tcp -s lpd -i root \
354
-m `nlsadmin -o /var/spool/lp/fifos/listenBSD -A ${LPD_ADDR}` \
358
if [ "${ADD_NIS}" = 1 ] ; then
359
if nistest "[printer_name=${UNIXPRINT}]printers.org_dir"; then
360
nistbladm -m printer_host=`uname -n` \
361
"[printer_name=${UNIXPRINT}]printers.org_dir" description="$DESC"
363
nistbladm -a printer_name=${UNIXPRINT} \
364
description="$DESC" printer_host=`uname -n` printers.org_dir