#!/bin/sh
# @(#) $Header: hpnpcfg,v 1.50 93/02/22 15:07:00 ss2 Exp $
#
#  mark variables which are modified or created for export
set -a

HPNP=/usr/lib/hpnp
QUITHELP='echo Enter "q" to return to the main menu'
SAVENAME=""
SAVEIPADDR=""
TFTPDIR=""

#
#   Make sure /tmp or /usr/tmp directories exist on host 
#
if [ -d /tmp ]
then
  TMP="/tmp"
elif [ -d /usr/tmp ]
then
  TMP="/usr/tmp" 
else
  echo "No /tmp or /usr/tmp working directories - cannot continue."
  exit 1
fi

LOG=$TMP/hpnpcfg.log
HOSTNAME=`uname -n`
ECHO="echo"
NL="\c"
PATH="/bin:/usr/bin:/usr/sbin:/etc:$PATH"
PATH="$HPNP:$HPNP/cfg:$PATH"


#
# Log the start time of hpnpcfg
#
echo "" >> $LOG
echo "======== `date` BEGIN HPNPCFG ON $HOSTNAME" >> $LOG



CHANGES=0
while [ 0 ]
do
  echo ""
  echo "        HP X STATION PRINTER CONFIGURATION TASKS"
  echo "                    MAIN MENU"
  echo ""
  echo "        1) Verify X Station network printer connectivity"
  echo "        2) Verify X Station network printer operation"
  echo "        3) Add X Station printer to UNIX spooler"
  echo "        4) Remove X Station printer from UNIX spooler"
  echo ""
  echo "             ?) Help            q) Quit"
  echo ""
  $ECHO "Please enter selection: $NL "
  read SEL
  case $SEL in
	1) echo "======== MENU CHOICE 4 - no system changes made" >> $LOG
	   #
           # Ignore interrupt signals since it is common
           # to interrupt ping.
	   #
	   trap "" 1 2 3 15
	   if [ "$SAVEIPADDR" = "" ]
	   then
	     option4 $SAVENAME
	   else
	     option4 $SAVEIPADDR
	   fi
	   #
	   # Reset signals handlers.
	   #
	   trap 1 2 3 15
	   ;;
	2) echo "======== MENU CHOICE 5 - no system changes made" >> $LOG
	   #
           # Ignore interrupt signals since user might interrupt
           # the file send if peripheral is not responding.
	   #
	   trap "" 1 2 3 15
	   if [ "$SAVEIPADDR" = "" ]
	   then
	     option5 "$SAVENAME" "$SAVEGETCOM"
	   else
	     option5 "$SAVEIPADDR" "$SAVEGETCOM"
	   fi
	   trap 1 2 3 15
	   ;;
        3) echo "======== BEGIN MENU CHOICE 6" >> $LOG
           option6solaris $SAVENAME
	   CHANGES=1
	   echo "======== END MENU CHOICE 6" >> $LOG
           ;;
        4) echo "======== BEGIN MENU CHOICE 8" >> $LOG
             option8solaris $SAVENAME
	     CHANGES=1
	     echo "======== END MENU CHOICE 8" >> $LOG
           ;;
        q|Q) 
	   if [ "$CHANGES" = "1" ]
	   then
	     echo ""
	     echo "A log of the system changes made during this configuration"
	     echo "session was appended to $LOG."
	     echo ""
	   fi
	   break;;
	\?) echo ""
            echo "To configure a new network printer, use options 1 through 4. "
            echo "Option 1 verifies that the X Station can operate as a network node."
            echo "Option 2 sends a test file to an X Station printer."
            echo "Option 3 adds an X Station printer to the UNIX spooler" 
            echo "Option 4 removes an X Station printer from the UNIX spooler"
            echo ""
            $ECHO "Press the return key to continue ... $NL"
            read RESP
	    ;;
          *) echo "Invalid selection";;
     esac
done
