#!/usr/bin/sh
#
# Script for starting and stoping vtund.
#
# Writen by Dag Wieers <dag@mind.be>. 
# Mandrake version by Olivier Thauvin <thauvin@aerov.jussieu.fr>
#
# chkconfig: 345 55 45
# description: vtund Virtual Tunnel Daemon.
#    VTun provides the method for creating Virtual Tunnels over TCP/IP networks
#    and allows to shape, compress, encrypt traffic in that tunnels.
#    This is the client part
### BEGIN INIT INFO
# Provides: vtunc
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Short-Description: Virtual Tunnel Client
# Description: Virtual Tunnel Client
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

. /etc/sysconfig/network

[ "$NETWORKING" != "yes" ] && exit 0

if [ -f /etc/sysconfig/vtunc ] ; then 
		. /etc/sysconfig/vtunc
else
		exit 0
fi

[ -n "$TUNNEL" ] || exit 0
[ -n "$IPSERVER" ] || exit 0
[ -n "$CONFFILE" ] || CONFFILE="/etc/vtund.conf"

if [ ! -f "$CONFFILE" ]; then
  #gprintf "%s not found, aborting\n" "$CONFFILE"
  exit 0
fi

start_vtun ()
	{
	# loading tun module.
	[ ! -a /dev/net/tun ] && modprobe tun
		
	[ -n "$PORT" ] && ARG="${ARG} -P $PORT"
	[ -n "$CONFFILE" ] && ARG="${ARG} -f $CONFFILE"
	ARG="${ARG} $TUNNEL $IPSERVER"
	
    gprintf "Starting vtund: "
    daemon vtund -p $ARG
    echo
	touch /var/lock/subsys/vtunc
	}


stop_vtun ()
	{
    gprintf "Stopping vtund: "
    killproc vtund
    echo
    rm -f /var/lock/subsys/vtunc
	}




# See how we were called.
case "$1" in
  start)
        start_vtun
  		;;
  stop)
  		stop_vtun
        ;;
  restart|reload)
  		stop_vtun
		start_vtun
		;;
  status)
        status vtund
        ;;
  *)
        gprintf "Usage: vtunc {start|stop|restart|status}\n"
        exit 1
esac

exit 0
