#!/bin/sh
#
# Startup script for the Tunnel Vision VPN software
#
# chkconfig: 345 85 15
# description: Tunnel Vision is a software to setup virtual private networks
# processname: tunnelv
# pidfile: /var/run/tunnelv.pid
# config: /etc/tunnelv.conf
# config: /etc/sysconfig/tunnelv

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

[ -f /etc/tunnelv.conf ] || exit
[ -f /etc/sysconfig/tunnelv ] || exit

# Source settings
. /etc/sysconfig/tunnelv

RETVAL=0

start() {
	echo -n $"Starting VPN tunnel: "
        daemon tunnelv.wrapper "$MODE" "$REMOTEHOST" "$PORT"
	RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/tunnelv
        return $RETVAL
}

stop() {
        echo -n $"Shutting down VPN tunnel: "
        killproc tunnelv
        RETVAL=$?
        echo
        if [ $RETVAL = 0 ]; then
	    rm -f /var/lock/subsys/tunnelv
            rm -f /var/run/tunnelv.pid
	fi
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status tunnelv
	;;
  restart|reload)
	stop
	start
	;;
  condrestart)
        if [ -f /var/lock/subsys/tunnelv ]; then
           stop
           start
        fi
        ;;
  *)
	echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}"
	exit 1
esac

exit $RETVAL
