Finished new mlat-client setup.

This commit is contained in:
Joe Prochazka 2016-08-29 12:25:12 -04:00
commit 87af8e9d45
4 changed files with 115 additions and 177 deletions

View file

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2015 Joe Prochazka
Copyright (c) 2015-2016 Joe Prochazka
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -14,12 +14,7 @@ Running the following commands will download the contents of this repository and
**After completing the setup do not delete this repository.**
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.
**no_dialogs.sh**
The file "no_dialogs.sh" can used in place of "setup.sh" to set up your receiver.
The only difference between the two files is "no_dialogs.sh" does not use Whiptail dialogs.
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.
### Reporting Issues

View file

@ -1,124 +0,0 @@
#!/bin/bash
# Check if user is using sudo or is logged in a root.
if [ "$(id -u)" != "0" ]; then
echo "This script must be ran using sudo or as root."
exit 1
fi
clear
# Set a variable containing the path to this script.
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
##############
## FUNCTIONS
# Configure FlightAware's PiAware software.
function ConfigurePiAware() {
# Retreive and clean the current PiAware mlatResultFormat setting.
echo -e "\033[33m"
echo "Adding the ADS-B Exchange feed to PiAware's configuration..."
ORIGINALFORMAT="`sudo piaware-config -show mlat-results-format`"
CLEANFORMAT=`sed 's/ beast,connect,feed.adsbexchange.com:30005//g' <<< $ORIGINALFORMAT`
FINALFORMAT="${CLEANFORMAT} beast,connect,feed.adsbexchange.com:30005"
# Set the new PiAware mlatResultFormat setting.
sudo piaware-config mlat-results-format "${FINALFORMAT}"
# Restart PiAware.
echo ""
echo "Restarting PiAware so new configuration takes effect..."
echo -e "\033[37m"
sudo piaware-config -restart
}
# Setup the Netcat script and execute it.
function SetupNetcat() {
# Check if netcat is installed and if not install it.
printf "\033[33mChecking if the package $1 is installed..."
if [ $(dpkg-query -W -f='${STATUS}' netcat 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
echo -e "\033[33m"
echo "Installing the Netcat package..."
echo -e "\033[37m"
sudo apt-get install -y netcat
fi
# Set permissions on the file adsbexchange-maint.sh.
chmod 755 $SCRIPTPATH/adsbexchange-maint.sh
# Add the ADS-B maintainance script to the file /etc/rc.local.
if ! grep -Fxq "${SCRIPTPATH}/adsbexchange-maint.sh &" /etc/rc.local; then
echo -e "\033[33m"
echo "Adding ADS-B Exchange maintainance script startup command to rc.local..."
echo -e "\033[37m"
lnum=($(sed -n '/exit 0/=' /etc/rc.local))
((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i ${SCRIPTPATH}/adsbexchange-maint.sh &\n" /etc/rc.local
fi
# Kill any currently running instances of the adsbexchange-maint.sh script.
echo -e "\033[33m"
echo "Killing any adsbexchange-maint.sh processes currently running..."
echo -e "\033[37m"
PIDS=`ps -efww | grep -w "adsbexchange-maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'`
if [ ! -z "$PIDS" ]; then
sudo kill $PIDS
sleep 5
sudo kill -9 $PIDS
fi
# Execute the ADS-B maintainance script.
echo -e "\033[33mRunning ADS-B Exchange maintainance script..."
sudo $SCRIPTPATH/adsbexchange-maint.sh &
}
################
## NO WHIPTAIL
# Welcome message.
echo -e "\033[31m"
echo "-----------------------------------------------------------------"
echo " ADS-B Exchange Setup Script"
echo "-----------------------------------------------------------------"
echo -e "\033[33m"
echo "Thanks for choosing to share your data with ADS-B Exchange!"
echo ""
echo "ADSBexchange.com is a co-op of ADS-B/Mode S/MLAT feeders"
echo "from around the world. This script will configure your"
echo "current PiAware and/or Dump1090 installation to share"
echo "your feeders data with ADS-B Exchange. It is recommeded"
echo "that FlightAware's PiAware software be installed in order"
echo "to feed accurate \"MLAT\" data but is not required."
echo -e "\033[37m"
read -p "Continue setup? [Y/n] " CONTINUE
if [[ $CONTINUE == "" ]]; then CONTINUE="Y"; fi
if [[ ! $CONTINUE =~ ^[Yy]$ ]]; then
echo ""
exit 1
fi
# Check if the PiAware package is installed.
if [ $(dpkg-query -W -f='${STATUS}' $1 2>/dev/null | grep -c "ok installed") -eq 1 ]; then
# PiAware appear to be installed.
ConfigurePiAware
fi
# Setup the Netcat script.
SetupNetcat
# Thank you message.
echo -e "\033[33m"
echo "Setup is now complete."
echo ""
echo "Your feeder should now be feeding data to ADS-B Exchange."
echo "Thanks again for choosing to share your data with ADS-B Exchange!"
echo ""
echo "If you have questions or encountered any issues while using this"
echo "script feel free to post them to one of the following places."
echo ""
echo "https://github.com/jprochazka/adsb-exchange"
echo "http://www.adsbexchange.com/forums/topic/ads-b-exchange-setup-script/"
echo -e "\033[37m"
exit 0

161
setup.sh
View file

@ -30,116 +30,170 @@
## CHECK IF SCRIPT WAS RAN USING SUDO
if [ "$(id -u)" != "0" ]; then
echo -e "\033[33m"
echo "This script must be ran using sudo or as root."
echo -e "\033[37m"
exit 1
fi
## ASSIGN VARIABLES
LOGDIRECTORY="$PWD/logs"
MLATCLIENTVERSION="0.2.6"
MLATCLIENTTAG="v0.2.6"
## WHIPTAIL DIALOGS
BACKTITLETEXT="ADS-B Exchange Setup Script"
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
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
CONTINUESETUP=$?
if [ $CONTINUESETUP = 1 ]; then
exit 0
fi
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)
RECEIVERLONGITUDE=$(whiptail --backtitle "$BACKTITLETEXT" --title "Receiver Latitude" --inputbox "Enter your recivers latitude.." 8 78 3>&1 1>&2 2>&3)
RECEIVERLATITUDE=$(whiptail --backtitle "$BACKTITLETEXT" --title "Receiver Longitude" --inputbox "Enter your receivers longitude." 8 78 3>&1 1>&2 2>&3)
RECEIVERLATITUDE=$(whiptail --backtitle "$BACKTITLETEXT" --title "Receiver Latitude" --inputbox "Enter your receivers latitude." 8 78 3>&1 1>&2 2>&3)
RECEIVERLONGITUDE=$(whiptail --backtitle "$BACKTITLETEXT" --title "Receiver Longitude" --inputbox "Enter your recivers longitude." 8 78 3>&1 1>&2 2>&3)
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)
## BEGIN SETUP
{
# Make a log directory if it does not already exist.
if [ ! -d "$LOGDIRECTORY" ]; then
mkdir $LOGDIRECTORY
fi
LOGFILE="$LOGDIRECTORY/image_setup-$(date +%F_%R)"
touch $LOGFILE
echo 4
sleep 0.25
# BUILD AND CONFIGURE THE MLAT-CLIENT PACKAGE
echo "INSTALLING PREREQUISITE PACKAGES" >> $LOGFILE
echo "--------------------------------------" >> $LOGFILE
echo "" >> $LOGFILE
# Check that the prerequisite packages needed to build and install mlat-client are installed.
if [ $(dpkg-query -W -f='$STATUS' build-essential 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
sudo apt-get install -y build-essential
sudo apt-get install -y build-essential >> $LOGFILE
fi
echo 10
sleep 0.25
if [ $(dpkg-query -W -f='$STATUS' debhelper 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
sudo apt-get install -y debhelper
sudo apt-get install -y debhelper >> $LOGFILE
fi
echo 16
sleep 0.25
if [ $(dpkg-query -W -f='$STATUS' python3-dev 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
sudo apt-get install -y python3-dev
sudo apt-get install -y python3-dev >> $LOGFILE
fi
echo 22
sleep 0.25
if [ $(dpkg-query -W -f='${STATUS}' netcat 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
sudo apt-get install -y netcat >> $LOGFILE
fi
echo 28
sleep 0.25
echo "" >> $LOGFILE
echo " BUILD AND INSTALL MLAT-CLIENT" >> $LOGFILE
echo "-----------------------------------" >> $LOGFILE
echo "" >> $LOGFILE
# Check if the mlat-client git repository already exists.
if [ -d mlat-client ] && [ -d mlat-client/.git ]; then
# If the mlat-client repository exists update the source code contained within it.
cd mlat-client
git pull
git checkout tags/$MLATCLIENTTAG
cd mlat-client >> $LOGFILE
git pull >> $LOGFILE 2>&1
git checkout tags/$MLATCLIENTTAG >> $LOGFILE 2>&1
else
# Download a copy of the mlat-client repository since the repository does not exist locally.
git clone https://github.com/mutability/mlat-client.git
cd mlat-client
git checkout tags/$MLATCLIENTTAG
git clone https://github.com/mutability/mlat-client.git >> $LOGFILE 2>&1
cd mlat-client >> $LOGFILE 2>&1
git checkout tags/$MLATCLIENTTAG >> $LOGFILE 2>&1
fi
echo 34
sleep 0.25
# Build and install the mlat-client package.
dpkg-buildpackage -b -uc
cd ..
sudo dpkg -i mlat-client_${MLATCLIENTVERSION}*.deb
dpkg-buildpackage -b -uc >> $LOGFILE 2>&1
cd .. >> $LOGFILE
sudo dpkg -i mlat-client_${MLATCLIENTVERSION}*.deb >> $LOGFILE
echo 40
sleep 0.25
echo "" >> $LOGFILE
echo " CREATE AND CONFIGURE MLAT-CLIENT STARTUP SCRIPTS" >> $LOGFILE
echo "------------------------------------------------------" >> $LOGFILE
echo "" >> $LOGFILE
# Create the mlat-client maintenance script.
tee -a adsbexchange-mlat_maint.sh > /dev/null <<EOF
tee adsbexchange-mlat_maint.sh > /dev/null <<EOF
#!/bin/sh
while true
do
sleep 30
/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
/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
done
EOF
echo 46
sleep 0.25
# Set execute permissions on the mlat-client maintenance script.
chmod +x adsbexchange-mlat_maint.sh
chmod +x adsbexchange-mlat_maint.sh >> $LOGFILE
echo 52
sleep 0.25
# 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.
if ! grep -Fxq "$PWD/adsbexchange-mlat_maint.sh &" /etc/rc.local; then
LINENUMBER=($(sed -n '/exit 0/=' /etc/rc.local))
((LINENUMBER>0)) && sudo sed -i "${LINENUMBER[$((${#LINENUMBER[@]}-1))]}i $PWD/adsbexchange-mlat_maint.sh &\n" /etc/rc.local
((LINENUMBER>0)) && sudo sed -i "${LINENUMBER[$((${#LINENUMBER[@]}-1))]}i $PWD/adsbexchange-mlat_maint.sh &\n" /etc/rc.local >> $LOGFILE
fi
echo 58
sleep 0.25
echo "" >> $LOGFILE
echo " CREATE AND CONFIGURE NETCAT STARTUP SCRIPTS" >> $LOGFILE
echo "-------------------------------------------------" >> $LOGFILE
echo "" >> $LOGFILE
# Kill any currently running instances of the adsbexchange-mlat_maint.sh script.
PIDS=`ps -efww | grep -w "adsbexchange-mlat_maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'`
if [ ! -z "$PIDS" ]; then
sudo kill $PIDS
sudo kill -9 $PIDS
sudo kill $PIDS >> $LOGFILE
sudo kill -9 $PIDS >> $LOGFILE
fi
# Execute the mlat-client maintenance script.
sudo $PWD/adsbexchange-mlat_maint.sh > /dev/null &
echo 64
sleep 0.25
# Execute the mlat-client maintenance script.
sudo $PWD/adsbexchange-mlat_maint.sh > /dev/null & >> $LOGFILE
echo 70
sleep 0.25
# SETUP NETCAT TO SEND DUMP1090 DATA TO ADS-B EXCHANGE
# Check if netcat is installed and if not install it.
if [ $(dpkg-query -W -f='${STATUS}' netcat 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
sudo apt-get install -y netcat
fi
# Create the netcat maintenance script.
tee -a adsbexchange-netcat_maint.sh > /dev/null <<EOF
tee adsbexchange-netcat_maint.sh > /dev/null <<EOF
#!/bin/sh
while true
do
@ -148,31 +202,44 @@ while true
done
EOF
# Set permissions on the file adsbexchange-maint.sh.
chmod +x adsbexchange-maint.sh
echo 76
sleep 0.25
# Set permissions on the file adsbexchange-netcat_maint.sh.
chmod +x adsbexchange-netcat_maint.sh >> $LOGFILE
echo 82
sleep 0.25
# 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.
if ! grep -Fxq "${SCRIPTPATH}/adsbexchange-netcat_maint.sh &" /etc/rc.local; then
if ! grep -Fxq "$PWD/adsbexchange-netcat_maint.sh &" /etc/rc.local; then
lnum=($(sed -n '/exit 0/=' /etc/rc.local))
((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i ${SCRIPTPATH}/adsbexchange-maint.sh &\n" /etc/rc.local
((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i $PWD/adsbexchange-netcat_maint.sh &\n" /etc/rc.local >> $LOGFILE
fi
echo 88
sleep 0.25
# Kill any currently running instances of the adsbexchange-netcat_maint.sh script.
PIDS=`ps -efww | grep -w "adsbexchange-netcat_maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'`
if [ ! -z "$PIDS" ]; then
sudo kill $PIDS
sudo kill -9 $PIDS
sudo kill $PIDS >> $LOGFILE
sudo kill -9 $PIDS >> $LOGFILE
fi
echo 94
sleep 0.25
# Execute the netcat maintenance script.
sudo $PWD/adsbexchange-netcat_maint.sh > /dev/null &
} | whiptail --backtitle "$BACKTITLETEXT" --title "Setting up ADS-B Exchange Feed" --gauge "Setting up your receiver to feed ADS-B Exchange..." 6 50 0
echo 100
sleep 0.25
} | whiptail --backtitle "$BACKTITLETEXT" --title "Setting Up ADS-B Exchange Feed" --gauge "Setting up your receiver to feed ADS-B Exchange..." 6 50 0
## SETUP COMPLETE
# Display the thank you message box.
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