#!/bin/sh
#
# nufw Startup script for nufw
#
# chkconfig:   - 86 16
# description: Nufw is user filtering firewall.

### BEGIN INIT INFO
# Provides:          nufw-nfqueue
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     
# Default-Stop:      0 1 2 3 4 5 6
# Short-Description: Control script for nufw
# Description:       Init script to control (start/stop/reload)
#                    the nufw server.
### END INIT INFO


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

exec=/usr/sbin/nufw
prog=nufw

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

if [ -z "$NUFW_VERBOSITY" ]; then
  NUFW_VERBOSITY="vv"
fi

if [ "$NUFW_NUAUTH_ADDRESS" != "" ]; then
  NUFW_OPTIONS="$NUFW_OPTIONS -d $NUFW_NUAUTH_ADDRESS"
fi

if [ "$NUFW_NUAUTH_PORT" != "" ]; then
  NUFW_OPTIONS="$NUFW_OPTIONS -p $NUFW_NUAUTH_PORT"
fi

if [ "$NUFW_TIMEOUT" != "" ]; then
  NUFW_OPTIONS="$NUFW_OPTIONS -t $NUFW_TIMEOUT"
fi

if [ "$NUFW_TRACK_SIZE" != "" ]; then
  NUFW_OPTIONS="$NUFW_OPTIONS -T $NUFW_TRACK_SIZE"
fi

DAEMON_OPTS="-D -$NUFW_VERBOSITY   \
        $NUFW_OPTIONS \
        -k $NUFW_SSL_KEY -c $NUFW_SSL_CERTIFICATE -C -M -m"

lockfile=/var/lock/subsys/$prog

start() {
    if [ "$NUFW_START" != "true" ]; then
      exit 1
    fi
    [ -x $exec ] || exit 5
    #[ -f $config ] || exit 6
    echo -n $"Starting $prog: "
    daemon $exec $DAEMON_OPTS
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?

