From 94d2c711ceb2559ce5d25d5d66e6dce34bc11bea Mon Sep 17 00:00:00 2001 From: Hudson Riggs Date: Tue, 2 Dec 2025 23:33:44 -0500 Subject: [PATCH] push wol --- enable_wol_proxmox.sh | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/enable_wol_proxmox.sh b/enable_wol_proxmox.sh index e9114cb..0665dbc 100644 --- a/enable_wol_proxmox.sh +++ b/enable_wol_proxmox.sh @@ -21,6 +21,47 @@ info() { echo "[*] $*" } +# Return 0 if interface is physical (non-virtual) +is_physical_iface() { + local iface="$1" + local dev_path + dev_path=$(readlink -f "/sys/class/net/${iface}/device" 2>/dev/null || true) + [[ -n "$dev_path" && "$dev_path" != *"/virtual/"* ]] +} + +# Resolve bridge/bond to the underlying physical NIC, if possible +resolve_physical_iface() { + local iface="$1" + local candidate resolved + + # If iface is a bridge, iterate its members + if [[ -d "/sys/class/net/${iface}/bridge" ]]; then + for brif in /sys/class/net/${iface}/brif/*; do + [[ -e "$brif" ]] || continue + candidate=$(basename "$brif") + resolved=$(resolve_physical_iface "$candidate") + [[ -n "$resolved" ]] && echo "$resolved" && return + done + fi + + # If iface is a bond, walk its slaves + if [[ -f "/sys/class/net/${iface}/bonding/slaves" ]]; then + for slave in $(<"/sys/class/net/${iface}/bonding/slaves"); do + resolved=$(resolve_physical_iface "$slave") + [[ -n "$resolved" ]] && echo "$resolved" && return + done + fi + + # If iface itself is physical, return it + if is_physical_iface "$iface"; then + echo "$iface" + return + fi + + # Fallback: return original iface even if virtual + echo "$iface" +} + # --- Preconditions ----------------------------------------------------------- if [[ $EUID -ne 0 ]]; then @@ -66,6 +107,14 @@ fi info "Detected primary interface: ${PRIMARY_IF}" +PHYSICAL_IF=$(resolve_physical_iface "$PRIMARY_IF") +if [[ "$PHYSICAL_IF" != "$PRIMARY_IF" ]]; then + info "Resolved underlying physical interface: ${PHYSICAL_IF}" + PRIMARY_IF="$PHYSICAL_IF" +else + info "Using ${PRIMARY_IF} as the primary physical interface." +fi + # --- Get MAC address & IP ---------------------------------------------------- MAC_ADDR=$(ip -o link show "$PRIMARY_IF" | awk '{for (i=1; i<=NF; i++) if ($i=="link/ether") print $(i+1)}')