#!/bin/sh
# Reading config

. /etc/sysconfig/network-scripts/ifcfg-ixp0
. /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

# 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
#	ip=`/sbin/ifconfig ixp0 | awk '$1 == "inet" {print $2}' | cut -f2 -d:`
#	echo "${ip}	 ${HOSTNAME}	${ip}" >> /etc/hosts >& /dev/null
elif [ $BOOTPROTO = "static" ] || [ $BOOTPROTO = "none" ]; then
	/sbin/ifconfig ${DEVICE} ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST} 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 ixp0
	else
		/sbin/route add default gw ${GATEWAY} metric 1
	fi

fi
