#! /bin/sh
#
# anon-proxy	File to start the an.on proxy at startup.
#		Written by David Spreen <netzwurm@debian.org>,
#               based on the skeleton script by 
#               Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>,
#               customized by dh-make.
#
# Version:	@(#)anon-proxy  1.0  15-Sep-2002  netzwurm@debian.org
#

### BEGIN INIT INFO
# Provides: anon-proxy
# Required-Start: $network $remote_fs $syslog
# Required-Stop:  $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts the anon-proxy mix
# Description: Starts the anon-proxy mix
### END INIT INFO

[ -f /etc/default/anon-proxy ] && . /etc/default/anon-proxy

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/mix
NAME=anon-proxy
DESC="Anonymising Proxy Service"
USER=anon-proxy
GROUP=nogroup
PIDFILE=/var/run/anon-proxy/mix.pid

[ -z "$CASCADE" ] && CASCADE="mix.inf.tu-dresden.de:443"
[ -z "$PORT" ] && PORT="4001"
[ -z "$OPTIONS" ] && OPTIONS="-a -d -j -r $PIDFILE -n $CASCADE -p $PORT"

test -f $DAEMON || exit 0

. /lib/lsb/init-functions

set -e

anon_start() {
    test -x $DAEMON || return 0
    log_daemon_msg "Starting anon-proxy mix"
    DIR=`dirname $PIDFILE`
    mkdir -p $DIR
    chown $USER $DIR
    start-stop-daemon --start --quiet -c $USER:$GROUP --pidfile $PIDFILE \
	--exec $DAEMON -- $OPTIONS  > /dev/null 2>&1 || true
    log_end_msg 0
}

anon_stop() {
    log_daemon_msg "Stopping anon-proxy mix"
    start-stop-daemon --quiet --stop --pidfile $PIDFILE  \
	--exec $DAEMON || true
    log_end_msg 0
}

case "$1" in
  start)
	anon_start
	;;
  stop)
	anon_stop
	;;
  restart|force-reload)
	anon_stop
	anon_start
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
