forked from 0unknwn/auto-hotspot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
83 lines (74 loc) · 2.21 KB
/
install.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
interfaceWifi=wlan0
interfaceWired=eth0
ipAddress=192.168.42.1/24
### Check if run as root ############################
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
echo "Try \"sudo $0\""
exit 1
fi
## Change over to systemd-networkd
## https://raspberrypi.stackexchange.com/questions/108592
# deinstall classic networking
apt --autoremove -y purge ifupdown dhcpcd5 isc-dhcp-client isc-dhcp-common rsyslog
apt-mark hold ifupdown dhcpcd5 isc-dhcp-client isc-dhcp-common rsyslog raspberrypi-net-mods openresolv
rm -r /etc/network /etc/dhcp
rm -f /etc/resolv.conf
cat > /etc/resolv.conf <<-EOF
nameserver 1.1.1.1
EOF
# setup/enable systemd-resolved and systemd-networkd
apt --autoremove -y purge avahi-daemon
apt-mark hold avahi-daemon libnss-mdns
apt install -y libnss-resolve
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
systemctl enable systemd-networkd.service systemd-resolved.service
## Install configuration files for systemd-networkd
cat > /etc/systemd/network/04-${interfaceWired}.network <<-EOF
[Match]
Name=$interfaceWired
[Network]
DHCP=yes
EOF
cat > /etc/systemd/network/08-${interfaceWifi}-CLI.network <<-EOF
[Match]
Name=$interfaceWifi
[Network]
DHCP=yes
MulticastDNS=yes
EOF
cat > /etc/systemd/network/12-${interfaceWifi}-AP.network <<-EOF
[Match]
Name=$interfaceWifi
[Network]
Address=$ipAddress
IPForward=yes
IPMasquerade=yes
DHCPServer=yes
MulticastDNS=yes
[DHCPServer]
EOF
cp $(pwd)/auto-hotspot /usr/local/sbin/
chmod +x /usr/local/sbin/auto-hotspot
## Install systemd-service to configure interface automatically
if [ ! -f /etc/systemd/system/wpa_cli@${interfaceWifi}.service ] ; then
cat > /etc/systemd/system/wpa_cli@${interfaceWifi}.service <<-EOF
[Unit]
Description=Wpa_cli to Automatically Create an Accesspoint if no Client Connection is Available
After=wpa_supplicant@%i.service
BindsTo=wpa_supplicant@%i.service
[Service]
ExecStart=/sbin/wpa_cli -i %I -a /usr/local/sbin/auto-hotspot
Restart=on-failure
RestartSec=1
[Install]
WantedBy=multi-user.target
EOF
else
echo "wpa_cli@$interfaceWifi.service is already installed"
fi
systemctl daemon-reload
systemctl enable wpa_cli@${interfaceWifi}.service
echo "Reboot now!"
exit 0