# Sourced by hotplug-call on interface events (no shebang, no exit).
# A network reload/WAN change wipes the policy routing the core installed at
# start, silently breaking the proxy; restart the core when WAN comes up
# (same reason OpenClash hooks hotplug). If the service is enabled but never
# came up (the mini edition boots before the WAN and cannot download its
# binaries), start it now.
if [ "$ACTION" = "ifup" ] && { [ "$INTERFACE" = "wan" ] || [ "$INTERFACE" = "wan6" ]; }; then
	if /etc/init.d/ednovas running 2>/dev/null; then
		agent="$(uci -q get ednovas.main.agent_path)"
		[ "$(uci -q get ednovas.main.mini)" = "1" ] && agent=/tmp/ednovas/ednovas-agent
		[ -x "$agent" ] || agent=/usr/share/ednovas/ednovas-agent
		( sleep 3; "$agent" reconnect >/dev/null 2>&1 ) &
	elif /etc/init.d/ednovas enabled 2>/dev/null; then
		( sleep 3; /etc/init.d/ednovas start >/dev/null 2>&1 ) &
	fi
fi
