#!/bin/sh
#
# chkconfig: 345 85 25
# description: vpnagentd is used for managing the cisco vpn client datapath.
# processname: vpnagentd



# Source function library.
if [ -e "/etc/init.d/functions" ]; then
  . /etc/init.d/functions
fi

RETVAL=0

start() {
  # If TUN isn't supported by the kernel, try loading the module...
  /sbin/lsmod | grep tun > /dev/null 
  if [ $? -ne 0 ]; then
    /sbin/modprobe tun > /dev/null 2> /dev/null
    if [ $? -ne 0 ]; then
      # check for /dev/net/tun
      [ -c "/dev/net/tun" ] || echo  Warning: Unable to verify that the tun/tap driver is loaded.  Contact your system administrator for assistance.
    fi
  fi

  echo -n $"Starting up Cisco VPN daemon "
  /opt/cisco/vpn/bin/vpnagentd
  RETVAL=$?
  echo
  return $RETVAL
}

stop() {
	echo -n $"Shutting down Cisco VPN daemon "
	killall vpnagentd
	RETVAL=$?
	echo
	return $RETVAL
}

dostatus() {
	status vpnagentd
}

restart() {
	stop
	start
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
    restart
    ;;
  status)
	dostatus
	;;
  *)
	echo $"Usage: vpnagent {start|stop|restart|status}"
	exit 1
esac

exit $RETVAL
