﻿#! /bin/sh

### BEGIN INIT INFO
# Provides:          vpnserver
# Required-Start:    $network $local_fs
# Required-Stop:     $network $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: SoftEther VPN Server
### END INIT INFO

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/local/vpnserver/vpnserver
 
test -x $DAEMON || exit 1

case "$1" in
  start)
    $DAEMON start
    sleep 5

    tap_dev=`/sbin/ip tuntap | awk -F: '{print $1}'`
    if [ -n "$tap_dev" ]; then
        /sbin/brctl addif br0 $tap_dev
    fi
    ;;
  stop)
    $DAEMON stop
    ;;
  restart)
    $0 stop
    sleep 3
    $0 start
    ;;
  *)
    echo "Usage: /etc/init.d/vpnserver {start|stop|restart}"
    exit 1
    ;;
esac

exit 0