#!/bin/sh
# chkconfig: 2345 50 50
# description: Setting up tun/tap for UML Networking
#
# GNU GPL (c) Eko M. Budi 2004
#         (c) Vector Linux 2004

#####################################
# Default settings
USER=1000
IPADDR=10.0.1.254
NETMASK=255.255.255.0
DEVICE=tap0

##############################
# Read settings if exist
if [ -x /etc/sysconfig/config/umlnet.conf ]; then
   . /etc/sysconfig/config/umlnet.conf   
fi

# Include the functions declared in the /etc/rc.d/functions file
source /etc/rc.d/functions

#server name & description
SERVER="UML Network Device"
# path to binary
ROOT="/usr/sbin"
# name of binary to run
APP="named"
#runtime options
OPT=""

start()
{
   modprobe tun
   DEVICE=`tunctl -u $USER -b`
   chmod 666 /dev/net/tun &> /dev/null
   ifconfig $DEVICE $IPADDR netmask $NETMASK up &> /dev/null
}

reload()
{
   ifconfig $DEVICE down
   ifconfig $DEVICE $IPADDR netmask $NETMASK up &> /dev/null 
}

stop()
{
   ifconfig $DEVICE down
   tunctl -d $DEVICE &> /dev/null
}

status()
{
   ifconfig $DEVICE
}


case "$1" in
        start)
                echo -n "Starting $SERVER............"
                start
		evaluate_retval
                ;;
	reload)
                echo -n "Reloading $SERVER............"
                reload
		evaluate_retval
                ;;      
        stop)
                echo -n "Stopping $SERVER............"
                stop
		evaluate_retval
                ;;
        restart)
                $0 stop
                /bin/sleep 1
                $0 start
                ;;
        status)
                status
                ;;
        *)
                echo "Usage: $0 {start|stop|restart|status|reload}"
                exit 1
        ;;
esac

# End script

