2 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
3 DAEMON
=/usr
/sbin
/anytun
4 ANYTUNCONFIG
=/usr
/bin
/anytun-config
5 CONTROLDAEMON
=/usr
/bin
/anytun-controld
6 CHROOTDIR
='/var/run/anytun'
7 # DAEMONOPTS="--chroot --username nobody --chroot-dir $CHROOTDIR"
10 CONFIG_DIR
=/etc
/anytun
11 VARCONFIG_DIR
=/var
/run
/anytun-controld
13 test -x $DAEMON ||
exit 0
15 # Include anytun defaults if available
16 if [ -f /etc
/default
/anytun
] ; then
22 if [ -f $CONFIG_DIR/$NAME/config
] ; then
24 test -f $CONFIG_DIR/$NAME/post-up.sh
&& POSTUP
="-x $CONFIG_DIR/$NAME/post-up.sh"
25 DAEMONARG
=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e '\w' | sed 's/^/ --/' | xargs echo`
26 $DAEMON --write-pid /var
/run
/anytun.
$NAME.pid
$POSTUP \
27 $DAEMONOPTS $DAEMONARG || STATUS
="FAILED"
29 STATUS
="no config found"
35 kill `cat $PIDFILE` || true
41 if [ -d $CONFIG_DIR/$NAME/conf.d
] ; then
42 test -d $VARCONFIG_DIR || mkdir
-p $VARCONFIG_DIR
43 chmod 700 $VARCONFIG_DIR
44 rm -f $VARCONFIG_DIR/$NAME 2>/dev
/null
45 for CLIENTNAME
in `ls $CONFIG_DIR/$NAME/conf.d`; do
46 echo -n " ($CLIENTNAME)"
47 DAEMONARG
=`sed 's/#.*//' < $CONFIG_DIR/$NAME/conf.d/$CLIENTNAME | grep -e '\w' | sed 's/^/ --/' | xargs echo`
48 $ANYTUNCONFIG $DAEMONARG >> $VARCONFIG_DIR/$NAME
50 CONTROLHOST
=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e 'control-host' | sed 's/^/ --/'`
51 $CONTROLDAEMON -f $VARCONFIG_DIR/$NAME $DAEMONOPTS $CONTROLHOST \
52 --write-pid $VARCONFIG_DIR/$NAME.pid
53 # rm -f $VARCONFIG_DIR/$NAME
57 if [ -d $CONFIG_DIR/$NAME/conf.d
] ; then
59 kill `cat $VARCONFIG_DIR/$NAME.pid` || true
60 rm $VARCONFIG_DIR/$NAME.pid
67 echo -n "Starting $DESC: "
68 test -d $CHROOTDIR || mkdir
-p $CHROOTDIR
69 if test -z "$2" ; then
70 if [ -f $CONFIG_DIR/autostart
] ; then
71 for NAME
in `sed 's/#.*//' < $CONFIG_DIR/autostart | grep -e '\w'`; do
76 echo "no config found"
91 echo -n "Stoping $DESC: "
92 if test -z "$2" ; then
93 for PIDFILE
in `ls /var/run/anytun.*.pid 2> /dev/null`; do
94 NAME
=`echo $PIDFILE | cut -c17-`
102 if test -e /var
/run
/anytun.
$1.pid
; then
103 PIDFILE
=`ls /var/run/anytun.$1.pid 2> /dev/null`
104 NAME
=`echo $PIDFILE | cut -c17-`
109 echo -n " (failure: No such tunnel is running: $1)"
116 if test -z "$2" ; then
117 for PIDFILE
in `ls /var/run/anytun.*.pid 2> /dev/null`; do
118 NAME
=`echo $PIDFILE | cut -c17-`
120 if [ -d $CONFIG_DIR/$NAME/conf.d
] ; then
132 if test -e /var
/run
/anytun.
$1.pid
; then
133 PIDFILE
=`ls /var/run/anytun.$1.pid 2> /dev/null`
134 NAME
=`echo $PIDFILE | cut -c17-`
137 if [ -d $CONFIG_DIR/$NAME/conf.d
] ; then
145 echo -n " (failure: No such tunnel is running: $1)"
151 echo -n "Restarting $DESC: "
152 if test -z "$2" ; then
153 for PIDFILE
in `ls /var/run/anytun.*.pid 2> /dev/null`; do
154 NAME
=`echo $PIDFILE | cut -c17-`
164 if test -e /var
/run
/anytun.
$1.pid
; then
165 PIDFILE
=`ls /var/run/anytun.$1.pid 2> /dev/null`
166 NAME
=`echo $PIDFILE | cut -c17-`
172 echo -n " (failure: No such tunnel is running: $1)"
187 echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2