#!/bin/bash

# This hook using for send signal to multiwan daemon (if multiwan autostart enabled) after interface was configured.

DEBUG="yes"
DEBUG_FILE="/tmp/multiwan_dhcp-hook.debug"

. /opt/multiwan/lib/bash/common_vars
. /opt/multiwan/lib/bash/common_lib
. /opt/multiwan/lib/bash/dhcp_hook_lib

function main {
    
    local RESULT=""
    
    debug "INFO: reason=$reason, interface=$interface, new_routers=$new_routers, old_routers=$old_routers, new_dhcp_lease_time=$new_dhcp_lease_time."
    
    # Processing reason REBOOT is required to install nexthop in case of emergency gateway reboot without release DHCP address.
    if [[ $reason == "BOUND" ]] || [[ $reason == "RENEW" ]] || [[ $reason == "REBOOT" ]]; then
        check_if_multiwan_autostart_enabled
        RESULT=$?
        if (( $RESULT == 0 )); then 
            debug "INFO: sending signal to multiwan for apply nexthop IP (only first) for iface "$interface" from DHCP server."
            send_signal_to_multiwan_for_reload_dhcp_configuration
        fi
    fi
}

main
