-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle_ap.sh
More file actions
executable file
·51 lines (43 loc) · 1.61 KB
/
toggle_ap.sh
File metadata and controls
executable file
·51 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Toggle between WiFi client mode and AP mode
# This script handles the transition in a single command to prevent disconnection issues
HOME_CONN="TheAddiction"
AP_CONN="Heatwave"
function activate_ap() {
echo "Activating Heatwave AP mode..."
# Execute both commands in sequence without allowing interruption
(nmcli con down "$HOME_CONN" && nmcli con up "$AP_CONN") &
echo "AP mode transition initiated!"
echo "You will be disconnected from SSH if connected via WiFi."
echo "The Heatwave AP will be available in a few seconds."
echo "Connect to the 'Heatwave' network to access the web interface."
}
function activate_client() {
echo "Switching back to home WiFi mode..."
# Execute both commands in sequence without allowing interruption
(nmcli con down "$AP_CONN" && nmcli con up "$HOME_CONN") &
echo "WiFi client mode transition initiated!"
echo "You will be disconnected from the AP if connected via it."
echo "The Raspberry Pi will attempt to connect back to your home WiFi."
}
# Show current state
echo "Current network status:"
nmcli con show --active
# Check if we're currently in AP mode
if nmcli -t -f NAME con show --active | grep -q "$AP_CONN"; then
echo "Currently in AP mode"
read -p "Switch back to home WiFi? (y/n): " choice
if [[ $choice == [Yy]* ]]; then
activate_client
else
echo "Staying in AP mode"
fi
else
echo "Currently in client WiFi mode"
read -p "Switch to AP mode? (y/n): " choice
if [[ $choice == [Yy]* ]]; then
activate_ap
else
echo "Staying in client mode"
fi
fi