#!/bin/sh
# @(#) $Header: getname,v 1.24 93/02/22 15:06:49 ss2 Exp $
#
#  Call this program as "getname option-name default-printer-name"

OPTION=$1
DEFAULT=$2

while [ 0 ] 
do
  if [ -n "$DEFAULT" ]
  then
    echo ""
    if [ "$OPTION" = "option4" -o "$OPTION" = "option5" ]
    then
      $ECHO "Enter the X Station name or IP address (default=$DEFAULT): $NL"
    else
      $ECHO "Enter the X Station name (default=$DEFAULT): $NL"
    fi
  else
    echo ""
    if [ "$OPTION" = "option4" -o "$OPTION" = "option5" ]
    then
      $ECHO "Enter the X Station name or IP address: $NL"
    else
      $ECHO "Enter the X Station name: $NL"
    fi
  fi
  read PNAME
  if [ "$PNAME" = "q" ]
  then
    exit 1
  fi
  if [ "$PNAME" = "" ]
  then
    PNAME="$DEFAULT"
  fi
  if [ "$PNAME" = "" ]
  then
    continue
  fi
  if [ "$PNAME" = "?" ]
  then
      case $OPTION in
	option4)
	  echo ""
	  echo "The X Station named will be sent five \"echo\" packets by the"
	  echo "ping utility.  This is a low level network test that tests if"
	  echo "the X Station is responding to its IP address."
	  echo ""
	  echo "If this test passes, the next step is to test the network"
	  echo "printer operation by sending a file to the printer."
	  echo ""
	  echo "If this test fails, the problem must be diagnosed before further"
	  echo "tests are made."
	  ;;
	option5)
	  echo ""
	  echo "The printer named will have a file sent to it over the"
	  echo "network.  The spooler is not involved in the file transfer."
	  echo "Sending the printer a file without involving the spooler"
	  echo "shows that the system is working so far and gives us confidence"
	  echo "that everything should work after configuring the spooler."
	  echo ""
	  echo "If this test passes, the next step is to configure the spooler"
	  echo "to transfer printjobs over the network."
	  echo ""
	  echo "If this test fails, the problem must be diagnosed before"
	  echo "configuring the spooler."
	  ;;
	option6hp|option6solaris)
	  echo ""
	  echo "The X Station name is the name entered in /etc/hosts,"
	  echo "NIS(+) (Network Information Service), or DNS (Domain Name System.)"
	  ;;
         *) 
	  echo "system error in \"getname\" (OPTION=$OPTION)"
          exit 1
	  ;;
      esac
      echo ""
      $QUITHELP
      continue
  fi

  case $OPTION in
    option4|option5)
      LOOKUPPNAME=`gethostaddr "$PNAME"`
      if [ "$LOOKUPPNAME" = "" ]
      then
	echo ""
	echo "$PNAME: unknown X Station"
	echo ""
	echo "The IP address was not found for this name.  Enter the name in"
	echo "/etc/hosts, NIS (Network Information Service), or DNS (Domain"
	echo "Name System) and try this test again.  An IP address can be given"
	echo "at the prompt for this test instead of a name although the name"
	echo "must still be entered /etc/hosts, NIS, or DNS before configuring"
	echo "the spooler."
	echo ""
	$QUITHELP
      else
        break
      fi
      ;;
    option6solaris)
      LOOKUPPNAME=`gethostaddr "$PNAME"`
      if [ "$LOOKUPPNAME" = "" ]
      then
	echo ""
	echo "*****************************************************************"
	echo "$PNAME: unknown X Station"
	echo ""
	echo "The IP address was not found for this name.  Enter the name in"
	echo "/etc/hosts, NIS (Network Information Service), or DNS (Domain"
	echo "Name System) before attempting to use this X Station through"
	echo "the spooler."
	echo "*****************************************************************"
      else 
        break   
      fi
      ;;
    *) break ;;
  esac
done

echo "$PNAME" > $TMP/NAME
echo "$PNAME" > $TMP/XTNAME
exit 0

