-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·70 lines (60 loc) · 2.32 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
#!/bin/bash
### Check if run as root ############################
# This blocks install at modules stage
# so that this script is ran later
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
echo "Try \"sudo $0\""
exit 1
fi
echo "-- install default network module config"
if [ ! -f /opt/emoncms/modules/network/config.ini ]; then
cp /opt/emoncms/modules/network/default.config.ini /opt/emoncms/modules/network/config.ini
chown pi:pi /opt/emoncms/modules/network/config.ini
fi
# ------------------------------------------------------
# Install network-sudoers
# ------------------------------------------------------
echo "-- install /etc/sudoers.d/network-sudoers"
filename=/etc/sudoers.d/network-sudoers
cat > $filename <<-EOF
www-data ALL=(ALL) NOPASSWD:/opt/emoncms/modules/network/scripts/wifi_connect.sh
www-data ALL=(ALL) NOPASSWD:/opt/emoncms/modules/network/scripts/wifi_rescan.sh
www-data ALL=(ALL) NOPASSWD:/opt/emoncms/modules/network/scripts/startAP.sh
www-data ALL=(ALL) NOPASSWD:/opt/emoncms/modules/network/scripts/stopAP.sh
www-data ALL=(ALL) NOPASSWD:/opt/emoncms/modules/network/scripts/nm_log.sh
EOF
echo "-- configure /etc/NetworkManager/NetworkManager.conf"
filename=/etc/NetworkManager/NetworkManager.conf
cat > $filename <<-EOF
[main]
plugins=ifupdown,keyfile
dns=dnsmasq
[ifupdown]
managed=false
[device]
wifi.scan-rand-mac-address=no
EOF
# dnsmasq captive portal settings
filename='/etc/NetworkManager/dnsmasq.d/redirect.conf'
cat > $filename <<-EOF
address=/connectivitycheck.gstatic.com/192.168.42.1
address=/clients3.google.com/192.168.42.1
address=/captive.apple.com/192.168.42.1
address=/apple.com/192.168.42.1
address=/www.msftncsi.com/192.168.42.1
EOF
# ------------------------------------------------------
# wifi-check not yet implemented (to review)
# ------------------------------------------------------
echo "-- install /usr/local/bin/wifi-check"
ln -sf /opt/emoncms/modules/network/scripts/wifi-check /usr/local/bin/wifi-check
echo "-- install wifi-check cron entry"
crontab -l > mycron
if grep -Fq "wifi-check" mycron; then
echo "wifi-check already present in crontab"
else
echo "* * * * * /usr/local/bin/wifi-check >> /var/log/emoncms/wificheck.log 2>&1" >> mycron
crontab mycron
rm mycron
fi