forked from selengalp/wifi_access_point_server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswitch_ap_mode.sh
executable file
·51 lines (34 loc) · 1.18 KB
/
switch_ap_mode.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
44
45
46
47
#!/bin/bash
# Switch to wifi AP mode
# Check if we are root
if [ $(id -u) -ne 0 ]; then
echo "Please run as root"
exit 1
fi
# Configure the dhcpcd to use the static IP address
cp ./ap_config_files/dhcpcd.conf /etc/dhcpcd.conf
# Configure the dnsmaq
cp ./ap_config_files/dnsmasq.conf /etc/dnsmasq.conf
# Update SSID in the hostapd.conf file
unique_part=$(ip link show eth0 | grep -oP 'ether \K[^ ]+' | cut -d: -f3-5 | tr -d ':')
sed -i "s/\[UNIQUE\]/$unique_part/" ./ap_config_files/hostapd.conf
# Configure the hostapd
cp ./ap_config_files/hostapd.conf /etc/hostapd/hostapd.conf
# Add new local host name to /etc/hosts
cp ./ap_config_files/hosts /etc/hosts
# Add exception for wlan0 to core configuration file
cp ./ap_config_files/core_config.yaml /home/pi/.core/configs/config.yaml
# Stop services
systemctl stop hostapd
systemctl stop dnsmasq
# Stop services conflicting with hostapd
systemctl stop systemd-resolved
systemctl stop wpa_supplicant
# Stop active wpa supplicant processes
pkill wpa_supplicant
rfkill block wifi
sleep 1
rfkill unblock wifi
# Restart dhcpcd, dnsmasq, hostapd, core_manager
systemctl daemon-reload
systemctl restart dhcpcd dnsmasq hostapd core_manager