
# HPUX_ID: @(#)29.1   86/07/04
#          @(#)getlp	29.1      86/04/23     

# Script to allow LP control without logging in, and still allow login.

# Usage: <script> line speed

# Called from inittab in place of getty.
# Arguments MUST be as shown; other args and/or options are not allowed.
# Forces its own value for timeout.


# INITIALIZE, CHECK ARGS:

	PATH="/bin:/usr/bin:/usr/local/bin:/usr/contrib/bin"
	TZ=MST7MDT
	export PATH TZ

	printers="epoc lp laser"		# complete list.

	timeout=20				# for getty.

	if [ $# -ne 2 ]				# bad call.
	then
	    sleep 300				# avoid fast loop.
	    exit 1				# no way to print an error.
	fi


# SET UP TERMINAL:

	exec < "/dev/$1" > "/dev/$1" 2>&1	# attach to device for R/W.

	stty 9600 erase \^h kill \^u eof \^d eol \^\`			\
		-parenb -parodd cs8 -cstopb -hupcl cread clocal -crts	\
		-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr	\
		-igncr icrnl -iuclc ixon ixany -ixoff ienqak		\
		isig icanon -xcase echo echoe echok -echonl -noflsh	\
		opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel 

	tabs
	slp='/usr/spool/lp'


# WAIT FOR COMMAND:

	while true				# until break.
	do
	    echo \
"\nLP:  Help, Status, Processes, Rcvlog, Files, Enable, Disable, Kill, Login? \c"

	    read command
	    echo				# blank line.


# EXECUTE A COMMAND:

	    case "$command" in

	    [hH]*)  cat <<-'!'
    Status	show LP spooler status (lpstat -t)
    Processes	show all lp and lprcv processes (ps -f -ulp -ulprcv)
    Rcvlog	show today's remote receive log (cat /usr/spool/lp/log.receive)
    Files	received but not yet respooled (ll -R /usr/spool/lp/receive)
    Enable	enable epoc printer
    Disable	disable epoc printer (usually saves current job)
    Kill	disable all printers, lpshut, wait, kill -9 all lp processes,
                remove lockfile, lpsched, enable all printers
    Login	start a getty on this terminal so you can log in

    If the printer is on-line but nothing is happening, check Status and
    Processes.  You may need to Enable.  If you see just two lpsched processes,
    with the child in an infinite loop, do a Kill.
!
	    ;;

	    [sS]*)  lpstat -t			;;
	    [pP]*)  ps -f -ulp -ulprcv		;;
	    [rR]*)  cat $slp/log.receive	;;
	    [fF]*)  ls -lR $slp/receive		;;
	    [eE]*)  enable epoc			;;

	    [dD]*)  echo "Reason for disabling? \c"
		    read reason
		    disable -r"$reason" epoc
		    ;;

	    [kK]*)  echo "Disabling printers..."
		    disable -r"restart lpsched" $printers

		    echo "Shutting lpsched..."
		    /usr/lib/lpshut
		    sleep 2

		    echo "Killing lp processes (if any)..."
		    kill -9 `ps -f -ulp | awk '($1 == "lp") {print $2}'`

		    echo "Starting lpsched..."
		    rm -f $slp/SCHEDLOCK
		    /usr/lib/lpsched
		    enable $printers
		    ;;

	    [lL]*)  break			  ;; # out of while loop.

	    *)	    echo "Unrecognized command: \"$command\""
		    echo "Commands are as shown above (or just first letters)."
		    ;;

	    esac
	done


# Start getty, force timeout:

	echo "Calling getty; you have $timeout seconds to login before reset."
	exec /etc/getty -t$timeout "$1" "$2"
