#!/bin/sh

### BEGIN INIT INFO
# Provides:          one-nat4
# Required-Start:    $network $syslog
# Required-Stop:     $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

NAME="one-nat4"
DESC="ONE-NAT4 is a provider of NAT iptables rules"

. /lib/lsb/init-functions

iptables_restore=/sbin/iptables-restore

check_iptables_restore() {
    if ! [ -x "${iptables_restore}" ] ; then
        log_failure_msg "Missing iptables-restore command!"
        log_failure_msg "'${iptables_restore}' does not exist"
        log_failure_msg "or is not an executable"
        return 1
    fi
    return 0
}

case "$1" in
    start)
        check_iptables_restore || return 1
        log_daemon_msg "Starting $NAME"
        "${iptables_restore}" --table=nat < "/etc/iptables/nat4-rules-enabled"
        log_end_msg $?
        ;;

    stop)
        log_daemon_msg "Stopping $NAME"
        "$iptables_restore" --table=nat < "/etc/iptables/nat4-rules-disabled"
        log_end_msg $?
        ;;

    *)
        log_action_msg $"Usage: $0 {start|stop}"
        exit 2
esac
