#!/bin/bash
#
# ufw - Uncomplicated firewall
#
# chkconfig: - 08 92
# description: The Uncomplicated Firewall(ufw) is a front-end for netfilter, which aims to \
#              make it easier for people unfamiliar with firewall concepts. Ufw provides a \
#              framework for managing netfilter as well as manipulating the firewall.

### BEGIN INIT INFO
# Provides: ufw
# Default-Start: 
# Default-Stop: 0 1 6
# Short-Description: Uncomplicated firewall
# Description: The Uncomplicated Firewall(ufw) is a front-end for netfilter, which aims to
#              make it easier for people unfamiliar with firewall concepts. Ufw provides a
#              framework for managing netfilter as well as manipulating the firewall.
### END INIT INFO

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

prog="Uncomplicated firewall"
exec="/lib/ufw/ufw-init"
lockfile="/var/lock/subsys/ufw"

[ -e /etc/sysconfig/ufw ] && . /etc/sysconfig/ufw

start() {
    [ -x $exec ] || exit 5
    gprintf "Starting %s: " "$prog"
    $exec start
    RETVAL=$?
    [ $RETVAL -eq 0 ] && (touch $lockfile; success) || failure
    echo
    return $RETVAL
}

stop() {
    gprintf "Stopping %s: " "$prog"
    $exec stop
    RETVAL=$?
    [ $RETVAL -eq 0 ] && (rm -f $lockfile; success) || failure
    echo
    return $RETVAL
}

rh_status() {
    if [ -f $lockfile ]; then
        gprintf "%s is running...\n" "${prog}"
        return 0
    else
        gprintf "%s is stopped\n" "${prog}"
        return 3
    fi
}

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)
        stop
        start
        ;;
    reload)
        exit 3
        ;;
    force-reload)
        restart
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        stop
        start
        ;;
    *)
        gprintf "Usage: %s {start|stop|status|restart|condrestart|try-restart|reload|force-reload}\n" "$0"
        exit 2
esac

exit $?
