#!/bin/sh
#
# Copyright (C) 2026 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# omr-bypass output WAN lists and source interface policies follow the
# tracker: a WAN going to ERROR (or back to OK, after its tries_up) moves
# the rules and policies using it to the next WAN of their list. Sourced by omr-tracker: stdout is eval'd, keep it quiet.

[ "$OMR_TRACKER_PREV_STATUS" = "$OMR_TRACKER_STATUS" ] && exit 0
[ -n "$OMR_TRACKER_INTERFACE" ] && [ -n "$OMR_TRACKER_STATUS" ] || exit 0
# Monitor only: the WAN stays in use whatever the tracker sees
[ "$OMR_TRACKER_MONITOR_ONLY" = "1" ] && [ "$OMR_TRACKER_STATUS" = "ERROR" ] && exit 0
[ -x /usr/lib/omr-bypass/wan-failover ] || exit 0
/usr/lib/omr-bypass/wan-failover event "$OMR_TRACKER_INTERFACE" "$OMR_TRACKER_STATUS" >/dev/null 2>&1 </dev/null
exit 0
