#! /bin/sh
##############################################
#                                            #
# Modified to use CAP printer types also     #
# rks 6/2/94 (smith@cbrsgi.med.harvard.edu)  #
#                                            #
##############################################
# This shell script creats a /tmp/.printtest 
# 		for printing from System Manager Printer Tool Test button.
#  This script creats a different file based on PrinterType.
#  Creates an either ASCII/PostScript/RGB file depending on dumb/ps/color
#						Printer Type.
#  Usage: /bin/sh printtest <PrinterName>  <PrinterType>
#  Expected arguments:
#  PrinterName ==> a valid string 
#  PrinterType ==> Dumb/PostScript/Color
#			* dumb  --> assumes a dumb line printer
#			* PostScript --> assumes a PostScirpt printer
#			* Color -->
#
PN=`echo $1`						# PrinterName
PT=`echo $2`						# PrinterType
PF=/tmp/.printtest					# PrintFile
UNAME=`/usr/bsd/hostname `					
HN=`echo $UNAME|awk '{print $1}'` 			# HostName
UN=`/usr/bin/logname`					# User Name

if [ -f "$PF" ]
then
	/bin/rm -f $PF					# Clean it up!
fi

touch $PF						# Create a new file
chmod 666 $PF						# 'rw' for all

case $PT  in
	Dumb) 						# Dumb printer 
	echo "\nTest Printout from the System Manager Printer Tool.\n\n" >> $PF
	echo "This test message was printed by $UN@$HN\c" >> $PF
	echo " on the $PT printer named \"$PN.\""	>> $PF
	;;
	PostScript)					# PostScript printer 
	echo "%! \n/S {show} def /M {0 -16665 rmoveto} def" > $PF
	echo "/N {/Helvetica findfont 16665 scalefont setfont} def" >> $PF
echo "/H {/Helvetica-Bold findfont 26000 scalefont setfont} def" >> $PF
echo "/MT {moveto} def /NL {()S M} def  /P  {100000} def" >> $PF
echo "/M1 {(Test Printout from the System Manager Printer Tool.)} def" >> $PF
echo "/M2 {(This test message was printed by )} def" >> $PF
echo "72 P div 72 P div scale H()pop" >> $PF
echo "P 983335 MT NL M1 S M N NL NL P 916675  MT M2 S ($UN)S (@)S \c" >> $PF
echo "($HN)S ( on the )S (PostScript)S ( printer named \")S ($PN)S (.\")S showpage" >> $PF
		;;
	CAP)					# CAP (PostScript) printer 
	echo "%! \n/S {show} def /M {0 -16665 rmoveto} def" > $PF
	echo "/N {/Helvetica findfont 16665 scalefont setfont} def" >> $PF
echo "/H {/Helvetica-Bold findfont 26000 scalefont setfont} def" >> $PF
echo "/MT {moveto} def /NL {()S M} def  /P  {100000} def" >> $PF
echo "/M1 {(Test Printout from the System Manager Printer Tool.)} def" >> $PF
echo "/M2 {(This test message was printed by )} def" >> $PF
echo "72 P div 72 P div scale H()pop" >> $PF
echo "P 983335 MT NL M1 S M N NL NL P 916675  MT M2 S ($UN)S (@)S \c" >> $PF
echo "($HN)S ( on the )S (PostScript)S ( printer named \")S ($PN)S (.\")S showpage" >> $PF
		;;
	Color) 					# Prints RGB file.
	/bin/cp /usr/lib/vadmin/Printtest.rgb /tmp/.printtest
		;;
esac
/usr/bin/lp -d$PN -c $PF                      # Print the file
/bin/rm -f $PF                                # Clean it up!!!

