#!/bin/sh

### BEGIN INIT INFO
# Provides:        gwmgr_restore
# Required-Start:  $network $remote_fs $syslog
# Required-Stop:   $network $remote_fs $syslog
# Default-Start:   2 3 4 5
# Default-Stop:    0 6
# Short-Description: Restore the last applied network configuration
### END INIT INFO

exec 2> /dev/null

ROOTACT=_REPLACEWITHROOTACT_
export ROOTACT


mkdir -p /var/volatile/log/_LRRLOG

[ -f "/var/run/lrrsystem" ] && . "/var/run/lrrsystem"
. "${ROOTACT}/lrr/com/system_setting.sh"
_system_api_loaded 2> /dev/null || . "${ROOTACT}/lrr/com/system_api.sh"
_functions_loaded 2> /dev/null || . "${ROOTACT}/lrr/com/_functions.sh"
. "${ROOTACT}/lrr/com/functionsservice.sh"
[ -f "${ROOTACT}/usr/etc/lrr/_parameters.sh" ] && . "${ROOTACT}/usr/etc/lrr/_parameters.sh"


OPTIONS="--boot"
SERVICE="gwmgr_restore"
SERVICE_RUNDIR="${ROOTACT}/lrr/gwmgr"
SERVICE_COMMAND="gwmgr.x"
COMMAND="${SERVICE_RUNDIR}/${SERVICE_COMMAND}"

# Customisable functions , see $SYSTEM/gwmgr_hooks.sh for implementation
gwmgr_prehook() {
    return
}

gwmgr_posthook() {
    return
}

SystemGetFilePath "$SERVICE_RUNDIR" "gwmgr_hooks.sh" "noroot"
[ -f "$sysfilepath" ] && . $sysfilepath

usage() {
    echo "Usage: $0 {start}"
    echo " Where options are:"
    echo "  -h|--help   Print this help message"
}

start () {
    _load_conf_system
    nfr920=$(_get_ini_var "suplog" "nfr920")

    if [ ! -z "$nfr920" ] && [ "$nfr920" = "1" ] && [ -f ${COMMAND} ] ; then
        gwmgr_prehook
        ${COMMAND} ${OPTIONS}
	gwmgr_posthook
    fi
}


case "$1" in
    start)
        start
        ;;
    restart|stop|reload|status)
        echo > /dev/null
        ;;
    *)
        echo $"Usage: $0 start"
        exit 1
esac

exit $?
