#!/bin/sh
#
# ipkungfu startup script
#
# chkconfig: 2345 98 92
#
# description: Starts the ipkungfu firewall
#
# by Rocco Stanzione, based on the iptables script:
# Script Author:	Rocco Stanzione <grasshopper@linuxkungfu.org>
#

# Source 'em up
. /etc/init.d/functions

IPKF_CONFIG=/etc/ipkungfu/ipkungfu.conf
IPKF_EXE=/usr/sbin/ipkungfu

if [ ! -x $IPKF_EXE ]; then
	exit 0
fi

KERNELMAJ=`uname -r | sed                   -e 's,\..*,,'`
KERNELMIN=`uname -r | sed -e 's,[^\.]*\.,,' -e 's,\..*,,'`

if [ "$KERNELMAJ" -lt 2 ] ; then
	exit 0
fi
if [ "$KERNELMAJ" -eq 2 -a "$KERNELMIN" -lt 3 ] ; then
	exit 0
fi

if  /sbin/lsmod 2>/dev/null |grep -q ipchains ; then
	gprintf "ipchains module loaded.  Aborting.  Try rmmod ipchains and try again.\n"
	exit 0
fi

start() {
	# don't do squat if we don't have the config file
	if [ -f $IPKF_CONFIG ]; then
	    gprintf "Starting ipkungfu: "
	    $IPKF_EXE --init && \
		    success "Starting ipkungfu" || \
		    failure "Starting ipkungfu"
	    echo
	    touch /var/lock/subsys/ipkungfu
	fi
}

stop() {
	$IPKF_EXE --disable
	rm -f /var/lock/subsys/ipkungfu
}

case "$1" in
  start)
	start
	;;

  stop)
	stop
	;;

  restart|reload)
	# "restart" is really just "start" as this isn't a daemon,
	#  and "start" clears any pre-defined rules anyway.
	#  This is really only here to make those who expect it happy
	start
	;;

  status)
	$IPKF_EXE --check
	;;

  panic)
	$IPKF_EXE --panic
        ;;
  *)
	gprintf "Usage: %s {start|stop|restart|status|panic}\n" "$0"
	exit 1
esac

exit 0

