#!/bin/sh
# /etc/hotplug.d/iface/99-shater
#
# netifd wipes `ip rule` / `ip route` on `network reload` and on interface
# churn, so our policy routing must be re-persisted on every ifup/ifdown.
# xrayctl reconcile is idempotent, so re-running it here is safe and cheap.
#
# Fully inert unless the Shater stack is enabled — never disturbs connectivity
# on boxes where the package is merely installed.

[ -x /usr/bin/xrayctl ] || exit 0

case "$ACTION" in
	ifup|ifdown) ;;
	*) exit 0 ;;
esac

# Only act when explicitly enabled.
en=$(uci -q get shater.globals.enabled) || exit 0
[ "$en" = "1" ] || exit 0

/usr/bin/xrayctl reconcile >/dev/null 2>&1

exit 0
