forked from ADSBexchange/adsbx-update
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-adsbfi.sh
executable file
·185 lines (142 loc) · 5.2 KB
/
update-adsbfi.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
#!/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
# let's do all of this in a clean directory:
updir=/tmp/update-adsbfi
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"
aptInstall $packages
git clone --quiet --depth 1 https://github.com/rhysackerman/adsbfi-update.git
cd adsbfi-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/adsbfi-config.txt); do
if ! grep -qs "$(echo $line | cut -d= -f1)" /boot/adsbfi-config.txt; then
echo $line >> /boot/adsbfi-config.txt
fi
done
# remove strange dhcpcd wait.conf in case it's there
rm -f /etc/systemd/system/dhcpcd.service.d/wait.conf
systemctl daemon-reload
# enable services
systemctl enable \
adsbfi-first-run.service \
readsb.service \
adsbfi-mlat.service \
adsbfi-feed.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/adsbfi/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/adsbfi-feeder
cp -f readsb /usr/bin/adsbfi-978
cp -f readsb /usr/bin/readsb
cp -f viewadsb /usr/bin/viewadsb
echo 'make sure unprivileged users exist (readsb / adsbfi) ......'
for USER in adsbfi 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 adsbfi-feed
restartIfEnabled adsbfi-978
cd $updir
rm -rf $updir/readsb
VENV=/usr/local/share/adsbfi/venv/
if [[ -f /usr/local/share/adsbfi/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/adsbfi/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 report this error to the ADSBfi discord."
echo "--------------------"
fi
echo 'starting services .......'
restartIfEnabled adsbfi-mlat
cd $updir
rm -f -R $updir/mlat-client
cd $updir
echo 'update tar1090 ...........'
bash -c "$(wget -nv -O - https://raw.githubusercontent.com/adsbfi/tar1090/master/install.sh)"
if [[ -f /boot/adsbfi-config.txt ]]; then
if ! grep -qs -e 'GRAPHS1090' /boot/adsbfi-config.txt; then
echo "GRAPHS1090=yes" >> /boot/adsbfi-config.txt
fi
fi
# the following doesn't apply for chroot (image creation)
if ischroot; then
exit 0
fi
echo "#####################################"
cat /boot/adsbfi-uuid
echo "#####################################"
echo "#####################################"
echo "8.2.$(date '+%y%m%d')" > /boot/adsbfi-version-decoder
echo '--------------------------------------------'
echo '--------------------------------------------'
echo ' UPDATE COMPLETE'
echo '--------------------------------------------'
echo '--------------------------------------------'
cd /tmp
rm -rf $updir