#! /bin/sh
#
# @(#)setHOSTNAME	1.5	LPS_UNX_COM	2/19/95
#
# Copyright 1994   Digital Equipment Corporation, Maynard, MA
#
# setHOSTNAME
#
# A script that produces a value for attribute HOSTNAME.   Currently
# this script is only designed for use with the PS class.
#
# To keep the user from unecessarily calling for support when the printer
# can't be reached, we FORCE the user to have already entered the hostname
# in the /etc/hosts file (or equivalent); letting the user setup the
# printer now, then expecting the hostname to be entered later (BEFORE the
# printer was accessed), was found to not work...invariably the user would
# forget, then call support to complain that a Management or Print Client
# couldn't connect to the printer.

# Parameters:
#    $1 - LPS class identifier, one of {PC, MC, PS, ENV}
#    $2 - Operating system type identifier (eg: SV2, BSD, etc)
#    $3 - Print client type identifier (eg: AIX, BSD, SV3, etc)
#    $4 - PrintServer printer model (eg: LPS17, LPS20)
#    $5 - Default value for the attribute (IGNORED)
#    $6 - Path of the output file to receive the final attribute value
#
# Global variables:
#    ECHON
#    FUNCS
#    PAGER
#    TMPDIR
#
# Exit values:
#    0 - Success, output file contains newly set attribute value.
#    1 - Error or interruption occurred, error messages go to stderr,
#	 contents of the output file are undefined.
###

CLASS=$1
OSTYPE=$2
PCTYPE=$3
PSMODEL=$4
DEFVAL=$5
OUTFILE=$6

. $FUNCS   # Import the standard LPS shell functions

SUFFIX="? "

if [ "$DEFVAL" ]
then
    if testhost "$DEFVAL" > /dev/null 2>&1
    then
	SUFFIX=" [$DEFVAL]? "
    else
	DEFVAL=""	# zap this bad host name, no default
    fi
fi

QUESTION="What is the internet host name of the printer$SUFFIX"

goodhost=false

while true
do
    echo
    $ECHON "$QUESTION"
    read RESPONSE

    if [ -z "$RESPONSE" ] ; then RESPONSE="$DEFVAL"; fi

    if [ "$RESPONSE" ]  # hostname entered
    then
	if testhost "$RESPONSE" > /dev/null 2>&1
	then
	    showhelp false "[That name exists in your system host database]"

	    goodhost=true
	else
	    $PAGER << END_OF_INPUT

    There is no record of the existence of an internet host with the name
    "$RESPONSE" here on host "$LOCALHOST".
    The printer's host name must be properly registered before the printer
    can be defined.

    Normally an entry can be created in the "/etc/hosts" file, but if your
    system is part of a network of machines that are under some type of
    distributed central administration (such as NIS/Yellow Pages or BIND),
    then typically you must add the host name definition in the appropriate
    central database and NOT on the local system.

    Please note that this script does not attempt to automatically modify
    your host database; you must do this yourself (or have someone do it
    for you), as most customers prefer complete control over this critical
    system database.

    If you would now like to go and register "$RESPONSE" in the database,
    then press CTRL/C to return to the previous menu.
END_OF_INPUT
	fi
    fi

    if $goodhost
    then
	echo "$RESPONSE" > $OUTFILE
	exit 0
    fi
done
