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
/
Copy pathinstall_socket30003.sh
245 lines (220 loc) · 7.97 KB
/
install_socket30003.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
#!/bin/bash
# INSTALL_SOCKET30003 - a Bash shell script to install Ted Sluis's socket30003
# based on socket30003
#
# Usage: ./install_socket30003.sh [lat lon]
# Or from your BASH command line on your Raspberry Pi:
# bash -c "$(wget -q -O - https://raw.githubusercontent.com/kx1t/planefence/master/install_socket30003.sh)"
#
# Developed/tested and Copyright 2020 Ramon F. Kolb, with contributions and collaboration 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/.
clear
echo "Welcome to Socket30003 Setup - version 200617-1600"
echo "https://github.com/kx1t/planefence"
echo "Copyright 2020 by Ramón F. Kolb"
echo ""
echo "This script will attempt to install and configure socket30003."
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
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 ""
read -p "Press enter to start."
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y git perl
echo "--------------------------------------------------------------------"
echo "Done installing the dependencies. Let's get Socket30003!"
# 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 "dump1090.socket30003" ]
then
git clone https://github.com/tedsluis/dump1090.socket30003.git
cd dump1090.socket30003
else
cd dump1090.socket30003
git pull
fi
echo ""
echo "--------------------------------------------------------------------"
echo ""
echo "Now installing configuring Socket30003..."
[ ! -z "$1" ] && LATITUDE="$1"
[ ! -z "$2" ] && LONGITUDE="$2"
a=""
while [ "$a" != "y" ]
do
if [ ! -z "$LATITUDE" ]
then
echo "You indicated that your station latitude is $LATITUDE."
else
read -p "Enter your latitude in decimal degrees N, for example 42.39663: " LATITUDE
fi
echo "Your station latitute is $LATITUDE"
echo ""
if [ ! -z "$LONGITUDE" ]
then
echo "You indicated that your station latitude is $LONGITUDE."
else
read -p "Enter your longitude in decimal degrees E, for example -71.17726: " LONGITUDE
fi
echo "Your station longitude is $LONGITUDE"
echo ""
read "Please confirm that these coordinates are correct? (Y/n): " a
[ "$a" == "n" ] && continue
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."
DISTUNIT="kilometer"
ALTUNIT="meter"
SPEEDUNIT="kilometerph"
INSTALLDIRECTORY="/usr/share/socket30003"
echo ""
echo "DISTANCE"
echo "Default: $DISTUNIT - press enter to keep this value"
echo "1) kilometer"
echo "2) nauticalmile"
echo "3) mile"
echo "4) meter"
read -p "Enter 1-4: " b
case "$b" in
1)
DISTUNIT="kilometer"
;;
2)
DISTUNIT="nauticalmile"
;;
3)
DISTUNIT="mile"
;;
4)
DISTUNIT="meter"
esac
echo ""
echo "ALTITUDE"
echo "Default: $ALTUNIT - press enter to keep this value"
echo "1) meter"
echo "2) feet"
read -p "Enter 1-2: " b
case "$b" in
1)
ALTUNIT="meter"
;;
2)
ALTUNIT="feet"
esac
echo ""
echo "SPEED"
echo "Default: $SPEEDUNIT - press enter to keep this value"
echo "1) kilometer per hour"
echo "2) knot per hour"
echo "3) mile per hour"
read -p "Enter 1-3: " b
case "$b" in
1)
SPEEDUNIT="kilometerph"
;;
2)
SPEEDUNIT="knotph"
;;
3)
SPEEDUNIT="mileph"
esac
echo ""
echo "INSTALL DIRECTORY"
echo "Default: $INSTALLDIRECTORY"
read -p "Press Enter to keep this, or type an installation directory below: " b
[ ! -z "$b" ] && INSTALLDIRECTORY="$b"
echo ""
echo "--------------------------------------------------------------------"
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 "Writing these values to the config file..."
INSTALLDIRX=$(echo $INSTALLDIRECTORY|sed 's;/;\\/;g')
cp socket30003.cfg socket30003.cfg.org
sed -i 's/\(^\s*latitude=\).*/\1'"$LATITUDE"'/' socket30003.cfg
sed -i 's/\(^\s*longitude=\).*/\1'"$LONGITUDE"'/' socket30003.cfg
sed -i 's/\(^\s*distanceunit=\).*/\1'"$DISTUNIT"'/' socket30003.cfg
sed -i 's/\(^\s*altitudeunit=\).*/\1'"$ALTUNIT"'/' socket30003.cfg
sed -i 's/\(^\s*speedunit=\).*/\1'"$SPEEDUNIT"'/' socket30003.cfg
sed -i 's/\(^\s*installdirectory=\).*/\1'"$INSTALLDIRX"'/' socket30003.cfg
echo "done!"
echo ""
echo "--------------------------------------------------------------------"
echo ""
echo "Invoking socket30003.pl installation script..."
# First create the install directory. This is needed because the install script attempts to do this as user=PI
# When using the default /usr/share/socket30003 target, this will fail because of permissions.
# So we need to pre-empt this:
[ ! -d "$INSTALLDIRECTORY" ] && sudo mkdir "$INSTALLDIRECTORY"
sudo chown pi:pi "$INSTALLDIRECTORY"
chmod u+rwx,go+rx-w "$INSTALLDIRECTORY"
./install.pl -install "$INSTALLDIRECTORY"
chmod a+x "$INSTALLDIRECTORY"/*.pl
echo ""
echo "--------------------------------------------------------------------"
echo ""
echo "Writing crontab..."
#write out current crontab
crontab -l > /tmp/mycron 2>/dev/null
#echo new cron into cron file
echo "*/5 * * * * sudo $INSTALLDIRECTORY/socket30003.pl" >> /tmp/mycron
#install new cron file
crontab /tmp/mycron
rm /tmp/mycron
echo "Done installing socket30003, goodbye!"
echo ""
echo "--------------------------------------------------------------------"
echo ""