From 0572fc8987ccf9d8538f71fcca995b8bbc5616a0 Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Fri, 2 Sep 2016 15:17:31 -0400 Subject: [PATCH] Cleaned up scripting. --- bash/decoders/dump1090-mutability.sh | 20 +- bash/decoders/dump978.sh | 266 ++++++++++++++++----------- bash/functions.sh | 1 - install.sh | 30 +-- 4 files changed, 186 insertions(+), 131 deletions(-) mode change 100644 => 100755 bash/decoders/dump978.sh diff --git a/bash/decoders/dump1090-mutability.sh b/bash/decoders/dump1090-mutability.sh index f207847..a8d6af5 100755 --- a/bash/decoders/dump1090-mutability.sh +++ b/bash/decoders/dump1090-mutability.sh @@ -36,7 +36,7 @@ PROJECTROOTDIRECTORY="$PWD" BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -DUMP1090BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build/dump1090" +DUMP1090BUILDDIRECTORY="$BUILDDIRECTORY/dump1090" ### INCLUDE EXTERNAL SCRIPTS @@ -49,7 +49,7 @@ clear echo -e "\n\e[91m THE ADS-B RECIEVER PROJECT VERSION $PROJECTVERSION" echo "" echo -e "\e[92m Setting up dump1090-mutability..." -echo -e "\e[93m------------------------------------------------------------------------------\e[96m" +echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" echo "" whiptail --title "Dump1090-mutability Setup" --yesno "Dump 1090 is a Mode S decoder specifically designed for RTLSDR devices. Dump1090-mutability is a fork of MalcolmRobb's version of dump1090 that adds new functionality and is designed to be built as a Debian/Raspbian package.\n\n https://github.com/mutability/dump1090\n\nContinue setup by installing dump1090-mutability?" 14 78 CONTINUESETUP=$? @@ -58,7 +58,7 @@ if [ $CONTINUESETUP = 1 ]; then echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" echo -e " Setup has been halted at the request of the user." echo "" - echo -e "\e[93m------------------------------------------------------------------------------" + echo -e "\e[93m----------------------------------------------------------------------------------------------------" echo -e "\e[92m Dump1090-mutability setup halted.\e[39m" echo "" read -p "Press enter to continue..." CONTINUE @@ -122,8 +122,9 @@ echo -e "\e[94m Installing the dump1090-mutability package...\e[97m" echo "" sudo dpkg -i dump1090-mutability_1.15~dev_*.deb -## CHECK THAT THE PACKAGE INSTALLED - +# Check that the package was installed. +echo "" +echo -e "\e[94m Checking that the dump1090-mutability package was installed properly...\e[97m" if [ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 0 ]; then # If the dump1090-mutability package could not be installed halt setup. echo "" @@ -133,11 +134,10 @@ if [ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "o echo "" echo -e "\e[93mThe package \"dump1090-mutability\" could not be installed.\e[39m" echo "" - echo -e "\e[93m------------------------------------------------------------------------------" + echo -e "\e[93m----------------------------------------------------------------------------------------------------" echo -e "\e[92m Dump1090-mutability setup halted.\e[39m" echo "" read -p "Press enter to continue..." CONTINUE - #kill -9 `ps --pid $$ -oppid=`; exit exit 1 fi @@ -151,12 +151,12 @@ if [[ `GetConfig "LAT" "/etc/default/dump1090-mutability"` == "" ]] || [[ `GetCo whiptail --title "Receiver Latitude and Longitude" --msgbox "Your receivers latitude and loingitude are required for certain features to function properly. You will now be asked to supply the latitude and longitude for your receiver. If you do not have this information you get it by using the web based \"Geocode by Address\" utility hosted on another of my websites.\n\n https://www.swiftbyte.com/toolbox/geocode" 13 78 RECEIVERLATITUDE_TITLE="Receiver Latitude" while [[ -z $RECEIVERLATITUDE ]]; do - RECEIVERLATITUDE=$(whiptail --title "$RECEIVERLATITUDE_TITLE" --nocancel --inputbox "\nEnter your receiver's latitude." 8 78 3>&1 1>&2 2>&3) + RECEIVERLATITUDE=$(whiptail --title "$RECEIVERLATITUDE_TITLE" --nocancel --inputbox "\nEnter your receiver's latitude.\n(Example: XX.XXXXXXX)" 9 78 3>&1 1>&2 2>&3) RECEIVERLATITUDE_TITLE="Receiver Latitude (REQUIRED)" done RECEIVERLONGITUDE_TITLE="Receiver Longitude" while [[ -z $RECEIVERLONGITUDE ]]; do - RECEIVERLONGITUDE=$(whiptail --title "$RECEIVERLONGITUDE_TITLE" --nocancel --inputbox "\nEnter your receeiver's longitude." 8 78 3>&1 1>&2 2>&3) + RECEIVERLONGITUDE=$(whiptail --title "$RECEIVERLONGITUDE_TITLE" --nocancel --inputbox "\nEnter your receeiver's longitude.\n(Example: XX.XXXXXXX)" 9 78 3>&1 1>&2 2>&3) RECEIVERLONGITUDE_TITLE="Receiver Longitude (REQUIRED)" done echo -e "\e[94m Setting the receiver's latitude to $RECEIVERLATITUDE...\e[97m" @@ -209,7 +209,7 @@ echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" cd $PROJECTROOTDIRECTORY echo "" -echo -e "\e[93m------------------------------------------------------------------------------" +echo -e "\e[93m----------------------------------------------------------------------------------------------------" echo -e "\e[92m Dump1090-mutability setup is complete.\e[39m" echo "" read -p "Press enter to continue..." CONTINUE diff --git a/bash/decoders/dump978.sh b/bash/decoders/dump978.sh old mode 100644 new mode 100755 index 49bc9f4..4b458e1 --- a/bash/decoders/dump978.sh +++ b/bash/decoders/dump978.sh @@ -9,7 +9,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Copyright (c) 2015 Joseph A. Prochazka # +# Copyright (c) 2015-2016 Joseph A. 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 # @@ -31,32 +31,44 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -BUILDDIR=$PWD -DUMP978DIR="$BUILDDIR/dump978" +### VARIABLES -source ../bash/functions.sh +PROJECTROOTDIRECTORY="$PWD" +BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" +BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" +DUMP978BUILDDIRECTORY="$BUILDDIRECTORY/dump978" + +### INCLUDE EXTERNAL SCRIPTS + +source $BASHDIRECTORY/variables.sh +source $BASHDIRECTORY/functions.sh + +### BEGIN SETUP clear - -echo -e "\033[31m" -echo "-------------------------------------------" -echo " Now ready to install dump978." -echo "-------------------------------------------" -echo -e "\033[33mDump 978 is an experimental demodulator/decoder for 978MHz UAT signals.." +echo -e "\n\e[91m THE ADS-B RECIEVER PROJECT VERSION $PROJECTVERSION" echo "" -echo "https://github.com/mutability/dump978" +echo -e "\e[92m Setting up dump978..." +echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" echo "" -echo -e "\033[31mBEFORE CONTINUING:\033[33m" -echo "It is recommended before continuing with the dump978 setup you read the wiki page" -echo "related to the installation of dump978. Doing so will help you through configuring" -echo "dump978 properly using this script." -echo "" -echo "https://github.com/jprochazka/adsb-feeder/wiki/dump978" -echo -e "\033[37m" -read -p "Press enter to continue..." CONTINUE +whiptail --title "Dump1090-mutability Setup" --yesno "Dump978 is an experimental demodulator/decoder for 978MHz UAT signals.\n\n https://github.com/mutability/dump978\n\nContinue setup by installing dump978?" 9 78 +CONTINUESETUP=$? +if [ $CONTINUESETUP = 1 ]; then + # Setup has been halted by the user. + echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" + echo -e " Setup has been halted at the request of the user." + echo "" + echo -e "\e[93m-------------------------------------------------------------------------------------------------------" + echo -e "\e[92m Dump978 setup halted.\e[39m" + echo "" + read -p "Press enter to continue..." CONTINUE + exit 1 +fi ## CHECK FOR PREREQUISITE PACKAGES +echo -e "\e[95m Installing packages needed to build and fulfill dependencies...\e[97m" +echo "" CheckPackage git CheckPackage make CheckPackage rtl-sdr @@ -64,11 +76,68 @@ CheckPackage librtlsdr-dev CheckPackage libusb-1.0-0-dev CheckPackage gcc CheckPackage netcat +CheckPackage lighttpd -## BLACKLIST UNWANTED RTL-SDR MODULES FROM BEING LOADED +## DOWNLOAD THE DUMP978 SOURCE CODE -echo -e "\033[33mStopping unwanted kernel modules from being loaded..." -echo -e "\033[37m" +echo "" +echo -e "\e[95m Preparing the dump978 Git repository...\e[97m" +echo "" + +# Remove the existing dumpp978 build directory if it exists. +if [ -d $DUMP978BUILDDIRECTORY ]; then + # Delete the current dump978 build directory if it already exists. + echo -e "\e[94m Deleting the existing dump978 git repository directory...\e[97m" + rm -rf $DUMP978BUILDDIRECTORY +fi + +# Clone the dump978 Git repository. +echo -e "\e[94m Entering the ADS-B Receiver Project build directory...\e[97m" +cd $BUILDDIRECTORY +echo -e "\e[94m Cloning the dump1090-mutability git repository locally...\e[97m" +echo "" +git clone https://github.com/mutability/dump978.git + +## BUILD THE DUMP978 BINARIES + +echo "" +echo -e "\e[95m Building the dump978 binaries...\e[97m" +echo "" +if [ ! $PWD = $DUMP978BUILDDIRECTORY ]; then + echo -e "\e[94m Entering the dump1090-mutability git repository directory...\e[97m" + cd $DUMP978BUILDDIRECTORY +fi +echo -e "\e[94m Building the dump1090-mutability package...\e[97m" +echo "" +make all +echo "" + +# Check that the dump978 binaries were built. +echo -e "\e[94m Checking that the dump978 binaries were built...\e[97m" +if [ ! -f $DUMP978BUILDDIRECTORY/dump978 ] || [ ! -f $DUMP978BUILDDIRECTORY/uat2esnt ] || [ ! -f $DUMP978BUILDDIRECTORY/uat2json ] || [ ! -f $DUMP978BUILDDIRECTORY/uat2text ]; then + # If the dump978 binaries could not be found halt setup. + echo "" + echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" + echo -e " UNABLE TO LOCATE THE DUMP978 BINARIES." + echo -e " SETUP HAS BEEN TERMINATED!" + echo "" + echo -e "\e[93mThe dump978 binaries appear to have not been built successfully..\e[39m" + echo "" + echo -e "\e[93m-------------------------------------------------------------------------------------------------------" + echo -e "\e[92m Dump978 setup halted.\e[39m" + echo "" + read -p "Press enter to continue..." CONTINUE + exit 1 +fi + +## SETUP AND CONFIGURE THE DEVICE TO UTILIZE THE DDUMP978 BINARIES + +echo "" +echo -e "\e[95m Configuring the device to utilize the dump978 binaries...\e[97m" +echo "" + +# Create an RTL-SDR blacklist file so the device does not claim SDR's for other purposes. +echo -e "\e[94m Creating an RTL-SDR kernel module blacklist file...\e[97m" sudo tee /etc/modprobe.d/rtlsdr-blacklist.conf > /dev/null </dev/null | grep -c "ok installed") -eq 1 ]; then # The dump1090-mutability package appear to be installed. - echo -e "\033[31m" - echo "ASSIGN RTL-SDR DEVICES TO DECODERS" - echo -e "\033[33m" - echo "It appears the dump1090-mutability package is installed on this device." - echo "In order to run dump978 in tandem with dump1090-mutability you will" - echo "need to specifiy which device each decoder is to use." - echo "" - echo "Keep in mind in order to run both decoders on a single device you will" - echo "need to have two separate RTL-SDR devices connected to your device." - echo -e "\033[37m" - read -p "Dump1090 Device: " DUMP1090DEVICE - read -p "Dump978 Device: " DUMP978DEVICE + whiptail --title "RTL-SDR Dongle Assignments" --msgbox "It appears the dump1090-mutability package is installed on this device. In order to run dump978 in tandem with dump1090-mutability you will need to specifiy which RTL-SDR dongle each decoder is to use.\n\nKeep in mind in order to run both decoders on a single device you will need to have two separate RTL-SDR devices connected to your device." 12 78 + DUMP1090DEVICE_TITLE="Dump1090 RTL-SDR Dongle" + while [[ -z $DUMP1090DEVICE ]]; do + DUMP1090DEVICE=$(whiptail --title "$DUMP1090DEVICE_TITLE" --nocancel --inputbox "\nEnter the ID for your dump1090 RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + DUMP1090DEVICE_TITLE="Dump1090 RTL-SDR Dongle (REQUIRED)" + done + DUMP978DEVICE_TITLE="Dump978 RTL-SDR Dongle" + while [[ -z $DUMP978DEVICE ]]; do + DUMP978DEVICE=$(whiptail --title "$DUMP978DEVICE_TITLE" --nocancel --inputbox "\nEnter the ID for your dump978 RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + DUMP978DEVICE_TITLE="Dump978 RTL-SDR Dongle (REQUIRED)" + done - # Assign the specified device to dump1090-mutability. - echo -e "\033[33m" - echo "Configuring dump1090-mutability to use the specified device..." + # Assign the specified RTL-SDR dongle to dump1090-mutability. + echo -e "\e[94m Assigning RTL-SDR dongle \"$DUMP1090DEVICE\" to dump1090-mutability...\e[97m" ChangeConfig "DEVICE" $DUMP1090DEVICE "/etc/default/dump1090-mutability" - echo "Restarting dump1090-mutability..." - echo -e "\033[37m" + echo -e "\e[94m Restarting dump1090-mutability...\e[97m" + echo "" sudo /etc/init.d/dump1090-mutability restart + echo "" fi -## CREATE JSON DATA DIRECTORY +# If a device has not yet been assigned to dump978 assign the first available. +if [ -z $DUMP978DEVICE ]; then + echo -e "\e[94m Assigning RTL-SDR dongle \"0\" to dump978...\e[97m" + DUMP978DEVICE="0" +fi -echo -e "\033[33mCreating Json data directory..." -echo -e "\033[37m" -sudo mkdir -p /var/www/html/dump978/data -sudo chmod 777 /var/www/html/dump978/data +# Create the dump978 JSON directory in Lighttpd's document root. +echo -e "\e[94m Getting the path to Lighttpd's document root...\e[97m" +LIGHTTPDDOCUMENTROOTSETTING=`/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -p | grep server.document-root` +LIGHTTPDDOCUMENTROOTDIRECTORY=`sed 's/.*"\(.*\)"[^"]*$/\1/' <<< $LIGHTTPDDOCUMENTROOTSETTING` +echo -e "\e[94m Creating the dump978 JSON data directory within Lighttpd's document root...\e[97m" +sudo mkdir -p $LIGHTTPDDOCUMENTROOTDIRECTORY/dump978/data +echo -e "\e[94m Setting permissions for the dump978 JSON data directory within Lighttpd's document root...\e[97m" +sudo chmod +w $LIGHTTPDDOCUMENTROOTDIRECTORY/dump978/data -## ADD SCRIPT AND COMMAND TO EXECUTE MAINTAINANCE SCRIPT USING RC.LOCAL - -echo -e "\033[33mCreating the script dump978-maint.sh..." -echo -e "\033[37m" -tee $DUMP978DIR/dump978-maint.sh > /dev/null < /dev/null < /dev/null <0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i ${DUMP978DIR}/dump978-maint.sh &\n" /etc/rc.local +# Add the dump978 maintenance script to /etc/rc.local. +echo -e "\e[94m Checking if the file /etc/rc.local is already set to execute the dump978 maintenance script...\e[97m" +if ! grep -Fxq "$DUMP978BUILDDIRECTORY/dump978-maint.sh &" /etc/rc.local; then + echo -e "\e[94m Adding a line to execute the dump978 maintenance script to the file /etc/rc.local...\e[97m" + LINENUMBER=($(sed -n '/exit 0/=' /etc/rc.local)) + ((LINENUMBER>0)) && sudo sed -i "${LINENUMBER[$((${#LINENUMBER[@]}-1))]}i ${DUMP978BUILDDIRECTORY}/dump978-maint.sh &\n" /etc/rc.local fi -## EXECUTE THE MAINTAINANCE SCRIPT +exit 0 -echo -e "\033[33m" -echo "Executing the dump978 maintainance script..." -echo -e "\033[37m" -sudo $DUMP978DIR/dump978-maint.sh > /dev/null & +## EXECUTE THE MAINTAINANCE SCRIPT TO START DUMP978 -## DISPLAY MESSAGE STATING DUMP978 SETUP IS COMPLETE +echo "" +echo -e "\e[95m Starting dump978...\e[97m" +echo "" +echo -e "\e[94m Starting dump978 by executing the dump978 maintenance script...\e[97m" +sudo $DUMP978BUILDDIRECTORY/dump978-maint.sh > /dev/null & -echo -e "\033[33m" -echo "Installation of dump978 is now complete." -echo "Please look over the output generated to be sure no errors were encountered." -echo -e "\033[37m" + +## DUMP978 SETUP COMPLETE + +# Enter into the project root directory. +echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" +cd $PROJECTROOTDIRECTORY + +echo "" +echo -e "\e[93m-------------------------------------------------------------------------------------------------------" +echo -e "\e[92m Dump978 setup is complete.\e[39m" +echo "" read -p "Press enter to continue..." CONTINUE + +exit 0 diff --git a/bash/functions.sh b/bash/functions.sh index f5c8755..2522fb8 100755 --- a/bash/functions.sh +++ b/bash/functions.sh @@ -88,7 +88,6 @@ function CheckPackage { function ChangeConfig { # Use sed to locate the "KEY" then replace the "VALUE", the portion after the equals sign, in the specified "FILE". # This function should work with any configuration file with settings formated as KEY="VALUE". - echo -e "\033[33mChanging the value for $1 to $2 in the file $3...\033[37m" sudo sed -i "s/\($1 *= *\).*/\1\"$2\"/" $3 } diff --git a/install.sh b/install.sh index 20ec22c..d7b02f8 100755 --- a/install.sh +++ b/install.sh @@ -60,11 +60,11 @@ function AptUpdate() { echo -e "\n\e[91m THE ADS-B RECIEVER PROJECT VERSION $PROJECTVERSION" echo "" echo -e "\e[92m Downloading the latest package lists for all enabled repositories and PPAs..." - echo -e "\e[93m------------------------------------------------------------------------------------\e[97m" + echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[97m" echo "" sudo apt-get update echo "" - echo -e "\e[93m------------------------------------------------------------------------------------" + echo -e "\e[93m----------------------------------------------------------------------------------------------------" echo -e "\e[92m Finished downloading and updating package lists.\e[39m" echo "" read -p "Press enter to continue..." CONTINUE @@ -76,11 +76,11 @@ function UpdateOperatingSystem() { echo -e "\n\e[91m THE ADS-B RECIEVER PROJECT VERSION $PROJECTVERSION" echo "" echo -e "\e[92m Downloading and installing the latest updates for your operating system..." - echo -e "\e[93m---------------------------------------------------------------------------------\e[97m" + echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[97m" echo "" sudo apt-get -y upgrade echo "" - echo -e "\e[93m---------------------------------------------------------------------------------" + echo -e "\e[93m----------------------------------------------------------------------------------------------------" echo -e "\e[92m Your operating system should now be up to date.\e[39m" echo "" read -p "Press enter to continue..." CONTINUE @@ -91,17 +91,25 @@ function InstallDump1090() { # Execute the dump1090-mutability setup script. chmod +x $BASHDIRECTORY/decoders/dump1090-mutability.sh $BASHDIRECTORY/decoders/dump1090-mutability.sh + if [ $? -ne 0 ]; then + echo "" + echo -e "\e[91m ANY FURTHER SETUP AND/OR INSTALLATION REQUESTS HAVE BEEN TERMINIATED\e[39m" + echo "" + exit 1 + fi } # Download and build dump978. function InstallDump978() { - clear - cd $BUILDDIR - echo -e "\033[33mExecuting the dump978 installation script..." - echo -e "\033[37m" - chmod +x $BASHDIR/decoders/dump978.sh - $BASHDIR/decoders/dump978.sh - cd $BASEDIR + # Execute the dump978 setup script. + chmod +x $BASHDIRECTORY/decoders/dump978.sh + $BASHDIRECTORY/decoders/dump978.sh + if [ $? -ne 0 ]; then + echo "" + echo -e "\e[91m ANY FURTHER SETUP AND/OR INSTALLATION REQUESTS HAVE BEEN TERMINIATED\e[39m" + echo "" + exit 1 + fi } # Download, build and then install the PiAware package.