-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_host.sh
executable file
·86 lines (72 loc) · 2.27 KB
/
setup_host.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
84
85
86
#!/bin/bash
set -o errexit -o pipefail -o noclobber -o nounset
usage() {
echo "Sets up all software requirements on a modified RPi OS host"
echo ""
echo "Usage: $(basename "$0")"
echo ""
echo " -a | --ap-mode setup this node as an access point"
echo " -h | --help show this message"
echo ""
}
die() {
printf "ERROR: Script failed: %s\n\n" "$1" >&2
cd "$pwd"
exit 1
}
pwd=$(pwd)
# make sure we're running this on the node so we won't seriously mess up our workstation
# use MAC address of wlan0 to verify
# see: https://macaddress.io/statistics/company/22305
mac=$(cat /sys/class/net/wlan0/address)
[[ $(echo $mac | grep -o ^........ | grep -i "B8:27:EB") ]] || die "Please run this on a RPi node, not anywhere else."
is_ap=""
while [[ "$#" -gt 0 ]]; do
case $1 in
-a|--ap-mode) is_ap="yes" ;;
-h|--help) usage; exit 0 ;;
*) die "Unkown parameter $1"
esac
shift
done
if [[ -n $is_ap ]]; then
echo "-------------------------------------------"
echo "Setting this node up to be an access point."
echo "Please look up SSID and password in"
echo "/etc/hostapd/wlan1.conf"
echo "-------------------------------------------"
fi
# check for all mandatory directories and files
dirs_exist="networking"
files_exist="networking/start-batman-adv.sh"
for dir in $dirs_exist; do
[[ -d "$dir" ]] || die "directory '$dir' not found"
done
for file in $files_exist; do
[[ -f "$file" ]] || die "file '$file' not found"
done
username=$(whoami)
cur_group=$(id -gn)
sudo chown -R $username:$cur_group .
echo ""
echo "Copying start script ..."
cp -v networking/start-batman-adv.sh .
# install software
echo ""
echo "Checking for network connectivity ..."
nc -z -w 2 8.8.8.8 53 >/dev/null 2>&1
online=$?
if [[ online -eq 0 ]]; then
echo "Updating system and installing software ..."
sudo apt update
sudo apt -y upgrade
if [[ -z $is_ap ]]; then
sudo apt -y install batctl
else
sudo DEBIAN_FRONTEND=noninteractive apt install -y batctl hostapd dnsmasq netfilter-persistent iptables-persistent
fi
else
die "no network connection, please check network configuration"
fi
echo ""
echo "Setup finished, you can now run the setup_mesh.sh script."