#!/bin/sh
#@(#)HP X Station Admin Scripts
#
# printermenu	Perform various Printer related administrative tasks 
#

CONTEXT=`/bin/getcontext 2>/dev/null`
if [ $? -eq 0 ]
then
  echo $CONTEXT | grep standalone > /dev/null 2>&1
  if [ $? -ne 0 ]
  then
    echo $CONTEXT | grep localroot > /dev/null 2>&1
    if [ $? -ne 0 ]
    then
      echo ""
      echo "This workstation is not a cluster server."
      echo "On clusters of HP 9000 computers sharing the HP-UX file"
      echo "system, printers can only be added to or removed from"
      echo "the spooler when xtadm is being run on the cluster server."
      echo ""
      exit 1
    fi
  fi
fi

if [ ! -f $HPNP/hpnpf ]
then
  echo ""
  echo "The X station printer software must not have been installed since"
  echo "$HPNP/hpnpf does not exist. Re-install the X station software."

  if [ $OS = "sun5" ]
  then
    echo ""
    echo "To add printer SW: run \"pkgadd\" on the \"HPXT-PRNT\" package"
  fi
  echo ""
  exit 1
fi


if [ $OS = "sun5" ]
then
  #
  # Change permission on log file just in case it had been reset
  # (This seems to be a bug in Solaris 2.3)
  #
  LPLOG=/var/spool/lp/log
  if [ ! -f "$LPLOG" ]
  then
    touch "$LPLOG"
  fi

  chown lp $LPLOG 
  chgrp lp $LPLOG 
  chmod 664 $LPLOG 


  # Now do the real thing
  #
  $HPNP/hpnpcfg
  exit 100
fi

while [ 0 ] 
do
	cat <<EOF

	_________________________________________________
		HP X STATION ADMINISTRATIVE TASKS
			PRINTER MENU

	1) Add a printer $PLOTTERMSG

	2) Remove a printer $PLOTTERMSG

	3) Check operation of printer $PLOTTERMSG

		?) Help		p) previous menu

EOF
  	$ECHO "Please enter selection (default=1): $NL"
	read SEL 
	case $SEL in
	   1|"")
		if [ $OS = "sco" ]
		then
			addprinter.sco
		fi

		if [ $OS = "sun4" ]
		then
			addprinter.sun
		fi
		if [ "$OS" = "hp" -o "$OS" = "hp10" ]
		then
			addprinter.hp
		fi
		;; 
	      2)
		if [ $OS = "sun4" ]
		then
			rmprinter.sun
		fi
		if [ "$OS" = "hp" -o "$OS" = "hp10" ]
		then
			rmprinter.hp
		fi
		if [ $OS = "sco" ]
		then
			rmprinter.sco
		fi
		;; 
	      3)
		if [ $OS = "sco" ]
		then
		 ckprinter.sco
		else
		  ckprinter
		fi
		;;
	  p*|P*)
		exit 100
		;; 
	     \?)
		cat <<EOF
Selecting:

1) Add a printer $PLOTTERMSG
	Will allow you to add an X station connected printer $PLOTTERMSG
	to the print spooler on this computer.

2) Remove a printer $PLOTTERMSG
	Will allow you to remove an X station connected printer $PLOTTERMSG
	from the print spooler on this computer.

3) Check operation of a printer
	Will allow you to send a test page to an X station connected
	printer, bypassing the print spooler.

EOF
		;;
	esac

	RETCODE=$?
	if [ $RETCODE -ne 100 ]
	then
		$ECHO "Please type <Enter> to continue $NL"
		read SEL
	fi
done
