#! /bin/sh
#
# ferm          Configure ferm firewall rules
#
# chkconig:	345 08 92
# description:	ferm is a frontend for iptables.
#		This script starts and stops ferm firewall.
# processname:	ferm
# config:	/etc/ferm/ferm.conf
### BEGIN INIT INFO
# Provides: ferm
# Required-Start: $remote_fs $syslog
# Required-Stop:  $remote_fs $syslog
# Default-Start:  3 4 5
# Default-Stop:   0 1 2 6
# Short-Description: ferm firewall
# Description:	ferm (For Easy Rule Making) is a frontend for iptables.
#		It reads the rules from a structured configuration file
#		and calls iptables(8) to insert them into the running
#		kernel.
### END INIT INFO
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/rc.d/init.d/functions

FERM_BIN=/usr/sbin/ferm
FERM_CONFIG=/etc/ferm/ferm.conf
NAME=ferm

# Get config
SourceIfNotEmpty /etc/sysconfig/ferm

LOCKFILE=/var/lock/subsys/$NAME
RETVAL=0

start()
{
	action "Start $NAME" $FERM_BIN "$FERM_CONFIG"
	RETVAL=$?
	[ "$RETVAL" -eq 0 ] && /bin/touch -- "$LOCKFILE"
	return $RETVAL
}

stop()
{
	action "Stop $NAME" $FERM_BIN -F "$FERM_CONFIG"
	RETVAL=$?
	/bin/rm -f -- "$LOCKFILE"
	return $RETVAL
}


# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		if [ -f "$LOCKFILE" ]; then
			printf "%s is started\n" "$NAME"
			RETVAL=0
		else
			prinnf "%s is stopped\n" "$NAME"
			RETVAL=1
		fi
		;;
	restart|reload|force-reload)
		start
		;;
	condstop)
		[ -f "$LOCKFILE" ] && stop
		;;
	condrestart|try-restart)
		[ -f "$LOCKFILE" ] && start
		;;
	*)
		msg_usage "${0##*/} {start|stop|status|restart|try-restart|reload|force-reload|condstop|condrestart}"
		RETVAL=1
esac

exit $RETVAL
