Some checks failed
Test / test (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
85 lines
2.0 KiB
Bash
Executable File
85 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Test interface detection logic (no root required)
|
|
|
|
echo "Testing Interface Detection Logic"
|
|
echo "================================="
|
|
echo ""
|
|
|
|
# Get all physical interfaces
|
|
PHYSICAL_IFACES=()
|
|
for iface in /sys/class/net/*; do
|
|
iface_name=$(basename "$iface")
|
|
|
|
# Skip loopback, virtual interfaces, bridges, bonds, and VLANs
|
|
if [[ "$iface_name" == "lo" ]] || \
|
|
[[ -L "$iface/device" ]] && [[ ! -d "$iface/device" ]] || \
|
|
[[ -d "$iface/bridge" ]] || \
|
|
[[ -d "$iface/bonding" ]] || \
|
|
[[ "$iface_name" =~ \. ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Check if it's a physical interface
|
|
if [ -d "$iface/device" ] || [ -L "$iface/device" ]; then
|
|
PHYSICAL_IFACES+=("$iface_name")
|
|
fi
|
|
done
|
|
|
|
# Sort interfaces for consistent selection
|
|
IFS=$'\n' PHYSICAL_IFACES=($(sort <<<"${PHYSICAL_IFACES[*]}"))
|
|
unset IFS
|
|
|
|
echo "Detected Physical Interfaces:"
|
|
for i in "${!PHYSICAL_IFACES[@]}"; do
|
|
idx=$((i+1))
|
|
iface="${PHYSICAL_IFACES[$i]}"
|
|
if [ $idx -eq 1 ]; then
|
|
echo " NIC $idx (LAN): $iface → vmbr0"
|
|
elif [ $idx -eq 2 ]; then
|
|
echo " NIC $idx (WAN): $iface → vmbr1"
|
|
else
|
|
echo " NIC $idx (unused): $iface"
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
if [ ${#PHYSICAL_IFACES[@]} -ge 2 ]; then
|
|
NIC1="${PHYSICAL_IFACES[0]}"
|
|
NIC2="${PHYSICAL_IFACES[1]}"
|
|
|
|
echo "Configuration Preview:"
|
|
echo "======================"
|
|
echo ""
|
|
cat <<EOF
|
|
# NIC 1 (LAN) - Physical interface
|
|
auto $NIC1
|
|
iface $NIC1 inet manual
|
|
|
|
# vmbr0 (LAN Bridge) - Connected to 192.168.1.0/24 network
|
|
auto vmbr0
|
|
iface vmbr0 inet dhcp
|
|
bridge-ports $NIC1
|
|
bridge-stp off
|
|
bridge-fd 0
|
|
bridge-vlan-aware no
|
|
metric 200
|
|
|
|
# NIC 2 (WAN) - Physical interface
|
|
auto $NIC2
|
|
iface $NIC2 inet manual
|
|
|
|
# vmbr1 (WAN Bridge) - Connected to Spectrum cable modem
|
|
auto vmbr1
|
|
iface vmbr1 inet dhcp
|
|
bridge-ports $NIC2
|
|
bridge-stp off
|
|
bridge-fd 0
|
|
bridge-vlan-aware no
|
|
metric 100
|
|
EOF
|
|
else
|
|
echo "⚠️ Warning: Need at least 2 physical interfaces"
|
|
echo " Found: ${#PHYSICAL_IFACES[@]}"
|
|
fi
|
|
|