
PATH=$PATH:/bin:/usr/bin:/etc:/usr/etc
export PATH
# figure out how to echo without a linefeed
BC=; NC=; n=`echo -n`; if [ -z "$n" ]; then NC="-n"; else BC="\\c"; fi 
export BC NC
qsroot=$1

echo "Printer Setup..."
n=0
echo $NC "Would you like to configure one or more printers? [y] $BC"
read ans
if [ "$ans" = "n" -o "$ans" = "no" ]
then echo "Exiting..."; exit 0
fi
if [ "$qsroot" = "" ]
then while true; do
	if [ "$QSROOT" = "" ]
	then QSROOT=/usr/qsp
	fi
	echo $NC "In what directory is the product installed? [$QSROOT] $BC"
	read ans
	if [ "$ans" = "" ]
	then qsroot=$QSROOT
	else qsroot=$ans
	fi
	touch $qsroot/printers/test$$ 2>/dev/null
	if [ ! -d $qsroot/printers ]
	then echo "$qsroot/printers does not exist"
	elif [ ! -f $qsroot/printers/test$$ ]
	then echo "You do not have write access to $qsroot/printers"
	else break
	fi
	echo $NC "Exit? [y] $BC"; read ans 
	if [ "$ans" = "y" -o "$ans" = "yes"  -o "$ans" = "" ]
	then exit; fi
done; fi
rm $qsroot/printers/test$$ 2>/dev/null
echo "Product installation directory (QSROOT) is set to $qsroot"
while true
do
n=`expr $n + 1`
echo "Printer #$n..."
echo "Please select one of the following print formats:

	1. ascii (any printer)
	2. ps (any PostScript printer)
	3. pcl5 (HP Laserjet III)
	4. gl2 (HP plotter)
"
while true
do
	echo $NC "Enter (1,2,3,4) [2] $BC"
	read ans
	case $ans in
		1 ) printformat=ascii; break;;
		3 ) printformat=pcl5; break;;
		4 ) printformat=gl2; break;;
		* ) printformat=ps; break;;
	esac
done
echo "Printer format is set to $printformat"
echo $NC "Please enter the print command as you would at the shell
(e.g. lpr): [lpr] $BC"
read printcom
if [ "$printcom" = "" ]
then printcom=lpr
fi
echo "Print command is $printcom"
while true
do
	while true
	do
		echo $NC "What do you wish to name this printer: $BC"
		read name
		if [ "$name" = "" ]
		then echo $NC "Exit? [n] $BC"
		     read ans
		     if [ "$ans" = "y" -o "$ans" = "yes" ]
		     then exit
		     fi
		else break
		fi
	done
	if [ -f $qsroot/printers/$name ]
	then echo $NC "$qsroot/printers/$name already exists - overwrite? [n] $BC"
	     read ans
	     if [ "$ans" = "" -o "$ans" = "n" -o "$ans" = "no" ]
	     then continue
	     else break
	     fi
	else break     
	fi
done
echo "Printer name is $name"
echo "Configuring printer $name..."
echo "
# printer profile created by printersetup script

printformat=$printformat
printcom=$printcom
" > $qsroot/printers/$name

echo $NC "Do you wish to configure another printer? [n] $BC"
read ans
if [ "$ans" = "" -o "$ans" = "n" -o "$ans" = "no" ]
then exit
fi
done
