Skip to content

Commit 87af8e9

Browse files
committedAug 29, 2016
Finished new mlat-client setup.
1 parent 3f44785 commit 87af8e9

File tree

4 files changed

+115
-177
lines changed

4 files changed

+115
-177
lines changed
 

‎LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Joe Prochazka
3+
Copyright (c) 2015-2016 Joe Prochazka
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎README.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ Running the following commands will download the contents of this repository and
1414

1515
**After completing the setup do not delete this repository.**
1616

17-
The script(s) create two files, one named adsbexchange-mlat_maint.sh and another named adsbexchange-netcat_maint.sh which will reside in this folder containing a clone of this repository. The path to execute these scripts after each reboot has been set to this location. Deleting this folder will result in both the adsbexchange-mlat_maint.sh and adsbexchange-netcat_maint.sh scripts to not be executed thus not enabling your receiver to feed ADS-B Exchange after your device has been rebooted.
18-
19-
**no_dialogs.sh**
20-
21-
The file "no_dialogs.sh" can used in place of "setup.sh" to set up your receiver.
22-
The only difference between the two files is "no_dialogs.sh" does not use Whiptail dialogs.
17+
The script creates two files, one named adsbexchange-mlat_maint.sh and another named adsbexchange-netcat_maint.sh which will reside in this folder containing a clone of this repository. The path to execute these scripts after each reboot has been set to this location. Deleting this folder will result in both the adsbexchange-mlat_maint.sh and adsbexchange-netcat_maint.sh scripts to not be executed thus not enabling your receiver to feed ADS-B Exchange after your device has been rebooted.
2318

2419
### Reporting Issues
2520

‎no_dialogs.sh

-124
This file was deleted.

‎setup.sh

+113-46
Original file line numberDiff line numberDiff line change
@@ -30,116 +30,170 @@
3030

3131
## CHECK IF SCRIPT WAS RAN USING SUDO
3232

33-
3433
if [ "$(id -u)" != "0" ]; then
34+
echo -e "\033[33m"
3535
echo "This script must be ran using sudo or as root."
36+
echo -e "\033[37m"
3637
exit 1
3738
fi
3839

39-
4040
## ASSIGN VARIABLES
4141

42-
42+
LOGDIRECTORY="$PWD/logs"
4343
MLATCLIENTVERSION="0.2.6"
4444
MLATCLIENTTAG="v0.2.6"
4545

46-
4746
## WHIPTAIL DIALOGS
4847

49-
5048
BACKTITLETEXT="ADS-B Exchange Setup Script"
5149

52-
whiptail --backtitle "$BACKTITLETEXT" --title "" --yesno "Thanks for choosing to share your data with ADS-B Exchange!\n\nADSBexchange.com is a co-op of ADS-B/Mode S/MLAT feeders from around the world. This script will configure your current your ADS-B receiver to share your feeders data with ADS-B Exchange.\n\nWould you like to continue setup?" 8 78
50+
whiptail --backtitle "$BACKTITLETEXT" --title "$BACKTITLETEXT" --yesno "Thanks for choosing to share your data with ADS-B Exchange!\n\nADSBexchange.com is a co-op of ADS-B/Mode S/MLAT feeders from around the world. This script will configure your current your ADS-B receiver to share your feeders data with ADS-B Exchange.\n\nWould you like to continue setup?" 13 78
5351
CONTINUESETUP=$?
5452
if [ $CONTINUESETUP = 1 ]; then
5553
exit 0
5654
fi
5755

5856
ADSBEXCHANGEUSERNAME=$(whiptail --backtitle "$BACKTITLETEXT" --title "ADS-B Exchange User Name" --inputbox "Please enter your ADS-B Exchange user name." 8 78 3>&1 1>&2 2>&3)
59-
60-
RECEIVERLONGITUDE=$(whiptail --backtitle "$BACKTITLETEXT" --title "Receiver Latitude" --inputbox "Enter your recivers latitude.." 8 78 3>&1 1>&2 2>&3)
61-
62-
RECEIVERLATITUDE=$(whiptail --backtitle "$BACKTITLETEXT" --title "Receiver Longitude" --inputbox "Enter your receivers longitude." 8 78 3>&1 1>&2 2>&3)
63-
57+
RECEIVERLATITUDE=$(whiptail --backtitle "$BACKTITLETEXT" --title "Receiver Latitude" --inputbox "Enter your receivers latitude." 8 78 3>&1 1>&2 2>&3)
58+
RECEIVERLONGITUDE=$(whiptail --backtitle "$BACKTITLETEXT" --title "Receiver Longitude" --inputbox "Enter your recivers longitude." 8 78 3>&1 1>&2 2>&3)
59+
RECEIVERALTITUDE=$(whiptail --backtitle "$BACKTITLETEXT" --title "Receiver Longitude" --inputbox "Enter your recivers atitude." 8 78 "`curl -s https://maps.googleapis.com/maps/api/elevation/json?locations=$RECEIVERLATITUDE,$RECEIVERLONGITUDE | python -c "import json,sys;obj=json.load(sys.stdin);print obj['results'][0]['elevation'];"`" 3>&1 1>&2 2>&3)
6460

6561
## BEGIN SETUP
6662

67-
6863
{
6964

65+
# Make a log directory if it does not already exist.
66+
if [ ! -d "$LOGDIRECTORY" ]; then
67+
mkdir $LOGDIRECTORY
68+
fi
69+
LOGFILE="$LOGDIRECTORY/image_setup-$(date +%F_%R)"
70+
touch $LOGFILE
71+
72+
echo 4
73+
sleep 0.25
74+
7075
# BUILD AND CONFIGURE THE MLAT-CLIENT PACKAGE
7176

77+
echo "INSTALLING PREREQUISITE PACKAGES" >> $LOGFILE
78+
echo "--------------------------------------" >> $LOGFILE
79+
echo "" >> $LOGFILE
80+
7281
# Check that the prerequisite packages needed to build and install mlat-client are installed.
7382
if [ $(dpkg-query -W -f='$STATUS' build-essential 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
74-
sudo apt-get install -y build-essential
83+
sudo apt-get install -y build-essential >> $LOGFILE
7584
fi
7685

86+
echo 10
87+
sleep 0.25
88+
7789
if [ $(dpkg-query -W -f='$STATUS' debhelper 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
78-
sudo apt-get install -y debhelper
90+
sudo apt-get install -y debhelper >> $LOGFILE
7991
fi
8092

93+
echo 16
94+
sleep 0.25
95+
8196
if [ $(dpkg-query -W -f='$STATUS' python3-dev 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
82-
sudo apt-get install -y python3-dev
97+
sudo apt-get install -y python3-dev >> $LOGFILE
98+
fi
99+
100+
echo 22
101+
sleep 0.25
102+
103+
if [ $(dpkg-query -W -f='${STATUS}' netcat 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
104+
sudo apt-get install -y netcat >> $LOGFILE
83105
fi
84106

107+
echo 28
108+
sleep 0.25
109+
110+
echo "" >> $LOGFILE
111+
echo " BUILD AND INSTALL MLAT-CLIENT" >> $LOGFILE
112+
echo "-----------------------------------" >> $LOGFILE
113+
echo "" >> $LOGFILE
114+
85115
# Check if the mlat-client git repository already exists.
86116
if [ -d mlat-client ] && [ -d mlat-client/.git ]; then
87117
# If the mlat-client repository exists update the source code contained within it.
88-
cd mlat-client
89-
git pull
90-
git checkout tags/$MLATCLIENTTAG
118+
cd mlat-client >> $LOGFILE
119+
git pull >> $LOGFILE 2>&1
120+
git checkout tags/$MLATCLIENTTAG >> $LOGFILE 2>&1
91121
else
92122
# Download a copy of the mlat-client repository since the repository does not exist locally.
93-
git clone https://github.com/mutability/mlat-client.git
94-
cd mlat-client
95-
git checkout tags/$MLATCLIENTTAG
123+
git clone https://github.com/mutability/mlat-client.git >> $LOGFILE 2>&1
124+
cd mlat-client >> $LOGFILE 2>&1
125+
git checkout tags/$MLATCLIENTTAG >> $LOGFILE 2>&1
96126
fi
97127

128+
echo 34
129+
sleep 0.25
130+
98131
# Build and install the mlat-client package.
99-
dpkg-buildpackage -b -uc
100-
cd ..
101-
sudo dpkg -i mlat-client_${MLATCLIENTVERSION}*.deb
132+
dpkg-buildpackage -b -uc >> $LOGFILE 2>&1
133+
cd .. >> $LOGFILE
134+
sudo dpkg -i mlat-client_${MLATCLIENTVERSION}*.deb >> $LOGFILE
135+
136+
echo 40
137+
sleep 0.25
138+
139+
echo "" >> $LOGFILE
140+
echo " CREATE AND CONFIGURE MLAT-CLIENT STARTUP SCRIPTS" >> $LOGFILE
141+
echo "------------------------------------------------------" >> $LOGFILE
142+
echo "" >> $LOGFILE
102143

103144
# Create the mlat-client maintenance script.
104-
tee -a adsbexchange-mlat_maint.sh > /dev/null <<EOF
145+
tee adsbexchange-mlat_maint.sh > /dev/null <<EOF
105146
#!/bin/sh
106147
while true
107148
do
108149
sleep 30
109-
/usr/bin/mlat-client --input-type dump1090 --input-connect localhost:30005 --lat $RECEIVERLATITUDE --lon $RECEIVERLONGITUDE --alt $RECEIVERLATITUDE --user $ADSBEXCHANGEUSERNAME --server feed.adsbexchange.com:31090 --no-udp --results beast,connect,localhost:30104
150+
/usr/bin/mlat-client --input-type dump1090 --input-connect localhost:30005 --lat $RECEIVERLATITUDE --lon $RECEIVERLONGITUDE --alt $RECEIVERALTITUDE --user $ADSBEXCHANGEUSERNAME --server feed.adsbexchange.com:31090 --no-udp --results beast,connect,localhost:30104
110151
done
111152
EOF
112153

154+
echo 46
155+
sleep 0.25
156+
113157
# Set execute permissions on the mlat-client maintenance script.
114-
chmod +x adsbexchange-mlat_maint.sh
158+
chmod +x adsbexchange-mlat_maint.sh >> $LOGFILE
159+
160+
echo 52
161+
sleep 0.25
115162

116163
# Add a line to execute the mlat-client maintenance script to /etc/rc.local so it is started after each reboot if one does not already exist.
117164
if ! grep -Fxq "$PWD/adsbexchange-mlat_maint.sh &" /etc/rc.local; then
118165
LINENUMBER=($(sed -n '/exit 0/=' /etc/rc.local))
119-
((LINENUMBER>0)) && sudo sed -i "${LINENUMBER[$((${#LINENUMBER[@]}-1))]}i $PWD/adsbexchange-mlat_maint.sh &\n" /etc/rc.local
166+
((LINENUMBER>0)) && sudo sed -i "${LINENUMBER[$((${#LINENUMBER[@]}-1))]}i $PWD/adsbexchange-mlat_maint.sh &\n" /etc/rc.local >> $LOGFILE
120167
fi
121168

169+
echo 58
170+
sleep 0.25
171+
172+
echo "" >> $LOGFILE
173+
echo " CREATE AND CONFIGURE NETCAT STARTUP SCRIPTS" >> $LOGFILE
174+
echo "-------------------------------------------------" >> $LOGFILE
175+
echo "" >> $LOGFILE
176+
122177
# Kill any currently running instances of the adsbexchange-mlat_maint.sh script.
123178
PIDS=`ps -efww | grep -w "adsbexchange-mlat_maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'`
124179
if [ ! -z "$PIDS" ]; then
125-
sudo kill $PIDS
126-
sudo kill -9 $PIDS
180+
sudo kill $PIDS >> $LOGFILE
181+
sudo kill -9 $PIDS >> $LOGFILE
127182
fi
128183

184+
echo 64
185+
sleep 0.25
186+
129187
# Execute the mlat-client maintenance script.
130-
sudo $PWD/adsbexchange-mlat_maint.sh > /dev/null &
188+
sudo $PWD/adsbexchange-mlat_maint.sh > /dev/null & >> $LOGFILE
131189

190+
echo 70
191+
sleep 0.25
132192

133193
# SETUP NETCAT TO SEND DUMP1090 DATA TO ADS-B EXCHANGE
134194

135-
136-
# Check if netcat is installed and if not install it.
137-
if [ $(dpkg-query -W -f='${STATUS}' netcat 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
138-
sudo apt-get install -y netcat
139-
fi
140-
141195
# Create the netcat maintenance script.
142-
tee -a adsbexchange-netcat_maint.sh > /dev/null <<EOF
196+
tee adsbexchange-netcat_maint.sh > /dev/null <<EOF
143197
#!/bin/sh
144198
while true
145199
do
@@ -148,31 +202,44 @@ while true
148202
done
149203
EOF
150204

151-
# Set permissions on the file adsbexchange-maint.sh.
152-
chmod +x adsbexchange-maint.sh
205+
echo 76
206+
sleep 0.25
207+
208+
# Set permissions on the file adsbexchange-netcat_maint.sh.
209+
chmod +x adsbexchange-netcat_maint.sh >> $LOGFILE
210+
211+
echo 82
212+
sleep 0.25
153213

154214
# Add a line to execute the netcat maintenance script to /etc/rc.local so it is started after each reboot if one does not already exist.
155-
if ! grep -Fxq "${SCRIPTPATH}/adsbexchange-netcat_maint.sh &" /etc/rc.local; then
215+
if ! grep -Fxq "$PWD/adsbexchange-netcat_maint.sh &" /etc/rc.local; then
156216
lnum=($(sed -n '/exit 0/=' /etc/rc.local))
157-
((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i ${SCRIPTPATH}/adsbexchange-maint.sh &\n" /etc/rc.local
217+
((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i $PWD/adsbexchange-netcat_maint.sh &\n" /etc/rc.local >> $LOGFILE
158218
fi
159219

220+
echo 88
221+
sleep 0.25
222+
160223
# Kill any currently running instances of the adsbexchange-netcat_maint.sh script.
161224
PIDS=`ps -efww | grep -w "adsbexchange-netcat_maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'`
162225
if [ ! -z "$PIDS" ]; then
163-
sudo kill $PIDS
164-
sudo kill -9 $PIDS
226+
sudo kill $PIDS >> $LOGFILE
227+
sudo kill -9 $PIDS >> $LOGFILE
165228
fi
166229

230+
echo 94
231+
sleep 0.25
232+
167233
# Execute the netcat maintenance script.
168234
sudo $PWD/adsbexchange-netcat_maint.sh > /dev/null &
169235

170-
} | whiptail --backtitle "$BACKTITLETEXT" --title "Setting up ADS-B Exchange Feed" --gauge "Setting up your receiver to feed ADS-B Exchange..." 6 50 0
236+
echo 100
237+
sleep 0.25
171238

239+
} | whiptail --backtitle "$BACKTITLETEXT" --title "Setting Up ADS-B Exchange Feed" --gauge "Setting up your receiver to feed ADS-B Exchange..." 6 50 0
172240

173241
## SETUP COMPLETE
174242

175-
176243
# Display the thank you message box.
177244
whiptail --title "ADS-B Exchange Setup Script" --msgbox "Setup is now complete.\n\nYour feeder should now be feeding data to ADS-B Exchange.\nThanks again for choosing to share your data with ADS-B Exchange!\n\nIf you have questions or encountered any issues while using this script feel free to post them to one of the following places.\n\nhttps://github.com/jprochazka/adsb-exchange\nhttp://www.adsbexchange.com/forums/topic/ads-b-exchange-setup-script/" 16 73
178245

0 commit comments

Comments
 (0)
Please sign in to comment.