3 # A lovely script to add netatalk printers
5 #ident "@(#)netatalk 0.5 99/06/22 job@uchicago.edu" /* Netatalk 1.4*/
7 # This File is released under the Perl Artistic Licence.
8 # See http://www.perl.org for details
10 # Or you can use it under the licence that accompanies Netatalk 1.3 =)
12 # This file is maintained by Job Bogan <job@uchicago.edu>
13 # Please contact me at this address for bug reports, problems, etc.
14 # Please do not bother the netatalk maintainers with problems from
19 # Exit Codes ... 1 for missed path or user input
20 # 2 for an aborted run (by not saying yes to a 'are you sure?'
21 # 3 for failed lpadmin commands
22 # 4 for possible security problem
24 # make base name for temp files.
26 TMP_STUFF="/tmp/`basename $0`.$$"
29 mkdir -m 700 ${TMP_STUFF} || exit 4
30 trap 'rm -f $TMP_STUFF > /dev/null 2>&1' 0
33 # grab the pathname the script was called w/
34 # if it was run by ./add... then make the path == `pwd`
38 if [ "$RUNHOME" = "." ]; then
42 # allow for the env NETATALKHOME to override the guessed one from above
44 NETATALKHOME=${NETATALKHOME:-$RUNHOME}
47 PATH=/bin:${PATH}:${NETATALKHOME}/bin:${NETATALKHOME}/etc:${NETATALKHOME}/etc/filters:/usr/lib:/usr/sbin
49 if [ ! -x ${NETATALKHOME}/bin/pap ]; then
50 echo "OPPS: I don't see ${NETATALKHOME}/bin/pap ,"
51 echo ' Check that it is executable or set ${NETATALKHOME}'
52 echo ' so i can find pap at ${NETATALKHOME}/bin/pap'
53 echo '[We are guessing the location of the binary from the'
54 exho 'path that was used to run this sctipt or $NETATALKHOME]'
58 # get the user to tell us where to look for things, and list things there.
61 echo "Enter Appletalk zone [default: local]: \c"
66 echo "Looking for LaserWriters in Zone ${ZONE} ..."
67 $NETATALKHOME/bin/nbplkup ":LaserWriter@${ZONE}"
70 echo "Enter AppleTalk printer name: \c"
74 if [ "$DEST" = "" ]; then
75 echo "OPPS: you need to tell me a printer name"
79 echo "checking nbplkup ${DEST}:LaserWriter@${ZONE}"
81 TestDEST=`$NETATALKHOME/bin/nbplkup "${DEST}:LaserWriter@${ZONE}"`
85 if [ "${TestDEST}" = "" ]; then
86 echo "I don't see that printer on the network. You may have entered an incorrect"
87 echo "printer name - if so, exit and restart."
88 echo "[You should only enter the printer name, not the :LaserWriter portion]"
94 NBPNAME="${DEST}@${ZONE}"
99 # scrunch all of the whitespace and / out of the appletalk name and suggest
100 # that as the unix name
102 SUGGEST=`echo "$DEST" | cut -d: -f1 | sed 's/ //g' | sed 's#/##g` ; export SUGGEST
104 # truncate the suggested name to 14 chars to conform to lp specs.
106 SUGGEST1=`expr ${SUGGEST} : '\(..............\)'`
107 SUGGEST=${SUGGEST1:-$SUGGEST}
109 echo "Enter Unix printer name - [default: ${SUGGEST}] : \c"
112 if [ "${UNIXPRINT}" = "" ]; then
113 UNIXPRINT="${SUGGEST}"
118 # Here we check for legal names again. >14 chars
121 UNIXPRINT1=`expr "${UNIXPRINT}" : '\(..............\)'`
123 # if UNIXPRINT is shorter than 14chars, UNIXPRINT1 ends up null ("")
124 # if UNIXPRINT was longer, then we get a 14char version of it. bleah.
126 if [ "${UNIXPRINT1}" = "" ]; then
127 UNIXPRINT1="${UNIXPRINT}"
129 #if [ "${UNIXPRINT1}" != "${UNIXPRINT}" ]; then
130 echo "Opps, that name was too long... Truncating to 14 chars."
131 echo "setting printer name to '${UNIXPRINT}'"
132 UNIXPRINT="${UNIXPRINT1}"
135 echo "Enter a Description for this printer. [The Appletalk name will"
136 echo "be included by default, and must be included for the printing"
137 echo "filters to work.] : \c"
140 DESC="${DESC} [${NBPNAME}]"
143 echo "Do you want all printjobs to print out in reversed page order?"
144 echo "This is usually only desired if this printer stacks jobs"
145 echo "face up in the output bin. [N/y] \c"
147 case ${REV} in [Yy]*) REV="Netatalk-R" ;;
152 if lpstat -p ${UNIXPRINT} >/dev/null 2>&1 ; then
154 echo "OPPS: There already exists a printer named '${UNIXPRINT}'"
155 echo " here are the comments from /etc/lp/printers/${UNIXPRINT}/comment"
156 cat /etc/lp/printers/${UNIXPRINT}/comment
158 echo "Do you still want to do this? This will flush "
159 echo "all pending jobs! [Y/n]? \c"
161 case ${DOTHIS} in [Yy]*) ;;
165 echo "Rejecting all new jobs for ${UNIXPRINT}"
166 reject -r "Making ${UNIXPRINT} a netatalk printer" ${UNIXPRINT}
167 echo "Disabling and Flushing the ${UNIXPRINT} queue"
168 disable -c -r "Making ${UNIXPRINT} a netatalk printer" ${UNIXPRINT}
172 # Check if we need to do silly tricks to share the printer... only on 5.5.1 or older
175 if [ "`uname -r`" -lt "5.6" ]; then
177 echo "Do you want to share this printer w/ other machines [Y/n]?\c"
180 echo "You're running SunOS 5.6 or higher... skipping 'sacadm' and 'pmadm'"
183 if nistest printers.org_dir; then
184 echo "Do you want to add this printer to your NIS printer map? [y/N]"
185 echo "(You will need to share this printer w/ other machines)"
187 case ${NIS} in [Yy]*) ADD_NIS=1 ;;
192 echo "Do you want to save the error messages from pap in"
193 echo "'/var/spool/lp/tmp/Netatalk/${UNIXPRINT}' [y/N]"
194 echo "(If you answer N, error messages will go to /dev/null.)"
196 case ${SAVEerr} in [Yy]*) SAVEerr=1 ;;
200 echo "Making ${UNIXPRINT} print to ${DEST} via netatalk"
202 if [ "${SAVEerr}" = "" ]; then
205 LOCKS=/var/spool/lp/tmp/Netatalk
206 if [ ! -d ${LOCKS} ]; then
207 mkdir -m 0771 ${LOCKS}
211 LOCKDEV=${LOCKS}/${UNIXPRINT}
213 chown lp:lp ${LOCKDEV}
219 if [ ! -r /etc/lp/filter.table ]; then
220 echo "Setting up the existing print filters..."
221 for i in `ls /etc/lp/fd | sed 's/.fd$//'`; do
222 lpfilter -f ${i} -F/etc/lp/fd/${i}.fd
225 if lpfilter -f netatalk -l > /dev/null 2>&1 ; then
226 echo 'Looks like you have a Netatalk printer filter defined. Good!'
228 echo "Humm... You need a Netatalk printer filter..."
229 echo "... making you one ..."
230 cat > /etc/lp/fd/netatalk.fd << EOF
231 #ident "@(#)netatalk.fd 0.2 97/09/04 job@uchicago.edu" /* Netatalk 1.4 */
233 Input types: postscript
235 Printer types: Netatalk
238 Command: ${NETATALKHOME}/etc/filters/ifpap 2>&1 > /dev/null
240 chown lp:lp /etc/lp/fd/netatalk.fd
241 chmod 664 /etc/lp/fd/netatalk.fd
242 lpfilter -f netatalk -F /etc/lp/fd/netatalk.fd
245 if lpfilter -f netatalk-r -l 2>&1 > /dev/null ; then
246 echo 'Looks like you have a Reverse Netatalk printer filter defined. Good!'
248 echo "Humm... You need a Reverse Netatalk printer filter..."
249 echo "... making you one ..."
250 cat > /etc/lp/fd/netatalk-r.fd << EOF
251 #ident "@(#)netatalk-r.fd 0.2 97/09/04 job@uchicago.edu" /* Netatalk 1.4 */
253 Input types: postscript
255 Printer types: Netatalk-R
258 Command: "/usr/lib/lp/postscript/postreverse | ${NETATALKHOME}/etc/filters/ifpap 2>&1 >/dev/null"
260 chown lp:lp /etc/lp/fd/netatalk-r.fd
261 chmod 664 /etc/lp/fd/netatalk-r.fd
262 lpfilter -f netatalk-r -F /etc/lp/fd/netatalk-r.fd
265 if [ ! -r /usr/share/lib/terminfo/N/Netatalk ]; then
266 echo "Making a Terminfo entry for Netatalk printers"
267 cat > ${TMP_STUFF}/terminfo << EOF
270 cpi=null, csnm=^D, lpi=null, scs=^D, slines=^D, u9=^D,
272 tic ${TMP_STUFF}/terminfo
273 chown bin:bin /usr/share/lib/terminfo/N/Netatalk
274 chmod 644 /usr/share/lib/terminfo/N/Netatalk
277 if [ ! -r /usr/share/lib/terminfo/N/Netatalk-R ]; then
278 echo "Making a Terminfo entry for Reversed Netatalk printers"
279 cat > ${TMP_STUFF}/terminfoR << EOF
282 cpi=null, csnm=^D, lpi=null, scs=^D, slines=^D, u9=^D,
284 tic "${TMP_STUFF}/terminfoR"
285 chown bin:bin /usr/share/lib/terminfo/N/Netatalk-R
286 chmod 644 /usr/share/lib/terminfo/N/Netatalk-R
290 # this is old cruft... we should not have done this in the 1st place.
291 # we need to edit the template interface file to point to the local netatalk bins
292 #cat ${RUNHOME}/etc/netatalk.template | sed "s#DEFAULT_NETATALK_HOME#${RUNHOME}#g" \
293 # > "/etc/lp/interfaces/${UNIXPRINT}"
294 #chown lp:lp /etc/lp/interfaces/${UNIXPRINT}
295 #chmod 0775 /etc/lp/interfaces/${UNIXPRINT}
296 # below is the correct way.
299 echo "Setting up ${UNIXPRINT} ... Edit options later as you see fit."
300 lpadmin -p ${UNIXPRINT} -D "${DESC}" -T ${REV} \
301 -i ${RUNHOME}/netatalk.template -I PS -v ${LOCKDEV} -A none || exit 3
302 accept ${UNIXPRINT} || exit 3
303 enable ${UNIXPRINT} || exit 3
305 case ${SHARE} in [Nn]*) exit; ;;
309 echo "Setting up network sharing for ${UNIXPRINT}"
311 # from p925 in the Solaris Administration Guide, Vol. II (2.5)
314 if sacadm -l -p tcp > /dev/null; then
315 echo "already running a tcp listener"
317 echo "Defining tcp listener ..."
318 sacadm -a -p tcp -t listen -c "/usr/lib/saf/listen tcp" \
319 -v `nlsadmin -V` -n 999
322 # this is extra, but a good idea...
324 LPD_ADDR="\\x`lpsystem -A`" ; export LPD_ADDR
325 ADDR_0=`echo $LPD_ADDR | sed -e 's/\\x00020203/\\x00020ACE/g'`; export ADDR_0
327 if pmadm -l -p tcp -s 0 > /dev/null; then
328 echo "<0> service is already defined."
330 echo "Defining <0>/tcp service ..."
331 pmadm -a -p tcp -s 0 -i root \
332 -m `nlsadmin -c /usr/lib/saf/nlps_server -A ${ADDR_0}` \
336 # again from the solaris book noted above.
338 if pmadm -l -p tcp -s lp > /dev/null; then
339 echo "<lp> service is already defined."
341 echo "Defining <lp>/tcp service ..."
342 pmadm -a -p tcp -s lp -i root \
343 -m `nlsadmin -o /var/spool/lp/fifos/listenS5` \
347 if pmadm -l -p tcp -s lpd > /dev/null; then
348 echo "<lpd> service is already defined."
350 echo "Defining <lpd>/tcp service ..."
351 pmadm -a -p tcp -s lpd -i root \
352 -m `nlsadmin -o /var/spool/lp/fifos/listenBSD -A ${LPD_ADDR}` \
356 if [ "${ADD_NIS}" = 1 ] ; then
357 if nistest "[printer_name=${UNIXPRINT}]printers.org_dir"; then
358 nistbladm -m printer_host=`uname -n` \
359 "[printer_name=${UNIXPRINT}]printers.org_dir" description="$DESC"
361 nistbladm -a printer_name=${UNIXPRINT} \
362 description="$DESC" printer_host=`uname -n` printers.org_dir