-
Notifications
You must be signed in to change notification settings - Fork 13
/
update-adsbx.sh
executable file
·215 lines (169 loc) · 6.37 KB
/
update-adsbx.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
set -e
trap 'echo "[ERROR] Error in line $LINENO when executing: $BASH_COMMAND"' ERR
if [[ "$(id -u)" != "0" ]]; then
exec sudo bash "$BASH_SOURCE"
fi
# This is required for low memory devices, else apt update locks
if swapon --summary | grep -q "^"; then
echo "Swap is already active."
else
# Activate the swap file using dphys-swapfile
echo "Activating swap..."
sudo dphys-swapfile swapon
echo "Swap activated."
fi
# let's do all of this in a clean directory:
updir=/tmp/update-adsbx
rm -rf $updir
mkdir -p $updir
cd $updir
# in case /var/log is full ... delete some logs
echo test > /var/log/.test 2>/dev/null || rm -f /var/log/*.log
restartIfEnabled() {
# check if enabled
if systemctl is-enabled "$1" &>/dev/null; then
systemctl restart "$1"
fi
}
function aptInstall() {
if ! apt install -y --no-install-recommends --no-install-suggests "$@"; then
apt update
apt install -y --no-install-recommends --no-install-suggests "$@"
fi
}
packages="git make gcc libusb-1.0-0 libusb-1.0-0-dev librtlsdr0 librtlsdr-dev ncurses-bin ncurses-dev zlib1g zlib1g-dev python3-dev python3-venv libzstd-dev libzstd1 bc"
aptInstall $packages
git clone --quiet --depth 1 https://github.com/adsbexchange/adsbx-update.git
cd adsbx-update
find skeleton -type d | cut -d / -f1 --complement | grep -v '^skeleton' | xargs -t -I '{}' -s 2048 mkdir -p /'{}' &>/dev/null
find skeleton -type f | cut -d / -f1 --complement | xargs -I '{}' -s 2048 cp -T --remove-destination -v skeleton/'{}' /'{}' >/dev/null
# make sure the config has all the options, if not add them with default value:
for line in $(grep -v -e '^#' -e '^$' boot-configs/adsb-config.txt); do
if ! grep -qs "$(echo $line | cut -d= -f1)" /boot/adsb-config.txt; then
echo $line >> /boot/adsb-config.txt
fi
done
# remove strange dhcpcd wait.conf in case it's there
rm -f /etc/systemd/system/dhcpcd.service.d/wait.conf
if [[ -f /etc/systemd/system/adsbexchange-978-convert.service ]]; then
systemctl disable --now adsbexchange-978-convert.service &>/dev/null || true
fi
rm -f /etc/systemd/system/adsbexchange-978-convert.service
rm -f /usr/local/bin/adsbexchange-978-convert.sh
systemctl daemon-reload
# enable services
systemctl enable \
adsbexchange-first-run.service \
adsbx-zt-enable.service \
readsb.service \
adsbexchange-mlat.service \
adsbexchange-feed.service \
gpsd.service \
adsbexchange-gpsmon.service \
pingfail.service
# mask services we don't need on this image
MASK="dump1090-fa dump1090 dump1090-mutability dump978-rb dump1090-rb"
for service in $MASK; do
systemctl disable $service || true
systemctl stop $service || true
systemctl mask $service || true
done &>/dev/null
cd $updir
git clone --quiet --depth 1 https://github.com/adsbexchange/readsb.git
echo 'compiling readsb (this can take a while) .......'
cd readsb
if dpkg --print-architecture | grep -qs armhf; then
make -j3 AIRCRAFT_HASH_BITS=12 RTLSDR=yes OPTIMIZE="-O2 -mcpu=arm1176jzf-s -mfpu=vfp"
else
make -j3 AIRCRAFT_HASH_BITS=12 RTLSDR=yes OPTIMIZE="-O3"
fi
echo 'copying new readsb binaries ......'
cp -f readsb /usr/bin/adsbxfeeder
cp -f readsb /usr/bin/adsbx-978
cp -f readsb /usr/bin/readsb
cp -f viewadsb /usr/bin/viewadsb
echo 'make sure unprivileged users exist (readsb / adsbexchange) ......'
for USER in adsbexchange readsb; do
if ! id -u "${USER}" &>/dev/null
then
adduser --system --home "/usr/local/share/$USER" --no-create-home --quiet "$USER"
fi
done
# plugdev required for bladeRF USB access
adduser readsb plugdev
# dialout required for Mode-S Beast and GNS5894 ttyAMA0 access
adduser readsb dialout
mkdir -p /var/globe_history
chown readsb /var/globe_history
echo 'restarting services .......'
restartIfEnabled readsb
restartIfEnabled adsbexchange-feed
restartIfEnabled adsbexchange-978
cd $updir
rm -rf $updir/readsb
echo 'updating adsbx stats .......'
wget --quiet -O /tmp/axstats.sh https://raw.githubusercontent.com/adsbexchange/adsbexchange-stats/master/stats.sh
bash /tmp/axstats.sh
echo 'cleaming up stats /tmp .......'
rm -f /tmp/axstats.sh
rm -f -R /tmp/adsbexchange-stats-git
VENV=/usr/local/share/adsbexchange/venv/
if [[ -f /usr/local/share/adsbexchange/venv/bin/python3.7 ]] && command -v python3.9 &>/dev/null;
then
rm -rf "$VENV"
fi
rm "$VENV-backup" -rf
mv "$VENV" "$VENV-backup" -f &>/dev/null || true
cd $updir
echo 'building mlat-client in virtual-environment .......'
if git clone --quiet --depth 1 --single-branch https://github.com/adsbexchange/mlat-client.git \
&& cd mlat-client \
&& /usr/bin/python3 -m venv $VENV \
&& source $VENV/bin/activate \
&& python3 setup.py build \
&& python3 setup.py install \
&& git rev-parse HEAD > $IPATH/mlat_version || rm -f $IPATH/mlat_version \
; then
rm "$VENV-backup" -rf
else
rm "$VENV" -rf
mv "$VENV-backup" "$VENV" &>/dev/null || true
echo "--------------------"
echo "Installing mlat-client failed, if there was an old version it has been restored."
echo "Will continue installation to try and get at least the feed client working."
echo "Please repot this error to the adsbexchange forums or discord."
echo "--------------------"
fi
echo 'starting services .......'
restartIfEnabled adsbexchange-mlat
cd $updir
rm -f -R $updir/mlat-client
cd $updir
echo 'update tar1090 ...........'
bash -c "$(wget -nv -O - https://raw.githubusercontent.com/wiedehopf/tar1090/master/install.sh)"
if [[ -f /boot/adsb-config.txt ]]; then
if ! grep -qs -e 'GRAPHS1090' /boot/adsb-config.txt; then
echo "GRAPHS1090=yes" >> /boot/adsb-config.txt
fi
if ! grep -qs -e "ZEROTIER_STANDALONE" /boot/adsb-config.txt; then
echo "ZEROTIER_STANDALONE=no" >> /boot/adsb-config.txt
fi
fi
# the following doesn't apply for chroot (image creation)
if ischroot; then
exit 0
fi
echo "#####################################"
cat /boot/adsbx-uuid
echo "#####################################"
sed -e 's$^$https://www.adsbexchange.com/api/feeders/?feed=$' /boot/adsbx-uuid
echo "#####################################"
echo "8.2.$(date '+%y%m%d')" > /boot/adsbx-version-decoder
echo '--------------------------------------------'
echo '--------------------------------------------'
echo ' UPDATE COMPLETE'
echo '--------------------------------------------'
echo '--------------------------------------------'
cd /tmp
rm -rf $updir