#! /bin/sh
# ipkungfu: An iptables-based Linux firewall
#
### BEGIN INIT INFO
# Provides:          ipkungfu
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start the ipkungfu firewall at boot time
# Description:       Script to start/stop/reload the ipkungfu script
### END INIT INFO
#
# The user must change /etc/default/ipkungfu (as per recommendation in # Bug#315074).
# Created on 2005 by Nigel Jones <nigelj@gmail.com> 
# Make LSB-compliant on 2006 by Luis Uribe <acme@eviled.org> 


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/ipkungfu
NAME=ipkungfu
DESC="iptables based firewall"
LOGFILE=/var/log/ipkungfu.log
SCRIPTNAME=/etc/init.d/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

ipkf_configerr () {
	echo "Not starting $NAME: Please read /usr/share/doc/ipkungfu/README.Debian for details"
	exit 0
}

test -x $DAEMON || exit 0

[ -r /etc/default/$NAME ] && . /etc/default/$NAME

if [ "$IPKFSTART" != "1" ] 
then
    ipkf_configerr
fi

case "$1" in
  start|reload|force-reload)
	#In IPKungfu reload and start are the same things...
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	if $DAEMON 2>&1 >>$LOGFILE ; then
        [ "$VERBOSE" != no ] && log_end_msg 0 ;
	else
        [ "$VERBOSE" != no ] && log_end_msg 1 ;
	fi
	;;
  stop)
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	if $DAEMON -d 2>&1 >>$LOGFILE ; then
        [ "$VERBOSE" != no ] && log_end_msg 0 ;
    else
        [ "$VERBOSE" != no ] && log_end_msg 1 ;
    fi
	;;
  restart)
    log_daemon_msg "Restarting $DESC" "$NAME"
	if ! $DAEMON -d 2>&1 >>$LOGFILE ; then
        [ "$VERBOSE" != no ] && log_end_msg 1 ;
    fi
	sleep 1
	if $DAEMON 2>&1 >>$LOGFILE ; then
        [ "$VERBOSE" != no ] && log_end_msg 0 ;
    else
        [ "$VERBOSE" != no ] && log_end_msg 1 ;
    fi
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 3
	;;
esac

exit 0
