#!/sbin/sh
#@(#)HP X Station Admin Scripts
#
# getuhatag	Get link level address of X station for bootptab file
#

while [ 0 ] 
do
	echo ""
	echo "The LAN hardware address of an HP X Station is shown on "
	echo "its boot screen and its shipping carton label."
	echo ""
  	$ECHO "Enter LAN hardware address of X station [q|?] : 080009$NL"
	read UHATAG 
	case $UHATAG in
	\?)
		echo ""
		echo "An example of a correct LAN hardware address is 08000903b186."
		echo "A LAN hardware address always consists of 12 hexadecimal digits."
		echo ""
		continue
		;;

	q)
		exit 100
		;;
	"")
		continue
		;;
	esac

	X=`echo $UHATAG | tr ABCDEF abcdef | sed "s/^0x//"`
	if [ "`echo $X | wc -c`" -le "12" ]
	then
	  UHATAG=080009$X
        else
	  UHATAG=$X
        fi
	echo $UHATAG | egrep '^[0-9|a-f][0-9|a-f][0-9|a-f][0-9|a-f][0-9|a-f][0-9|a-f][0-9|a-f][0-9|a-f][0-9|a-f][0-9|a-f][0-9|a-f][0-9|a-f]' > /dev/null 2>&1
	if [ $? -eq 0 ]
	then
		RETCODE=`echo $UHATAG | awk '{print $1}' | wc -c`
		if [ $RETCODE = "13" ]
		then
			break
		fi
	fi
		echo ""
		echo "Invalid value (must contain hexadecimal digits only)."
  		echo "Please enter 12 hexadecimal digits."
		echo ""
done


echo $UHATAG > $TMP/UHATAG
if [ $? != 0 ]
then
	echo "Couldn't create a temporary file, is directory $TMP NFS mounted?"
	exit 1
fi

exit 0
