#! /bin/sh
### BEGIN INIT INFO
# Provides:          reductor
# Required-Start:    
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:	 0 6
# Short-Description: insert kernel module and create firewall rules
### END INIT INFO

PATH=/sbin:/bin

. /etc/init.d/functions
. /usr/local/Reductor/etc/const

case "$1" in
	start)
		setsid $BINDIR/start.sh &>$LOGDIR/$1.log & disown -a
		;;
	restart)
		$BINDIR/restart.sh
		;;
	stop)
		$BINDIR/stop.sh
		echo_result
		;;
	status)
		get_reductor_state
		;;
	reload)
		$BINDIR/prepare_lists.sh
		$BINDIR/load.sh
		;;
	check)
		$BINDIR/diagnostic.sh
		;;
	update)
		$BINDIR/update.sh
		;;
	export)
		shift
		$BINDIR/export.sh "$@"
		;;
	import)
		shift
		$BINDIR/import.sh "$@"
		;;
	upgrade)
		$BINDIR/autoupdate.sh
		;;
	*)
		echo "Usage: $0 start|stop|restart|status|reload|check|update|upgrade|export|import" >&2
		echo "	start				configure firewall and load current lists and ipsets" >&2
		echo "	stop				clean up firewall and unload kernel module" >&2
		echo "	status				show activation state" >&2
		echo "	reload				prepare url & ip lists and load them into kernel" >&2
		echo "	check				run diagnostic that shows (and try to fix) known problems" >&2
		echo "	update				try to download new lists from rkn and minjust" >&2
		echo "	upgrade				search for and install new reductor version" >&2
		echo "	export <path to archive>	create backup of user data (tar.gz)" >&2
		echo "	import <path to archive>	restore user data from backup (tar.gz)" >&2
		exit 3
		;;
esac

if [ "$1" = 'start' ]; then
	sleep 8
	cat $LOGDIR/$1.log
fi
echo
