#!/sbin/sh
#@(#)HP X Station Admin Scripts
#
#  masks	Get sub-net mask and gateway for bootp
#

GATEWAY=none
SUBNETMASK=none

if [ -f $ADMINDIR/SUBNETMASK ]
then
    SUBNETMASK=`cat $ADMINDIR/SUBNETMASK`
fi

if [ -f $ADMINDIR/GATEWAY ]
then
    GATEWAY=`cat $ADMINDIR/GATEWAY`
fi


while [ 0 ] 
do
	echo ""
  	$ECHO "Enter subnet mask in dot notation [q|?] ($SUBNETMASK): $NL"  
	read SUBM
	case $SUBM in
	    q)
		exit 100
		;;
	   \?)
		cat <<EOF

Specifying a subnet mask helps insure correct operation of your network
when it is connected to other networks through gateways.
The subnet mask allows the X station to decide which computers are
located on its local network and which must be reached through gateways.
The subnet mask should be specified in dot notation similar to an IP address.
An example of a subnet mask would be 255.255.255.0

EOF
		continue
		;;
	   "")
		SUBM=$SUBNETMASK
		;;
	esac

	if [ $SUBM = "none" ]
	then
		break
	fi

	echo $SUBM | egrep '^[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+$' > /dev/null
	if [ $? -eq 0 ]
	then
		break
	fi
	echo "Format error in subnet mask."
	echo "An example of a valid subnet mask is 255.255.255.0  - please re-try!" 
done


while [ 0 ] 
do
	echo ""
  	$ECHO "Enter gateway IP address in dot notation [q|?] ($GATEWAY): $NL"  
	read GW 
	case $GW in
	    q)
		exit 100
		;;
	   \?)
		cat <<EOF

Specifying a default gateway makes it possible for the X station
to run X applications on computers outside its own subnet.
An example of a default gateway IP address would be 192.81.146.3

EOF
		continue
		;;
	   "")
		GW=$GATEWAY
		;;
	esac

	if [ $GW = "none" ]
	then
		break
	fi

	echo $GW | egrep '^[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+$' > /dev/null
	if [ $? -eq 0 ]
	then
		break
	else
		echo "Format error in gateway IP address. "
		echo "An example of a valid gateway is 16.4.2.156  - please re-try!" 
	fi
done

echo $SUBM	> $ADMINDIR/SUBNETMASK 

echo $GW	> $ADMINDIR/GATEWAY 

exit 0
