add network switch script

This commit is contained in:
Torben Haack 2024-10-09 15:23:13 +02:00
parent 67ec8eebc8
commit baf5bc4d36

View File

@ -0,0 +1,31 @@
#!/bin/sh
# Define the state file
STATE_FILE="/tmp/network_toggle_state"
# Check if the state file exists
if [ -f "$STATE_FILE" ]; then
# If the state file exists, read the state
STATE=$(cat "$STATE_FILE")
else
# If the state file does not exist, initialize it to "down"
STATE="down"
echo "$STATE" > "$STATE_FILE"
fi
# Toggle the state
if [ "$STATE" == "down" ]; then
echo "Bringing interfaces down and up..."
sudo ip link set macvlan0 down
sudo ip link set macvlan1 down
sudo ip link set eth0 down
sudo ip link set wlan1 up
echo "up" > "$STATE_FILE" # Update the state to "up"
else
echo "Bringing interfaces up and down..."
sudo ip link set wlan1 down
sudo ip link set eth0 up
sudo ip link set macvlan1 up
sudo ip link set macvlan0 up
echo "down" > "$STATE_FILE" # Update the state to "down"
fi