
. net_int.sh

readonly HELP_NET="net.hlp"

TMP_IP=""
TMP_NM=""
TMP_GW=""


net_setup()
{
	local old_PS3="$PS3"
	local item=""
	local -i done=0

	net_restore

	PS3="[Enter number] "
	while test $done -eq 0; do
		mhdr "NETWORK SETUP"
		
		select item in "Shell" "Help" "Back" "Save" "List" \
				"IP Address" "Netmask" "Gateway"
		do
			case "$item" in
			"Shell")      invoke_shell ;;
			"Help")       show_help "$HELP_NET" ;;
			"Back")       net_back; done=1 ;;
			"Save")       net_save; done=1 ;;
			"List")       net_list ;;
			"IP Address") net_ip ;;
			"Netmask")    net_netmask ;;
			"Gateway")    net_gateway ;;
			esac
			break
		done
	done

	PS3=$old_PS3
}

net_restore()
{
	eval TMP_IP=\${${XID_NETWORK}_IP}
	eval TMP_NM=\${${XID_NETWORK}_NM}
	eval TMP_GW=\${${XID_NETWORK}_GW}
}

net_back()
{
	eval ${XID_NETWORK}_IP=$TMP_IP
	eval ${XID_NETWORK}_NM=$TMP_NM
	eval ${XID_NETWORK}_GW=$TMP_GW
}

net_save()
{
	: # nothing to do
}

net_list()
{
	local ip=""
	local nm=""
	local gw=""

	eval ip=\${${XID_NETWORK}_IP}
	eval nm=\${${XID_NETWORK}_NM}
	eval gw=\${${XID_NETWORK}_GW}

	ihdr "NETWORK CONFIGURATION"
	msg  "IP Address : ${ip:-<unset>}"
	msg  "Netmask    : ${nm:-<unset>}"
	msg  "Gateway    : ${gw:-<unset>}"
}

net_ip()
{
	local ip=""

	ip=`input_field "Enter IP address" validate_ip`
	if test $? -eq 0; then
		eval ${XID_NETWORK}_IP=\"$ip\"
	fi
}

net_netmask()
{
	local mask=""

	mask=`input_field "Enter netmask" validate_netmask`
	if test $? -eq 0; then
		eval ${XID_NETWORK}_NM=\"$mask\"
	fi
}

net_gateway()
{
	local gw=""

	gw=`input_field "Enter gateway" validate_gateway`
	if test $? -eq 0; then
		eval ${XID_NETWORK}_GW=\"$gw\"
	fi
}
