-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrestore_wifi.sh
executable file
·50 lines (39 loc) · 1.13 KB
/
restore_wifi.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
48
49
50
#!/usr/bin/env bash
if [ "$(id -u)" != "0" ]; then
echo "This must be run as root." 1>&2
exit 1
fi
# Get the script folder
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Enter SSID of WiFi network to which to connect:"
read SSID
echo "Enter WiFi Password:"
read PSK
echo "Copying config files..."
rm -f ${SCRIPT_DIR}/cfg/interfaces.d/br0
cp -f ${SCRIPT_DIR}/cfg/rules.v4.wifi /etc/iptables/rules.v4
echo "done!"
echo "Modifying config files..."
sed -i -- 's/net.ipv4.ip_forward=1/#net.ipv4.ip_forward=1/g' /etc/sysctl.conf
sed -i -- 's/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/#DAEMON_CONF=""/g' /etc/default/hostapd
sed -i -- 's/ENABLED=1/ENABLED=0/g' /etc/default/dnsmasq
echo "done!"
echo "Enable DHCP..."
update-rc.d dhcpcd enable
echo "done!"
echo "Disable dnsmasq..."
systemctl disable dnsmasq
echo "done!"
echo "Disable hostapd..."
systemctl disable hostapd
systemctl mask hostapd
echo "done!"
cat > /etc/wpa_supplicant/wpa_supplicant.conf <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="${SSID}"
psk="${PSK}"
}
EOF
echo "All done! Reboot to apply changes."