#!/bin/sh
# Reading config

. /etc/sysconfig/network-scripts/ifcfg-egiga0
. /etc/sysconfig/network

# Activing loop device
/sbin/ifconfig lo 127.0.0.1 up
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 dev lo
killall lld2d 2>/dev/null
# Activing eth0 device
if [ $BOOTPROTO = "dhcp" ]; then
	/sbin/udhcpc -H ${HOSTNAME} 2> /dev/null
	/bin/sleep 1
	# Rebuilding /etc/hosts
	echo "127.0.0.1		localhost	127.0.0.1" > /etc/hosts
elif [ $BOOTPROTO = "static" ] || [ $BOOTPROTO = "none" ]; then
	/sbin/ifconfig ${DEVICE} ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST} mtu ${MTU} up
	# Updating /etc/hosts
	echo "127.0.0.1		localhost 	127.0.0.1" > /etc/hosts
	echo "${IPADDR}		${HOSTNAME}	 ${IPADDR}" >> /etc/hosts #>& /dev/null	
	/sbin/route del -net default gw 0.0.0.0 >/dev/null 2>&1
	# Starting static route
	if [ -z "${GATEWAY}" ]; then
		/sbin/route add default dev ${DEVICE}
	else
		/sbin/route add default gw ${GATEWAY} metric 1
	fi
fi
/sbin/route add -net 239.0.0.0 netmask 255.0.0.0 egiga0
