#!/bin/sh
#
# This will bring the network interface up.
#
# Usage: network_up.man <prot> <IP> <gateway> <DNS1> <DNS2>
#

# Check that we were supplied with at least one parameter.
#
if [ $# -eq 0 ]
then
	#                            $1     $2   $3        $4     $5
	echo "Usage: network_up.man <prot> <IP> <gateway> <DNS1> <DNS2>"
	exit 1
fi

# Bring up the local interface.
#
ifconfig lo 127.0.0.1 up

# Add a route for it.
#
route add 127.0.0.1 lo

# Check for propa protcol.
#
if [ $1 = "dhcp" ]
then
	# Start the dhcp daemon daemon.
	# This should try forever to start DHCP.
	echo "Starting DHCP..."
	/scripts/dhcp_up
	# And exit.
	exit 0
elif [ $1 != "none" ]
then
	echo "Protocol must be either 'dhcp' or 'none'..."
	exit 1
fi

# Otherwise we are supplied with parameters.
#
if [ $# -ge 2 ]
then
	# Bring up the interface manually.
	echo "Manually initializing eth0 to $2"
	/sbin/ifconfig eth0 $2 up
	# If DNS servers supplied.
	if [ $# -ge 4 ]
	then
		# Create resolv.conf
		echo "With DNS server $4"
		echo "nameserver $4"  > /etc/resolv.conf
	fi
	if [ $# -eq 5 ]
	then
		# Add second dns to resolv.conf
		echo "And DNS server $5"
		echo "nameserver $5" >> /etc/resolv.conf
	fi
	# If we were supplied with a gateway address.
	if [ $# -ge 3 ]
	then
		echo "With gateway address $3"
		# Add a route for it.
		route add default gw $3 eth0
	fi
	# And exit.
	exit 0
else
	echo "Must have at least IP address if not using dhcp..."
	exit 1
fi
