#!/bin/bash
# Re-run the idempotent bridge enslaving when an ethernet port appears or comes
# up (cable hotplug, or a NIC that showed up after a rename). A freshly plugged
# LAN port then gets added to br0 without waiting for a reboot.

IFACE="$1"
ACTION="$2"

# Only react to events that can mean "a port appeared / changed".
case "$ACTION" in
    up|connectivity-change) : ;;
    *) exit 0 ;;
esac

# Ignore the bridge itself, wifi, tun and loopback to avoid needless churn/loops.
case "$IFACE" in
    lo|br0|wl*|p2p-dev*|tun*|wg*) exit 0 ;;
esac

[ -x /usr/share/trutz-network/ensure-bridge.sh ] || exit 0

logger -i -t "ensure-bridge" "hotplug $IFACE/$ACTION -> ensure-bridge"
/usr/share/trutz-network/ensure-bridge.sh >/dev/null 2>&1 || true
exit 0
