#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
# Description: This program will startup the iptables NAT for DRBL clients when DRBL server boots.
# Note: This program is different with drbl-nat-rules
#       drbl-nat-rules: a program to generate "NAT rules" for DRBL clients.
#       drbl-clients-nat: a startup "NAT service" for DRBL server when it boots.

### BEGIN INIT INFO
# Provides:          drbl-clients-nat
# Required-Start:    $local_fs $all
# Required-Stop:
# X-Start-Before:
# X-Stop-After:
# Default-Start:     2
# Default-Stop:
### END INIT INFO

#set -e

DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"

. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions

export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"

#
do_start_drbl_nat_rules() {
 if  [ -f $SYSCONF_PATH/drbl-nat.up.rules ]; then
   iptables-restore < $SYSCONF_PATH/drbl-nat.up.rules
 else
   echo "$SYSCONF_PATH/drbl-nat.up.rules is not found, skip this."
 fi
}
do_stop_drbl_nat_rules() {
  $DRBL_SCRIPT_PATH/sbin/drbl-nat-rules stop
}

case "$1" in
  start)
        echo -n "Starting the NAT services for DRBL clients... "
        do_start_drbl_nat_rules
	echo "done!"
	;;
  stop)
        echo -n "Stopping the NAT services for DRBL clients... "
        do_stop_drbl_nat_rules
	echo "done!"
	;;
  restart)
	$0 stop
	$0 start
	;;
  status)
        iptables -L -t nat -n
	;;

  *)
	echo "Usage: $0 {start|stop|status}"
	exit 1
esac

exit 0
