#!/bin/sh

DEFAULT_IP="192.168.1.200"
DEFAULT_GW="192.168.1.1"
DEFAULT_SUBNET="255.255.252.0"

GATEWAY=
MAC=
IP_ADDR=
SUBNET_MASK=

# get the network & tz from flash and place in net_cfg
/usr/local/bin/files_load -s > /dev/null

source /etc/sysconfig/net_cfg

echo "gateway is: $GATEWAY"
echo "MAC is: $MAC"
echo "IP is: $IP_ADDR"
echo "SUBNET Mask is: $SUBNET_MASK"

if [ "X${MAC}" == "X" ]
then
	echo "MAC not provided"
else
	/sbin/ifconfig eth0 down
	/sbin/ifconfig eth0 hw ether $MAC
	/sbin/ifconfig eth0 up
fi

source /etc/sysconfig/config

if [ "X${CONFIG_NETWORK_IPADDR_DYNAMIC}" == "Xy" ]
then
	echo "dynamic addressing"
else
	echo "static addressing"
	if [ "X${IP_ADDR}" != "X" ]
	then
		if [ "X${SUBNET_MASK}" != "X" ]
		then
			/sbin/ifconfig eth0 down
			/sbin/ifconfig eth0 $IP_ADDR netmask $SUBNET_MASK up
		else
			/sbin/ifconfig eth0 down
			/sbin/ifconfig eth0 $IP_ADDR netmask $DEFAULT_SUBNET up
		fi	

		if [ "X${GATEWAY}" != "X" ]
		then
			/sbin/route add -net default gw $GATEWAY dev eth0
		else
			/sbin/route add -net default gw $DEFAULT_GW dev eth0
		fi

	else
		echo "no ip info found, Use default network config"	
		/sbin/ifconfig eth0 down
		/sbin/ifconfig eth0 $DEFAULT_IP netmask $DEFAULT_SUBNET up
		/sbin/route add -net default gw $DEFAULT_GW dev eth0
	fi
fi

exit 0;
