femtofox/scripts/networkinterfaces.sh

30 lines
870 B
Bash
Raw Normal View History

2024-11-16 01:10:00 +02:00
#!/bin/bash
2024-11-16 01:50:20 +02:00
# Get the current MAC address for eth0
current_mac=$(cat /sys/class/net/eth0/address)
2024-11-16 01:10:00 +02:00
2024-11-16 02:01:06 +02:00
# Define the configuration string to replace
2024-11-16 02:07:50 +02:00
config="# interfaces(5) file used by ifup(8) and ifdown(8)
2024-11-16 02:01:06 +02:00
# Include files from /etc/network/interfaces.d:
source /etc/network/interfaces.d/*
2024-11-16 01:10:00 +02:00
auto lo
iface lo inet loopback
# static mac address for onboard ethernet (castellated pins)
allow-hotplug eth0
iface eth0 inet dhcp
2024-11-16 01:50:20 +02:00
hwaddress ether $current_mac
2024-11-16 01:10:00 +02:00
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
"
2024-11-16 02:01:06 +02:00
# Replace the existing configuration for eth0 in /etc/network/interfaces
sudo sed -i "/iface eth0 inet/d" /etc/network/interfaces
echo "$config" | sudo tee /etc/network/interfaces > /dev/null
2024-11-16 01:10:00 +02:00
2024-11-16 01:50:20 +02:00
# Output the current MAC address
2024-11-16 16:01:06 +02:00
echo "Replaced /etc/network/interfaces with new MAC address ($current_mac) and wifi support\n"