#! /bin/sh

#
# /etc/rc.d/init.d/S20network - Start/Stop the network interface(s).
#

# Comment out the following exit line to enable this script.
# Before doing so, you need to edit the network address information below.
exit 0

#######################################
##### network address information #####
#######################################
# The netmask is in vlsm format (variable length subnet masking)
# Example: NETMASK = 25 is the same as 255.255.255.128
INTERFACE0=eth0
IPADDR0=192.168.1.250
NETMASK0=24
NETWORK0=192.168.1.0
BROADCAST0=192.168.1.255
GATEWAY=192.168.1.1

#Change this to your hostname; don't forget to add it to /etc/hosts.
HOSTNAME="NEC-DSX-${IPADDR0}"

if [ ! -x /sbin/ip ]; then
	echo "$0: Missing /sbin/ip"
	exit 1
fi

case "$1" in

    start)
	echo "Setting up link for loopback"
	ip address add 127.0.0.1/8 dev lo brd + scope host
	ip link set up dev lo
	if [ "$?" = "0" ]; then echo "Done"
	else                    echo "FAILED"; fi

	echo "Setting up link for ${INTERFACE0}"
	ip addr add ${IPADDR0}/${NETMASK0} dev ${INTERFACE0} brd ${BROADCAST0} scope global
	ip link set ${INTERFACE0} up
	ip route append default via ${GATEWAY} metric 30001
	if [ "$?" = "0" ]; then echo "Done"
	else                    echo "FAILED"; fi
	hostname ${HOSTNAME}
	;;

    stop)
	echo "Shutting down link for ${INTERFACE0}"
	ip link set down dev ${INTERFACE0}
	ip addr del ${IPADDR0} dev ${INTERFACE0}
	if [ "$?" = "0" ]; then echo "Done"
	else                    echo "FAILED"; fi

	echo "Shutting down link for loopback"
	ip link set down dev lo
	ip addr del 127.0.0.1 dev lo
	if [ "$?" = "0" ]; then echo "Done"
	else                    echo "FAILED"; fi
	;;

    restart)
	$0 stop
	sleep 1
	$0 start
	;;

    *)
	echo "Usage: $0 (start|stop|restart)"
	exit 1
	;;

esac

exit 0

