#!/sbin/sh
#@(#)HP X station Admin Scripts
#
# whichport	 find out if printer port is serial1, serial 2 or parallel
#

while [ 0 ] 
do
  echo
  echo
  cat <<EOF
        _________________________________________________

		Type of Connection:

	1) Serial

	2) Parallel

		?) Help		p) return to printer menu

EOF

  $ECHO "Which type of connection does your printer have? (default=2): $NL"
  SEL=`line` 
  case $SEL in
    1)
      while [ 0 ]
      do
        echo
        cat <<EOF
        _________________________________________________

                Port Reserved for Printer: 

        1) Serial 1 (or RS-232)

        2) Serial 2

                ?) Help         p) return to printer menu

EOF
       $ECHO "Which port is reserved for the printer? (default=1): $NL"
        SEL=`line`
        case $SEL in
          1|"")
	    PERIPHPORT=9100
	    break ;;
          2)
            xtutil_can-ping $XTNAME
            if [ $? -eq 0 ]
            then
              $REMSH $XTNAME get config \
                | egrep '(^SP1)|(^Serial[	 ]*[(]1[)])'> /dev/null 2>&1
              if [ $? -eq 0 ]
              then
                $REMSH $XTNAME get config \
                 | egrep '(^SP2)|(^Serial[ 	]*[(]2[)])'> /dev/null 2>&1
                if [ $? -ne 0 ]
                then
                  cat <<EOF

Error: Unable to communicate with Serial Port 2 for this X station
Explanation: All X stations have at least one serial port (labelled Serial 1 
or RS-232). Selected ENTRIA and ENVIZEX models have an additional serial 
port (labelled Serial 2).
This error message indicates that the X station you are administering has only
one serial port. When the "Connect to Port" menu is re-displayed, select:
         1) Serial 1 (or RS-232)
EOF
	          continue 
                else
	          PERIPHPORT=9102
	          break 
                fi
              fi
            fi
            
            cat <<EOF
Error: Unable to verify the existence of Serial Port 2 on this X station.
Explanation: The X station is likely powered off and therefore not responding
to communication attempts to either serial port.
Please note: All X stations have at least one serial port (labelled Serial 1 
or RS-232). Only Selected ENTRIA and ENVIZEX models have an additional serial 
port (labelled Serial 2).

EOF
            $ECHO "Are you sure that this X station has a second serial port? [y|n] (y): $NL"
            SEL=`line`
            case $SEL in
              y*|Y*|"")
                PERIPHPORT=9102
                break ;;
              *) 
                echo "" 
                echo "No changes to print spooler." 
                echo "" 
                exit 100
                ;;
            esac
	    ;;
	  p*|P*)
	    exit 100 ;;
	  \?)
	    cat <<EOF


Depending upon the model of your X station you may have one or two serial ports
available for connecting printers.

All X stations have at least one serial port (labelled Serial 1 or RS-232).
Selected ENTRIA models and ENVIZEX (p series) models have an additional
serial port (labelled Serial 2).

If you are unsure whether this X station has a second serial port,
choose the default, Serial 1.

EOF
	    continue ;;
          *)
            echo ""
            echo "Invalid selection"
            continue ;;
        esac 
      done
      break
      ;;
  2|"")
    PERIPHPORT=9101
    break ;;
  p*|P*)
    exit 100 ;;
  \?)
     cat <<EOF



A serial printer connects to a serial port on the back of your X station.
All X stations have at least one serial port (labelled Serial 1 or RS-232).
Selected ENTRIA models and ENVIZEX "Series p" base units have an additional
serial port (labelled Serial 2).

A parallel printer connects to the port on the back of your X station 
labelled "PARALLEL".

EOF
    continue ;;
 *)
    echo ""
    echo "Invalid selection"
    continue ;;
  esac
done

echo $PERIPHPORT > $TMP/PERIPHPORT

exit 0
