#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin

. $1

if [ "foo$2" = "fooboot" -a ${ONBOOT} = "no" ]
then
	exit
fi

DEVICETYPE=`echo $DEVICE | sed "s/[0-9]*$//"`

if [ -e /etc/sysconfig/pcmcia ]; then
	. /etc/sysconfig/pcmcia
else
	PCMCIA=no
fi

if [ $DEVICETYPE = "eth" -a "foo${ISPCMCIA}" = "foo" ]; then
	# this is a horrible hack to work around prior brokenness 
	if [ "$PCMCIA" = "yes" -a "foo$2" = "fooboot" ]; then
		# cardmgr will start us up properly
		exit 0;
	fi
elif [ "${ISPCMCIA}" = "yes" -a "$2" = "boot" ]; then
	# cardmgr will start us up properly
	exit 0;
fi
	
### end of horrible hack

OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${DEVICETYPE}"

if [ -x $OTHERSCRIPT ]; then
	$OTHERSCRIPT $1 $2
	exit $?
fi

# is this device available? (this catches PCMCIA devices for us)
/sbin/ifconfig ${DEVICE} 2>&1 | grep -s "unknown interface" > /dev/null
if [ "$?" = "0" ]; then
	echo "Delaying ${DEVICE} initialization."
	exit 0
fi

ifconfig ${DEVICE} ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST}
route add -net ${NETWORK} netmask ${NETMASK} ${DEVICE}

# this is broken! it's only here to keep compatibility with old RH sytstems
if [ "${GATEWAY}" != "" -a "${GATEWAY}" != "none" ]
then
	route add default gw ${GATEWAY} metric 1 ${DEVICE}
fi

. /etc/sysconfig/network

if [ "${GATEWAY}" != "" ]; then
	if [ "${GATEWAYDEV}" = "" -o "${GATEWAYDEV}" = "${DEVICE}" ]; then
		# set up default gateway
		route add default gw ${GATEWAY}
	fi
fi

/etc/sysconfig/network-scripts/ifup-routes ${DEVICE}

if echo $DEVICE | grep -qv ':' ; then
	for alias in `ls /etc/sysconfig/network-scripts/${DEVICE}:* 2>/dev/null | \
		      egrep ':[0-9]+$'` ; do
		/etc/sysconfig/network-scripts/ifup alias
	done
fi

