diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..9d671a6 --- /dev/null +++ b/setup.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +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. + ORIGINALFORMAT=`sudo piaware-config -show | sed -n 's/.*{\(.*\)}.*/\1/p'` + CLEANFORMAT=`sed 's/ beast,connect,feed.adsbexchange.com:30005//g' <<< $ORIGINALFORMAT` + + # Set the new PiAware mlatResultFormat setting. + sudo piaware-config -mlatResultsFormat "${CLEANFORMAT} beast,connect,feed.adsbexchange.com:30005" + + # Restart PiAware. + sudo piaware-config -restart +} + +# Setup the Netcat script and execute it. +function SetupNetcat() { + # Set permissions on teh 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 + 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. + PIDS=`ps -efww | grep -w "adsbexchange-maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'` + if [ ! -z "$PIDS" ]; then + sudo kill $PIDS + for ((i = i ; i <= 5 ; i+=1)); do + sleep 1 + done + sudo kill -9 $PIDS + fi + + # Execute the ADS-B maintainance script. + sudo $SCRIPTPATH/adsbexchange-maint.sh & +} + +############# +## WHIPTAIL + +# Welcome text. +read -d '' WELCOME <<"EOF" +Thanks for choosing to share your data with ADS-B Exchange! + +ADSBexchange.com is a co-op of ADS-B/Mode S/MLAT feeders +from around the world. This script will configure your +current PiAware and/or Dump1090 installation to share +your feeders data with ADS-B Exchange. It is recommeded +that FlightAware's PiAware software be installed in order +to feed accurate "MLAT" data but is not required. + +Press Enter to continue setup. +EOF + +# Display the welcome message box. +whiptail --title "ADS-B Exchange Setup Script" --msgbox "$WELCOME" 17 65 + +# Check if the PiAware package is installed. +if [ $(dpkg-query -W -f='${STATUS}' $1 2>/dev/null | grep -c "ok installed") -eq 0 ]; then + # PiAware does not appear to be installed. + ConfigurePiAware +fi + +# Setup the Netcat script. + +SetupNetcat + +# Thank you text. +read -d '' THANKS <<"EOF" +Setup is now complete. + +Your feeder should now be feeding data to ADS-B Exchange. + +Press Enter to exit setup. +EOF + +# Display the thank you message box. +whiptail --title "ADS-B Exchange Setup Script" --msgbox "$THANKS" 17 65 + +exit 0