-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_ap.sh
executable file
·43 lines (34 loc) · 1.36 KB
/
setup_ap.sh
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
#!/bin/bash
# Check if NetworkManager is running, and exit if it is
if systemctl is-active --quiet NetworkManager; then
echo "NetworkManager is currently active. Please disable NetworkManager to avoid conflicts and rerun this script."
exit 1
fi
# Get UAV_NAME from /etc/hosts associated with 127.0.1.1
UAV_NAME=$(grep -w '127.0.1.1' /etc/hosts | awk '{print $2}')
if [ -z "$UAV_NAME" ]; then
UAV_NAME="uav00"
fi
# Define the AP password
AP_PASSWORD="drone@f4f"
# Use the 5GHz band if supported
FREQUENCY_BAND="5"
# Define backup and current netplan files
CURRENT_NETPLAN_FILE="/etc/netplan/01-netcfg.yaml"
BACKUP_NETPLAN_FILE="/etc/netplan/01-netcfg.yaml.bak"
# Backup netplan configuration if not already backed up
if [ ! -f "$BACKUP_NETPLAN_FILE" ]; then
echo "Backing up netplan configuration..."
cp "$CURRENT_NETPLAN_FILE" "$BACKUP_NETPLAN_FILE"
else
echo "Netplan configuration backup already exists."
fi
# Remove the 'wifis' section from the netplan configuration using yq
echo "Removing the 'wifis' section using yq..."
yq e 'del(.network.wifis)' -i "$CURRENT_NETPLAN_FILE"
# Apply netplan changes
echo "Applying modified netplan configuration..."
netplan apply
# Start the access point using create_ap
echo "Starting Access Point..."
sudo create_ap --no-virt -n --freq-band "$FREQUENCY_BAND" --redirect-to-localhost wlan0 "${UAV_NAME}_WIFI" "$AP_PASSWORD"