## -*- mode: shell-script; -*- 
##
## To be able to make changes to the part of configuration created
## from this configlet you need to copy this file to the directory
## fwbuilder/configlets/ipcop/ in your home directory and modify it.
## Double "##" comments are removed during processing but single "#"
## comments are be retained and appear in the generated script. Empty
## lines are removed as well.  
##
## Configlets support simple macro language with these constructs:
## {{$var}} is variable expansion
## {{if var}} is conditional operator.
##
{{$top_comment}}

{{$shell_debug}}

{{$path}}

{{$constants}}

{{$tools}}

{{$shell_functions}}

{{$run_time_address_tables}}

verify_interfaces() {
    :
    {{$verify_interfaces}}
}

prolog_commands() {
    echo "Running prolog script"
    {{$prolog_script}}
}

epilog_commands() {
    echo "Running epilog script"
    {{$epilog_script}}
}

run_epilog_and_exit() {
    epilog_commands
    exit $1
}

script_body() {
    {{$script_body}}
}

reset_all() {
    :
    {{$reset_all}}
}

case "$1" in
    start)
        check_tools
        check_run_time_address_table_files
        {{if using_ipset}}
        check_module_ipset
        load_run_time_address_table_files
        {{endif}}
        verify_interfaces
        prolog_commands
        script_body
        epilog_commands
        ;;

    stop)
    # on IPCOP "/etc/rc.firewall stop" purges all tables and chains
    # and then calls this script with command "stop", but there is
    # nothing left for us to do here.
        ;;
    
    reload)
        $0 stop
        $0 start
        ;;

    *)
        echo "Usage $0 {start|stop|reload}"
        ;;
    
esac

