forked from adsb-related-code/tar1090
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·347 lines (293 loc) · 10.3 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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/bin/bash
set -e
srcdir=/run/dump1090-fa
repo="https://github.com/wiedehopf/tar1090"
db_repo="https://github.com/wiedehopf/tar1090-db"
ipath=/usr/local/share/tar1090
lighttpd=no
nginx=no
mkdir -p $ipath
if ! id -u tar1090 &>/dev/null
then
adduser --system --home $ipath --no-create-home --quiet tar1090
fi
command_package="git git/jq jq/7za p7zip-full/"
packages=""
while read -r -d '/' CMD PKG
do
if ! command -v "$CMD" &>/dev/null
then
echo "command $CMD not found, will try to install package $PKG"
packages+="$PKG "
fi
done < <(echo "$command_package")
if [[ -n "$packages" ]]
then
echo "Installing required packages: $packages"
apt-get update || true
if ! apt-get install -y $packages
then
echo "Failed to install required packages: $packages"
echo "Exiting ..."
exit 1
fi
hash -r || true
fi
if [ -d /etc/lighttpd/conf.d/ ] && ! [ -d /etc/lighttpd/conf-enabled/ ] && ! [ -d /etc/lighttpd/conf-available ] && command -v lighttpd &>/dev/null
then
ln -s /etc/lighttpd/conf.d /etc/lighttpd/conf-enabled
mkdir -p /etc/lighttpd/conf-available
fi
if [ -d /etc/lighttpd/conf-enabled/ ] && [ -d /etc/lighttpd/conf-available ] && command -v lighttpd &>/dev/null
then
lighttpd=yes
fi
if command -v nginx &>/dev/null
then
nginx=yes
fi
dir=$(pwd)
if { ! [ -d "$ipath/git-db" ] && git clone --depth 1 $db_repo $ipath/git-db; } || { cd $ipath/git-db && ! [[ "$1" == "test" ]] ; }
then
cd $ipath/git-db
git fetch --depth 1 origin master
git reset --hard origin/master
fi
cd $ipath/git-db
DB_VERSION=$(git rev-parse --short HEAD)
cd "$dir"
if [[ "$1" == "test" ]]
then
rm -r /tmp/tar1090-test 2>/dev/null || true
mkdir -p /tmp/tar1090-test
cp -r ./* /tmp/tar1090-test
cd /tmp/tar1090-test
elif { ! [ -d "$ipath/git" ] && git clone --single-branch -b master --depth 1 $repo $ipath/git; } || cd $ipath/git
then
cd $ipath/git
git fetch origin master
git reset --hard origin/master
elif wget --timeout=30 -q -O /tmp/master.zip $repo/archive/master.zip && unzip -q -o master.zip
then
cd /tmp/tar1090-master
else
echo "Unable to download files, exiting! (Maybe try again?)"
exit 1
fi
if [[ -n $1 ]] && [ "$1" != "test" ] ; then
srcdir=$1
elif ! [[ -d /run/dump1090-fa ]] ; then
if [[ -d /run/readsb ]]; then
srcdir=/run/readsb
elif [[ -d /run/dump1090 ]]; then
srcdir=/run/dump1090
elif [[ -d /run/dump1090-mutability ]]; then
srcdir=/run/dump1090-mutability
elif [[ -d /run/skyaware978 ]]; then
srcdir=/run/skyaware978
fi
fi
if [ -f /etc/default/tar1090_instances ]; then
instances=$(</etc/default/tar1090_instances)
else
instances="$srcdir tar1090"
fi
if ! diff tar1090.sh /usr/local/share/tar1090/tar1090.sh &>/dev/null; then
changed=yes
while read -r srcdir instance; do
if [[ "$instance" != "tar1090" ]]; then
service="tar1090-$instance"
else
service="tar1090"
fi
systemctl stop $service 2>/dev/null || true
done < <(echo "$instances")
cp tar1090.sh $ipath
fi
# copy over base files
cp default install.sh uninstall.sh LICENSE README.md \
95-tar1090-otherport.conf $ipath
services=""
names=""
while read -r srcdir instance
do
if [[ "$instance" != "tar1090" ]]; then
html_path="$ipath/html-$instance"
service="tar1090-$instance"
else
html_path="$ipath/html"
service="tar1090"
fi
services+="$service "
names+="$instance "
# don't overwrite existing configuration
cp -n default /etc/default/$service
sed -i -e 's/skyview978/skyaware978/' /etc/default/$service
if [[ "$instance" == "webroot" ]]
then
sed -i.orig -e "s?SOURCE_DIR?$srcdir?g" -e "s?SERVICE?$service?g" \
-e "s?/INSTANCE??g" -e "s?HTMLPATH?$html_path?g" 88-tar1090.conf
sed -i.orig -e "s?SOURCE_DIR?$srcdir?g" -e "s?SERVICE?$service?g" \
-e "s?/INSTANCE/?/?g" -e "s?HTMLPATH?$html_path?g" nginx.conf
sed -i -e "s?/INSTANCE?/?g" nginx.conf
else
sed -i.orig -e "s?SOURCE_DIR?$srcdir?g" -e "s?SERVICE?$service?g" \
-e "s?INSTANCE?$instance?g" -e "s?HTMLPATH?$html_path?g" 88-tar1090.conf
sed -i.orig -e "s?SOURCE_DIR?$srcdir?g" -e "s?SERVICE?$service?g" \
-e "s?INSTANCE?$instance?g" -e "s?HTMLPATH?$html_path?g" nginx.conf
fi
sed -i.orig -e "s?SOURCE_DIR?$srcdir?g" -e "s?SERVICE?$service?g" tar1090.service
# keep some stuff around
if [ -f $html_path/defaults*.js ]; then
cp $html_path/config.js /tmp/tar1090_config.js 2>/dev/null || true
fi
cp $html_path/upintheair.json /tmp/tar1090_upintheair.json 2>/dev/null || true
cp $html_path/color*.css /tmp/tar1090_colors.css 2>/dev/null || true
rm -rf $html_path 2>/dev/null || true
cp -r -T html $html_path
cp -r -T $ipath/git-db/db $html_path/db-$DB_VERSION
sed -i -e "s/var databaseFolder = .*/var databaseFolder = \"db-$DB_VERSION\";/" $html_path/early.js
mv /tmp/tar1090_config.js $html_path/config.js 2>/dev/null || true
mv /tmp/tar1090_colors.css $html_path/colors.css 2>/dev/null || true
mv /tmp/tar1090_upintheair.json $html_path/upintheair.json 2>/dev/null || true
epoch=$(date +%s)
# bust cache for all css and js files
dir=$(pwd)
cd $html_path
sed -i \
-e "s/dbloader.js/dbloader_$epoch.js/" \
-e "s/defaults.js/defaults_$epoch.js/" \
-e "s/early.js/early_$epoch.js/" \
-e "s/flags.js/flags_$epoch.js/" \
-e "s/formatter.js/formatter_$epoch.js/" \
-e "s/layers.js/layers_$epoch.js/" \
-e "s/markers.js/markers_$epoch.js/" \
-e "s/planeObject.js/planeObject_$epoch.js/" \
-e "s/registrations.js/registrations_$epoch.js/" \
-e "s/script.js/script_$epoch.js/" \
-e "s/colors.css/colors_$epoch.css/" \
-e "s/style.css/style_$epoch.css/" \
index.html
sed -i -e "s/tar1090 on github/tar1090 on github ($(date +%y%m%d))/" index.html
mv dbloader.js dbloader_$epoch.js
mv defaults.js defaults_$epoch.js
mv early.js early_$epoch.js
mv flags.js flags_$epoch.js
mv formatter.js formatter_$epoch.js
mv layers.js layers_$epoch.js
mv markers.js markers_$epoch.js
mv planeObject.js planeObject_$epoch.js
mv registrations.js registrations_$epoch.js
mv script.js script_$epoch.js
mv colors.css colors_$epoch.css
mv style.css style_$epoch.css
if [[ $nginx == yes ]]; then
gzip -k -9 dbloader_$epoch.js
gzip -k -9 defaults_$epoch.js
gzip -k -9 early_$epoch.js
gzip -k -9 flags_$epoch.js
gzip -k -9 formatter_$epoch.js
gzip -k -9 layers_$epoch.js
gzip -k -9 markers_$epoch.js
gzip -k -9 planeObject_$epoch.js
gzip -k -9 registrations_$epoch.js
gzip -k -9 script_$epoch.js
gzip -k -9 colors_$epoch.css
gzip -k -9 style_$epoch.css
gzip -k -9 jquery/*.js
gzip -k -9 ol/*.js
#gzip -k -9 db2/*.json .... already exists compressed
fi
cd "$dir"
cp nginx.conf $ipath/nginx-$service.conf
if [[ $lighttpd == yes ]] && diff 88-tar1090.conf /etc/lighttpd/conf-enabled/99-$service.conf &>/dev/null
then
true
elif [[ $lighttpd == yes ]] && ! diff 88-tar1090.conf /etc/lighttpd/conf-enabled/88-$service.conf &>/dev/null
then
changed_lighttpd=yes
if [ -f /etc/lighttpd/conf.d/69-skybup.conf ] && [[ "$instance" == "webroot" ]]; then
true
elif [[ "$instance" == "webroot" ]]
then
cp 88-tar1090.conf /etc/lighttpd/conf-available/99-$service.conf
ln -f -s /etc/lighttpd/conf-available/99-$service.conf /etc/lighttpd/conf-enabled/99-$service.conf
else
cp 88-tar1090.conf /etc/lighttpd/conf-available/88-$service.conf
if [ -f /etc/lighttpd/conf.d/69-skybup.conf ]; then
ln -f -s /etc/lighttpd/conf-available/88-$service.conf /etc/lighttpd/conf-enabled/66-$service.conf
else
ln -f -s /etc/lighttpd/conf-available/88-$service.conf /etc/lighttpd/conf-enabled/88-$service.conf
fi
fi
fi
if [[ $changed == yes ]] || ! diff tar1090.service /lib/systemd/system/$service.service &>/dev/null
then
cp tar1090.service /lib/systemd/system/$service.service
if systemctl enable $service
then
echo "Restarting $service ..."
systemctl restart $service
else
echo "$service.service is masked, could not start it!"
fi
fi
# restore sed modified configuration files
mv 88-tar1090.conf.orig 88-tar1090.conf
mv nginx.conf.orig nginx.conf
mv tar1090.service.orig tar1090.service
done < <(echo "$instances")
if [ -d /etc/lighttpd/conf-enabled/ ]
then
while read -r FILE; do
sed -i -e 's/^server.modules += ( "mod_setenv" )/#server.modules += ( "mod_setenv" )/' "$FILE"
done < <(find /etc/lighttpd/conf-available/* | grep -v dump1090-fa)
# add mod_setenv to lighttpd modules, check if it's one too much
if [ -f /etc/lighttpd/conf-enabled/87-mod_setenv.conf ]; then
setenv_file="present"
fi
echo 'server.modules += ( "mod_setenv" )' > /etc/lighttpd/conf-available/87-mod_setenv.conf
ln -s -f /etc/lighttpd/conf-available/87-mod_setenv.conf /etc/lighttpd/conf-enabled/87-mod_setenv.conf
if lighttpd -tt -f /etc/lighttpd/lighttpd.conf 2>&1 | grep mod_setenv >/dev/null
then
rm /etc/lighttpd/conf-enabled/87-mod_setenv.conf
if [[ "$setenv_file" == "present" ]]; then
changed_lighttpd=yes
fi
else
if [[ "$setenv_file" != "present" ]]; then
changed_lighttpd=yes
fi
fi
fi
if [[ $changed_lighttpd == yes ]] && systemctl status lighttpd >/dev/null; then
echo "Restarting lighttpd ..."
systemctl restart lighttpd
fi
echo --------------
if [[ $nginx == yes ]]; then
echo
echo "To configure nginx for tar1090, please add the following line(s) in the server {} section:"
echo
for service in $services; do
echo "include /usr/local/share/tar1090/nginx-$service.conf;"
done
if [[ "$1" == "test" ]]
then
if [ -d /run/readsb ]; then
sed -i -e 's/dump1090-fa/readsb/g' /usr/local/share/tar1090/nginx_webroot.conf
fi
fi
fi
echo --------------
if [[ $lighttpd == yes ]]; then
for name in $names; do
echo "All done! Webinterface available at http://$(ip route | grep -m1 -o -P 'src \K[0-9,.]*')/$name"
done
elif [[ $nginx == yes ]]; then
for name in $names; do
echo "All done! Webinterface once nginx is configured will be available at http://$(ip route | grep -m1 -o -P 'src \K[0-9,.]*')/$name"
done
else
echo "All done! You'll need to configure your webserver yourself, see /usr/local/share/tar1090/nginx-tar1090.conf for a reference nginx configuration"
fi