This repository has been archived by the owner on Feb 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install_planefence.sh
359 lines (334 loc) · 14.7 KB
/
install_planefence.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
347
348
349
350
351
352
353
354
355
356
357
358
359
#!/bin/bash
# INSTALL_PLANEFENCE - a Bash shell script to render a HTML and CSV table with nearby aircraft
# based on socket30003
#
# Usage: ./install_planefence.sh
# Or from your BASH command line on your Raspberry Pi:
# bash -c "$(wget -q -O - https://raw.githubusercontent.com/kx1t/planefence/master/install_planefence.sh)"
#
# Copyright 2020 by Ramón F. Kolb, with collaborations by Rodney Yeo
#
# This software may be used under the terms and conditions of the GPLv3 license.
# The terms and conditions of this license are included with the Github
# distribution of this package, and are also available here:
# https://raw.githubusercontent.com/kx1t/planefence/master/LICENSE
#
# The package contains parts of, and modifications or derivatives to the following:
# Dump1090.Socket30003 by Ted Sluis: https://github.com/tedsluis/dump1090.socket30003
# These packages may incorporate other software and license terms.
#
# Summary of License Terms
# This program is free software: you can redistribute it and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation, either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see https://www.gnu.org/licenses/.
VERSION="200619-1445"
clear
echo "Welcome to PlaneFence Setup - version $VERSION"
echo "https://github.com/kx1t/planefence"
echo "Copyright 2020 by Ramón F. Kolb, with collaborations by Rodney Yeo"
echo ""
echo "This script will attempt to install and configure PlaneFence."
echo ""
echo "--------------------------------------------------------------------"
# Let's start checking if we're running as user=PI. If not, throw a bunch of warnings
if [ "$USER" != "pi" ]
then
echo "WARNING... You should really run this script as user \"pi\"."
echo "Instead, you are running it as user \""$USER"\"."
echo ""
read -p "Are you sure you want to continue? (y/N) " choice
[ "${choice:0:1}" != "y" ] && exit -1
echo "--------------------------------------------------------------------"
fi
if [ "$USER" == "root" ]
then
echo "Sorry to bother again. You should REALLY NOT run this script as user \"root\"."
echo "Did you invoke the script with \"sudo\"? Then please run it without \"sudo\"."
echo ""
echo "Installing the software as \"root\" will cause all kind of security issues later."
echo ""
echo "--> We strongly recommend you answer \"NO\" below. <--"
echo ""
read -p "Are you sure you want to continue? (y/N) " choice
[ "${choice:0:1}" != "y" ] && exit -1
echo "Ok then, you have been warned. Don't blame us..."
echo "--------------------------------------------------------------------"
fi
# Let's find out what the dump1090 directory is
echo "Figuring out where your dump1090 directory is..."
if [ -d "/usr/share/dump1090-fa" ] && [ -d "/usr/share/dump1090" ]
then
echo "It appears that both \"/usr/share/dump1090-fa\" and \"/usr/share/dump1090\" exist on your system.
echo "Which one would you like to use for your PlaneFence installation?
echo "1) /usr/share/dump1090-fa"
echo "2) /usr/share/dump1090"
a=""
while [ "$a" == "" ]
do
read -p "Please enter 1 or 2, or enter a custom directory name: " a
[ "$a" == "1" ] && DUMPDIR="/usr/share/dump1090-fa"
[ "$a" == "2" ] && DUMPDIR="/usr/share/dump1090"
done
elif [ -d "/usr/share/dump1090-fa" ]
then
DUMPDIR="/usr/share/dump1090-fa"
echo "We found $DUMPDIR."
read -p "Press ENTER to use this, or type a custom directory name: " a
[ "$a" != "" ] && DUMPDIR="$a"
elif [ -d "/usr/share/dump1090" ]
then
DUMPDIR="/usr/share/dump1090"
echo "We found $DUMPDIR."
read -p "Press ENTER to use this, or type a custom directory name: " a
[ "$a" != "" ] && DUMPDIR="$a"
elif [ -d "/usr/share/dump1090-mutability" ]
then
DUMPDIR="/usr/share/dump1090-mutability"
echo "We found $DUMPDIR."
read -p "Press ENTER to use this, or type a custom directory name: " a
[ "$a" != "" ] && DUMPDIR="$a"
else
echo "We cannot find any dump1090 installation."
echo "Are you sure FlightAware or Dump1090 is correctly installed?"
echo "If you are sure and know the directory name, type it here."
read -p "Otherwise, please press ENTER to exit the installation script: " a
if [ "$a" != "" ]
then
DUMPDIR="$a"
else
echo "To install dump1090-fa, you can find easy to follow instructions at:"
echo "https://github.com/wiedehopf/adsb-scripts/wiki/Automatic-installation-for-dump1090-fa"
exit -1
fi
fi
echo "--------------------------------------------------------------------"
echo "Now, we will install a number of dependencies. Some packages may already be installed"
echo "so you can safely ignore any warning about this."
echo ""
echo "This will take while - initial installation may take 15 - 30 minutes."
echo "Go get some coffee. Or tea. Or beer. Or pizza. Or, if you want to be boring, a drink of water!"
echo ""
read -p "Press enter to start."
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y python-pip python-numpy python-pandas python-dateutil jq bc gnuplot git sox
sudo pip install tzlocal
echo "--------------------------------------------------------------------"
echo "Done installing the dependencies. Let's get PlaneFence!"
# Now we are going to make the GIT directory and clone PlaneFence into it:
[ ! -d "$HOME/git" ] && mkdir $HOME/git
cd $HOME/git
if [ ! -d "planefence" ]
then
git clone https://github.com/kx1t/planefence.git
cd planefence
else
cd planefence
git pull
fi
echo ""
echo "--------------------------------------------------------------------"
echo ""
echo "Now installing PlaneFence..."
# Now make some directories and ensure that the right owners and modes are set
[ ! -d "/usr/share/planefence" ] && sudo mkdir /usr/share/planefence
[ ! -d "/usr/share/dump1090-fa/html/planefence" ] && sudo mkdir /usr/share/dump1090-fa/html/planefence
sudo chown pi:pi /usr/share/planefence "$DUMPDIR"/html/planefence
chmod u+rwx,go+rx-w /usr/share/planefence "$DUMPDIR"/html/planefence
# Copy the scipts and other files into their location
cp scripts/* /usr/share/planefence
cp jscript/* "$DUMPDIR"/html/planefence
cp systemd/start_* /usr/share/planefence
sudo cp systemd/*.service /lib/systemd/system
chmod a+x /usr/share/planefence/*.sh
chmod a+x /usr/share/planefence/*.py
chmod a+x /usr/share/planefence/*.pl
chmod a+x /usr/share/planefence/start_*
echo ""
echo "--------------------------------------------------------------------"
echo "The installation is now complete. Let's configure PlaneFence so you are ready to go!"
echo ""
a=""
while [ "$a" != "y" ]
do
# get lat/lon from dump1090 config and strip it from any extraneous characters
b="$(cat /etc/default/dump1090* | grep -oP '(?<=lat )[^ ]*')"
LATITUDE="$(grep -m1 -Eo '[+-]?[0-9]+([.][0-9]+)?' <<< $b | head -1)"
b="$(cat /etc/default/dump1090* | grep -oP '(?<=lon )[^ ]*')"
LONGITUDE="$(grep -m1 -Eo '[+-]?[0-9]+([.][0-9]+)?' <<< $b | head -1)"
[ "$LATITUDE$LONGITUDE" != "" ] && echo "We found your Lat/Lon in your dump1090 setup as $LATITUDE N/$LONGITUDE E".
echo -n "Enter your latitude in decimal degrees N, "
[ "$LATITUDE" != "" ] && read -p "or press enter to keep $LATITUDE: " b || read -p "for example 42.39663: " b
[ "$b" != "" ] && LATITUDE="$(grep -m1 -Eo '[+-]?[0-9]+([.][0-9]+)?' <<< $b | head -1)"
if [ "$LATITUDE" == "" ]
then
echo "You must enter a Latitude to continue. Try again!"
continue;
fi
echo "Your station latitute is $LATITUDE"
echo ""
echo -n "Enter your longitude in decimal degrees E, "
[ "$LONGITUDE" != "" ] && read -p "or press enter to keep $LONGITUDE: " b || read -p "for example -71.1772: " b
[ "$b" != "" ] && LONGITUDE="$(grep -m1 -Eo '[+-]?[0-9]+([.][0-9]+)?' <<< $b | head -1)"
if [ "$LONGITUDE" == "" ]
then
echo "You must enter a Longitude to continue. Try again!"
continue;
fi
echo "Your station longitude is $LONGITUDE"
echo ""
echo "Let's establish some range parameters."
echo "Please note that the default units are those that you set in socket30003."
echo "If you like to keep the default values, simply press ENTER for each question."
MAXALT=5000
echo ""
read -p "Maximum in-range altitude ["$MAXALT"]: " b
[ "$b" != "" ] && MAXALT="$b"
DIST=1.73795
echo ""
read -p "Maximum radius around your Long/Lat ["$DIST"]: " b
[ "$b" != "" ] && DIST="$b"
MY="my"
echo ""
read -p "What is the name you want to put in the webpage title? ["$MY"]: " b
[ "$b" != "" ] && MY="$b"
echo ""
echo Check if your answers are correct. Do you want to continue?""
read -p "(Answering \"N\" will allow you to re-enter your data.) (y/N) " a
done
echo ""
echo "--------------------------------------------------------------------"
echo ""
echo "NEXT - SOCKET30003 INSTALLATION"
if [ "$(crontab -l |grep socket30003 | wc -l)" -gt "0" ]
then
echo "We think that Socket30003 has already been installed here:"
read -raa <<< $(crontab -l |grep socket30003)
SOCKDIR=$(dirname ${a[6]})
echo $SOCKDIR
unset a
read -p "Press ENTER to use this, or type a custom directory name: " a
[ "$a" != "" ] && SOCKDIR="$a"
else
echo "We cannot find any socket30003 installation."
echo "Are you sure Socket30003 is correctly installed?"
echo "If you are sure and know the directory name, type it here."
read -p "Otherwise, please press ENTER to INSTALL Socket30003: " a
[ "$a" != "" ] && SOCKDIR="$a" || bash -c "$(wget -q -O - https://raw.githubusercontent.com/kx1t/planefence/master/install_socket30003.sh)" install_socket30003.sh $LATITUDE $LONGITUDE
if [ "$SOCKDIR" == "" ]
then
clear
echo "--------------------------------------------------------------------"
echo "Welcome back to PlaneFence Installation and Configuration."
echo "Socket30003 was successfully installed and configured. Let's go on to the next thing!"
echo ""
read -raa <<< $(crontab -l |grep socket30003)
SOCKDIR=$(dirname ${a[6]})
fi
fi
echo ""
echo "--------------------------------------------------------------------"
echo ""
echo "Configuration summary:"
echo "Latitude (N): "$LATITUDE""
echo "Longitude (E): "$LONGITUDE""
echo "Maximum in-range altitude: "$MAXALT""
echo "Maximum in-range distance from $LATITUDE N / $LONGITUDE E: "$DIST""
echo "Socket30003 directory: "$SOCKDIR""
echo "Dump1090 directory: "$DUMPDIR""
read -p "Press ENTER to continue or CTRL-C to abort..."
echo ""
echo "--------------------------------------------------------------------"
echo ""
echo "Writing configuration values..."
# First escape all forward slashes in DUMPDIR and SOCKDIR:
DUMPDIR=$(echo $DUMPDIR|sed 's;/;\\/;g')
SOCKDIR=$(echo $SOCKDIR|sed 's;/;\\/;g')
sed -i 's/\(^\s*LAT=\).*/\1'"$LATITUDE"'/' /usr/share/planefence/planefence.conf
sed -i 's/\(^\s*LON=\).*/\1'"$LONGITUDE"'/' /usr/share/planefence/planefence.conf
sed -i 's/\(^\s*MAXALT=\).*/\1'"$MAXALT"'/' /usr/share/planefence/planefence.conf
sed -i 's/\(^\s*DIST=\).*/\1'"$DIST"'/' /usr/share/planefence/planefence.conf
sed -i 's/\(^\s*SOCKETCONFIG=\).*/\1'"$SOCKDIR"'/' /usr/share/planefence/planefence.conf
sed -i 's/\(^\s*MY=\).*/\1'"$MY"'/' /usr/share/planefence/planefence.conf
sed -i 's/\(^\s*OUTFILEDIR=\).*/\1'"$DUMPDIR\/html\/planefence"'/' /usr/share/planefence/planefence.conf
sed -i 's/\(^\s*LAT=\).*/\1'"$LATITUDE"'/' /usr/share/planefence/planeheat.sh
sed -i 's/\(^\s*LON=\).*/\1'"$LONGITUDE"'/' /usr/share/planefence/planeheat.sh
sed -i 's/\(^\s*MAXALT=\).*/\1'"$MAXALT"'/' /usr/share/planefence/planeheat.sh
sed -i 's/\(^\s*DIST=\).*/\1'"$DIST"'/' /usr/share/planefence/planeheat.sh
echo ""
echo "--------------------------------------------------------------------"
echo ""
echo "OPTIONAL ADD-ONS"
echo ""
echo "NoiseCapt add-on"
echo "If you have a soundcard / microphone that you can dedicate to \"listen\""
echo "continuously for sound levels closeby your ADS-B station, you can enable"
echo "NoiseCapt to capture the sound levels and graph them for each plane that"
echo "is in range for PlaneFence."
echo "A quick-n-dirty way of implementing this is to connect an old webcam with microphone"
echo "to your Raspberry Pi. Only the microphone will be used. The camera won't be used."
echo ""
echo "If you have such a device, please connect it to your Raspberry Pi before going any further."
read "Press ENTER to continue, and we will try to detect it."
CARD=$(arecord -l |grep -oP "card\s+\K\w+")
DEVICE=$(arecord -l |grep -oP "device\s+\K\w+")
if [ "$CARD$DEVICE" == "" ]
then
echo "I cannot find any sound recording devices. If you think that this is a mistake, please"
echo "following the instructions in /usr/share/planefence/noisecapt.sh on how to manually configure it."
else
echo "I found an audio device on Card $CARD / Device $DEVICE."
read -p "Do you want to use this device? If you are not sure, you can always manually configure it afterwards. (Y/n)" a
if [ ${a:0:1} != "n" ]
then
echo "Enabling NoiseCapt..."
sudo cp ~/git/noisecapt/service/noisecapt.service /lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable noisecapt
sudo systemctl start noisecapt
echo "NoiseCapt enabled!"
echo "Note - you can always temporary stop NoiseCapt by issuing the following command:"
echo "sudo systemctl stop noisecapt # stop noisecapt until the next reboot"
echo "sudo systemctl disable noisecapt # do not restart noisecapt after the next reboot"
else
echo "NoiseCapt won't be enabled."
echo "If you wish to enable it in the future, please follow the instructions at /usr/share/planefence/noisecapt.sh"
fi
fi
echo "--------------------------------------------------------------------"
echo ""
echo "OPTIONAL ADD-ONS"
echo ""
echo "PlaneTweet add-on"
echo ""
echo "PlaneTweet enables sending out a Tweet every time a plane goes through the PlaneFence coverage area."
echo "In order to use PlaneTweet, you will need to sign up for a Twitter Developer account."
echo "Unfortunately, this isn't easily automated. As such, it made little sense to include PlaneTweet configuration in this script."
echo ""
echo "You can find and follow instructions to install and configure PlaneTweet here:"
echo "https://github.com/kx1t/planefence/blob/master/README-planetweet.md"
echo ""
read -p "Press ENTER to continue..."
echo ""
echo "--------------------------------------------------------------------"
echo ""
echo "Almost done. PlaneFence is fully installed and configured, all we need to do is start it:"
echo "Starting PlaneFence service..."
sudo systemctl daemon-reload
sudo systemctl enable planefence
sudo systemctl start planefence
echo ""
echo "--------------------------------------------------------------------"
echo ""
echo "Done!"
echo "You can find more settings in /usr/share/planefence/planefence.conf"
echo "Feel free to look at those and change them to your liking."
echo ""
echo "Sayonara! Best regards"