#!/bin/sh
#
# This will bring the network interface up.
#

# Splash.
#
echo "Executing /scripts/network_up..."

# Source the network definitions.
# We will initialize the variables to their default values, then
# if network.ini exists, it will overwrite these values.
#
BOOTPROTO=none
NETMASK=255.255.255.0
IPADDR=192.168.92.68
GATEWAY=0.0.0.0
DNS_SERVER1=0.0.0.0
DNS_SERVER2=0.0.0.0
. /app/config/network.ini

# Source the hardware mac id(s).
EP93XX_MAC=$(getmac)
if [ "$EP93XX_MAC" == "FF:FF:FF:FF:FF:FF" ]; then
	EP93XX_MAC=00:50:DB:12:F4:49
fi

# Bring up the local interface.
#
ifconfig lo 127.0.0.1 up
route add -net 127.0.0.0 netmask 255.0.0.0 lo

# Either NFS mounted, dhcp, or direct IP.
#
if [ -e /NFS_ROOT ]
then
        echo "NFS Mounted; will leave network alone..."
        # Create resolv.conf
        echo "nameserver $DNS_SERVER1"  > /etc/resolv.conf
        echo "nameserver $DNS_SERVER2" >> /etc/resolv.conf
        # Add default route (can't UDP broadcast without it).
        route add default gw $GATEWAY eth0
elif [ "$BOOTPROTO" = "dhcp" ]
then
	# Start the dhcp daemon daemon.
	# This should try forever to start DHCP.
	# It will also create /etc/resolv.conf and add routes???
	echo "Starting DHCP..."
        udhcpc -i eth0 -b -p /var/run/udhcpc.eth0 >/dev/null 2>&1
else
	# Bring up the interface manually.
	echo "Manually initializing eth0 to $IPADDR..."
	/sbin/ifconfig eth0 down
	/sbin/ifconfig eth0 hw ether $EP93XX_MAC
	/sbin/ifconfig eth0 $IPADDR netmask $NETMASK up
	# Create resolv.conf
	echo "nameserver $DNS_SERVER1"  > /etc/resolv.conf
	echo "nameserver $DNS_SERVER2" >> /etc/resolv.conf
	# Add a route for it.
	route add default gw $GATEWAY eth0
fi

# And exit.
#
exit 0
