#! /bin/sh
#
# @(#)setENETADDR	1.6	LPS_UNX_COM	04/17/95
#
# Copyright 1995   Digital Equipment Corporation, Maynard, MA
#
# setENETADDR
#
# A script that produces a value for attribute ENETADDR.
#
# 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
#    $6 - Path of the output file to receive the final attribute value
#
# Global variables:
#    ECHON
#    FUNCS
#    PAGER
#    TR
#
# 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

showhelp true "
What is the Ethernet address of the printer?

In order to boot the printer after it has been powered up, your
system needs to know the Ethernet address of the printer.  By
knowing the printer's Ethernet address, your system is able to
recognize and respond to the network boot request messages sent
by the printer.

If you do not know the printer's Ethernet address, you can find out by
examining the printer's front panel shortly after powering on the printer.
Once a printer has been powered up and has run through its internal
diagnostics, the Ethernet address is displayed on the front panel.
Record this information and enter it here.

The format used to specify an Ethernet address is:  xx-xx-xx-xx-xx-xx

That is, six pairs of hexadecimal digits separated by hyphen (\"-\")
characters.

In example of a valid Ethernet address is: 08-00-2b-0c-7e-8b

NOTE:  If you are not planning to boot this printer from this system,
       then you may simply press RETURN at the prompt.

For more information about Ethernet addresses, please refer to the
Management Guide.
"

testaddr ()
{
    addr=$1

    if [ -z "`echo $addr | $TR -d 'ABCDEFabcdef0123456789\-'`" ]
    then
	if [ `expr "$addr" : '.*'` -eq 17 ]
	then
	    return 0
	fi
    fi

    return 1
}

# See if the default value is usable or not, then set the question
# text based on the results.

RESPONSE="$DEFVAL"

if testaddr $RESPONSE
then
    QUESTION="Ethernet address [${RESPONSE}]: "
else
    QUESTION="Ethernet address: "
    DEFVAL=""
fi

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

    # If the user entered a null response (ie, just pressed RETURN),
    # then if there is no default value, simply write out a null value
    # to the output file and be done with it.
    #
    # Otherwise, if a null response was entered, but there *is* a default
    # value, then ask the user if this variable should be "blanked out",
    # or whether the default value should indeed be used.

    if [ -z "$RESPONSE" ]
    then
	if [ -z "$DEFVAL" ]
	then
	    break	# Leave this value NULL, then
	else
	    if yesno y "Do you wish to retain the current value"
	    then
	    	RESPONSE="$DEFVAL"
		break	# Break out and write out the default value
	    fi

	    if yesno y "Do you want to leave this value blank"
	    then
		break	# Break out and write out a NULL value
	    fi
	fi

    else	# User entered some sort of value

	if testaddr $RESPONSE
	then
	    break	# Break out and write out this entered value
	fi

	cat << END_OF_INPUT

    Sorry, but "$RESPONSE" is an invalid Ethernet address.

    A valid Ethernet address consists of no more than 17 characters,
    consisting of six pairs of hexadecimal digits separated by hyphens.
    Do not use space or tab characters at any time to enter this address.

    An example of a valid Ethernet address is:  08-00-2b-0c-7e-8b
END_OF_INPUT

    fi

done

# Come here only when we've broken out of the while loop above

echo "$RESPONSE" > $OUTFILE

exit 0
