#!/bin/bash
# make_new_atalk_printer
#
# David Mathog, mathog@caltech.edu 24-OCT-2001.
#
# Installs a new atalk printer into the printcap etc in a manner
# compatible with Linux printtool. It assumes that printtool etc.
# are installed. Netatalk must be working, as must nbplkup and pap.
#
# Arguments are:
# 1. queue name (may be "name1|name2")
# 2. full ethertalk path (MUST be in quotes)
#
# There is some error checking
#
#
NBPLKUP=/usr/bin/nbplkup
LPDSPOOL=/var/spool/lpd
PRINTCAP=/etc/printcap
PRINTGRP=lp
THEFILTER=/usr/libexec/master-filter
#
invalid=N
if [ $# -ne 2 ]
then
invalid=Y
fi
if [ ! "$1" ]
then
invalid=Y
fi
if [ ! "$2" ]
then
invalid=Y
fi
if [ $invalid = Y ]
then
echo "Usage: make_new_atalk_printer queue_name(s) full_ethertalk_address"
echo "example: make_new_atalk_printer \"newone|name2\" \"Fred's Printer:LaserWriter@Net54\""
exit
fi
#
param1=$1
param2=$2
echo "=======CREATING PRINT QUEUE================="
echo "Queue name(s) will be: $param1"
echo "Ethertalk printer address: $param2"
#
# get the first name if param1 is a list
#
set `echo $param1 | tr "|" " " `
qname=$1
#
# check that directory does not already exist
#
if [ -d $LPDSPOOL/$qname ]
then
echo "The directory $LPDSPOOL/$qname already exists."
echo "A second print queue of the same name may not be added"
exit
fi
#
# check that the filter does exist
#
if [ ! -e $THEFILTER ]
then
echo "The file $THEFILTER was not found"
echo "Either printtool is not installed or it was placed in an unusual location."
echo "No print queues may be added until this problem is resolved."
exit
fi
#
# verify that the printer name is reasonable
#
echo "Checking for existence of ethertalk printer > $param2 <"
$NBPLKUP "$param2" >/dev/null
if [ $? -eq 0 ]
then
echo " Ethertalk printer was not found by. No print queue was created"
exit
else
echo " Ethertalk printer exists. Now making queue."
fi
#
# at this point we're in pretty good shape, just go ahead and do everything
#
QDIR=$LPDSPOOL/$qname
mkdir $QDIR
chown root.$PRINTGRP $QDIR
mknod -m 0666 $QDIR/null c 1 3
chown root.root $QDIR/null
ln -s $THEFILTER $QDIR/filter
echo $param2 >$QDIR/.paprc
chown root.$PRINTGRP $QDIR/.paprc
cat >>$PRINTCAP <