#! /bin/sh
#
# Author: Friedrich Lobenstock <fl@fl.priv.at>
#
# Remarks: 
#   This script works only for SuSE Linux, so someone has to
#   rework this for RedHat, Connectiva, Mandrak, ... Linux.
#

. /etc/rc.config

# Determine the base and follow a runlevel link name.
base=${0##*/}
link=${base#*[SK][0-9][0-9]}

# Force execution if not called by a runlevel directory.
test $link = $base && START_IPAC=yes
test "$START_IPAC" = yes || exit 0

# The echo return value for success (defined in /etc/rc.config).
return=$rc_done
case "$1" in
    start)
	echo -n "Starting IP accouting (ipac) in the background"
	/usr/local/bin/ipacset &> /var/log/ipac.log &

	echo -e "$return"
	;;
    stop)
	if [ -f /var/run/ip-accounting-rules ]; then
		echo -n "Shutting IP accounting. Saving last accounting data..."
		/usr/local/bin/fetchipac || return=$rc_failed
		rm -f /var/run/ip-accounting-rules
	fi

	echo -e "$return"
	;;
    restart)
	## If first returns OK call the second, if first or
	## second command fails, set echo return value.
	$0 stop  &&  $0 start  ||  return=$rc_failed
	;;
    reload)
	$0 stop  &&  $0 start  ||  return=$rc_failed
	;;
    probe)
	## Optional: Probe for the necessity of a reload,
	## give out the argument which is required for a reload.

	test /etc/ipac.conf -nt /var/run/ip-accounting-rules && echo reload
	;;
    *)
	echo "Usage: $0 {start|stop|restart|reload|probe}"
	exit 1
	;;
esac

# Inform the caller not only verbosely and set an exit status.
test "$return" = "$rc_done" || exit 1
exit 0
