#!/bin/bash
# Network interface configuration
### BEGIN INIT INFO
# Provides:       andrea.network
# Required-Start: $local_fs $syslog $time
# Required-Stop: $remote_fs $syslog
# Default-Start:  2 3 5
# Default-Stop:   0 1 6
# Description:    Configure the network interfaces and set up routing
### END INIT INFO

. /etc/rc.status
. /opt/andrea/conf/andrea.conf

case "$1" in
	start)
		echo Setting up andrea network interfaces:
                ifconfig eth0 $RN_ANDREAIP netmask $RN_NETMASKL up
                RN=`ifconfig eth0|grep $RN_ANDREAIP`
                if [ "$RN" ]; then
                 echo -n eth0 $RN_ANDREAIP/$RN_NETMASKL 
                 rc_status -v
                else
                 echo -n failed starting $RN_ANDREAIP
                 rc_failed
                fi
                ifconfig eth0:1 $BN_ANDREAIP netmask $BN_NETMASKL up
                BN=`ifconfig eth0:1|grep $BN_ANDREAIP`
                if [ "$BN" ]; then
                 echo -n eth0:1 $BN_ANDREAIP/$BN_NETMASKL done
                 rc_status -v
                else
                 echo -n failed starting $BN_ANDREAIP
                 rc_failed
                fi
                route add default gw $PROVIDER_GW
                echo restarting bind/dns server
                /etc/init.d/named restart
                echo restarting andrea dhcp server
                /etc/init.d/andrea_dhcpd restart
                echo restarting smb server
                /etc/init.d/smb restart
                echo restarting nmb server
                /etc/init.d/nmb restart
		;;

	stop)
		echo Shutting down andrea.network interfaces:
                ifconfig eth0:1 down
                RN=`ifconfig |grep eth0:1`
                if ! [ "$RN" ]; then
                 echo -n shutting down eth0:1 
                 rc_status -v
                else
                 echo -n shutting down eth0:1
                 rc_failed
                fi
                ifconfig eth0 down
                BN=`ifconfig |grep eth0`
                if ! [ "$BN" ]; then
                 echo -n shutting down eth0
                 rc_status -v
                else
                 echo -n shutting down eth0
                 rc_failed
                fi
		;;

	restart|force-reload)
		$0 stop 
       		$0 start 
		;;

	*)
		echo "Usage: $0 <action> "
		echo "actions: {start|stop|restart}"
		exit 1

esac

rc_exit
