From 79aad377a0fc2f6374e5d4cb5821c4df1fbcf666 Mon Sep 17 00:00:00 2001 From: jprochazka Date: Mon, 2 Oct 2017 15:36:29 -0400 Subject: [PATCH] Master branch now contains Romeo-Golf's 2.6.0 branch with fixes added to it. --- CHANGELOG.md | 10 +- CREDITS.md | 34 +- bash/decoders/dump1090-fa.sh | 207 ++-- bash/decoders/dump1090-mutability.sh | 478 +++++++--- bash/decoders/dump978.sh | 260 ++--- bash/decoders/rtlsdr-ogn.sh | 421 ++++++-- bash/extras/abovetustin.sh | 750 +++++++++------ bash/extras/beastsplitter.sh | 272 ++++++ bash/extras/duckdns.sh | 187 ++++ bash/feeders/adsbexchange.sh | 588 ++++++++---- bash/feeders/flightradar24.sh | 292 ++++-- bash/feeders/piaware.sh | 282 ++++-- bash/feeders/planefinder.sh | 271 ++++-- bash/functions.sh | 74 +- bash/image.sh | 238 ++--- bash/init.sh | 251 +++++ bash/main.sh | 898 +++++++++++++----- bash/portal/core.sh | 44 +- bash/portal/graphs.sh | 326 +++++-- bash/portal/install.sh | 466 ++++----- bash/portal/logging.sh | 52 +- bash/tools/image_setup.sh | 90 +- bash/tools/portal_backup.sh | 115 +-- bash/variables.sh | 26 +- build/.gitignore | 15 + build/portal/graphs/dump1090.db | 2 +- build/portal/html/admin/index.php | 4 +- build/portal/html/classes/common.class.php | 4 +- build/portal/html/flights.php | 8 +- .../portal/html/templates/default/flights.tpl | 31 +- build/portal/python/maintenance.py | 2 +- example.config | 438 +++++++++ install.sh | 251 ++--- logs/placeholder.txt | 1 + 34 files changed, 5249 insertions(+), 2139 deletions(-) create mode 100755 bash/extras/beastsplitter.sh create mode 100755 bash/extras/duckdns.sh create mode 100755 bash/init.sh create mode 100644 build/.gitignore create mode 100644 example.config create mode 100644 logs/placeholder.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a4a5ab..7c03c99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ The following is a history of the changes made to this project. -## v2.6.0 *(prerelease)* +## v2.6.0 (*prerelease*) * As requested users must now claim PiAware receivers via the FlightAware site. * Updated to install planfinder.net ARM client version 3.7.20. @@ -13,6 +13,14 @@ The following is a history of the changes made to this project. * Added check for the dvb_usb_rtl28xxu kernel module before trying to remove it. * Checks for the package dirmngr before executing the Flightradar24 setup script. * Fixed text displaying date time formats which were swapped in the portal settings. +* Added the ability to install beast-splitter as an extra. +* Added the ability to setup Duck DNS dynamic DNS service as an extra. +* Added the ability to setup the AboveTustin Twitter bot. +* Help pertaining to the new switches is available using the -h or --help switch. +* An installation log file can be kept by using either the -l or --log-output switch. +* The branch you wish to use can be specified using the -b or --branch switch. +* Pagination on the flights page has been minimized. +* Corrected the page count on the flights page. ## v2.5.0 *(December 5th, 2016)* diff --git a/CREDITS.md b/CREDITS.md index 9e78bb5..70471ae 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -3,50 +3,54 @@ ## People and Places First off I would like to thank the collaborators and contributors who have contributed to the project -directly. Their time and effort is greatly appreciated. +directly. Their time and effort is greatly appreciated by myself as well as many others I am sure. -**Collaborators** +**Direct Contributors** -* @mgunther68 - -**Contributors** - -* @jdwall * @adamkaplan -* @leearmstrong * @dschaper +* @leearmstrong +* @jdwall +* @mgunther68 +* @Romeo-Golf I would like to thank the members and contributors to the following forums for all the time and effort they have put in in order to create a useful and informative place to discuss aircraft tracking. -* The FlightAware Forums: http://discussions.flightaware.com -* The PlaneFinder Forums: http://forum.planefinder.net -* The ADS-B Exchange Forums: http://www.adsbexchange.com/forums/ +* The ADS-B Receiver Project Forums: https://www.adsb-receiver.net +* The FlightAware Forums: http://discussions.flightaware.com +* The PlaneFinder Forums: http://forum.planefinder.net +* The ADS-B Exchange Forums: http://www.adsbexchange.com/forums/ The performance graphs were created thanks in part to the great contributions made by members of both the FlightAware and PlaneFinder communities. Through their examples and help posted to the following -threads I was able to add these very informative graphs. +threads myself and a couple contributors were able to add these very informative graphs. * http://discussions.flightaware.com/ads-b-flight-tracking-f21/system-monitoring-t26999.html * http://forum.planefinder.net/threads/web-portal-and-collectd-rrd-graphs-automated-installation.256/ ## Third Party Software -Thanks to the people over at JetBrains for the complementary licenses for PhpStorm which is being used -to develop the portal portion of this project. https://www.jetbrains.com +Thanks to the people over at JetBrains for the complementary licenses for PhpStorm and PyCharms which +is being used to develop the portal portion of this project. https://www.jetbrains.com -I would like to thank the developers and contributors to the following projects. Without their +I would also like to thank the developers and contributors to the following projects. Without their hard work and dedication this project would not have been possible. * Dump1090 (mutability): https://github.com/mutability/dump1090 +* Dump1090 (fa): https://github.com/flightaware/dump1090 * Dump978: https://github.com/mutability/dump978 * FlightAware's PiAware: http://flightaware.com * Plane Finder ADS-B Client: https://planefinder.net * Flightradar24 Client: https://www.flightradar24.com * Dump1090-Tools: https://github.com/mutability/dump1090-tools +* AboveTustin https://github.com/kevinbrandon/abovetustin +* Beast-Splitter https://github.com/flightaware/beast-splitter +* bootpag http://botmonster.com/jquery-bootpag * Bootstrap: http://getbootstrap.com/ * jQuery: http://jquery.com/ * jQuery Steps: http://www.jquery-steps.com * js-cookie: https://github.com/js-cookie/js-cookie/releases * jquery-validation: https://github.com/jzaefferer/jquery-validation * Google Charts: https://developers.google.com/chart +* Duck DNS http://www.duckdns.com diff --git a/bash/decoders/dump1090-fa.sh b/bash/decoders/dump1090-fa.sh index d136550..b69af66 100755 --- a/bash/decoders/dump1090-fa.sh +++ b/bash/decoders/dump1090-fa.sh @@ -31,44 +31,61 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -## VARIABLES +### VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -DUMP1090BUILDDIRECTORY="$BUILDDIRECTORY/dump1090-fa" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" -## INCLUDE EXTERNAL SCRIPTS +# Component specific variables. -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +# Component service script variables. -## BEGIN SETUP +### INCLUDE EXTERNAL SCRIPTS -clear -echo -e "\n\e[91m $ADSB_PROJECTTITLE" -echo "" +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +## SET INSTALLATION VARIABLES + +# Source the automated install configuration file if this is an automated installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "true" ]] && [[ -s "${RECEIVER_CONFIGURATION_FILE}" ]] ; then + source ${RECEIVER_CONFIGURATION_FILE} +else + DUMP1090_BING_MAPS_KEY=`GetConfig "BingMapsAPIKey" "/usr/share/dump1090-mutability/html/config.js"` + DUMP1090_MAPZEN_KEY=`GetConfig "MapzenAPIKey" "/usr/share/dump1090-mutability/html/config.js"` +fi + +### BEGIN SETUP + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +fi +echo -e "" echo -e "\e[92m Setting up dump1090-fa..." -echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" -echo "" -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Dump1090-fa Setup" --yesno "Dump 1090 is a Mode-S decoder specifically designed for RTL-SDR devices. Dump1090-fa is a fork of the dump1090-mutability version of dump1090 that is specifically designed for FlightAware's PiAware software.\n\nIn order to use this version of dump1090 FlightAware's PiAware software must be installed as well.\n\n https://github.com/flightaware/dump1090\n\nContinue setup by installing dump1090-fa?" 14 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 Dump1090-fa setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE - exit 1 +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump1090-fa Setup" --yesno "Dump 1090 is a Mode-S decoder specifically designed for RTL-SDR devices. Dump1090-fa is a fork of the dump1090-mutability version of dump1090 that is specifically designed for FlightAware's PiAware software.\n\nIn order to use this version of dump1090 FlightAware's PiAware software must be installed as well.\n\n https://github.com/flightaware/dump1090\n\nContinue setup by installing dump1090-fa?" 14 78 + if [[ $? -eq 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 -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m Dump1090-fa setup halted.\e[39m" + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi fi ## CHECK FOR PREREQUISITE PACKAGES echo -e "\e[95m Installing packages needed to build and fulfill dependencies...\e[97m" -echo "" +echo -e "" CheckPackage git CheckPackage curl CheckPackage build-essential @@ -85,61 +102,61 @@ CheckPackage libncurses5-dev ## DOWNLOAD OR UPDATE THE DUMP1090-FA SOURCE -echo "" +echo -e "" echo -e "\e[95m Preparing the dump1090-fa Git repository...\e[97m" -echo "" -if [ -d $DUMP1090BUILDDIRECTORY/dump1090 ] && [ -d $DUMP1090BUILDDIRECTORY/dump1090/.git ]; then +echo -e "" +if [[ -d "${RECEIVER_BUILD_DIRECTORY}/dump1090/dump1090" ]] && [[ -d "${RECEIVER_BUILD_DIRECTORY}/dump1090/dump1090/.git" ]] ; then # A directory with a git repository containing the source code already exists. echo -e "\e[94m Entering the dump1090-fa git repository directory...\e[97m" - cd $DUMP1090BUILDDIRECTORY/dump1090 + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090/dump1090 2>&1 echo -e "\e[94m Updating the local dump1090-fa git repository...\e[97m" - echo "" + echo -e "" git pull else # A directory containing the source code does not exist in the build directory. echo -e "\e[94m Entering the ADS-B Receiver Project build directory...\e[97m" - mkdir -p $DUMP1090BUILDDIRECTORY - cd $DUMP1090BUILDDIRECTORY + mkdir -vp ${RECEIVER_BUILD_DIRECTORY}/dump1090 + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090 2>&1 echo -e "\e[94m Cloning the dump1090-fa git repository locally...\e[97m" - echo "" + echo -e "" git clone https://github.com/flightaware/dump1090.git - echo "" + echo -e "" fi ## BUILD AND INSTALL THE DUMP1090-FA PACKAGE -echo "" +echo -e "" echo -e "\e[95m Building and installing the dump1090-fa package...\e[97m" -echo "" -if [ ! $PWD = $DUMP1090BUILDDIRECTORY/dump1090 ]; then +echo -e "" +if [[ ! "${PWD}" = "${RECEIVER_BUILD_DIRECTORY}/dump1090/dump1090" ]] ; then echo -e "\e[94m Entering the dump1090-fa git repository directory...\e[97m" - cd $DUMP1090BUILDDIRECTORY/dump1090 + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090/dump1090 2>&1 fi echo -e "\e[94m Building the dump1090-fa package...\e[97m" -echo "" +echo -e "" dpkg-buildpackage -b -echo "" +echo -e "" echo -e "\e[94m Entering the dump1090-fa build directory...\e[97m" -cd $DUMP1090BUILDDIRECTORY +cd ${RECEIVER_BUILD_DIRECTORY}/dump1090 2>&1 echo -e "\e[94m Installing the dump1090-fa package...\e[97m" -echo "" -sudo dpkg -i dump1090-fa_${PIAWAREVERSION}_*.deb +echo -e "" +sudo dpkg -i dump1090-fa_${PIAWARE_VERSION}_*.deb # Check that the package was installed. -echo "" +echo -e "" echo -e "\e[94m Checking that the dump1090-fa package was installed properly...\e[97m" -if [ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 0 ]; then +if [[ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then # If the dump1090-fa package could not be installed halt setup. - echo "" + echo -e "" echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." echo -e " SETUP HAS BEEN TERMINATED!" - echo "" + echo -e "" echo -e "\e[93mThe package \"dump1090-fa\" could not be installed.\e[39m" - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m Dump1090-fa setup halted.\e[39m" - echo "" + echo -e "" read -p "Press enter to continue..." CONTINUE exit 1 fi @@ -147,51 +164,69 @@ fi ## DUMP1090-FA POST INSTALLATION CONFIGURATION # Ask for a Bing Maps API key. -BINGMAPSKEY=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Bing Maps API Key" --nocancel --inputbox "\nProvide a Bing Maps API key here to enable the Bing imagery layer.\nYou can obtain a free key at https://www.bingmapsportal.com/\n\nProviding a Bing Maps API key is not required to continue." 11 78 `GetConfig "BingMapsAPIKey" "/usr/share/dump1090-mutability/html/config.js"` 3>&1 1>&2 2>&3) -if [[ ! -z $BINGMAPSKEY ]]; then - echo -e "\e[94m Setting the Bing Maps API Key to $BINGMAPSKEY...\e[97m" - ChangeConfig "BingMapsAPIKey" "$BINGMAPSKEY" "/usr/share/dump1090-fa/html/config.js" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + DUMP1090_BING_MAPS_KEY=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Bing Maps API Key" --nocancel --inputbox "\nProvide a Bing Maps API key here to enable the Bing imagery layer.\nYou can obtain a free key at https://www.bingmapsportal.com/\n\nProviding a Bing Maps API key is not required to continue." 11 78 "${DUMP1090_BING_MAPS_KEY}" 3>&1 1>&2 2>&3) +fi +if [[ -n "${DUMP1090_BING_MAPS_KEY}" ]] ; then + echo -e "\e[94m Setting the Bing Maps API Key to ${DUMP1090_BING_MAPS_KEY}...\e[97m" + ChangeConfig "BingMapsAPIKey" "${DUMP1090_BING_MAPS_KEY}" "/usr/share/dump1090-fa/html/config.js" fi # Ask for a Mapzen API key. -MAPZENKEY=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Mapzen API Key" --nocancel --inputbox "\nProvide a Mapzen API key here to enable the Mapzen vector tile layer within the dump1090-mutability map. You can obtain a free key at https://mapzen.com/developers/\n\nProviding a Mapzen API key is not required to continue." 13 78 `GetConfig "MapzenAPIKey" "/usr/share/dump1090-mutability/html/config.js"` 3>&1 1>&2 2>&3) -if [[ ! -z $MAPZENKEY ]]; then - echo -e "\e[94m Setting the Mapzen API Key to $MAPZENKEY...\e[97m" - ChangeConfig "MapzenAPIKey" "$MAPZENKEY" "/usr/share/dump1090-fa/html/config.js" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + DUMP1090_MAPZEN_KEY=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Mapzen API Key" --nocancel --inputbox "\nProvide a Mapzen API key here to enable the Mapzen vector tile layer within the dump1090-mutability map. You can obtain a free key at https://mapzen.com/developers/\n\nProviding a Mapzen API key is not required to continue." 13 78 ${DUMP1090_MAPZEN_KEY} 3>&1 1>&2 2>&3) +fi +if [[ -n "${DUMP1090_MAPZEN_KEY}" ]] ; then + echo -e "\e[94m Setting the Mapzen API Key to ${DUMP1090_MAPZEN_KEY}...\e[97m" + ChangeConfig "MapzenAPIKey" "${DUMP1090_MAPZEN_KEY}" "/usr/share/dump1090-fa/html/config.js" fi # Download Heywhatsthat.com maximum range rings. -if [ ! -f /usr/share/dump1090-fa/html/upintheair.json ] && (whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Heywhaststhat.com Maimum Range Rings" --yesno "Maximum range rings can be added to dump1090-fa usings data obtained from Heywhatsthat.com. In order to add these rings to your dump1090-fa map you will first need to visit http://www.heywhatsthat.com and generate a new panarama centered on the location of your receiver. Once your panarama has been generated a link to the panarama will be displayed in the up left hand portion of the page. You will need the view id which is the series of letters and/or numbers after \"?view=\" in this URL.\n\nWould you like to add heywatsthat.com maximum range rings to your map?" 16 78); then - HEYWHATSTHATID_TITLE="Heywhatsthat.com Panarama ID" - while [[ -z $HEYWHATSTHATID ]]; do - HEYWHATSTHATID=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$HEYWHATSTHATID_TITLE" --nocancel --inputbox "\nEnter your Heywhatsthat.com panarama ID." 8 78 3>&1 1>&2 2>&3) - HEYWHATSTHATID_TITLE="Heywhatsthat.com Panarama ID (REQUIRED)" - done - HEYWHATSTHATRINGONE_TITLE="Heywhatsthat.com First Ring Altitude" - while [[ -z $HEYWHATSTHATRINGONE ]]; do - HEYWHATSTHATRINGONE=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$HEYWHATSTHATRINGONE_TITLE" --nocancel --inputbox "\nEnter the first ring's altitude in meters.\n(default 3048 meters or 10000 feet)" 8 78 "3048" 3>&1 1>&2 2>&3) - HEYWHATSTHATRINGONE_TITLE="Heywhatsthat.com First Ring Altitude (REQUIRED)" - done - HEYWHATSTHATRINGTWO_TITLE="Heywhatsthat.com Second Ring Altitude" - while [[ -z $HEYWHATSTHATRINGTWO ]]; do - HEYWHATSTHATRINGTWO=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$HEYWHATSTHATRINGTWO_TITLE" --nocancel --inputbox "\nEnter the second ring's altitude in meters.\n(default 12192 meters or 40000 feet)" 8 78 "12192" 3>&1 1>&2 2>&3) - HEYWHATSTHATRINGTWO_TITLE="Heywhatsthat.com Second Ring Altitude (REQUIRED)" - done - echo -e "\e[94m Downloading JSON data pertaining to the supplied panorama ID...\e[97m" - echo "" - sudo wget -O /usr/share/dump1090-fa/html/upintheair.json "http://www.heywhatsthat.com/api/upintheair.json?id=${HEYWHATSTHATID}&refraction=0.25&alts=$HEYWHATSTHATRINGONE,$HEYWHATSTHATRINGTWO" +if [[ ! -f "/usr/share/dump1090-fa/html/upintheair.json" ]] ; then + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + if (whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Heywhaststhat.com Maximum Range Rings" --yesno "Maximum range rings can be added to dump1090-fa usings data obtained from Heywhatsthat.com. In order to add these rings to your dump1090-fa map you will first need to visit http://www.heywhatsthat.com and generate a new panorama centered on the location of your receiver. Once your panorama has been generated a link to the panorama will be displayed in the top left hand portion of the page. You will need the view id which is the series of letters and/or numbers after \"?view=\" in this URL.\n\nWould you like to add heywatsthat.com maximum range rings to your map?" 16 78); then + # Set the DUMP1090_HEYWHATSTHAT_INSTALL variable to true. + DUMP1090_HEYWHATSTHAT_INSTALL="true" + # Ask the user for the Heywhatsthat.com panorama ID. + DUMP1090_HEYWHATSTHAT_ID_TITLE="Heywhatsthat.com Panorama ID" + while [[ -z "${DUMP1090_HEYWHATSTHAT_ID}" ]] ; do + DUMP1090_HEYWHATSTHAT_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DUMP1090_HEYWHATSTHAT_ID_TITLE}" --nocancel --inputbox "\nEnter your Heywhatsthat.com panorama ID." 8 78 3>&1 1>&2 2>&3) + DUMP1090_HEYWHATSTHAT_ID_TITLE="Heywhatsthat.com Panorama ID (REQUIRED)" + done + # Ask the user what altitude in meters to set the first range ring. + DUMP1090_HEYWHATSTHAT_RING_ONE_TITLE="Heywhatsthat.com First Ring Altitude" + while [[ -z "${DUMP1090_HEYWHATSTHAT_RING_ONE}" ]] ; do + DUMP1090_HEYWHATSTHAT_RING_ONE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DUMP1090_HEYWHATSTHAT_RING_ONE_TITLE}" --nocancel --inputbox "\nEnter the first ring's altitude in meters.\n(default 3048 meters or 10000 feet)" 8 78 "3048" 3>&1 1>&2 2>&3) + DUMP1090_HEYWHATSTHAT_RING_ONE_TITLE="Heywhatsthat.com First Ring Altitude (REQUIRED)" + done + # Ask the user what altitude in meters to set the second range ring. + DUMP1090_HEYWHATSTHAT_RING_TWO_TITLE="Heywhatsthat.com Second Ring Altitude" + while [[ -z "${DUMP1090_HEYWHATSTHAT_RING_TWO}" ]] ; do + DUMP1090_HEYWHATSTHAT_RING_TWO=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DUMP1090_HEYWHATSTHAT_RING_TWO_TITLE}" --nocancel --inputbox "\nEnter the second ring's altitude in meters.\n(default 12192 meters or 40000 feet)" 8 78 "12192" 3>&1 1>&2 2>&3) + DUMP1090_HEYWHATSTHAT_RING_TWO_TITLE="Heywhatsthat.com Second Ring Altitude (REQUIRED)" + done + fi + fi + # If the Heywhatsthat.com maximum range rings are to be added download them now. + if [[ "${DUMP1090_HEYWHATSTHAT_INSTALL}" = "true" ]] ; then + echo -e "\e[94m Downloading JSON data pertaining to the supplied panorama ID...\e[97m" + echo -e "" + sudo wget -O /usr/share/dump1090-fa/html/upintheair.json "http://www.heywhatsthat.com/api/upintheair.json?id=${DUMP1090_HEYWHATSTHAT_ID}&refraction=0.25&alts=${DUMP1090_HEYWHATSTHAT_RING_ONE},${DUMP1090_HEYWHATSTHAT_RING_TWO}" + fi fi -## DUMP1090-FA SETUP COMPLETE +### SETUP COMPLETE -# Enter into the project root directory. +# Return to the project root directory. echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" -cd $PROJECTROOTDIRECTORY +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 -echo "" -echo -e "\e[93m----------------------------------------------------------------------------------------------------" +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m Dump1090-fa setup is complete.\e[39m" -echo "" -read -p "Press enter to continue..." CONTINUE +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi exit 0 diff --git a/bash/decoders/dump1090-mutability.sh b/bash/decoders/dump1090-mutability.sh index 0a04df3..4afef44 100755 --- a/bash/decoders/dump1090-mutability.sh +++ b/bash/decoders/dump1090-mutability.sh @@ -9,7 +9,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Copyright (c) 2015-2016 Joseph A. Prochazka # +# Copyright (c) 2015-2017, 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,214 +31,376 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -## VARIABLES +### VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -DUMP1090BUILDDIRECTORY="$BUILDDIRECTORY/dump1090-mutability" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" -## INCLUDE EXTERNAL SCRIPTS +# Component specific variables. +COMPONENT_NAME="Dump1090-mutability" +COMPONENT_PACKAGE_NAME="dump1090-mutability" +COMPONENT_WEBSITE="https://github.com/mutability/dump1090" +COMPONENT_GITHUB_URL="https://github.com/mutability/dump1090.git" +COMPONENT_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/dump1090-mutability" +DUMP1090_CONFIGURATION_FILE="/etc/default/dump1090-mutability" -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +# Component service script variables. +COMPONENT_SERVICE_NAME="dump1090-mutability" -## BEGIN SETUP +### INCLUDE EXTERNAL SCRIPTS -clear -echo -e "\n\e[91m $ADSB_PROJECTTITLE" -echo "" -echo -e "\e[92m Setting up dump1090-mutability..." -echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" -echo "" -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Dump1090-mutability Setup" --yesno "Dump 1090 is a Mode-S decoder specifically designed for RTL-SDR 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=$? -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 Dump1090-mutability setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +## SET INSTALLATION VARIABLES + +# Source the automated install configuration file if this is an automated installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "true" ]] && [[ -s "${RECEIVER_CONFIGURATION_FILE}" ]] ; then + source ${RECEIVER_CONFIGURATION_FILE} +else + RECEIVER_LATITUDE=`GetConfig "LAT" "${DUMP1090_CONFIGURATION_FILE}"` + RECEIVER_LONGITUDE=`GetConfig "LON" "${DUMP1090_CONFIGURATION_FILE}"` + DUMP1090_BING_MAPS_KEY=`GetConfig "BingMapsAPIKey" "/usr/share/dump1090-mutability/html/config.js"` + DUMP1090_MAPZEN_KEY=`GetConfig "MapzenAPIKey" "/usr/share/dump1090-mutability/html/config.js"` +fi + +### BEGIN SETUP + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +fi +echo -e "" +echo -e "\e[92m Setting up ${COMPONENT_NAME}..." +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" + +# Check for existing component install. + +# Confirm component installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Interactive install. + CONTINUE_SETUP=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${COMPONENT_NAME} Setup" --yesno "Dump1090 is a Mode-S decoder specifically designed for RTL-SDR devices.\n\n${COMPONENT_NAME} 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 ${COMPONENT_WEBSITE} \n\nContinue setup by installing ${COMPONENT_NAME}?" 15 78 3>&1 1>&2 2>&3) + if [[ ${CONTINUE_SETUP} -eq 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 -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi +else + # Warn that automated installation is not supported. + echo -e "\e[92m Automated installation of this script is not yet supported...\e[39m" + echo -e "" exit 1 fi -## CHECK FOR PREREQUISITE PACKAGES +### CHECK FOR PREREQUISITE PACKAGES -echo -e "\e[95m Installing packages needed to build and fulfill dependencies...\e[97m" -echo "" +echo -e "\e[95m Installing packages needed to fulfill dependencies for ${COMPONENT_NAME}...\e[97m" +echo -e "" + +# Required by install script. CheckPackage git CheckPackage curl CheckPackage build-essential CheckPackage debhelper CheckPackage cron -CheckPackage rtl-sdr +# Required for USB SDR devices. CheckPackage librtlsdr-dev CheckPackage libusb-1.0-0-dev +CheckPackage rtl-sdr +# Required by component. CheckPackage pkg-config CheckPackage lighttpd CheckPackage fakeroot -## DOWNLOAD OR UPDATE THE DUMP1090-MUTABILITY SOURCE +### STOP ANY RUNNING SERVICES -echo "" -echo -e "\e[95m Preparing the dump1090-mutability Git repository...\e[97m" -echo "" -if [ -d $DUMP1090BUILDDIRECTORY/dump1090 ] && [ -d $DUMP1090BUILDDIRECTORY/dump1090/.git ]; then - # A directory with a git repository containing the source code already exists. - echo -e "\e[94m Entering the dump1090-mutability git repository directory...\e[97m" - cd $DUMP1090BUILDDIRECTORY/dump1090 - echo -e "\e[94m Updating the local dump1090-mutability git repository...\e[97m" - echo "" - git pull -else - # A directory containing the source code does not exist in the build directory. - echo -e "\e[94m Entering the ADS-B Receiver Project build directory...\e[97m" - mkdir -p $DUMP1090BUILDDIRECTORY - cd $DUMP1090BUILDDIRECTORY - echo -e "\e[94m Cloning the dump1090-mutability git repository locally...\e[97m" - echo "" - git clone https://github.com/mutability/dump1090.git +### START INSTALLATION + +echo -e "" +echo -e "\e[95m Begining the ${COMPONENT_NAME} installation process...\e[97m" +echo -e "" + +## ATTEMPT TO DOWNLOAD OR UPDATE THE COMPONENT FROM GITHUB + +if [[ -n "${COMPONENT_GITHUB_URL}" ]] ; then + # Github installation. + if [[ -d "${RECEIVER_BUILD_DIRECTORY}/dump1090/dump1090" ]] && [[ -d "${RECEIVER_BUILD_DIRECTORY}/dump1090/dump1090/.git" ]] ; then + # A directory with a git repository containing the source code already exists. + echo -e "\e[94m Entering the ${COMPONENT_NAME} git repository directory...\e[97m" + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090/dump1090 2>&1 + echo -e "\e[94m Updating the local ${COMPONENT_NAME} git repository...\e[97m" + echo -e "" + git pull 2>&1 + else + # A directory containing the source code does not exist in the build directory. + echo -e "\e[94m Entering ${RECEIVER_PROJECT_TITLE} build directory...\e[97m" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY}/dump1090 + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090 2>&1 + echo -e "\e[94m Cloning the ${COMPONENT_NAME} git repository locally...\e[97m" + echo -e "" + git clone ${COMPONENT_GITHUB_URL} 2>&1 + fi +elif [[ -n "${COMPONENT_BUILD_DIRECTORY}" ]] ; then + # Create the component build directory if it does not exist. + if [[ ! -d "${COMPONENT_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Creating the ${COMPONENT_NAME} build directory...\e[97m" + mkdir -vp ${COMPONENT_BUILD_DIRECTORY} + fi fi -## BUILD AND INSTALL THE DUMP1090-MUTABILITY PACKAGE +## BUILD AND INSTALL THE COMPONENT PACKAGE -echo "" -echo -e "\e[95m Building and installing the dump1090-mutability package...\e[97m" -echo "" -if [ ! $PWD = $DUMP1090BUILDDIRECTORY/dump1090 ]; then - echo -e "\e[94m Entering the dump1090-mutability git repository directory...\e[97m" - cd $DUMP1090BUILDDIRECTORY/dump1090 -fi -echo -e "\e[94m Building the dump1090-mutability package...\e[97m" -echo "" -dpkg-buildpackage -b -echo "" -echo -e "\e[94m Entering the ADS-B Receiver Project build directory...\e[97m" -cd $DUMP1090BUILDDIRECTORY -echo -e "\e[94m Installing the dump1090-mutability package...\e[97m" -echo "" -sudo dpkg -i dump1090-mutability_1.15~dev_*.deb +echo -e "" +echo -e "\e[95m Building and installing the ${COMPONENT_NAME} package...\e[97m" +echo -e "" -# 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 "" - echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" - echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." - echo -e " SETUP HAS BEEN TERMINATED!" - echo "" - echo -e "\e[93mThe package \"dump1090-mutability\" could not be installed.\e[39m" - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" - echo -e "\e[92m Dump1090-mutability setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE - exit 1 +# Change to the component build directory. +if [[ ! "${PWD}" = "${RECEIVER_BUILD_DIRECTORY}/dump1090/dump1090" ]] ; then + echo -e "\e[94m Entering the ${COMPONENT_NAME} build directory...\e[97m" + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090/dump1090 2>&1 fi -## DUMP1090-MUTABILITY POST INSTALLATION CONFIGURATION +# Dummy test for consistency with other feeder install scripts. +if [[ -n "${CPU_ARCHITECTURE}" ]] ; then -# Set the receiver's latitude and longitude if it is not already set in the dump1090-mutibility configuration file. -echo "" + # Build binary package. + echo -e "\e[94m Building the ${COMPONENT_NAME} package...\e[97m" + echo -e "" + dpkg-buildpackage -b 2>&1 + echo -e "" + + # Prempt the dpkg question asking if the user would like dump1090 to start automatically. + if [[ ! "`sudo debconf-get-selections 2>/dev/null | grep "dump1090-mutability/auto-start" | awk '{print $4}'`" = "true" ]] ; then + echo -e "\e[94m Configuring ${COMPONENT_NAME} to start automatically....\e[97m]" + ACTION=$(echo 'dump1090-mutability dump1090-mutability/auto-start boolean true' | sudo debconf-set-selections -v 2>&1) + echo -e "" + fi + + # Install binary package. + echo -e "\e[94m Installing the ${COMPONENT_NAME} package...\e[97m" + echo -e "" + sudo dpkg -i ${RECEIVER_BUILD_DIRECTORY}/dump1090/${COMPONENT_PACKAGE_NAME}_1.15~dev_*.deb 2>&1 + echo -e "" + + # Check that the component package was installed successfully. + echo -e "" + echo -e "\e[94m Checking that the ${COMPONENT_NAME} package was installed properly...\e[97m" + echo -e "" + + if [[ $(dpkg-query -W -f='${STATUS}' ${COMPONENT_PACKAGE_NAME} 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + # If the component package could not be installed halt setup. + echo -e "" + echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" + echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." + echo -e " SETUP HAS BEEN TERMINATED!" + echo -e "" + echo -e "\e[93mThe package \"${COMPONENT_PACKAGE_NAME}\" could not be installed.\e[39m" + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE + fi + exit 1 + else + # Create binary package archive directory. + if [[ ! -d "${RECEIVER_BUILD_DIRECTORY}/package-archive" ]] ; then + echo -e "\e[94m Creating package archive directory...\e[97m" + echo -e "" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + fi + + # Archive binary package. + echo -e "\e[94m Moving the ${COMPONENT_NAME} binary package into the archive directory...\e[97m" + echo -e "" + mv -vf ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_*.deb ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + fi +fi + +## COMPONENT POST INSTALL ACTIONS + +# Confirm the receiver's latitude and longitude if it is not already set in the component configuration file. +echo -e "" echo -e "\e[95m Begining post installation configuration...\e[97m" -echo "" -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Receiver Latitude and Longitude" --msgbox "Your receivers latitude and longitude 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=`GetConfig "LAT" "/etc/default/dump1090-mutability"` - RECEIVERLATITUDE=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$RECEIVERLATITUDE_TITLE" --nocancel --inputbox "\nEnter your receiver's latitude.\n(Example: XX.XXXXXXX)" 9 78 " $RECEIVERLATITUDE" 3>&1 1>&2 2>&3) - RECEIVERLATITUDE_TITLE="Receiver Latitude (REQUIRED)" -done -RECEIVERLONGITUDE_TITLE="Receiver Longitude" -while [[ -z $RECEIVERLONGITUDE ]]; do - RECEIVERLONGITUDE=`GetConfig "LON" "/etc/default/dump1090-mutability"` - RECEIVERLONGITUDE=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$RECEIVERLONGITUDE_TITLE" --nocancel --inputbox "\nEnter your receeiver's longitude.\n(Example: XX.XXXXXXX)" 9 78 " $RECEIVERLONGITUDE" 3>&1 1>&2 2>&3) - RECEIVERLONGITUDE_TITLE="Receiver Longitude (REQUIRED)" -done +echo -e "" -echo -e "\e[94m Setting the receiver's latitude to $RECEIVERLATITUDE...\e[97m" +# Ask for the receivers latitude and longitude. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Explain to the user that the receiver's latitude and longitude is required. + RECEIVER_LATLON_DIALOG=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Receiver Latitude and Longitude" --msgbox "Your receivers latitude and longitude are required for distance calculations, you will now be asked to supply these values for your receiver.\n\nIf you do not have this information you can obtain it using the web based \"Geocode by Address\" utility hosted on another of the lead developers websites:\n\n https://www.swiftbyte.com/toolbox/geocode" 15 78 3>&1 1>&2 2>&3) -ChangeConfig "LAT" "$(sed -e 's/[[:space:]]*$//' <<<${RECEIVERLATITUDE})" "/etc/default/dump1090-mutability" -echo -e "\e[94m Setting the receiver's longitude to $RECEIVERLONGITUDE...\e[97m" -ChangeConfig "LON" "$(sed -e 's/[[:space:]]*$//' <<<${RECEIVERLONGITUDE})" "/etc/default/dump1090-mutability" + # Ask the user for the receiver's latitude. + RECEIVER_LATITUDE_TITLE="Receiver Latitude" + RECEIVER_LATITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LATITUDE_TITLE}" --nocancel --inputbox "\nEnter your receiver's latitude.\n(Example: XX.XXXXXXX)" 9 78 -- "${RECEIVER_LATITUDE}" 3>&1 1>&2 2>&3) + while [[ -z "${RECEIVER_LATITUDE}" ]] || [[ `echo -n "${RECEIVER_LATITUDE}" | sed -e 's/[0-9]//g' -e 's/\.//g' -e 's/-//g' | wc -c` -gt 0 ]] ; do + RECEIVER_LATITUDE_TITLE="Receiver Latitude (REQUIRED)" + RECEIVER_LATITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LATITUDE_TITLE}" --nocancel --inputbox "\nEnter your receiver's latitude.\n(Example: XX.XXXXXXX)" 9 78 -- "${RECEIVER_LATITUDE}" 3>&1 1>&2 2>&3) + done + + # Ask the user for the receiver's longitude. + RECEIVER_LONGITUDE_TITLE="Receiver Longitude" + RECEIVER_LONGITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LONGITUDE_TITLE}" --nocancel --inputbox "\nEnter your receeiver's longitude.\n(Example: XX.XXXXXXX)" 9 78 -- "${RECEIVER_LONGITUDE}" 3>&1 1>&2 2>&3) + while [[ -z "${RECEIVER_LONGITUDE}" ]] || [[ `echo -n "${RECEIVER_LONGITUDE}" | sed -e 's/[0-9]//g' -e 's/\.//g' -e 's/-//g' | wc -c` -gt 0 ]] ; do + RECEIVER_LONGITUDE_TITLE="Receiver Longitude (REQUIRED)" + RECEIVER_LONGITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LONGITUDE_TITLE}" --nocancel --inputbox "\nEnter your receeiver's longitude.\n(Example: XX.XXXXXXX)" 9 78 -- "${RECEIVER_LONGITUDE}" 3>&1 1>&2 2>&3) + done +fi + +# Save the receiver's latitude and longitude values to dump1090 configuration file. +RECEIVER_LATITUDE_CONFIGURED=`GetConfig "LON" "${DUMP1090_CONFIGURATION_FILE}"` +if [[ ! "${RECEIVER_LATITUDE}" = "${RECEIVER_LATITUDE_CONFIGURED}" ]] ; then + echo -e "\e[94m Setting the receiver's latitude to ${RECEIVER_LATITUDE}...\e[97m" + ChangeConfig "LAT" "${RECEIVER_LATITUDE}" "${DUMP1090_CONFIGURATION_FILE}" +fi +RECEIVER_LONGITUDE_CONFIGURED=`GetConfig "LON" "${DUMP1090_CONFIGURATION_FILE}"` +if [[ ! "${RECEIVER_LONGITUDE}" = "${RECEIVER_LONGITUDE_CONFIGURED}" ]] ; then + echo -e "\e[94m Setting the receiver's longitude to ${RECEIVER_LONGITUDE}...\e[97m" + ChangeConfig "LON" "${RECEIVER_LONGITUDE}" "${DUMP1090_CONFIGURATION_FILE}" +fi # Ask for a Bing Maps API key. -BINGMAPSKEY=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Bing Maps API Key" --nocancel --inputbox "\nProvide a Bing Maps API key here to enable the Bing imagery layer.\nYou can obtain a free key at https://www.bingmapsportal.com/\n\nProviding a Bing Maps API key is not required to continue." 12 78 `GetConfig "BingMapsAPIKey" "/usr/share/dump1090-mutability/html/config.js"` 3>&1 1>&2 2>&3) -if [[ ! -z $BINGMAPSKEY ]]; then - echo -e "\e[94m Setting the Bing Maps API Key to $BINGMAPSKEY...\e[97m" - ChangeConfig "BingMapsAPIKey" "$BINGMAPSKEY" "/usr/share/dump1090-mutability/html/config.js" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + DUMP1090_BING_MAPS_KEY=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Bing Maps API Key" --nocancel --inputbox "\nProvide a Bing Maps API key here to enable the Bing imagery layer within the ${COMPONENT_NAME} map, you can obtain a free key at the following website:\n\n https://www.bingmapsportal.com/\n\nProviding a Bing Maps API key is not required to continue." 15 78 -- "${DUMP1090_BING_MAPS_KEY}" 3>&1 1>&2 2>&3) +fi +if [[ -n "${DUMP1090_BING_MAPS_KEY}" ]] ; then + echo -e "\e[94m Setting the Bing Maps API Key to ${DUMP1090_BING_MAPS_KEY}...\e[97m" + ChangeConfig "BingMapsAPIKey" "${DUMP1090_BING_MAPS_KEY}" "/usr/share/dump1090-mutability/html/config.js" fi # Ask for a Mapzen API key. -MAPZENKEY=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Mapzen API Key" --nocancel --inputbox "\nProvide a Mapzen API key here to enable the Mapzen vector tile layer within the dump1090-mutability map. You can obtain a free key at https://mapzen.com/developers/\n\nProviding a Mapzen API key is not required to continue." 13 78 `GetConfig "MapzenAPIKey" "/usr/share/dump1090-mutability/html/config.js"` 3>&1 1>&2 2>&3) -if [[ ! -z $MAPZENKEY ]]; then - echo -e "\e[94m Setting the Mapzen API Key to $MAPZENKEY...\e[97m" - ChangeConfig "MapzenAPIKey" "$MAPZENKEY" "/usr/share/dump1090-mutability/html/config.js" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + DUMP1090_MAPZEN_KEY=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Mapzen API Key" --nocancel --inputbox "\nProvide a Mapzen API key here to enable the Mapzen vector tile layer within the ${COMPONENT_NAME} map, you can obtain a free key at the following website:\n\n https://mapzen.com/developers/\n\nProviding a Mapzen API key is not required to continue." 15 78 -- "${DUMP1090_MAPZEN_KEY}" 3>&1 1>&2 2>&3) +fi +if [[ -n "${DUMP1090_MAPZEN_KEY}" ]] ; then + echo -e "\e[94m Setting the Mapzen API Key to ${DUMP1090_MAPZEN_KEY}...\e[97m" + ChangeConfig "MapzenAPIKey" "${DUMP1090_MAPZEN_KEY}" "/usr/share/dump1090-mutability/html/config.js" fi -# Ask if dump1090-mutability should bind on all IP addresses. -if (whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Bind Dump1090-mutability To All IP Addresses" --yesno "By default dump1090-mutability is bound only to the local loopback IP address(s) for security reasons. However some people wish to make dump1090-mutability's data accessable externally by other devices. To allow this dump1090-mutability can be configured to listen on all IP addresses bound to this device. It is recommended that unless you plan to access this device from an external source that dump1090-mutability remain bound only to the local loopback IP address(s).\n\nWould you like dump1090-mutability to listen on all IP addesses?" 15 78) then - echo -e "\e[94m Binding dump1090-mutability to all available IP addresses...\e[97m" - CommentConfig "NET_BIND_ADDRESS" "/etc/default/dump1090-mutability" +# Ask if the component should bind on all IP addresses. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Bind ${COMPONENT_NAME} To All IP Addresses" --yesno "By default ${COMPONENT_NAME} is bound only to the local loopback IP address(s) for security reasons. However some people wish to make ${COMPONENT_NAME}'s data accessable externally by other devices. To allow this ${COMPONENT_NAME} can be configured to listen on all IP addresses bound to this device. It is recommended that unless you plan to access this device from an external source that ${COMPONENT_NAME} remain bound only to the local loopback IP address(s).\n\nWould you like ${COMPONENT_NAME} to listen on all IP addesses?" 15 78 + case $? in + 0) + DUMP1090_BIND_TO_ALL_IPS="true" + ;; + 1) + DUMP1090_BIND_TO_ALL_IPS="false" + ;; + esac +fi +if [[ ! "${DUMP1090_BIND_TO_ALL_IPS}" = "false" ]] ; then + echo -e "\e[94m Binding ${COMPONENT_NAME} to all available IP addresses...\e[97m" + CommentConfig "NET_BIND_ADDRESS" "${DUMP1090_CONFIGURATION_FILE}" else - echo -e "\e[94m Binding dump1090-mutability to the localhost IP addresses...\e[97m" - UncommentConfig "NET_BIND_ADDRESS" "/etc/default/dump1090-mutability" - ChangeConfig "NET_BIND_ADDRESS" "127.0.0.1" "/etc/default/dump1090-mutability" + echo -e "\e[94m Binding ${COMPONENT_NAME} to the localhost IP addresses...\e[97m" + UncommentConfig "NET_BIND_ADDRESS" "${DUMP1090_CONFIGURATION_FILE}" + ChangeConfig "NET_BIND_ADDRESS" "127.0.0.1" "${DUMP1090_CONFIGURATION_FILE}" fi -# Ask if measurments should be displayed using imperial or metric. -UNITOFMEASUREMENT=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Unit of Measurement" --nocancel --menu "\nChoose unit of measurement to be used by dump1090-mutbility." 11 78 2 "Imperial" "" "Metric" "" 3>&1 1>&2 2>&3) -if [ $UNITOFMEASUREMENT = "Metric" ]; then - echo -e "\e[94m Setting dump1090-mutability unit of measurement to Metric...\e[97m" +# In future ask the user if they would like to specify the maximum range manually, if not set to 360 nmi / ~667 km to match dump1090-fa. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + DUMP1090_MAX_RANGE_DIALOG=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${COMPONENT_NAME} Maximum Range" --msgbox "The ${COMPONENT_NAME} default maximum range value of 300 nmi (~550km) has been reported to be below what is possible under the right conditions, so this value will be increased to 360 nmi (~660 km) to match the value used by the dump1090-fa fork." 10 78 3>&1 1>&2 2>&3) +fi +if [[ -z "${DUMP1090_MAX_RANGE}" ]] ; then + DUMP1090_MAX_RANGE="360" +fi +if [[ `grep "MAX_RANGE" ${DUMP1090_CONFIGURATION_FILE} | awk -F \" '{print $2}'` = "${DUMP1090_MAX_RANGE}" ]] ; then + ChangeConfig "MAX_RANGE" "${DUMP1090_MAX_RANGE}" "${DUMP1090_CONFIGURATION_FILE}" +fi + +# Ask if measurements should be displayed using imperial or metric. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Unit of Measurement" --yes-button "Imperial" --no-button "Metric" --yesno "\nPlease select the unit of measurement to be used by ${COMPONENT_NAME}." 8 78 + case $? in + 0) + DUMP1090_UNIT_OF_MEASUREMENT="imperial" + ;; + 1) + DUMP1090_UNIT_OF_MEASUREMENT="metric" + ;; + esac +fi +if [[ "${DUMP1090_UNIT_OF_MEASUREMENT}" = "metric" ]] ; then + echo -e "\e[94m Setting ${COMPONENT_NAME} unit of measurement to Metric...\e[97m" ChangeConfig "Metric" "true;" "/usr/share/dump1090-mutability/html/config.js" else - echo -e "\e[94m Setting dump1090-mutability unit of measurement to Imperial...\e[97m" + echo -e "\e[94m Setting ${COMPONENT_NAME} unit of measurement to Imperial...\e[97m" ChangeConfig "Metric" "false;" "/usr/share/dump1090-mutability/html/config.js" fi # Download Heywhatsthat.com maximum range rings. -if [ ! -f /usr/share/dump1090-mutability/html/upintheair.json ] && (whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Heywhaststhat.com Maimum Range Rings" --yesno "Maximum range rings can be added to dump1090-mutability usings data obtained from Heywhatsthat.com. In order to add these rings to your dump1090-mutability map you will first need to visit http://www.heywhatsthat.com and generate a new panarama centered on the location of your receiver. Once your panarama has been generated a link to the panarama will be displayed in the up left hand portion of the page. You will need the view id which is the series of letters and/or numbers after \"?view=\" in this URL.\n\nWould you like to add heywatsthat.com maximum range rings to your map?" 16 78); then - HEYWHATSTHATID_TITLE="Heywhatsthat.com Panarama ID" - while [[ -z $HEYWHATSTHATID ]]; do - HEYWHATSTHATID=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$HEYWHATSTHATID_TITLE" --nocancel --inputbox "\nEnter your Heywhatsthat.com panarama ID." 8 78 3>&1 1>&2 2>&3) - HEYWHATSTHATID_TITLE="Heywhatsthat.com Panarama ID (REQUIRED)" - done - HEYWHATSTHATRINGONE_TITLE="Heywhatsthat.com First Ring Altitude" - while [[ -z $HEYWHATSTHATRINGONE ]]; do - HEYWHATSTHATRINGONE=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$HEYWHATSTHATRINGONE_TITLE" --nocancel --inputbox "\nEnter the first ring's altitude in meters.\n(default 3048 meters or 10000 feet)" 8 78 "3048" 3>&1 1>&2 2>&3) - HEYWHATSTHATRINGONE_TITLE="Heywhatsthat.com First Ring Altitude (REQUIRED)" - done - HEYWHATSTHATRINGTWO_TITLE="Heywhatsthat.com Second Ring Altitude" - while [[ -z $HEYWHATSTHATRINGTWO ]]; do - HEYWHATSTHATRINGTWO=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$HEYWHATSTHATRINGTWO_TITLE" --nocancel --inputbox "\nEnter the second ring's altitude in meters.\n(default 12192 meters or 40000 feet)" 8 78 "12192" 3>&1 1>&2 2>&3) - HEYWHATSTHATRINGTWO_TITLE="Heywhatsthat.com Second Ring Altitude (REQUIRED)" - done - echo -e "\e[94m Downloading JSON data pertaining to the supplied panorama ID...\e[97m" - echo "" - sudo wget -O /usr/share/dump1090-mutability/html/upintheair.json "http://www.heywhatsthat.com/api/upintheair.json?id=${HEYWHATSTHATID}&refraction=0.25&alts=$HEYWHATSTHATRINGONE,$HEYWHATSTHATRINGTWO" +if [[ ! -f "/usr/share/dump1090-mutability/html/upintheair.json" ]] ; then + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + if (whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Heywhaststhat.com Maximum Range Rings" --yesno "Maximum range rings can be added to ${COMPONENT_NAME} using data obtained from Heywhatsthat.com. In order to add these rings to your ${COMPONENT_NAME} map you will first need to visit http://www.heywhatsthat.com and generate a new panorama centered on the location of your receiver. Once your panorama has been generated a link to the panorama will be displayed in the top left hand portion of the page. You will need the view id which is the series of letters and/or numbers after \"?view=\" in this URL.\n\nWould you like to add heywatsthat.com maximum range rings to your map?" 16 78) ; then + # Set the DUMP1090_HEYWHATSTHAT_INSTALL variable to true. + DUMP1090_HEYWHATSTHAT_INSTALL="true" + # Ask the user for the Heywhatsthat.com panorama ID. + DUMP1090_HEYWHATSTHAT_ID_TITLE="Heywhatsthat.com Panorama ID" + while [[ -z "${DUMP1090_HEYWHATSTHAT_ID}" ]] ; do + DUMP1090_HEYWHATSTHAT_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DUMP1090_HEYWHATSTHAT_ID_TITLE}" --nocancel --inputbox "\nEnter your Heywhatsthat.com panorama ID." 8 78 3>&1 1>&2 2>&3) + DUMP1090_HEYWHATSTHAT_ID_TITLE="Heywhatsthat.com Panorama ID (REQUIRED)" + done + # Ask the user what altitude in meters to set the first range ring. + DUMP1090_HEYWHATSTHAT_RING_ONE_TITLE="Heywhatsthat.com First Ring Altitude" + while [[ -z "${DUMP1090_HEYWHATSTHAT_RING_ONE}" ]] ; do + DUMP1090_HEYWHATSTHAT_RING_ONE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DUMP1090_HEYWHATSTHAT_RING_ONE_TITLE}" --nocancel --inputbox "\nEnter the first ring's altitude in meters.\n(default 3048 meters or 10000 feet)" 8 78 "3048" 3>&1 1>&2 2>&3) + DUMP1090_HEYWHATSTHAT_RING_ONE_TITLE="Heywhatsthat.com First Ring Altitude (REQUIRED)" + done + # Ask the user what altitude in meters to set the second range ring. + DUMP1090_HEYWHATSTHAT_RING_TWO_TITLE="Heywhatsthat.com Second Ring Altitude" + while [[ -z "${DUMP1090_HEYWHATSTHAT_RING_TWO}" ]] ; do + DUMP1090_HEYWHATSTHAT_RING_TWO=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DUMP1090_HEYWHATSTHAT_RING_TWO_TITLE}" --nocancel --inputbox "\nEnter the second ring's altitude in meters.\n(default 12192 meters or 40000 feet)" 8 78 "12192" 3>&1 1>&2 2>&3) + DUMP1090_HEYWHATSTHAT_RING_TWO_TITLE="Heywhatsthat.com Second Ring Altitude (REQUIRED)" + done + fi + fi + # If the Heywhatsthat.com maximum range rings are to be added download them now. + if [[ "${DUMP1090_HEYWHATSTHAT_INSTALL}" = "true" ]] ; then + echo -e "\e[94m Downloading JSON data pertaining to the supplied panorama ID...\e[97m" + echo -e "" + sudo wget -O /usr/share/dump1090-mutability/html/upintheair.json "http://www.heywhatsthat.com/api/upintheair.json?id=${DUMP1090_HEYWHATSTHAT_ID}&refraction=0.25&alts=${DUMP1090_HEYWHATSTHAT_RING_ONE},${DUMP1090_HEYWHATSTHAT_RING_TWO}" + fi fi -# Reload dump1090-mutability to ensure all changes take effect. -echo -e "\e[94m Reloading dump1090-mutability...\e[97m" -echo "" -sudo /etc/init.d/dump1090-mutability force-reload +# Dummy test for consistency with other feeder install scripts. +if [[ -n "${CPU_ARCHITECTURE}" ]] ; then + if [[ -n "${COMPONENT_SERVICE_NAME}" ]] ; then + # (re)start the component service. + if [[ "`sudo systemctl status ${COMPONENT_SERVICE_NAME} 2>&1 | egrep -c "Active: active (running)"`" -gt 0 ]] ; then + echo -e "\e[94m Restarting the ${COMPONENT_NAME} service...\e[97m" + sudo systemctl restart ${COMPONENT_SERVICE_NAME} 2>&1 + else + echo -e "\e[94m Starting the ${COMPONENT_NAME} service...\e[97m" + sudo systemctl start ${COMPONENT_SERVICE_NAME} 2>&1 + fi + echo -e "" + fi +fi -## DUMP1090-MUTABILITY SETUP COMPLETE +### SETUP COMPLETE -# Enter into the project root directory. -echo "" -echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" -cd $PROJECTROOTDIRECTORY +# Return to the project root directory. +echo -e "\e[94m Returning to ${RECEIVER_PROJECT_TITLE} root directory...\e[97m" +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 -echo "" -echo -e "\e[93m----------------------------------------------------------------------------------------------------" -echo -e "\e[92m Dump1090-mutability setup is complete.\e[39m" -echo "" -read -p "Press enter to continue..." CONTINUE +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" +echo -e "\e[92m ${COMPONENT_NAME} setup is complete.\e[39m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi exit 0 diff --git a/bash/decoders/dump978.sh b/bash/decoders/dump978.sh index dbd35fe..0f5a308 100755 --- a/bash/decoders/dump978.sh +++ b/bash/decoders/dump978.sh @@ -33,42 +33,81 @@ ### VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -DUMP978BUILDDIRECTORY="$BUILDDIRECTORY/dump978" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" + +# Component specific variables. + +# Component service script variables. ### INCLUDE EXTERNAL SCRIPTS -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +# To be moved to functions.sh... + +################################################################################# +# Blacklist DVB-T drivers for RTL-SDR devices. + +function BlacklistModules () { + RECEIVER_KERNEL_MODULE_BLACKLIST="/etc/modprobe.d/rtlsdr-blacklist.conf" + if [[ ! -f "${RECEIVER_KERNEL_MODULE_BLACKLIST}" ]] || [[ `cat ${RECEIVER_KERNEL_MODULE_BLACKLIST} | wc -l` -lt 9 ]] ; then + echo -en "\e[94m Installing blacklist to prevent unwanted kernel modules from being loaded...\e[97m" + sudo tee ${RECEIVER_KERNEL_MODULE_BLACKLIST} > /dev/null <&1 echo -e "\e[94m Cloning the dump978 Git repository locally...\e[97m" -echo "" +echo -e "" git clone https://github.com/mutability/dump978.git ## BUILD THE DUMP978 BINARIES -echo "" +echo -e "" echo -e "\e[95m Building the dump978 binaries...\e[97m" -echo "" -if [ ! $PWD = $DUMP978BUILDDIRECTORY ]; then +echo -e "" +# Enter the dump978 repository if we are not already in it. +if [[ ! "${PWD}" = "${RECEIVER_BUILD_DIRECTORY}/dump978" ]] ; then echo -e "\e[94m Entering the dump978 Git repository directory...\e[97m" - cd $DUMP978BUILDDIRECTORY + cd ${RECEIVER_BUILD_DIRECTORY}/dump978 2>&1 fi +# Build the dump978 binaries from source. echo -e "\e[94m Building the dump978 binaries...\e[97m" -echo "" +echo -e "" make all -echo "" +echo -e "" # 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 [[ ! -f "${RECEIVER_BUILD_DIRECTORY}/dump978/dump978" ]] || [[ ! -f "${RECEIVER_BUILD_DIRECTORY}/dump978/uat2esnt" ]] || [[ ! -f "${RECEIVER_BUILD_DIRECTORY}/dump978/uat2json" ]] || [[ ! -f "${RECEIVER_BUILD_DIRECTORY}/dump978/uat2text" ]] ; then # If the dump978 binaries could not be found halt setup. - echo "" + echo -e "" 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 "" echo -e "\e[93mThe dump978 binaries appear to have not been built successfully..\e[39m" - echo "" - echo -e "\e[93m-------------------------------------------------------------------------------------------------------" + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m Dump978 setup halted.\e[39m" - echo "" + echo -e "" read -p "Press enter to continue..." CONTINUE exit 1 fi ## SETUP AND CONFIGURE THE DEVICE TO UTILIZE THE DDUMP978 BINARIES -echo "" +echo -e "" echo -e "\e[95m Configuring the device to utilize the dump978 binaries...\e[97m" -echo "" +echo -e "" + +### BLACKLIST UNWANTED RTL-SDR MODULES # 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 ; then echo -e "\e[94m Removing the kernel module dvb_usb_rtl28xxu...\e[97m" @@ -189,109 +228,118 @@ fi # Check if the dump1090-mutability package is installed. echo -e "\e[94m Checking if the dump1090-mutability package is installed...\e[97m" -if [ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]; then +if [[ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then # The dump1090-mutability package appear to be installed. - whiptail --backtitle "$ADSB_PROJECTTITLE" --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 --backtitle "$ADSB_PROJECTTITLE" --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 --backtitle "$ADSB_PROJECTTITLE" --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 - + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --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 + # Ask the user which USB device is to be used for dump1090. + DUMP1090_DEVICE_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump1090 RTL-SDR Dongle" --nocancel --inputbox "\nEnter the ID for your dump1090 RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DUMP1090_DEVICE_ID}" ]] ; do + DUMP1090_DEVICE_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump1090 RTL-SDR Dongle (REQUIRED)" --nocancel --inputbox "\nEnter the ID for your dump1090 RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + done + # Ask the user which USB device is to be use for dump978. + DUMP978_DEVICE_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump978 RTL-SDR Dongle" --nocancel --inputbox "\nEnter the ID for your dump978 RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DUMP978_DEVICE_ID}" ]] ; do + DUMP978_DEVICE_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump978 RTL-SDR Dongle (REQUIRED)" --nocancel --inputbox "\nEnter the ID for your dump978 RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + done + fi # 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 -e "\e[94m Assigning RTL-SDR dongle \"${DUMP1090_DEVICE_ID}\" to dump1090-mutability...\e[97m" + ChangeConfig "DEVICE" ${DUMP1090_DEVICE_ID} "/etc/default/dump1090-mutability" echo -e "\e[94m Restarting dump1090-mutability...\e[97m" - echo "" + echo -e "" sudo /etc/init.d/dump1090-mutability restart - echo "" + echo -e "" # Get the latitude and longitude set in the dump1090-mutability configuration file to be used later. echo -e "\e[94m Retrieving the receiver's latitude from /etc/default/dump1090-mutability...\e[97m" - RECEIVERLATITUDE=`GetConfig "LAT" "/etc/default/dump1090-mutability"` + RECEIVER_LATITUDE=`GetConfig "LAT" "/etc/default/dump1090-mutability"` echo -e "\e[94m Retrieving the receiver's longitude from /etc/default/dump1090-mutability...\e[97m" - RECIEVERLONGITUDE=`GetConfig "LON" "/etc/default/dump1090-mutability"` + RECEIVER_LONGITUDE=`GetConfig "LON" "/etc/default/dump1090-mutability"` fi # If a device has not yet been assigned to dump978 assign the first available. -if [ -z $DUMP978DEVICE ]; then +if [[ -z "${DUMP978_DEVICE_ID}" ]] ; then echo -e "\e[94m Assigning RTL-SDR dongle \"0\" to dump978...\e[97m" - DUMP978DEVICE="0" + DUMP978_DEVICE_ID="0" fi -# Declare the LIGHTTPDDOCUMENTROOTDIRECTORY variable. +# Declare the LIGHTTPD_DOCUMENT_ROOT_DIRECTORY variable. 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` +LIGHTTPD_DOCUMENT_ROOT_SETTING=`/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -p | grep server.document-root` +LIGHTTPD_DOCUMENT_ROOT_DIRECTORY=`sed 's/.*"\(.*\)"[^"]*$/\1/' <<< ${LIGHTTPD_DOCUMENT_ROOT_SETTING}` # Set the receivers latitude and longitude. -if [ -z $RECEIVERLATITUDE ] && [ -z $RECEIVERLONGITUDE ]; then - # If dump1090-mutability is not installed ask for the latitude and longitude of this receiver. - RECEIVERLATITUDE=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Receiver Latitude (OPTIONAL)" --nocancel --inputbox "\nEnter your receiver's latitude.\n(Example: XX.XXXXXXX)\n\nLeave blank and select to skip." 12 78 3>&1 1>&2 2>&3) - RECEIVERLONGITUDE_TITLE="Receiver Longitude" - while [[ -z $RECEIVERLONGITUDE ]]; do - RECEIVERLONGITUDE=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --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)" +if [[ -z "${RECEIVER_LATITUDE}" ]] && [[ -z "${RECEIVER_LONGITUDE}" ]] && [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # If the receiver's' latitude has not yet been set ask for it. + RECEIVER_LATITUDE_TITLE="Receiver Latitude" + while [[ -z "${RECEIVER_LATITUDE}" ]] ; do + RECEIVER_LATITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LATITUDE_TITLE}" --nocancel --inputbox "\nEnter your receiver's latitude.\n(Example: XX.XXXXXXX)" 9 78 3>&1 1>&2 2>&3) + RECEIVER_LATITUDE_TITLE="Receiver Latitude (REQUIRED)" + done + # If the receiver's' longitude has not yet been set ask for it. + RECEIVER_LONGITUDE_TITLE="Receiver Longitude" + while [[ -z "${RECEIVER_LONGITUDE}" ]] ; do + RECEIVER_LONGITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LONGITUDE_TITLE}" --nocancel --inputbox "\nEnter your receiver's longitude.\n(Example: XX.XXXXXXX)" 9 78 3>&1 1>&2 2>&3) + RECEIVER_LONGITUDE_TITLE="Receiver Latitude (REQUIRED)" done fi -if [ ! -z $RECEIVERLATITUDE ] && [ ! -z $RECEIVERLONGITUDE ]; then - echo -e "\e[94m Setting the receiver's latitude to $RECEIVERLATITUDE...\e[97m" - ChangeConfig "SiteLat" "$RECEIVERLATITUDE" "$LIGHTTPDDOCUMENTROOTDIRECTORY/dump978/config.js" - echo -e "\e[94m Setting the receiver's longitude to $RECEIVERLONGITUDE...\e[97m" - ChangeConfig "SiteLon" "$RECEIVERLONGITUDE" "$LIGHTTPDDOCUMENTROOTDIRECTORY/dump978/config.js" +# Finally set the reciver's latitude and longitude if these variables were supplied. +if [[ -n "${RECEIVER_LATITUDE}" ]] && [[ -n "${RECEIVER_LONGITUDE}" ]] ; then + echo -e "\e[94m Setting the receiver's latitude to ${RECEIVER_LATITUDE}...\e[97m" + ChangeConfig "SiteLat" "${RECEIVER_LATITUDE}" "${LIGHTTPD_DOCUMENT_ROOT_DIRECTORY}/dump978/config.js" + echo -e "\e[94m Setting the receiver's longitude to ${RECEIVER_LONGITUDE}...\e[97m" + ChangeConfig "SiteLon" "${RECEIVER_LONGITUDE}" "${LIGHTTPD_DOCUMENT_ROOT_DIRECTORY}/dump978/config.js" fi # Create the dump978 JSON directory in Lighttpd's document root. echo -e "\e[94m Creating the dump978 JSON data directory within Lighttpd's document root...\e[97m" -sudo mkdir -p $LIGHTTPDDOCUMENTROOTDIRECTORY/dump978/data +sudo mkdir -vp ${LIGHTTPD_DOCUMENT_ROOT_DIRECTORY}/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 +sudo chmod +w ${LIGHTTPD_DOCUMENT_ROOT_DIRECTORY}/dump978/data # Create the dump978 maintenance script. echo -e "\e[94m Creating the dump978 maintenance script...\e[97m" -tee $DUMP978BUILDDIRECTORY/dump978-maint.sh > /dev/null < /dev/null <($DUMP978BUILDDIRECTORY/uat2json $LIGHTTPDDOCUMENTROOTDIRECTORY/dump978/data) | $DUMP978BUILDDIRECTORY/uat2esnt | /bin/nc -q1 127.0.0.1 30001 + rtl_sdr -d ${DUMP978_DEVICE_ID} -f 978000000 -s 2083334 -g 48 - | ${RECEIVER_BUILD_DIRECTORY}/dump978 | tee >(${RECEIVER_BUILD_DIRECTORY}/uat2json ${LIGHTTPD_DOCUMENT_ROOT_DIRECTORY}/dump978/data) | ${RECEIVER_BUILD_DIRECTORY}/uat2esnt | /bin/nc -q1 127.0.0.1 30001 sleep 15 done EOF echo -e "\e[94m Setting permissions on the dump978 maintenance script...\e[97m" -chmod +x $DUMP978BUILDDIRECTORY/dump978-maint.sh +chmod +x ${RECEIVER_BUILD_DIRECTORY}/dump978/dump978-maint.sh # 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 +if [[ `grep -cFx "${RECEIVER_BUILD_DIRECTORY}/dump978/dump978-maint.sh &" /etc/rc.local` -eq 0 ]] ; 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 + ((LINENUMBER>0)) && sudo sed -i "${LINENUMBER[$((${#LINENUMBER[@]}-1))]}i ${RECEIVER_BUILD_DIRECTORY}/dump978/dump978-maint.sh &\n" /etc/rc.local fi ## EXECUTE THE MAINTAINANCE SCRIPT TO START DUMP978 -echo "" +echo -e "" echo -e "\e[95m Starting dump978...\e[97m" -echo "" +echo -e "" echo -e "\e[94m Starting dump978 by executing the dump978 maintenance script...\e[97m" -sudo nohup $DUMP978BUILDDIRECTORY/dump978-maint.sh > /dev/null 2>&1 & +sudo nohup ${RECEIVER_BUILD_DIRECTORY}/dump978/dump978-maint.sh > /dev/null 2>&1 & -## DUMP978 SETUP COMPLETE +### SETUP COMPLETE -# Enter into the project root directory. +# Return to the project root directory. echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" -cd $PROJECTROOTDIRECTORY +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 -echo "" -echo -e "\e[93m-------------------------------------------------------------------------------------------------------" +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m Dump978 setup is complete.\e[39m" -echo "" -read -p "Press enter to continue..." CONTINUE +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi exit 0 diff --git a/bash/decoders/rtlsdr-ogn.sh b/bash/decoders/rtlsdr-ogn.sh index 52e77c4..f2a9276 100644 --- a/bash/decoders/rtlsdr-ogn.sh +++ b/bash/decoders/rtlsdr-ogn.sh @@ -9,7 +9,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Copyright (c) 2015 Joseph A. Prochazka # +# Copyright (c) 2016-2017, Joseph A. Prochazka & Romeo Golf # # # # 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,127 +31,394 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -BUILDDIR=$PWD +### VARIABLES -source ../bash/functions.sh +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" -clear +# Component specific variables. -echo "http://wiki.glidernet.org" -echo "" -echo -e "\033[31mBEFORE CONTINUING:\033[33m" -echo "RTLSDR-OGN requires it's own dedicated dongle." -echo "" -echo -e "\033[37m" -read -p "Press enter to continue..." CONTINUE +# Component service script variables. -## CHECK FOR PREREQUISITE PACKAGES +### INCLUDE EXTERNAL SCRIPTS -CheckPackage git -CheckPackage wget -CheckPackage rtl-sdr -CheckPackage librtlsdr-dev -CheckPackage libusb-1.0-0-dev -CheckPackage libconfig-dev -CheckPackage fftw3-dev -CheckPackage libjpeg-dev -CheckPackage libconfig9 +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh -## BLACKLIST UNWANTED RTL-SDR MODULES FROM BEING LOADED +# To be moved to functions.sh... -echo -e "\033[33mStopping unwanted kernel modules from being loaded..." -echo -e "\033[37m" -sudo tee /etc/modprobe.d/rtlsdr-blacklist.conf > /dev/null < /dev/null </dev/null | grep -c "ok installed") -eq 1 ]] ; then + DUMP1090_IS_INSTALLED="true" +# Check if the dump1090-fa package is installed. +elif [[ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then + DUMP1090_IS_INSTALLED="true" +else + DUMP1090_IS_INSTALLED="false" +fi + +# Check if the dump978 binaries exist. +echo -e "\e[94m Checking if the dump978 binaries exist on this device...\e[97m" +if [[ -f "${RECEIVER_BUILD_DIRECTORY}/dump978/dump978" ]] && [[ -f "${RECEIVER_BUILD_DIRECTORY}/dump978/uat2text" ]] && [[ -f "${RECEIVER_BUILD_DIRECTORY}/dump978/uat2esnt" ]] && [[ -f "${RECEIVER_BUILD_DIRECTORY}/dump978/uat2json" ]] ; then + DUMP978_IS_INSTALLED="true" +else + DUMP978_IS_INSTALLED="false" +fi + +# If either dump1090 or dump978 is installed we must assign RTL-SDR dongles for each of these decoders. +if [[ "${DUMP1090_IS_INSTALLED}" = "true" ]] || [[ "${DUMP978_IS_INSTALLED}" = "true" ]] ; then + # Check if Dump1090 is installed. + if [[ "${DUMP1090_IS_INSTALLED}" = "true" ]] ; then + # The dump1090-mutability package appear to be installed. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Ask the user which USB device is to be used for dump1090. + DUMP1090_DEVICE_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump1090 RTL-SDR Dongle" --nocancel --inputbox "\nEnter the ID for your dump1090 RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DUMP1090_DEVICE_ID}" ]] ; do + DUMP1090_DEVICE_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump1090 RTL-SDR Dongle (REQUIRED)" --nocancel --inputbox "\nEnter the ID for your dump1090 RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + done + else + ### GET DONGLE ID FROM THE INSTALLATION CONFIGURATION FILE... + true + fi + fi + # Check if Dump978 is installed. + if [[ "${DUMP978_IS_INSTALLED}" = "true" ]] ; then + # The dump978 binaries appear to exist on this device. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Ask the user which USB device is to be use for dump978. + DUMP978_DEVICE_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump978 RTL-SDR Dongle" --nocancel --inputbox "\nEnter the ID for your dump978 RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DUMP978_DEVICE_ID}" ]] ; do + DUMP978_DEVICE_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump978 RTL-SDR Dongle (REQUIRED)" --nocancel --inputbox "\nEnter the ID for your dump978 RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + done + else + ### GET DONGLE ID FROM THE INSTALLATION CONFIGURATION FILE... + true + fi + fi + # + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Ask the user which USB device is to be use for RTL-SDR OGN. + RTLSDROGN_DEVICE_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "RTL-SDR OGN RTL-SDR Dongle" --nocancel --inputbox "\nEnter the ID for your RTL-SDR OGN RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DUMP978_DEVICE_ID}" ]] ; do + RTLSDROGN_DEVICE_ID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "RTL-SDR OGN RTL-SDR Dongle (REQUIRED)" --nocancel --inputbox "\nEnter the ID for your RTL-SDR OGN RTL-SDR dongle." 8 78 3>&1 1>&2 2>&3) + done + else + ### GET DONGLE ID FROM THE INSTALLATION CONFIGURATION FILE... + true + fi + # Assign the specified RTL-SDR dongle to dump1090. + if [[ "${DUMP1090_IS_INSTALLED}" = "true" ]] && [[ -n "${DUMP1090_DEVICE_ID}" ]] ; then + echo -e "\e[94m Assigning RTL-SDR dongle \"${DUMP1090_DEVICE_ID}\" to dump1090-mutability...\e[97m" + ChangeConfig "DEVICE" ${DUMP1090_DEVICE_ID} "/etc/default/dump1090-mutability" + echo -e "\e[94m Reloading dump1090-mutability...\e[97m" + echo -e "" + sudo /etc/init.d/dump1090-mutability force-reload + echo -e "" + fi + # Assign the specified RTL-SDR dongle to dump978 + if [[ "${DUMP978_IS_INSTALLED}" = "true" ]] && [[ -n "${DUMP978_DEVICE_ID}" ]] ; then + echo -e "\e[94m Assigning RTL-SDR dongle \"${DUMP978_DEVICE_ID}\" to dump978...\e[97m" + ### ADD DEVICE TO MAINTENANCE SCRIPT... + echo -e "\e[94m Reloading dump978...\e[97m" + ### KILL EXISTING DUMP978 PROCESSES... + echo -e "" + ### RESTART DUMP978... + echo -e "" + fi +fi + +### ASSIGN RTL-SDR DONGLE FOR RTL-SDR OGN... + +### DOWNLOAD AND SET UP THE BINARIES + +# Create build directory if not already present. +if [[ ! -d "${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn" ]] ; then + echo -e "\e[94m Creating the directory (${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn)...\e[97m" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn +fi + +# Enter the build directory. +if [[ ! "${PWD}" = "${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn" ]] ; then + echo -e "\e[94m Entering the directory (${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn)...\e[97m" + cd ${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn 2>&1 +fi + +# Use function to detect cpu architecture. +if [[ -z "${CPU_ARCHITECTURE}" ]] ; then + Check_CPU + echo -e "" +fi + +# Identify the correct binaries to download. +case ${CPU_ARCHITECTURE} in "armv6l") - # Raspberry Pi 1 - wget http://download.glidernet.org/rpi-gpu/rtlsdr-ogn-bin-RPI-GPU-latest.tgz -O $BUILDDIR/rtlsdr-ogn-bin-RPI-GPU-latest.tgz - tar xvzf rtlsdr-ogn-bin-RPI-GPU-latest.tgz -C $BUILDDIR + # Raspberry Pi 1. + COMPONENT_BINARY_URL="http://download.glidernet.org/rpi-gpu/rtlsdr-ogn-bin-RPI-GPU-latest.tgz" + echo -e "\e[94m Downloading the latest RTL-SDR OGN RPI-GPU binaries...\e[97m" + echo -e "" + wget "${COMPONENT_BINARY_URL}" -O "${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn/rtlsdr-ogn-bin-RPI-GPU-latest.tgz" + echo -e "" + echo -e "\e[94m Extracting the latest RTL-SDR OGN RPI-GPU binaries from the archive...\e[97m" + echo -e "" + tar xvzf rtlsdr-ogn-bin-RPI-GPU-latest.tgz -C ${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn ;; "armv7l") - # Raspberry Pi 2 - wget http://download.glidernet.org/arm/rtlsdr-ogn-bin-ARM-latest.tgz -O $BUILDDIR/rtlsdr-ogn-bin-ARM-latest.tgz - tar xvzf rtlsdr-ogn-bin-ARM-latest.tgz -C $BUILDDIR + # Raspberry Pi 2 onwards. + COMPONENT_BINARY_URL="http://download.glidernet.org/arm/rtlsdr-ogn-bin-ARM-latest.tgz" + echo -e "\e[94m Downloading the latest RTL-SDR OGN ARM binaries...\e[97m" + echo -e "" + wget "${COMPONENT_BINARY_URL}" -O "${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn/rtlsdr-ogn-bin-ARM-latest.tgz" + echo -e "" + echo -e "\e[94m Extracting the latest RTL-SDR OGN ARM binaries from the archive...\e[97m" + echo -e "" + tar xvzf rtlsdr-ogn-bin-ARM-latest.tgz -C ${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn ;; "x86_64") - # 64 Bit - wget http://download.glidernet.org/x64/rtlsdr-ogn-bin-x64-latest.tgz -O $BUILDDIR/rtlsdr-ogn-bin-x64-latest.tgz - tar xvzf rtlsdr-ogn-bin-x64-latest.tgz -C $BUILDDIR + # 64 Bit. + COMPONENT_BINARY_URL="http://download.glidernet.org/x64/rtlsdr-ogn-bin-x64-latest.tgz" + echo -e "\e[94m Downloading the latest RTL-SDR OGN x64 binaries...\e[97m" + echo -e "" + wget "${COMPONENT_BINARY_URL}" -O "${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn/rtlsdr-ogn-bin-x64-latest.tgz" + echo -e "" + echo -e "\e[94m Extracting the latest RTL-SDR OGN x64 binaries from the archive...\e[97m" + echo -e "" + tar xvzf rtlsdr-ogn-bin-x64-latest.tgz -C ${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn ;; *) - # 32 Bit (default install if no others matched) - wget http://download.glidernet.org/x86/rtlsdr-ogn-bin-x86-latest.tgz -O $BUILDDIR/rtlsdr-ogn-bin-x86-latest.tgz - tar xvzf rtlsdr-ogn-bin-x86-latest.tgz -C $BUILDDIR + # 32 Bit (default install if no others matched). + COMPONENT_BINARY_URL="http://download.glidernet.org/x86/rtlsdr-ogn-bin-x86-latest.tgz" + echo -e "\e[94m Downloading the latest RTL-SDR OGN x86 binaries...\e[97m" + echo -e "" + wget "${COMPONENT_BINARY_URL}" -O "${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn/rtlsdr-ogn-bin-x86-latest.tgz" + echo -e "" + echo -e "\e[94m Extracting the latest RTL-SDR OGN x86 binaries from the archive...\e[97m" + echo -e "" + tar xvzf rtlsdr-ogn-bin-x86-latest.tgz -C ${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn ;; esac -# Create named pipe -cd $BUILDDIR/rtlsdr-ogn -sudo mkfifo ogn-rf.fifo +# Change to component work directory for post-build actions. +echo -e "" +echo -e "\e[94m Entering the directory containing the RTL-SDR binaries...\e[97m" +cd ${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn/rtlsdr-ogn 2>&1 -# Set file permissions. -sudo chown root gsm_scan -sudo chmod a+s gsm_scan -sudo chown root rtlsdr-ogn -sudo chmod a+s rtlsdr-ogn - -# Check if kernel v4.1 or higher is being used. - -KERNEL=`uname -r` -VERSION="`echo $KERNEL | cut -d \. -f 1`.`echo $KERNEL | cut -d \. -f 2`" - -if [[ $VERSION < 4.1 ]]; then - # Kernel is older than version 4.1. - sudo mknod gpu_dev c 100 0 -else - # Kernel is version 4.1 or newer. - sudo mknod gpu_dev c 249 0 +# Create named pipe if required. +if [[ ! -p "ogn-rf.fifo" ]] ; then + echo -e "\e[94m Creating named pipe...\e[97m" + sudo mkfifo ogn-rf.fifo fi -## CREATE THE CONFIGURATION FILE +# Set file permissions. +echo -e "\e[94m Setting proper file permissions...\e[97m" +sudo chown root gsm_scan +sudo chmod a+s gsm_scan +sudo chown root ogn-rf +sudo chmod a+s ogn-rf +sudo chown root rtlsdr-ogn +sudo chmod a+s rtlsdr-ogn +# And check that the file permissions have been applied. + +# Creat GPU device if required. +if [[ ! -c "gpu_dev" ]] ; then + # The mknod major_version number varies with kernel version. + echo -e "\e[94m Getting the version of the kernel currently running...\e[97m" + KERNEL=`uname -r` + RECEIVER_KERNEL_VERSION=`echo ${KERNEL} | cut -d \. -f 1`.`echo ${KERNEL} | cut -d \. -f 2` + # Check if the currently running kernel is version 4.1 or higher. + if [[ "${RECEIVER_KERNEL_VERSION}" < 4.1 ]] ; then + # Kernel is older than version 4.1. + echo -e "\e[94m Executing mknod for older kernels...\e[97m" + sudo mknod gpu_dev c 100 0 + else + # Kernel is version 4.1 or newer. + echo -e "\e[94m Executing mknod for newer kernels...\e[97m" + sudo mknod gpu_dev c 249 0 + fi +fi + +## GATHER INFORMATION FROM USER -####################################################### -# CREATE THE CONFIGURATION FILE # -# http://wiki.glidernet.org/wiki:receiver-config-file # -####################################################### +# Latitude. +# Longitude. -## INSTALL AS A SERVICE +# Altitude. -echo -e "\033[33mDownloading and setting permissions on the init script..." -echo -e "\033[37m" +# Check for component specific variables, otherwise populate with dummy values to ensure valid config generation. + +# Ask if user would like to calibrate the tuner. + +### CREATE THE CONFIGURATION FILE + +# Update existing or create new config file. +######################################################### +# # +# CREATE THE CONFIGURATION FILE # +# # +# http://wiki.glidernet.org/wiki:receiver-config-file # +# # +######################################################### + +# Update ownership of new config file. + +### INSTALL AS A SERVICE + +# Install service script. +echo -e "\e[94m Downloading and setting permissions on the init script...\e[97m" +echo -e "" sudo wget http://download.glidernet.org/common/service/rtlsdr-ogn -O /etc/init.d/rtlsdr-ogn sudo chmod +x /etc/init.d/rtlsdr-ogn -echo -e "\033[33mCreating file /etc/rtlsdr-ogn.conf..." -echo -e "\033[37m" +# Generate and install service script configuration file. +echo -e "\e[94m Creating the file /etc/rtlsdr-ogn.conf...\e[97m" +echo -e "" sudo tee /etc/rtlsdr-ogn.conf > /dev/null < #Syntax: #port user directory command args -50000 pi ${BUILDDIR}/rtlsdr-ogn ./ogn-rf rtlsdr-ogn.conf -50001 pi ${BUILDDIR}/rtlsdr-ogn ./ogn-decode rtlsdr-ogn.conf +50000 pi ${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn/rtlsdr-ogn ./ogn-rf rtlsdr-ogn.conf +50001 pi ${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn/rtlsdr-ogn ./ogn-decode rtlsdr-ogn.conf EOF -echo -e "\033[33mSetting up rtlsdr-ogn as a service..." -echo -e "\033[37m" +# Configure component as a service. +echo -e "\e[94m Setting up rtlsdr-ogn as a service...\e[97m" +echo -e "" sudo update-rc.d rtlsdr-ogn defaults -echo -e "\033[33mStarting the rtlsdr-ogn service..." -echo -e "\033[37m" +# (re)start the component service. +echo -e "\e[94m Starting the rtlsdr-ogn service...\e[97m" +echo -e "" sudo service rtlsdr-ogn start + +### SETUP COMPLETE + +# Return to the project root directory. +echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 + +echo -e "\e[93m ------------------------------------------------------------------------------\n" +echo -e "\e[92m RTL-SDR OGN setup is complete.\e[39m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi + +exit 0 diff --git a/bash/extras/abovetustin.sh b/bash/extras/abovetustin.sh index e2e856a..2881997 100644 --- a/bash/extras/abovetustin.sh +++ b/bash/extras/abovetustin.sh @@ -31,149 +31,163 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -## VARIABLES +## SET INSTALLATION VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -PHANTOMJSBUILDDIRECTORY="$BUILDDIRECTORY/phantomjs" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" -## INCLUDE EXTERNAL SCRIPTS +# Component specific variables. -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +COMPONENT_NAME="AboveTustin" +COMPONENT_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/abovetustin" -## BEGIN SETUP +### INCLUDE EXTERNAL SCRIPTS -clear -echo -e "\n\e[91m $ADSB_PROJECTTITLE" -echo "" -echo -e "\e[92m Setting up AboveTustin..." -echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" -echo "" -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "AboveTustin Setup" --yesno "AboveTustin is an ADS-B Twitter Bot. Uses dump1090-mutability to track airplanes and then tweets whenever an airplane flies overhead.\n\n https://github.com/kevinabrandon/AboveTustin\n\nContinue setting up AboveTustin?" 13 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 AboveTustin setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE - exit 1 +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "true" ]] && [[ -s "${RECEIVER_CONFIGURATION_FILE}" ]] ; then + source ${RECEIVER_CONFIGURATION_FILE} fi -## CHECK IF A PHANTOMJS ALREADY EXISTS OR IF A PRECOMPILED BINARY IS AVAILABLE FOR THIS DEVICE +### BEGIN SETUP + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +fi +echo -e "" +echo -e "\e[92m Setting up ${COMPONENT_NAME}..." +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${COMPONENT_NAME} Setup" --yesno "${COMPONENT_NAME} is an ADS-B Twitter Bot. Uses dump1090-mutability to track airplanes and then tweets whenever an airplane flies overhead.\n\n https://github.com/kevinabrandon/AboveTustin\n\nContinue setting up ${COMPONENT_NAME}?" 13 78 + if [[ $? -eq 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 -e "" + echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi +fi + +echo -e "\e[95m Setting up ${COMPONENT_NAME} on this device...\e[97m" +echo -e "" + +## ENABLE THE USE OF /ETC/RC.LOCAL IF THE FILE DOES NOT EXIST + +if [ ! -f /etc/rc.local ]; then + echo "" + echo -e "\e[95m Enabling the use of the /etc/rc.local file...\e[97m" + echo "" + + # In Debian Stretch /etc/rc.local has been removed. + # However at this time we can bring this file back into play. + # As to if in future releases this will work remains to be seen... + + echo -e "\e[94m Creating the file /etc/rc.local...\e[97m" + sudo tee /etc/rc.local > /dev/null <&1 1>&2 2>&3) - TWITTERACCESSTOKEN_TITLE="Twitter Access Token (REQUIRED)" -done -TWITTERACCESSTOKENSECRET_TITLE="Twitter Access Token Secret" -while [[ -z $TWITTERACCESSTOKENSECRET ]]; do - TWITTERACCESSTOKENSECRET="" - if [ -f $BUILDDIRECTORY/AboveTustin/keys/token_secret ]; then - TWITTERACCESSTOKENSECRET=`cat $BUILDDIRECTORY/AboveTustin/keys/token_secret` - fi - TWITTERACCESSTOKENSECRET=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$TWITTERACCESSTOKENSECRET_TITLE" --nocancel --inputbox "\nEnter your Twitter Access Token Secret." 7 " $TWITTERACCESSTOKENSECRET"78 3>&1 1>&2 2>&3) - TWITTERACCESSTOKENSECRET_TITLE="Twitter Access Token Secret (REQUIRED)" -done -TWITTERCONSUMERKEY_TITLE="Twitter Consumer Key" -while [[ -z $TWITTERCONSUMERKEY ]]; do - TWITTERCONSUMERKEY="" - if [ -f $BUILDDIRECTORY/AboveTustin/keys/consumer_key ]; then - TWITTERCONSUMERKEY=`cat $BUILDDIRECTORY/AboveTustin/keys/consumer_key` - fi - TWITTERCONSUMERKEY=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$TWITTERCONSUMERKEY_TITLE" --nocancel --inputbox "\nEnter your Twitter Consumer Key." 7 78 "TWITTERCONSUMERKEY" 3>&1 1>&2 2>&3) - TWITTERCONSUMERKEY_TITLE="Twitter Consumer Key (REQUIRED)" -done -TWITTERCONSUMERSECRET_TITLE="Twitter Consumer Secret" -while [[ -z $TWITTERCONSUMERSECRET ]]; do - TWITTERCONSUMERSECRET="" - if [ -f $BUILDDIRECTORY/AboveTustin/keys/consumer_secret ]; then - TWITTERCONSUMERSECRET=`cat $BUILDDIRECTORY/AboveTustin/keys/consumer_secret` - fi - TWITTERCONSUMERSECRET=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$TWITTERCONSUMERSECRET_TITLE" --nocancel --inputbox "\nEnter your Twitter Consumer Secret." 7 78 "$TWITTERCONSUMERSECRET" 3>&1 1>&2 2>&3) - TWITTERCONSUMERSECRET_TITLE="Twitter Consumer Secret (REQUIRED)" -done - -## CHECK FOR PREREQUISITE PACKAGES +### CHECK FOR PREREQUISITE PACKAGES +echo -e "" echo -e "\e[95m Installing packages needed to build and fulfill dependencies...\e[97m" -echo "" +echo -e "" # The package ttf-mscorefonts-installer requires contrib be added to the Debian repositories contained in /etc/apt/sources.list. # The contrib flag does not need to be added for Raspbian Jessie and Ubuntu only Debian so far. -if [ `lsb_release -si` = "Debian" ]; then +if [[ `lsb_release -si` = "Debian" ]] ; then echo -e "\e[94m Adding the contrib component to the repositories contained sources.list...\e[97m" - sudo sed -i 's/main/main contrib/g' /etc/apt/sources.list + sudo sed -i 's/main/main contrib/g' /etc/apt/sources.list 2>&1 echo -e "\e[94m Updating the repository package lists...\e[97m" - sudo apt-get update + sudo apt-get update 2>&1 fi + +# Check that the required packages are installed. CheckPackage ttf-mscorefonts-installer CheckPackage python3-pip CheckPackage libstdc++6 @@ -194,8 +208,9 @@ CheckPackage libx11-dev CheckPackage libxext-dev CheckPackage libpng12-dev CheckPackage libc6 +CheckPackage curl -if [ $BINARYAVAILABLE = "false" ]; then +if [[ "${PHANTOMJS_BINARY_AVAILABLE}" = "false" ]] ; then # These packages are only needed if the user decided to build PhantomJS. CheckPackage build-essential CheckPackage g++ @@ -204,264 +219,445 @@ else CheckPackage bzip2 fi -## SETUP PHANTOMJS IF IT DOES NOT ALREADY EXIST ON THIS DEVICE +### CONFIRM SETTINGS -if [ $PHANTOMJSEXISTS = "false" ]; then - if [ $BINARYAVAILABLE = "true" ]; then +# GATHER TWITTER API INFORMATION FROM THE USER + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Twiter Keys and Tokens" --yesno "In order to send Tweets to Twitter using ${COMPONENT_NAME} you will need to obtain the proper keys and tokens from Twitter. You will need to sign up for a Twitter developer account at https://apps.twitter.com and create an application there in order to obtain this information.\n\nMore information on obtaining Twitter keys and access tokens can be found in the projects wiki page.\n\n https://github.com/jprochazka/adsb-receiver/wiki/Setting-Up-AboveTustin\n\nProceed with the ${COMPONENT_NAME} setup?" 20 78 + if [[ $? -eq 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 -e "" + echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi +fi + +# If any exist assign the current Twitter keys and access tokens to variables. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + TWITTER_ACCESS_TOKEN_TITLE="Twitter Access Token" + while [[ -z "${TWITTER_ACCESS_TOKEN}" ]] ; do + if [[ `grep -c "^access_token =" ${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini` -gt 0 ]] ; then + TWITTER_ACCESS_TOKEN=$(grep "^access_token =" "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" | awk '{print $3}') + fi + TWITTER_ACCESS_TOKEN=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${TWITTER_ACCESS_TOKEN_TITLE}" --nocancel --inputbox "\nEnter your Twitter Access Token." 7 78 "${TWITTER_ACCESS_TOKEN}" 3>&1 1>&2 2>&3) + TWITTER_ACCESS_TOKEN_TITLE="Twitter Access Token (REQUIRED)" + done + # + TWITTER_ACCESS_TOKEN_SECRET_TITLE="Twitter Access Token Secret" + while [[ -z "${TWITTER_ACCESS_TOKEN_SECRET}" ]] ; do + if [[ `grep -c "^access_token_secret =" ${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini` -gt 0 ]] ; then + TWITTER_ACCESS_TOKEN_SECRET=$(grep "^access_token_secret =" "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" | awk '{print $3}') + fi + TWITTER_ACCESS_TOKEN_SECRET=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${TWITTER_ACCESS_TOKEN_SECRET_TITLE}" --nocancel --inputbox "\nEnter your Twitter Access Token Secret." 7 78 "${TWITTER_ACCESS_TOKEN_SECRET}" 3>&1 1>&2 2>&3) + TWITTER_ACCESS_TOKEN_SECRET_TITLE="Twitter Access Token Secret (REQUIRED)" + done + # + TWITTER_CONSUMER_KEY_TITLE="Twitter Consumer Key" + while [[ -z "${TWITTER_CONSUMER_KEY}" ]] ; do + if [[ `grep -c "^consumer_key =" ${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini` -gt 0 ]] ; then + TWITTER_CONSUMER_KEY=$(grep "^consumer_key =" "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" | awk '{print $3}') + fi + TWITTER_CONSUMER_KEY=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${TWITTER_CONSUMER_KEY_TITLE}" --nocancel --inputbox "\nEnter your Twitter Consumer Key." 7 78 "${TWITTER_CONSUMER_KEY}" 3>&1 1>&2 2>&3) + TWITTER_CONSUMER_KEY_TITLE="Twitter Consumer Key (REQUIRED)" + done + # + TWITTER_CONSUMER_SECRET_TITLE="Twitter Consumer Secret" + while [[ -z "${TWITTER_CONSUMER_SECRET}" ]] ; do + if [[ `grep -c "^consumer_secret =" ${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini` -gt 0 ]] ; then + TWITTER_CONSUMER_SECRET=$(grep "^consumer_secret =" "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" | awk '{print $3}') + fi + TWITTER_CONSUMER_SECRET=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${TWITTER_CONSUMER_SECRET_TITLE}" --nocancel --inputbox "\nEnter your Twitter Consumer Secret." 7 78 "${TWITTER_CONSUMER_SECRET}" 3>&1 1>&2 2>&3) + TWITTER_CONSUMER_SECRET_TITLE="Twitter Consumer Secret (REQUIRED)" + done +fi + +# Ask for the receivers latitude and longitude. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Explain to the user that the receiver's latitude and longitude is required. + RECEIVER_LATLON_DIALOG=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Receiver Latitude and Longitude" --msgbox "Your receivers latitude and longitude are required for distance calculations, you will now be asked to supply these values for your receiver.\n\nIf you do not have this information you can obtain it using the web based \"Geocode by Address\" utility hosted on another of the lead developers websites:\n\n https://www.swiftbyte.com/toolbox/geocode" 15 78 3>&1 1>&2 2>&3) + + # Ask the user to confirm the receivers latitude, this will be prepopulated by the latitude assigned dump1090-mutability. + RECEIVER_LATITUDE_TITLE="Receiver Latitude" + while [[ -z "${RECEIVER_LATITUDE}" ]] ; do + if [[ `grep "^latitude = " ${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini | awk '{print $3}' | wc -c` -gt 1 ]] ; then + RECEIVER_LATITUDE=$(grep "^latitude =" "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" | awk '{print $3}') + RECEIVER_LATITUDE_SOURCE=", the value below is configured in AboveTustin" + elif [[ -s "/etc/default/dump1090-mutability" ]] && [[ `grep -c "^LAT =" /etc/default/dump1090-mutability` -gt 0 ]] ; then + RECEIVER_LATITUDE=$(GetConfig "LAT" "/etc/default/dump1090-mutability") + RECEIVER_LATITUDE_SOURCE=", the value below is configured in Dump1090" + fi + RECEIVER_LATITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LATITUDE_TITLE}" --nocancel --inputbox "\nPlease confirm your receiver's latitude${RECEIVER_LATITUDE_SOURCE}:\n" 10 78 -- "${RECEIVER_LATITUDE}" 3>&1 1>&2 2>&3) + RECEIVER_LATITUDE_TITLE="Receiver Latitude (REQUIRED)" + done + + # Ask the user to confirm the receivers longitude, this will be prepopulated by the longitude assigned dump1090-mutability. + RECEIVER_LONGITUDE_TITLE="Receiver Longitude" + while [[ -z "${RECEIVER_LONGITUDE}" ]] ; do + if [[ `grep "^longitude = " ${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini | awk '{print $3}' | wc -c` -gt 1 ]] ; then + RECEIVER_LONGITUDE=$(grep "^longitude =" "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" | awk '{print $3}') + RECEIVER_LONGITUDE_SOURCE=", the value below is configured in AboveTustin" + elif [[ -s "/etc/default/dump1090-mutability" ]] && [[ `grep -c "^LON =" /etc/default/dump1090-mutability` -gt 0 ]] ; then + RECEIVER_LONGITUDE=$(GetConfig "LON" "/etc/default/dump1090-mutability") + RECEIVER_LONGITUDE_SOURCE=", the value below is configured in Dump1090" + fi + RECEIVER_LONGITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LONGITUDE_TITLE}" --nocancel --inputbox "\nEnter your receiver's longitude${RECEIVER_LONGITUDE_SOURCE}:\n" 10 78 -- "${RECEIVER_LONGITUDE}" 3>&1 1>&2 2>&3) + RECEIVER_LONGITUDE_TITLE="Receiver Longitude (REQUIRED)" + done +fi + +### START INSTALLATION + +echo -e "" +echo -e "\e[95m Commencing installation...\e[97m" +echo -e "" + +# Confirm timezone. +if [[ -z "${TIME_ZONE}" ]] ; then + echo -e "\e[94m Confirming time zone...\e[97m" + TIME_ZONE=`cat /etc/timezone 2>&1` + TIME_ZONE_ESCAPED=`echo ${TIME_ZONE} | sed -e 's/\\//\\\\\//g'` +fi + +### PROJECT BUILD DIRECTORY + +# Create the build directory if it does not already exist. +if [[ ! -d "${RECEIVER_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Creating the ADS-B Receiver Project build directory...\e[97m" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY} 2>&1 +fi + +# Create a component directory within the build directory if it does not already exist. +if [[ ! -d "${COMPONENT_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Creating the directory ${COMPONENT_BUILD_DIRECTORY}...\e[97m" + mkdir -vp ${COMPONENT_BUILD_DIRECTORY} 2>&1 +fi + +### SETUP PHANTOMJS IF IT DOES NOT ALREADY EXIST ON THIS DEVICE + +if [[ "${PHANTOMJS_EXISTS}" = "false" ]] ; then + if [[ "${PHANTOMJS_BINARY_AVAILABLE}" = "true" ]] ; then # DOWNLOAD THE PHANTOMJS BINARY - echo "" - echo -e "\e[95m Downloading then placing the PhantomJS binary...\e[97m" - echo "" + echo -e "" + echo -e "\e[95m Downloading and installing the PhantomJS binary...\e[97m" + echo -e "" # Enter the root of the project build directory. - echo -e "\e[94m Entering the ADS-B Receiver Project build directory...\e[97m" - cd $BUILDDIRECTORY + echo -e "\e[94m Entering the build directory...\e[97m" + cd ${COMPONENT_BUILD_DIRECTORY} 2>&1 - # Download the proper PhantomJS binary. - case $CPUARCHITECTURE in - "x86_64") - # Download the x86_64 version of the PhantomJS binary. - echo -e "\e[94m Downloading the official x86_64 PhantomJS v$PHANTOMJSVERSION binary for Linux...\e[97m" - echo "" - wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 + # Select the relevant PhantomJS binary. + case ${CPU_ARCHITECTURE} in + "armv7l") + # Use the armv7l version of the PhantomJS binary from https://github.com/jprochazka/phantomjs-linux-armv7l. + echo -e "\e[94m Downloading the ${CPU_ARCHITECTURE} PhantomJS v${PHANTOMJS_VERSION} binary for Linux...\e[97m" + echo -e "" + PHANTOMJS_BINARY_URL="https://github.com/jprochazka/phantomjs-linux-armv7l/releases/download/${PHANTOMJS_VERSION}/phantomjs-${PHANTOMJS_VERSION}-linux-${CPU_ARCHITECTURE}.tar.bz2" ;; - "i686" - # Download the i686 version of the PantomJS binary. - echo -e "\e[94m Downloading the official i686 PhantomJS v$PHANTOMJSVERSION binary for Linux...\e[97m" - echo "" - wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-i686.tar.bz2 + "x86_64") + # Use the x86_64 version of the PhantomJS binary from the PhantomJS web site. + echo -e "\e[94m Downloading the official ${CPU_ARCHITECTURE} PhantomJS v${PHANTOMJS_VERSION} binary for Linux...\e[97m" + echo -e "" + PHANTOMJS_BINARY_URL="https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${PHANTOMJS_VERSION}-linux-${CPU_ARCHITECTURE}.tar.bz2" + ;; + "i686") + # Use the i686 version of the PantomJS binary from the PhantomJS web site. + echo -e "\e[94m Downloading the official ${CPU_ARCHITECTURE} PhantomJS v${PHANTOMJS_VERSION} binary for Linux...\e[97m" + echo -e "" + PHANTOMJS_BINARY_URL="https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${PHANTOMJS_VERSION}-linux-${CPU_ARCHITECTURE}.tar.bz2" ;; esac - echo -e "\e[94m Extracting the PhantomJS binary archive...\e[97m" - echo "" - bunzip2 -v phantomjs-${PHANTOMJSVERSION}-linux-$PHANTOMJSVERSION.tar.bz2 - tar -vxf phantomjs-${PHANTOMJSVERSION}-linux-$PHANTOMJSVERSION.tar - rm -f phantomjs-${PHANTOMJSVERSION}-linux-$PHANTOMJSVERSION.tar + # Download the PantomJS binary. + if [[ -n "${PHANTOMJS_BINARY_URL}" ]] ; then + curl -L "${PHANTOMJS_BINARY_URL}" -O 2>&1 + fi + + # Extract the files from the PhantomJS archive which was just downloaded. + if [[ -f "phantomjs-${PHANTOMJS_VERSION}-linux-${CPU_ARCHITECTURE}.tar.bz2" ]] ; then + echo -e "\e[94m Extracting the PhantomJS binary archive...\e[97m" + tar -vxj -f phantomjs-${PHANTOMJS_VERSION}-linux-${CPU_ARCHITECTURE}.tar.bz2 2>&1 + echo -e "" + echo -e "\e[94m Removing the PhantomJS binary archive...\e[97m" + rm -vf phantomjs-${PHANTOMJS_VERSION}-linux-${CPU_ARCHITECTURE}.tar.bz2 2>&1 + echo -e "" + else + echo -e "\e[94m Unable to extract the PhantomJS binary archive...\e[97m" + fi # Move the binary into the /usr/bin directory and make it executable. - echo -e "\e[94m Copying the PhantomJS binary into the directory /usr/bin...\e[97m" - sudo cp phantomjs-${PHANTOMJSVERSION}-linux-$PHANTOMJSVERSION/bin/phantomjs /usr/bin - echo -e "\e[94m Making the file /usr/bin/phantomjs executable...\e[97m" - sudo chmod +x /usr/bin/phantomjs + if [[ -f "phantomjs-${PHANTOMJS_VERSION}-linux-${CPU_ARCHITECTURE}/bin/phantomjs" ]] ; then + echo -e "\e[94m Copying the PhantomJS binary into the directory /usr/bin...\e[97m" + echo -e "" + sudo cp -v phantomjs-${PHANTOMJS_VERSION}-linux-${CPU_ARCHITECTURE}/bin/phantomjs /usr/bin 2>&1 + else + echo -e "\e[94m Unable to copying the PhantomJS binary into the directory /usr/bin...\e[97m" + fi + + # Make the binary in /usr/bin executable. + if [[ -f "/usr/bin/phantomjs" ]] ; then + echo -e "\e[94m Making the file /usr/bin/phantomjs executable...\e[97m" + echo -e "" + sudo chmod -v +x /usr/bin/phantomjs 2>&1 + else + echo -e "\e[94m Unable to make the file /usr/bin/phantomjs executable...\e[97m" + fi else # BUILD PHANTOMJS - echo "" + echo -e "" echo -e "\e[95m Building then placing the PhantomJS binary...\e[97m" - echo "" + echo -e "" # Download the source code. - echo "" + echo -e "" echo -e "\e[95m Preparing the PhantomJS Git repository...\e[97m" - echo "" - if [ -d $PHANTOMJSBUILDDIRECTORY ] && [ -d $PHANTOMJSBUILDDIRECTORY/.git ]; then + echo -e "" + if [[ -d "${COMPONENT_BUILD_DIRECTORY}/phantomjs" ]] && [[ -d "${COMPONENT_BUILD_DIRECTORY}/phantomjs/.git" ]] ; then # A directory with a git repository containing the source code already exists. echo -e "\e[94m Entering the PhantomJS git repository directory...\e[97m" - cd $PHANTOMJSBUILDDIRECTORY + cd ${COMPONENT_BUILD_DIRECTORY}/phantomjs 2>&1 + echo -e "" echo -e "\e[94m Updating the local PhantomJS git repository...\e[97m" - echo "" - git pull --all + git pull --all 2>&1 + echo -e "" else # A directory containing the source code does not exist in the build directory. - echo -e "\e[94m Entering the ADS-B Receiver Project build directory...\e[97m" - cd $BUILDDIRECTORY + echo -e "\e[94m Entering the build directory...\e[97m" + cd ${COMPONENT_BUILD_DIRECTORY} 2>&1 + echo -e "" + if [[ -d "${COMPONENT_BUILD_DIRECTORY}/phantomjs" ]] ; then + echo -e "\e[94m Removing old PhantomJS build directory...\e[97m" + rm -vrf "${COMPONENT_BUILD_DIRECTORY}/phantomjs" 2>&1 + echo -e "" + fi echo -e "\e[94m Cloning the PhantomJS git repository locally...\e[97m" - echo "" - git clone git://github.com/ariya/phantomjs.git - echo "" + echo -e "" + git clone git://github.com/ariya/phantomjs.git "${COMPONENT_BUILD_DIRECTORY}/phantomjs" 2>&1 + echo -e "" fi # Enter the PhantomJS build directory if not already there. - if [ ! $PWD = $PHANTOMJSBUILDDIRECTORY ]; then + if [[ ! "${PWD}" = "${COMPONENT_BUILD_DIRECTORY}/phantomjs" ]] ; then echo -e "\e[94m Entering the PhantomJS Git repository directory...\e[97m" - cd $PHANTOMJSBUILDDIRECTORY + cd ${COMPONENT_BUILD_DIRECTORY}/phantomjs 2>&1 fi # Checkout the proper branch then init and update the submodules. - echo -e "\e[94m Checking out the branch $PHANTOMJSVERSION...\e[97m" - echo "" - git checkout $PHANTOMJSVERSION - echo "" + echo -e "\e[94m Checking out the branch ${PHANTOMJS_VERSION}...\e[97m" + echo -e "" + git checkout ${PHANTOMJS_VERSION} 2>&1 + echo -e "" echo -e "\e[94m Initializing Git submodules...\e[97m" - echo "" - git submodule init - echo "" + echo -e "" + git submodule init 2>&1 + echo -e "" echo -e "\e[94m Updating Git submodules...\e[97m" - echo "" - git submodule update - echo "" + echo -e "" + git submodule update 2>&1 + echo -e "" # Compile and link the code. - if [[ `uname -m` == "armv7l" ]] || [[ `uname -m` == "armv6l" ]] || [[ `uname -m` == "aarch64" ]]; then + if [[ "${CPU_ARCHITECTURE}" = "armv7l" ]] || [[ "${CPU_ARCHITECTURE}" = "armv6l" ]] || [[ "${CPU_ARCHITECTURE}" = "aarch64" ]] ; then # Limit the amount of processors being used on Raspberry Pi devices. # Not doing will very likely cause the compile to fail due to an out of memory error. echo -e "\e[94m Building PhantomJS... (Job will be limited to using 1 processor.)\e[97m" - python build.py -j 1 + python build.py -j 1 2>&1 else echo -e "\e[94m Building PhantomJS...\e[97m" - python build.py + python build.py 2>&1 fi - echo "" + echo -e "" # Test that the binary was built properly. - if [ ! -f bin/pahntomjs ] || [ ! `bin/phantomjs --version` = $PHANTOMJSVERSION ]; then + if [[ ! -f "bin/pahntomjs" ]] || [[ ! "`bin/phantomjs --version`" = "${PHANTOMJS_VERSION}" ]] ; then # If the dump978 binaries could not be found halt setup. - echo "" + echo -e "" echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" echo -e " THE PHANTOMJS BINARIES BUILD APPEARS TO HAVE FAILED." echo -e " SETUP HAS BEEN TERMINATED!" - echo "" + echo -e "" echo -e "\e[93mThe PhantomJS binary appear to have not been built successfully..\e[39m" - echo "" - echo -e "\e[93m-------------------------------------------------------------------------------------------------------" - echo -e "\e[92m AboveTustin setup halted.\e[39m" - echo "" + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" read -p "Press enter to continue..." CONTINUE exit 1 fi # Move the binary into the /usr/bin directory and make it executable. echo -e "\e[94m Copying the PhantomJS binary into the directory /usr/bin...\e[97m" - sudo cp bin/phantomjs /usr/bin + sudo cp -v bin/phantomjs /usr/bin 2>&1 echo -e "\e[94m Making the file /usr/bin/phantomjs executable...\e[97m" - sudo chmod +x /usr/bin/phantomjs + sudo chmod -v +x /usr/bin/phantomjs 2>&1 fi fi -## INSTALL THE NEEDED PYTHON MODULES +### INSTALL THE NEEDED PYTHON MODULES -echo "" +echo -e "" echo -e "\e[95m Setting up the required Python modules...\e[97m" -echo "" +echo -e "" # Upgrade pip. echo -e "\e[94m Upgrading pip...\e[97m" -echo "" -sudo pip3 install --upgrade pip -echo "" +echo -e "" +sudo pip3 install --upgrade pip 2>&1 +echo -e "" echo -e "\e[94m Upgrading virtualenv...\e[97m" -echo "" -sudo pip3 install --upgrade virtualenv -echo "" +echo -e "" +sudo pip3 install --upgrade virtualenv 2>&1 +echo -e "" # Install Python modules. echo -e "\e[94m Installing the selenium Python module...\e[97m" -echo "" -sudo pip3 install selenium -echo "" +echo -e "" +sudo pip3 install selenium 2>&1 +echo -e "" echo -e "\e[94m Installing the twitter Python module...\e[97m" -echo "" -sudo pip3 install twitter -echo "" +echo -e "" +sudo pip3 install twitter 2>&1 +echo -e "" echo -e "\e[94m Installing the python-dateutil Python module...\e[97m" -echo "" -sudo pip3 install python-dateutil -echo "" +echo -e "" +sudo pip3 install python-dateutil 2>&1 +echo -e "" -## SETUP ABOVETUSTIN +### DOWNLOAD SOURCE -echo "" -echo -e "\e[95m Downloading and configuring AboveTustin...\e[97m" -echo "" +echo -e "" +echo -e "\e[95m Downloading and configuring ${COMPONENT_NAME}...\e[97m" +echo -e "" -echo -e "\e[94m Entering the ADS-B Receiver Project build directory...\e[97m" -cd $BUILDDIRECTORY - -echo -e "\e[94m Checking if the AboveTustin Git repository has been cloned...\e[97m" -if [ -d $BUILDDIRECTORY/AboveTustin ] && [ -d $BUILDDIRECTORY/AboveTustin/.git ]; then +echo -e "\e[94m Checking if the Git repository has been cloned...\e[97m" +if [[ -d "${COMPONENT_BUILD_DIRECTORY}/AboveTustin" ]] && [[ -d "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/.git" ]] ; then # A directory with a git repository containing the source code already exists. - echo -e "\e[94m Entering the AboveTustin git repository directory...\e[97m" - cd $BUILDDIRECTORY/AboveTustin - echo -e "\e[94m Updating the local AboveTustin git repository...\e[97m" - echo "" - git pull + echo -e "\e[94m Entering the local ${COMPONENT_NAME} git repository directory...\e[97m" + cd ${COMPONENT_BUILD_DIRECTORY}/AboveTustin 2>&1 + echo -e "" + echo -e "\e[94m Updating the local ${COMPONENT_NAME} git repository...\e[97m" + git pull 2>&1 + echo -e "" else # A directory containing the source code does not exist in the build directory. - echo -e "\e[94m Entering the ADS-B Receiver Project build directory...\e[97m" - mkdir -p $BUILDDIRECTORY - cd $BUILDDIRECTORY - echo -e "\e[94m Cloning the AboveTustin git repository locally...\e[97m" - echo "" - git clone https://github.com/kevinabrandon/AboveTustin.git - echo "" + echo -e "\e[94m Entering the ${COMPONENT_NAME} build directory...\e[97m" + cd ${COMPONENT_BUILD_DIRECTORY} 2>&1 + echo -e "" + if [[ -d "${COMPONENT_BUILD_DIRECTORY}/AboveTustin" ]] ; then + echo -e "\e[94m Removing old build directory...\e[97m" + rm -vrf "${COMPONENT_BUILD_DIRECTORY}/AboveTustin" 2>&1 + echo -e "" + fi + echo -e "\e[94m Cloning the ${COMPONENT_NAME} git repository locally...\e[97m" + echo -e "" + git clone https://github.com/kevinabrandon/AboveTustin.git "${COMPONENT_BUILD_DIRECTORY}/AboveTustin" 2>&1 + echo -e "" fi -# Make the logs directory if it does not already exist. -cho -e "Checking if the directory $BUILDDIRECTORY/AboveTustin/logs exists...\e[97m" -if [ ! -d $BUILDDIRECTORY/AboveTustin/logs ]; then - echo -e "\e[94m Creating the directory $BUILDDIRECTORY/AboveTustin/logs...\e[97m" - mkdir $BUILDDIRECTORY/AboveTustin/logs +### BUILD AND INSTALL + +### APPLY CONFIGURATION + +# Copy the file config.sample.ini to config.ini +if [[ -s "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" ]] ; then + echo -e "\e[94m Found existing configuration file config.ini...\e[97m" +elif [[ -s "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.sample.ini" ]] ; then + echo -e "\e[94m Copying the file config.sample.ini to the file config.ini...\e[97m" + cp -v ${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.sample.ini ${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini 2>&1 +else + echo -e "\e[94m Unable to install configuration file config.ini...\e[97m" fi -# Make the key directory if it does not already exist. -echo -e "Checking if the directory $BUILDDIRECTORY/AboveTustin/keys exists...\e[97m" -if [ ! -d $BUILDDIRECTORY/AboveTustin/keys ]; then - echo -e "\e[94m Creating the directory $BUILDDIRECTORY/AboveTustin/keys...\e[97m" - mkdir $BUILDDIRECTORY/AboveTustin/keys +# Write out the supplied values to the file config.ini. +if [[ -n "${TWITTER_ACCESS_TOKEN}" ]] ; then + echo -e "\e[94m Writing Twitter token value to the config.ini file...\e[97m" + ChangeConfig access_token ${TWITTER_ACCESS_TOKEN} "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" +fi +if [[ -n "${TWITTER_ACCESS_TOKEN_SECRET}" ]] ; then + echo -e "\e[94m Writing Twitter token secret value to the config.ini file...\e[97m" + ChangeConfig access_token_secret ${TWITTER_ACCESS_TOKEN_SECRET} "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" +fi +if [[ -n "${TWITTER_CONSUMER_KEY}" ]] ; then + echo -e "\e[94m Writing Twitter consumer key value to the config.ini file...\e[97m" + ChangeConfig consumer_key ${TWITTER_CONSUMER_KEY} "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" +fi +if [[ -n "${TWITTER_CONSUMER_SECRET}" ]] ; then + echo -e "\e[94m Writing Twitter consumer secret to the config.ini file...\e[97m" + ChangeConfig consumer_secret ${TWITTER_CONSUMER_SECRET} "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" +fi +if [[ -n "${TIME_ZONE_ESCAPED}" ]] ; then + echo -e "\e[94m Writing receiver timezone to the config.ini file...\e[97m" + ChangeConfig time_zone ${TIME_ZONE_ESCAPED} "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" +fi +if [[ -n "${RECEIVER_LATITUDE}" ]] ; then + echo -e "\e[94m Writing receiver latitude to the config.ini file...\e[97m" + ChangeConfig latitude ${RECEIVER_LATITUDE} "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" +fi +if [[ -n "${RECEIVER_LONGITUDE}" ]] ; then + echo -e "\e[94m Writing receiver longitude to the config.ini file...\e[97m" + ChangeConfig longitude ${RECEIVER_LONGITUDE} "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" fi -# Write out the files which will contain the user's Twitter keys and access tokens. -echo -e "\e[94m Adding the supplied token to the Twitter Token file...\e[97m" -echo "$TWITTERACCESSTOKEN" > $BUILDDIRECTORY/AboveTustin/keys/token -echo -e "\e[94m Adding the supplied token secret to the Twitter Token Secret file...\e[97m" -echo "$TWITTERACCESSTOKENSECRET" > $BUILDDIRECTORY/AboveTustin/keys/token_secret -echo -e "\e[94m Adding the supplied consumer key to the Twitter Consumer Key file...\e[97m" -echo "$TWITTERCONSUMERKEY" > $BUILDDIRECTORY/AboveTustin/keys/consumer_key -echo -e "\e[94m Adding the supplied consumer secret to the Twitter Consumer Secret file...\e[97m" -echo "$TWITTERCONSUMERSECRET" > $BUILDDIRECTORY/AboveTustin/keys/consumer_secret +# Quick fix to remove quotes from config. +sed -e 's/= "/= /g' -e 's/"$//g' -i "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/config.ini" 2>&1 + +### CREATE SCRIPTS # Add the run_tracker.sh script to /etc/rc.local so it is executed at boot up. -echo -e "\e[94m Checking if the AboveTustin startup line is contained within the file /etc/rc.local...\e[97m" -if ! grep -Fxq "$BUILDDIRECTORY/AboveTustin/run_tracker.sh &" /etc/rc.local; then - echo -e "\e[94m Adding the AboveTustin startup line to the file /etc/rc.local...\e[97m" +echo -e "\e[94m Checking if the ${COMPONENT_NAME} startup line is contained within the file /etc/rc.local...\e[97m" +if [[ `grep -cFx "${COMPONENT_BUILD_DIRECTORY}/AboveTustin/run_tracker.sh &" /etc/rc.local` -eq 0 ]] ; then + echo -e "\e[94m Adding the ${COMPONENT_NAME} startup line to the file /etc/rc.local...\e[97m" lnum=($(sed -n '/exit 0/=' /etc/rc.local)) - ((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i $BUILDDIRECTORY/AboveTustin/run_tracker.sh &\n" /etc/rc.local + ((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i ${COMPONENT_BUILD_DIRECTORY}/AboveTustin/run_tracker.sh &\n" /etc/rc.local fi -# Kill any currently running instances of the run_tracker.sh script. -echo -e "\e[94m Checking for any running run_tracker.sh processes...\e[97m" -PIDS=`ps -efww | grep -w "run_tracker.sh" | awk -vpid=$$ '$2 != pid { print $2 }'` -if [ ! -z "$PIDS" ]; then - echo -e "\e[94m Killing any running run_tracker.sh processes...\e[97m" - sudo kill $PIDS - sudo kill -9 $PIDS -fi +### START SCRIPTS -echo -e "\e[94m Checking for any running tracker.py processes...\e[97m" -PIDS=`ps -efww | grep -w "tracker.py" | awk -vpid=$$ '$2 != pid { print $2 }'` -if [ ! -z "$PIDS" ]; then - echo -e "\e[94m Killing any running tracker.py processes...\e[97m" - sudo kill $PIDS - sudo kill -9 $PIDS -fi +echo -e "" +echo -e "\e[95m Starting ${COMPONENT_NAME}...\e[97m" +echo -e "" -echo -e "\e[94m Checking for any running phantomjs processes...\e[97m" -PIDS=`ps -efww | grep -w "phantomjs" | awk -vpid=$$ '$2 != pid { print $2 }'` -if [ ! -z "$PIDS" ]; then - echo -e "\e[94m Killing any running phantomjs processes...\e[97m" - sudo kill $PIDS - sudo kill -9 $PIDS -fi +# Kill any currently running instances. +PROCS="run_tracker.sh tracker.py phantomjs" +for PROC in ${PROCS} ; do + PIDS=`ps -efww | grep -w "${PROC} " | awk -vpid=$$ '$2 != pid { print $2 }'` + if [[ -n "${PIDS}" ]] ; then + echo -e "\e[94m Killing any running ${PROC} processes...\e[97m" + sudo kill ${PIDS} 2>&1 + sudo kill -9 ${PIDS} 2>&1 + fi + unset PIDS +done -echo -e "\e[94m Executing the adsbexchange-netcat_maint.sh script...\e[97m" -sudo nohup $BUILDDIRECTORY/AboveTustin/run_tracker.sh > /dev/null 2>&1 & +# Start the run_tracker.sh script. +echo -e "\e[94m Executing the run_tracker.sh script...\e[97m" +echo -e "" +sudo nohup ${COMPONENT_BUILD_DIRECTORY}/AboveTustin/run_tracker.sh > /dev/null 2>&1 & +echo -e "" -## OVERTUSTIN SETUP COMPLETE +### SETUP COMPLETE -# Enter into the project root directory. +# Return to the project root directory. echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" -cd $PROJECTROOTDIRECTORY +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 -echo "" -echo -e "\e[93m----------------------------------------------------------------------------------------------------" -echo -e "\e[92m OverTustin setup is complete.\e[39m" -echo "" -read -p "Press enter to continue..." CONTINUE +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" +echo -e "\e[92m ${COMPONENT_NAME} setup is complete.\e[39m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi exit 0 diff --git a/bash/extras/beastsplitter.sh b/bash/extras/beastsplitter.sh new file mode 100755 index 0000000..8f34b5a --- /dev/null +++ b/bash/extras/beastsplitter.sh @@ -0,0 +1,272 @@ +#!/bin/bash + +##################################################################################### +# ADS-B RECEIVER # +##################################################################################### +# # +# This script is not meant to be executed directly. # +# Instead execute install.sh to begin the installation process. # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # +# 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 # +# in the Software without restriction, including without limitation the rights # +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # +# copies of the Software, and to permit persons to whom the Software is # +# furnished to do so, subject to the following conditions: # +# # +# The above copyright notice and this permission notice shall be included in all # +# copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # +# SOFTWARE. # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +## SET INSTALLATION VARIABLES + +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" + +# Component specific variables. + +COMPONENT_NAME="Beast-Splitter" +COMPONENT_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/beastsplitter" + +### INCLUDE EXTERNAL SCRIPTS + +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "true" ]] && [[ -s "${RECEIVER_CONFIGURATION_FILE}" ]] ; then + source ${RECEIVER_CONFIGURATION_FILE} +fi + +### BEGIN SETUP + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +fi +echo -e "" +echo -e "\e[92m Setting up ${COMPONENT_NAME}..." +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${COMPONENT_NAME} Setup" --yesno "${COMPONENT_NAME} is a helper utility for the Mode-S Beast.\n\nThe Beast provides a single data stream over a (USB) serial port. If you have more than one thing that wants to read that data stream, you need something to redistribute the data. This is what ${COMPONENT_NAME} does.\n\n https://github.com/flightaware/beast-splitter\n\nContinue beast-splitter setup?" 15 78 + if [[ $? -eq 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 -e "" + echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi +fi + +echo -e "\e[95m Setting up ${COMPONENT_NAME} on this device...\e[97m" +echo -e "" + +## ENABLE THE USE OF /ETC/RC.LOCAL IF THE FILE DOES NOT EXIST + +if [ ! -f /etc/rc.local ]; then + echo "" + echo -e "\e[95m Enabling the use of the /etc/rc.local file...\e[97m" + echo "" + + # In Debian Stretch /etc/rc.local has been removed. + # However at this time we can bring this file back into play. + # As to if in future releases this will work remains to be seen... + + echo -e "\e[94m Creating the file /etc/rc.local...\e[97m" + sudo tee /etc/rc.local > /dev/null <&1 1>&2 2>&3) + BEASTSPLITTER_LISTEN_PORT_TITLE="Listen Port (REQUIRED)" + done + # Ask the beast-splitter connect port. + BEASTSPLITTER_CONNECT_PORT_TITLE="Connect Port" + while [[ -z "${BEASTSPLITTER_CONNECT_PORT}" ]] ; do + BEASTSPLITTER_CONNECT_PORT=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${BEASTSPLITTER_CONNECT_PORT_TITLE}" --nocancel --inputbox "\nPlease enter the port ${COMPONENT_NAME} will connect to.\nThis is generally port 30104 on dump1090." 10 78 "30104" 3>&1 1>&2 2>&3) + BEASTSPLITTER_CONNECT_PORT_TITLE="Connect Port (REQUIRED)" + done +fi + +### START INSTALLATION + +### PROJECT BUILD DIRECTORY + +# Create the build directory if it does not already exist. +if [[ ! -d "${RECEIVER_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Creating the ADS-B Receiver Project build directory...\e[97m" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY} 2>&1 +fi + +# Create a component directory within the build directory if it does not already exist. +if [[ ! -d "${COMPONENT_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Creating the directory ${COMPONENT_BUILD_DIRECTORY}...\e[97m" + mkdir -vp ${COMPONENT_BUILD_DIRECTORY} 2>&1 +fi + +### DOWNLOAD SOURCE + +echo -e "" +echo -e "\e[95m Downloading and configuring ${COMPONENT_NAME}...\e[97m" +echo -e "" + +echo -e "\e[94m Checking if the Git repository has been cloned...\e[97m" +if [[ -d "${COMPONENT_BUILD_DIRECTORY}/beast-splitter" ]] && [[ -d "${COMPONENT_BUILD_DIRECTORY}/beast-splitter/.git" ]] ; then + # A directory with a git repository containing the source code already exists. + echo -e "\e[94m Entering the local ${COMPONENT_NAME} git repository directory...\e[97m" + cd ${COMPONENT_BUILD_DIRECTORY}/beast-splitter 2>&1 + echo -e "\e[94m Updating the local ${COMPONENT_NAME} git repository...\e[97m" + echo -e "" + git pull 2>&1 + echo -e "" +else + # A directory containing the source code does not exist in the build directory. + echo -e "\e[94m Entering the ${COMPONENT_NAME} build directory...\e[97m" + cd ${COMPONENT_BUILD_DIRECTORY} 2>&1 + echo -e "" + if [[ -d "${COMPONENT_BUILD_DIRECTORY}/beast-splitter" ]] ; then + echo -e "\e[94m Removing old build directory...\e[97m" + rm -vrf "${COMPONENT_BUILD_DIRECTORY}/beast-splitter" 2>&1 + echo -e "" + fi + echo -e "\e[94m Cloning the ${COMPONENT_NAME} git repository locally...\e[97m" + echo -e "" + git clone https://github.com/flightaware/beast-splitter.git "${COMPONENT_BUILD_DIRECTORY}/beast-splitter" 2>&1 + echo -e "" +fi + +### BUILD AND INSTALL + +echo -e "" +echo -e "\e[95m Building and installing the ${COMPONENT_NAME} package...\e[97m" +echo -e "" +if [[ ! "${PWD}" = "${COMPONENT_BUILD_DIRECTORY}/beast-splitter" ]] ; then + echo -e "\e[94m Entering the ${COMPONENT_NAME} git repository directory...\e[97m" + cd ${COMPONENT_BUILD_DIRECTORY}/beast-splitter 2>&1 +fi +echo -e "\e[94m Executing the ${COMPONENT_NAME} build script...\e[97m" +echo -e "" +dpkg-buildpackage -b 2>&1 +echo -e "" +echo -e "\e[94m Entering the build directory...\e[97m" +cd ${COMPONENT_BUILD_DIRECTORY} 2>&1 +echo -e "\e[94m Installing the ${COMPONENT_NAME} package...\e[97m" +sudo dpkg -i beast-splitter_*.deb 2>&1 + +### CREATE SCRIPTS + +echo -e "\e[94m Creating the file beast-splitter_maint.sh...\e[97m" +tee ${COMPONENT_BUILD_DIRECTORY}/beast-splitter_maint.sh > /dev/null <&1 + +echo -e "\e[94m Checking if the ${COMPONENT_NAME} startup line is contained within the file /etc/rc.local...\e[97m" +if [[ `grep -cFx "${COMPONENT_BUILD_DIRECTORY}/beast-splitter_maint.sh &" /etc/rc.local` -eq 0 ]] ; then + echo -e "\e[94m Adding the ${COMPONENT_NAME} startup line to the file /etc/rc.local...\e[97m" + lnum=($(sed -n '/exit 0/=' /etc/rc.local)) + ((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i ${COMPONENT_BUILD_DIRECTORY}/beast-splitter_maint.sh &\n" /etc/rc.local +fi + +### START SCRIPTS + +echo -e "" +echo -e "\e[95m Starting ${COMPONENT_NAME}...\e[97m" +echo -e "" + +# Kill any currently running instances. +PROCS="beast-splitter_maint.sh beast-splitter" +for PROC in ${PROCS} ; do + PIDS=`ps -efww | grep -w "${PROC} " | awk -vpid=$$ '$2 != pid { print $2 }'` + if [[ -n "${PIDS}" ]] ; then + echo -e "\e[94m Killing any running ${PROC} processes...\e[97m" + sudo kill ${PIDS} 2>&1 + sudo kill -9 ${PIDS} 2>&1 + fi + unset PIDS +done + +# Start the beast-splitter_maint.sh script. +echo -e "\e[94m Executing the ${COMPONENT_NAME} script...\e[97m" +echo -e "" +sudo nohup ${COMPONENT_BUILD_DIRECTORY}/beast-splitter_maint.sh > /dev/null 2>&1 & +echo -e "" + +### SETUP COMPLETE + +# Return to the project root directory. +echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 + +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" +echo -e "\e[92m ${COMPONENT_NAME} setup is complete.\e[39m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi + +exit 0 diff --git a/bash/extras/duckdns.sh b/bash/extras/duckdns.sh new file mode 100755 index 0000000..5851cb5 --- /dev/null +++ b/bash/extras/duckdns.sh @@ -0,0 +1,187 @@ +#!/bin/bash + +##################################################################################### +# ADS-B RECEIVER # +##################################################################################### +# # +# This script is not meant to be executed directly. # +# Instead execute install.sh to begin the installation process. # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # +# 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 # +# in the Software without restriction, including without limitation the rights # +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # +# copies of the Software, and to permit persons to whom the Software is # +# furnished to do so, subject to the following conditions: # +# # +# The above copyright notice and this permission notice shall be included in all # +# copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # +# SOFTWARE. # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +## SET INSTALLATION VARIABLES + +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" + +# Component specific variables. + +COMPONENT_NAME="Duck DNS" +COMPONENT_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/duckdns" + +### INCLUDE EXTERNAL SCRIPTS + +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "true" ]] && [[ -s "${RECEIVER_CONFIGURATION_FILE}" ]] ; then + source ${RECEIVER_CONFIGURATION_FILE} +fi + +### BEGIN SETUP + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +fi +echo -e "" +echo -e "\e[92m Setting up ${COMPONENT_NAME}..." +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${COMPONENT_NAME} Dynamic DNS" --yesno "${COMPONENT_NAME} is a free dynamic DNS service hosted on Amazon VPC.\n\nPLEASE NOTE:\n\nBefore continuing this setup it is recommended that you visit the ${COMPONENT_NAME} website and signup for then setup a sub domain which will be used by this device. You will need both the domain and token supplied to you after setting up your account.\n\n http://www.duckdns.org\n\nContinue with ${COMPONENT_NAME} update script setup?" 18 78 + if [[ $? -eq 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 -e "" + echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi +fi + +echo -e "\e[95m Setting up ${COMPONENT_NAME} on this device...\e[97m" +echo -e "" + +### CHECK FOR PREREQUISITE PACKAGES + +# Check that the required packages are installed. +echo -e "" +echo -e "\e[95m Installing packages needed to build and fulfill dependencies...\e[97m" +echo -e "" +CheckPackage cron +CheckPackage curl + +### CONFIRM SETTINGS + +# Confirm settings with user. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Ask for the user sub domain to be assigned to this device. + DUCKDNS_DOMAIN_TITLE="Duck DNS Sub Domain" + while [[ -z "${DUCKDNS_DOMAIN}" ]] ; do + DUCKDNS_DOMAIN=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DUCKDNS_DOMAIN_TITLE}" --nocancel --inputbox "\nPlease enter the Duck DNS sub domain you selected after registering.\nIf you do not have one yet visit http://www.ducknds.org to obtain one." 9 78 3>&1 1>&2 2>&3) + DUCKDNS_DOMAIN_TITLE="Duck DNS Sub Domain (REQUIRED)" + done + # Ask for the Duck DNS token to be assigned to this receiver. + DUCKDNS_TOKEN_TITLE="Duck DNS Token" + while [[ -z "${DUCKDNS_TOKEN}" ]] ; do + DUCKDNS_TOKEN=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DUCKDNS_TOKEN_TITLE}" --nocancel --inputbox "\nPlease enter your Duck DNS token." 8 78 3>&1 1>&2 2>&3) + DUCKDNS_TOKEN_TITLE="Duck DNS Token (REQUIRED)" + done +fi + +### PROJECT BUILD DIRECTORY + +# Create the build directory if it does not already exist. +if [[ ! -d "${RECEIVER_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Creating the ADS-B Receiver Project build directory...\e[97m" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY} 2>&1 +fi + +# Create a component directory within the build directory if it does not already exist. +if [[ ! -d "${COMPONENT_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Creating the directory ${COMPONENT_BUILD_DIRECTORY}...\e[97m" + mkdir -vp ${COMPONENT_BUILD_DIRECTORY} 2>&1 +fi + +### DOWNLOAD SOURCE + +### BUILD AND INSTALL + +# Create then set permissions on the file duck.sh. +echo -e "\e[94m Creating the ${COMPONENT_NAME} update script...\e[97m" +tee ${COMPONENT_BUILD_DIRECTORY}/duck.sh > /dev/null <&1 + +### CREATE SCRIPTS + +# Add job to the users crontab if it does not exist. +echo -e "\e[94m Adding the ${COMPONENT_NAME} update command to your crontab if it does not exist already...\e[97m" +COMMAND="${COMPONENT_BUILD_DIRECTORY}/duck.sh >/dev/null 2>&1" +JOB="*/5 * * * * ${COMMAND}" + +# Should only add the job if the COMMAND does not already exist in the users crontab. +(crontab -l | grep -v -F "${COMMAND}" ; echo "${JOB}") | crontab - + +# The following command should remove the job from the users crontab. +#(crontab -l | grep -v -F "${COMMAND}" ) | crontab - + +### START SCRIPTS + +echo -e "" +echo -e "\e[95m Starting ${COMPONENT_NAME}...\e[97m" +echo -e "" + +# Kill any currently running instances. +PROCS="duck.sh" +for PROC in ${PROCS} ; do + PIDS=`ps -efww | grep -w "${PROC} " | awk -vpid=$$ '$2 != pid { print $2 }'` + if [[ -n "${PIDS}" ]] ; then + echo -e "\e[94m Killing any running ${PROC} processes...\e[97m" + sudo kill ${PIDS} 2>&1 + sudo kill -9 ${PIDS} 2>&1 + fi + unset PIDS +done + +# Run the Duck DNS update script for the first time.. +echo -e "\e[94m Executing the ${COMPONENT_NAME} update script...\e[97m" +echo -e "" +${COMPONENT_BUILD_DIRECTORY}/duck.sh 2>&1 +echo -e "" + +### SETUP COMPLETE + +# Return to the project root directory. +echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 + +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" +echo -e "\e[92m ${COMPONENT_NAME} setup is complete.\e[39m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi + +#exit 0 diff --git a/bash/feeders/adsbexchange.sh b/bash/feeders/adsbexchange.sh index 8f8b50a..5d5749e 100755 --- a/bash/feeders/adsbexchange.sh +++ b/bash/feeders/adsbexchange.sh @@ -9,7 +9,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Copyright (c) 2015-2016 Joseph A. Prochazka # +# Copyright (c) 2016-2017, Joseph A. Prochazka & Romeo Golf # # # # 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,38 +31,82 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -## VARIABLES +### VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -MLATCLIENTBUILDDIRECTORY="$PROJECTROOTDIRECTORY/build/mlat-client" -ADSBEXCHANGEBUILDDIRECTORY="$PROJECTROOTDIRECTORY/build/adsbexchange" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" -## INCLUDE EXTERNAL SCRIPTS +# Component specific variables. +MLAT_CLIENT_GITHUB_URL="https://github.com/mutability/mlat-client.git" +MLAT_CLIENT_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/mlat-client" -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +# Preconfigured values for ADSB Exchange. +FEEDER_NAME="adsbexchange" +COMPONENT_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/${FEEDER_NAME}" +# +FEEDER_BEAST_SRC_HOST="127.0.0.1" +FEEDER_BEAST_SRC_PORT="30005" +FEEDER_BEAST_DST_HOST="feed.adsbexchange.com" +FEEDER_BEAST_DST_PORT="30005" +# +FEEDER_MLAT_SRC_HOST="127.0.0.1" +FEEDER_MLAT_SRC_PORT="30005" +FEEDER_MLAT_DST_HOST="feed.adsbexchange.com" +FEEDER_MLAT_DST_PORT="31090" +# +FEEDER_MLAT_RETURN_HOST="127.0.0.1" +FEEDER_MLAT_RETURN_PORT="30104" -## BEGIN SETUP +# Default values. +FEEDER_BEAST_SRC_HOST_DEFAULT="127.0.0.1" +FEEDER_BEAST_SRC_PORT_DEFAULT="30005" +FEEDER_BEAST_DST_PORT_DEFAULT="30004" +# +FEEDER_MLAT_SRC_HOST_DEFAULT="127.0.0.1" +FEEDER_MLAT_SRC_PORT_DEFAULT="30005" +FEEDER_MLAT_DST_PORT_DEFAULT="31090" -clear -echo -e "\n\e[91m $ADSB_PROJECTTITLE" -echo "" +### INCLUDE EXTERNAL SCRIPTS + +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +# Source the automated install configuration file if this is an automated installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "true" ]] ; then + source ${RECEIVER_CONFIGURATION_FILE} +fi + +### BEGIN SETUP + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +fi +echo -e "" echo -e "\e[92m Setting up the ADS-B Exchange feed..." -echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" -echo "" -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "ADS-B Exchange Feed Setup" --yesno "ADS-B Exchange is a co-op of ADS-B/Mode S/MLAT feeders from around the world, and the world’s largest source of unfiltered flight data.\n\n http://www.adsbexchange.com/how-to-feed/\n\nContinue setting up the ADS-B Exchange feed?" 12 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 ADS-B Exchange feed setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Interactive install. + CONTINUE_SETUP=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "ADS-B Exchange Feed Setup" --yesno "ADS-B Exchange is a co-op of ADS-B/Mode S/MLAT feeders from around the world, and the world’s largest source of unfiltered flight data.\n\n http://www.adsbexchange.com/how-to-feed/\n\nContinue setting up the ADS-B Exchange feed?" 12 78 3>&1 1>&2 2>&3) + if [[ ${CONTINUE_SETUP} -eq 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 -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m ADS-B Exchange feed setup halted.\e[39m" + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi +else + # Warn that automated installation is not supported. + echo -e "\e[92m Automated installation of this script is not yet supported...\e[39m" + echo -e "" exit 1 fi @@ -100,33 +144,33 @@ EOF sudo systemctl start rc-local fi -## CHECK FOR AND REMOVE ANY OLD STYLE ADB-B EXCHANGE SETUPS IF ANY EXIST +## CHECK FOR AND REMOVE ANY OLD STYLE ADB-B EXCHANGE SETUPS IF ANY EXIST echo -e "\e[95m Checking for and removing any old style ADS-B Exchange setups if any exist...\e[97m" -echo "" -# Check if the old adsbexchange-maint.sh line exists in /etc/rc.local. +echo -e "" +# Check if the old style ${FEEDER_NAME}-maint.sh line exists in /etc/rc.local. echo -e "\e[94m Checking for any preexisting older style setups...\e[97m" -if grep -Fxq "$ADSBEXCHANGEBUILDDIRECTORY/adsbexchange-maint.sh &" /etc/rc.local; then - # Kill any currently running instances of the adsbexchange_maint.sh script. - echo -e "\e[94m Checking for any running adsbexchange-maint.sh processes...\e[97m" - PIDS=`ps -efww | grep -w "$ADSBEXCHANGEBUILDDIRECTORY/adsbexchange-maint.sh &" | awk -vpid=$$ '$2 != pid { print $2 }'` - if [ ! -z "$PIDS" ]; then - echo -e "\e[94m Killing any running adsbexchange-maint.sh processes...\e[97m" - echo "" - sudo kill $PIDS - sudo kill -9 $PIDS - echo "" +if [[ `grep -cFx "${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-maint.sh &" /etc/rc.local` -gt 0 ]] ; then + # Kill any currently running instances of the ${FEEDER_NAME}-maint.sh script. + echo -e "\e[94m Checking for any running ${FEEDER_NAME}-maint.sh processes...\e[97m" + PIDS=`ps -efww | grep -w "${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-maint.sh &" | awk -vpid=$$ '$2 != pid { print $2 }'` + if [[ -n "${PIDS}" ]] ; then + echo -e "\e[94m -Killing any running ${FEEDER_NAME}-maint.sh processes...\e[97m" + echo -e "" + sudo kill ${PIDS} 2>&1 + sudo kill -9 ${PIDS} 2>&1 + echo -e "" fi # Remove the old line from /etc/rc.local. - echo -e "\e[94m Removing the old adsbexchange-maint.sh startup line from /etc/rc.local...\e[97m" - sudo sed -i /$$ADSBEXCHANGEDIR\/adsbexchange-maint.sh &/d /etc/rc.local + echo -e "\e[94m Removing the old ${FEEDER_NAME}-maint.sh startup line from /etc/rc.local...\e[97m" + sudo sed -i /$${COMPONENT_BUILD_DIRECTORY}\/${FEEDER_NAME}-maint.sh &/d /etc/rc.local 2>&1 fi -echo "" +echo -e "" ## CHECK FOR PREREQUISITE PACKAGES echo -e "\e[95m Installing packages needed to build and fulfill dependencies...\e[97m" -echo "" +echo -e "" CheckPackage curl CheckPackage build-essential CheckPackage debhelper @@ -134,182 +178,370 @@ CheckPackage python-dev CheckPackage python3-dev CheckPackage netcat -## DOWNLOAD OR UPDATE THE MLAT-CLIENT SOURCE +## CONFIRM DERIVED VALUES + +# For interactive install we test each required variable and prompt the user if not present. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Explain to the user that the receiver's latitude and longitude is required. + RECEIVER_LATLON_DIALOG=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Receiver Latitude and Longitude" --msgbox "Your receivers latitude and longitude are required for distance calculations, you will now be asked to supply these values for your receiver.\n\nIf you do not have this information you can obtain it using the web based \"Geocode by Address\" utility hosted on another of the lead developers websites:\n\n https://www.swiftbyte.com/toolbox/geocode" 15 78 3>&1 1>&2 2>&3) + + # Ask the user for the mlat user name for this receiver. + FEEDER_USERNAME_TITLE="Receiver MLAT Username" + while [[ -z "${FEEDER_USERNAME}" ]] ; do + FEEDER_USERNAME=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${FEEDER_USERNAME_TITLE}" --nocancel --inputbox "\nPlease enter a name for this receiver.\n\nIf you have more than one receiver, this name should be unique.\nExample: \"username-01\", \"username-02\", etc." 12 78 -- "${ADSBEXCHANGE_RECEIVER_USERNAME}" 3>&1 1>&2 2>&3) + FEEDER_USERNAME_TITLE="Receiver Name (REQUIRED)" + done + + # Ask the user to confirm the receivers latitude, this will be prepopulated by the latitude assigned dump1090-mutability. + RECEIVER_LATITUDE_TITLE="Receiver Latitude" + while [[ -z "${RECEIVER_LATITUDE}" ]] ; do + if [[ -s /etc/default/dump1090-mutability ]] && [[ `grep -c "^LAT" "/etc/default/dump1090-mutability"` -gt 0 ]] ; then + RECEIVER_LATITUDE=$(GetConfig "LAT" "/etc/default/dump1090-mutability") + RECEIVER_LATITUDE_SOURCE=", the value below is configured in Dump1090" + fi + RECEIVER_LATITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LATITUDE_TITLE}" --nocancel --inputbox "\nPlease confirm your receiver's latitude${RECEIVER_LATITUDE_SOURCE}:\n" 10 78 -- "${RECEIVER_LATITUDE}" 3>&1 1>&2 2>&3) + RECEIVER_LATITUDE_TITLE="Receiver Latitude (REQUIRED)" + done + + # Ask the user to confirm the receivers longitude, this will be prepopulated by the longitude assigned dump1090-mutability. + RECEIVER_LONGITUDE_TITLE="Receiver Longitude" + while [[ -z "${RECEIVER_LONGITUDE}" ]] ; do + if [[ -s /etc/default/dump1090-mutability ]] && [[ `grep -c "^LON" "/etc/default/dump1090-mutability"` -gt 0 ]] ; then + RECEIVER_LONGITUDE=$(GetConfig "LON" "/etc/default/dump1090-mutability") + RECEIVER_LONGITUDE_SOURCE=", the value below is configured in Dump1090" + fi + RECEIVER_LONGITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LONGITUDE_TITLE}" --nocancel --inputbox "\nEnter your receiver's longitude${RECEIVER_LONGITUDE_SOURCE}:\n" 10 78 -- "${RECEIVER_LONGITUDE}" 3>&1 1>&2 2>&3) + RECEIVER_LONGITUDE_TITLE="Receiver Longitude (REQUIRED)" + done + + # Ask the user to confirm the receivers altitude, this will be prepopulated by the altitude returned from the Google Maps API. + RECEIVER_ALTITUDE_TITLE="Receiver Altitude" + while [[ -z "${RECEIVER_ALTITUDE}" ]] ; do + if [[ -n "${RECEIVER_LATITUDE}" ]] && [[ -n "${RECEIVER_LONGITUDE}" ]] ; then + RECEIVER_ALTITUDE=$(curl -s https://maps.googleapis.com/maps/api/elevation/json?locations=${RECEIVER_LATITUDE},${RECEIVER_LONGITUDE} | python -c "import json,sys;obj=json.load(sys.stdin);print obj['results'][0]['elevation'];" | awk '{printf("%.0f\n", $1)}') + RECEIVER_ALTITUDE_SOURCE=", the below value is obtained from google but should be increased to reflect your antennas height above ground level" + fi + RECEIVER_ALTITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_ALTITUDE_TITLE}" --nocancel --inputbox "\nEnter your receiver's altitude${RECEIVER_ALTITUDE_SOURCE}:\n" 11 78 -- "${RECEIVER_ALTITUDE}" 3>&1 1>&2 2>&3) + RECEIVER_ALTITUDE_TITLE="Receiver Altitude (REQUIRED)" + done -echo "" -echo -e "\e[95m Preparing the mlat-client Git repository...\e[97m" -echo "" -if [ -d $MLATCLIENTBUILDDIRECTORY ] && [ -d $MLATCLIENTBUILDDIRECTORY/.git ]; then - # A directory with a git repository containing the source code already exists. - echo -e "\e[94m Entering the mlat-client git repository directory...\e[97m" - cd $MLATCLIENTBUILDDIRECTORY - echo -e "\e[94m Updating the local mlat-client git repository...\e[97m" - echo "" - git pull else - # A directory containing the source code does not exist in the build directory. - echo -e "\e[94m Entering the ADS-B Receiver Project build directory...\e[97m" - cd $BUILDDIRECTORY - echo -e "\e[94m Cloning the mlat-client git repository locally...\e[97m" - echo "" - git clone https://github.com/mutability/mlat-client.git + # Attempt to derive required values at some point... + echo -e "\e[92m Automated installation of this script is not yet supported...\e[39m" + echo -e "" + exit 1 fi -## BUILD AND INSTALL THE MLAT-CLIENT PACKAGE +# Check that all information required to configure the feeder has been provided. +if [[ -n "${FEEDER_NAME}" ]] ; then + # Configure feeder build directory. + COMPONENT_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/${FEEDER_NAME}" -echo "" -echo -e "\e[95m Building and installing the mlat-client package...\e[97m" -echo "" -if [ ! $PWD = $MLATCLIENTBUILDDIRECTORY ]; then - echo -e "\e[94m Entering the mlat-client git repository directory...\e[97m" - cd $MLATCLIENTBUILDDIRECTORY -fi -echo -e "\e[94m Building the mlat-client package...\e[97m" -echo "" -dpkg-buildpackage -b -uc -echo "" -echo -e "\e[94m Installing the mlat-client package...\e[97m" -echo "" -sudo dpkg -i $BUILDDIRECTORY/mlat-client_${MLATCLIENTVERSION}*.deb + # Confirm that all required information has been obtained for BEAST feed. + if [[ -n "${FEEDER_BEAST_DST_HOST}" ]] && [[ -n "${FEEDER_BEAST_DST_HOST}" ]] && [[ -n "${FEEDER_BEAST_DST_HOST}" ]] && [[ -n "${FEEDER_BEAST_DST_HOST}" ]] ; then + FEEDER_BEAST_ENABLED="true" + else + FEEDER_BEAST_ENABLED="false" + fi -# Check that the mlat-client package was installed successfully. -echo "" -echo -e "\e[94m Checking that the mlat-client package was installed properly...\e[97m" -if [ $(dpkg-query -W -f='${STATUS}' mlat-client 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - # If the mlat-client package could not be installed halt setup. - echo "" + # Confirm that all required information has been obtained for MLAT feed. + if [[ -n "${FEEDER_MLAT_DST_HOST}" ]] && [[ -n "${FEEDER_MLAT_DST_HOST}" ]] && [[ -n "${FEEDER_MLAT_DST_HOST}" ]] && [[ -n "${FEEDER_MLAT_DST_HOST}" ]] ; then + FEEDER_MLAT_ENABLED="true" + else + FEEDER_MLAT_ENABLED="false" + fi + + # Establish if MLAT results should be fed back into local dump1090 instance. + if [[ "${FEEDER_MLAT_ENABLED}" = "true" ]] && [[ -n "${FEEDER_MLAT_RETURN_HOST}" ]] && [[ -n "${FEEDER_MLAT_RETURN_PORT}" ]] ; then + FEEDER_MLAT_RETURN_RESULTS="--results beast,connect,${FEEDER_MLAT_SRC_HOST}:${FEEDER_MLAT_RETURN_PORT}" + else + FEEDER_MLAT_RETURN_RESULTS="" + fi +else + # Insufficent information to continue. echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" - echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." - echo -e " SETUP HAS BEEN TERMINATED!" - echo "" - echo -e "\e[93mThe package \"mlat-client\" could not be installed.\e[39m" - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" + echo -e " Setup has been halted due to insufficent information to configure this feeder." + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m ADS-B Exchange feed setup halted.\e[39m" - echo "" + echo -e "" read -p "Press enter to continue..." CONTINUE exit 1 fi -## CREATE THE SCRIPT TO EXECUTE AND MAINTAIN MLAT-CLIENT AND NETCAT TO FEED ADS-B EXCHANGE +## DOWNLOAD OR UPDATE THE MLAT-CLIENT SOURCE -echo "" -echo -e "\e[95m Creating maintenance for both the mlat-client and netcat feeds...\e[97m" -echo "" +if [[ "${FEEDER_MLAT_ENABLED}" = "true" ]] ; then + echo -e "" + echo -e "\e[95m Preparing the mlat-client Git repository...\e[97m" + echo -e "" -# Ask the user for the user name for this receiver. -RECEIVERNAME_TITLE="Receiver Name" -while [[ -z $RECEIVERNAME ]]; do - RECEIVERNAME=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --backtitle "$BACKTITLETEXT" --title "$RECEIVERNAME_TITLE" --nocancel --inputbox "\nPlease enter a name for this receiver.\n\nIf you have more than one receiver, this name should be unique.\nExample: \"username-01\", \"username-02\", etc." 12 78 3>&1 1>&2 2>&3) - RECEIVERNAME_TITLE="Receiver Name (REQUIRED)" -done + # Check if build directory exists and contains the relevant git repository. + if [[ -d "${MLAT_CLIENT_BUILD_DIRECTORY}/.git" ]] && [[ -f "${MLAT_CLIENT_BUILD_DIRECTORY}/.git/config" ]] && [[ `grep -c "url = ${MLAT_CLIENT_GITHUB_URL}" ${MLAT_CLIENT_BUILD_DIRECTORY}/.git/config` -gt 0 ]] ; then + # A directory with a git repository containing the source code already exists. + echo -e "\e[94m Entering the mlat-client git repository directory...\e[97m" + cd ${MLAT_CLIENT_BUILD_DIRECTORY} 2>&1 + echo -e "\e[94m Fetching changes from the remote mlat-client git repository...\e[97m" + echo -e "" + git fetch --tags origin 2>&1 + echo -e "\e[94m Updating the local mlat-client git repository...\e[97m" + echo -e "" + git reset --hard origin/master 2>&1 + else + # A directory containing the source code does not exist locally. + echo -e "\e[94m Entering the ${RECEIVER_PROJECT_TITLE} build directory...\e[97m" + cd ${RECEIVER_BUILD_DIRECTORY} 2>&1 + echo -e "\e[94m Cloning the mlat-client git repository locally...\e[97m" + echo -e "" + git clone ${MLAT_CLIENT_GITHUB_URL} 2>&1 + fi -# Get the altitude of the receiver from the Google Maps API using the latitude and longitude assigned dump1090-mutability. -RECEIVERLATITUDE=`GetConfig "LAT" "/etc/default/dump1090-mutability"` -RECEIVERLONGITUDE=`GetConfig "LON" "/etc/default/dump1090-mutability"` + # Enter the git repository directory. + if [[ ! "${PWD}" = "${MLAT_CLIENT_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Entering the mlat-client git repository directory...\e[97m" + echo -e "" + cd ${MLAT_CLIENT_BUILD_DIRECTORY} 2>&1 + fi -# Ask the user for the receivers altitude. (This will be prepopulated by the altitude returned from the Google Maps API. -RECEIVERALTITUDE=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --backtitle "$BACKTITLETEXT" --title "Receiver Altitude" --nocancel --inputbox "\nEnter your receiver's altitude." 9 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) + # Check that a git tag has been specified and that it is valid. + if [[ -z "${MLAT_CLIENT_TAG}" ]] || [[ `git ls-remote 2>/dev/null| grep -c "refs/tags/${MLAT_CLIENT_TAG}\$"` -eq 0 ]] ; then + # No tag has been specified, or the this tag is not present in the remote repo. + if [[ -n "${MLAT_CLIENT_VERSION}" ]] && [[ `git ls-remote 2>/dev/null| grep -c "refs/tags/v${MLAT_CLIENT_VERSION}\$"` -gt 0 ]] ; then + # If there is a tag matching the configured version use that. + MLAT_CLIENT_TAG="v${MLAT_CLIENT_VERSION}" + else + # Otherwise get the most recent tag in the hope that it is a stable release. + MLAT_CLIENT_TAG=`git ls-remote | grep "refs/tags/v" | awk '{print $2}'| sort -V | awk -F "/" '{print $3}' | tail -1` + fi + fi -# Create the adsbexchange directory in the build directory if it does not exist. -echo -e "\e[94m Checking for the adsbexchange build directory...\e[97m" -if [ ! -d "$ADSBEXCHANGEBUILDDIRECTORY" ]; then - echo -e "\e[94m Creating the adsbexchange build directory...\e[97m" - mkdir $ADSBEXCHANGEBUILDDIRECTORY + # Attempt to check out the required code version based on the supplied tag. + if [[ -n "${MLAT_CLIENT_TAG}" ]] && [[ `git ls-remote 2>/dev/null| grep -c "refs/tags/${MLAT_CLIENT_TAG}"` -gt 0 ]] ; then + # If a valid git tag has been specified then check that out. + echo -e "\e[94m Checking out mlat-client version \"${MLAT_CLIENT_TAG}\"...\e[97m" + git checkout tags/${MLAT_CLIENT_TAG} 2>&1 + else + # Otherwise checkout the master branch. + echo -e "\e[94m Checking out mlat-client from the master branch...\e[97m" + git checkout master 2>&1 + fi + + ## BUILD AND INSTALL THE MLAT-CLIENT PACKAGE + + echo -e "" + echo -e "\e[95m Building and installing the mlat-client package...\e[97m" + echo -e "" + + # Build binary package. + echo -e "\e[94m Building the mlat-client package...\e[97m" + echo -e "" + dpkg-buildpackage -b -uc 2>&1 + echo -e "" + + # Install binary package. + echo -e "\e[94m Installing the mlat-client package...\e[97m" + echo -e "" + sudo dpkg -i ${RECEIVER_BUILD_DIRECTORY}/mlat-client_${MLAT_CLIENT_VERSION}*.deb 2>&1 + echo -e "" + + # Check installed version. + MLAT_CLIENT_VERSION_AVAILABLE=$(echo ${MLAT_CLIENT_VERSION} | tr -cd '[:digit:]' | sed -e 's/^0//g') + MLAT_CLIENT_VERSION_INSTALLED=$(sudo dpkg -s mlat-client 2>/dev/null | grep "^Version:" | awk '{print $2}' | tr -cd '[:digit:]' | sed -e 's/^0//g') + + # Check that the component package was installed successfully. + echo -e "" + echo -e "\e[94m Checking that the mlat-client package was installed properly...\e[97m" + echo -e "" + + if [[ $(dpkg-query -W -f='${STATUS}' mlat-client 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + # If the mlat-client package could not be installed halt setup. + echo -e "" + echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" + echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." + echo -e " SETUP HAS BEEN TERMINATED!" + echo -e "" + echo -e "\e[93mThe package \"mlat-client\" could not be installed.\e[39m" + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m ADS-B Exchange feed setup halted.\e[39m" + echo -e "" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE + fi + exit 1 + else + # Create binary package archive directory. + if [[ ! -d "${RECEIVER_BUILD_DIRECTORY}/package-archive" ]] ; then + echo -e "\e[94m Creating package archive directory...\e[97m" + echo -e "" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + fi + + # Archive binary package. + echo -e "\e[94m Archiving the mlat-client package...\e[97m" + echo -e "" + mv -vf ${RECEIVER_BUILD_DIRECTORY}/mlat-client_*.deb ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + + # Archive changelog. + echo -e "\e[94m Archiving the mlat-client changelog...\e[97m" + echo -e "" + mv -vf ${RECEIVER_BUILD_DIRECTORY}/mlat-client_*.changes ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + fi fi -echo -e "\e[94m Creating the file adsbexchange-netcat_maint.sh...\e[97m" -tee $ADSBEXCHANGEBUILDDIRECTORY/adsbexchange-netcat_maint.sh > /dev/null <&1 +fi +echo -e "" + +# Create netcat maint script if required. +if [[ "${FEEDER_BEAST_ENABLED}" = "true" ]] ; then + echo -e "\e[94m Creating the file ${FEEDER_NAME}-netcat_maint.sh...\e[97m" + tee ${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-netcat_maint.sh > /dev/null < /dev/null < /dev/null <0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i $ADSBEXCHANGEBUILDDIRECTORY/adsbexchange-netcat_maint.sh &\n" /etc/rc.local + echo -e "" fi -echo -e "\e[94m Checking if the mlat-client startup line is contained within the file /etc/rc.local...\e[97m" -if ! grep -Fxq "$ADSBEXCHANGEBUILDDIRECTORY/adsbexchange-mlat_maint.sh &" /etc/rc.local; then - echo -e "\e[94m Adding the mlat-client startup line to the file /etc/rc.local...\e[97m" - lnum=($(sed -n '/exit 0/=' /etc/rc.local)) - ((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i $ADSBEXCHANGEBUILDDIRECTORY/adsbexchange-mlat_maint.sh &\n" /etc/rc.local +# Set permissions on netcat script. +if [[ "${FEEDER_BEAST_ENABLED}" = "true" ]] ; then + echo -e "\e[94m Setting file permissions for ${FEEDER_NAME}-netcat_maint.sh...\e[97m" + sudo chmod +x ${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-netcat_maint.sh 2>&1 fi -## START THE MLAT-CLIENT AND NETCAT FEED - -echo "" -echo -e "\e[95m Starting both the mlat-client and netcat feeds...\e[97m" -echo "" - -# Kill any currently running instances of the adsbexchange-netcat_maint.sh script. -echo -e "\e[94m Checking for any running adsbexchange-netcat_maint.sh processes...\e[97m" -PIDS=`ps -efww | grep -w "adsbexchange-netcat_maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'` -if [ ! -z "$PIDS" ]; then - echo -e "\e[94m Killing any running adsbexchange-netcat_maint.sh processes...\e[97m" - sudo kill $PIDS - sudo kill -9 $PIDS -fi -PIDS=`ps -efww | grep -w "/bin/nc feed.adsbexchange.com" | awk -vpid=$$ '$2 != pid { print $2 }'` -if [ ! -z "$PIDS" ]; then - echo -e "\e[94m Killing any running netcat processes...\e[97m" - sudo kill $PIDS - sudo kill -9 $PIDS +# Set permissions on MLAT script. +if [[ "${FEEDER_MLAT_ENABLED}" = "true" ]] ; then + echo -e "\e[94m Setting file permissions for ${FEEDER_NAME}-mlat_maint.sh...\e[97m" + sudo chmod +x ${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-mlat_maint.sh 2>&1 + echo -e "" fi -# Kill any currently running instances of the adsbexchange-mlat_maint.sh script. -echo -e "\e[94m Checking for any running adsbexchange-mlat_maint.sh processes...\e[97m" -PIDS=`ps -efww | grep -w "adsbexchange-mlat_maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'` -if [ ! -z "$PIDS" ]; then - echo -e "\e[94m Killing any running adsbexchange-mlat_maint.sh processes...\e[97m" - sudo kill $PIDS - sudo kill -9 $PIDS -fi -PIDS=`ps -efww | grep -w "mlat-client" | awk -vpid=$$ '$2 != pid { print $2 }'` -if [ ! -z "$PIDS" ]; then - echo -e "\e[94m Killing any running mlat-client processes...\e[97m" - sudo kill $PIDS - sudo kill -9 $PIDS +# Add netcat script to startup. +if [[ "${FEEDER_BEAST_ENABLED}" = "true" ]] ; then + echo -e "\e[94m Checking if the netcat startup line is contained within the file /etc/rc.local...\e[97m" + if [[ `grep -cFx "${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-netcat_maint.sh &" /etc/rc.local` -eq 0 ]] ; then + echo -e "\e[94m Adding the netcat startup line to the file /etc/rc.local...\e[97m" + lnum=($(sed -n '/exit 0/=' /etc/rc.local)) + ((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i ${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-netcat_maint.sh &\n" /etc/rc.local + echo -e "" + fi fi -echo -e "\e[94m Executing the adsbexchange-netcat_maint.sh script...\e[97m" -sudo nohup $ADSBEXCHANGEBUILDDIRECTORY/adsbexchange-netcat_maint.sh > /dev/null 2>&1 & +# Add MLAT script to startup. +if [[ "${FEEDER_MLAT_ENABLED}" = "true" ]] ; then + echo -e "\e[94m Checking if the mlat-client startup line is contained within the file /etc/rc.local...\e[97m" + if [[ `grep -cFx "${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-mlat_maint.sh &" /etc/rc.local` -eq 0 ]] ; then + echo -e "\e[94m Adding the mlat-client startup line to the file /etc/rc.local...\e[97m" + lnum=($(sed -n '/exit 0/=' /etc/rc.local)) + ((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i ${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-mlat_maint.sh &\n" /etc/rc.local + echo -e "" + fi + echo -e "" +fi -echo -e "\e[94m Executing the adsbexchange-mlat_maint.sh script...\e[97m" -sudo nohup $ADSBEXCHANGEBUILDDIRECTORY/adsbexchange-mlat_maint.sh > /dev/null 2>&1 & +## START THE NETCAT FEED AND MLAT-CLIENT -## ADS-B EXCHANGE FEED SETUP COMPLETE +echo -e "" +if [[ "${FEEDER_BEAST_ENABLED}" = "true" ]] && [[ "${FEEDER_MLAT_ENABLED}" = "true" ]] ; then + echo -e "\e[95m Starting the netcat and mlat-client feeds...\e[97m" +elif [[ "${FEEDER_BEAST_ENABLED}" = "true" ]] ; then + echo -e "\e[95m Starting the netcat feed...\e[97m" +elif [[ "${FEEDER_MLAT_ENABLED}" = "true" ]] ; then + echo -e "\e[95m Starting the mlat-client feed...\e[97m" +fi +echo -e "" -# Enter into the project root directory. -echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" -cd $PROJECTROOTDIRECTORY +# Kill any currently running instances of the feeder netcat_maint.sh script. +if [[ "${FEEDER_BEAST_ENABLED}" = "true" ]] ; then + echo -e "\e[94m Checking for any running ${FEEDER_NAME}-netcat_maint.sh processes...\e[97m" + PIDS=`ps -efww | grep -w "${FEEDER_NAME}-netcat_maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'` + if [[ -n "${PIDS}" ]] ; then + echo -e "\e[94m Killing any running ${FEEDER_NAME}-netcat_maint.sh processes...\e[97m" + sudo kill ${PIDS} 2>&1 + sudo kill -9 ${PIDS} 2>&1 + fi + PIDS=`ps -efww | grep -w "/bin/nc ${FEEDER_BEAST_DST_HOST}" | awk -vpid=$$ '$2 != pid { print $2 }'` + if [[ -n "${PIDS}" ]] ; then + echo -e "\e[94m Killing any running netcat processes...\e[97m" + sudo kill ${PIDS} 2>&1 + sudo kill -9 ${PIDS} 2>&1 + fi + echo -e "" +fi -echo "" -echo -e "\e[93m-------------------------------------------------------------------------------------------------------" +# Kill any currently running instances of the feeder mlat_maint.sh script. +if [[ "${FEEDER_MLAT_ENABLED}" = "true" ]] ; then + echo -e "\e[94m Checking for any running ${FEEDER_NAME}-mlat_maint.sh processes...\e[97m" + PIDS=`ps -efww | grep -w "${FEEDER_NAME}-mlat_maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'` + if [[ -n "${PIDS}" ]] ; then + echo -e "\e[94m Killing any running ${FEEDER_NAME}-mlat_maint.sh processes...\e[97m" + sudo kill ${PIDS} 2>&1 + sudo kill -9 ${PIDS} 2>&1 + fi + PIDS=`ps -efww | grep -w "mlat-client --input-type .* --server ${FEEDER_MLAT_DST_HOST}" | awk -vpid=$$ '$2 != pid { print $2 }'` + if [[ -n "${PIDS}" ]] ; then + echo -e "\e[94m Killing any running mlat-client processes...\e[97m" + sudo kill ${PIDS} 2>&1 + sudo kill -9 ${PIDS} 2>&1 + fi + echo -e "" +fi + +# Start netcat script. +if [[ "${FEEDER_BEAST_ENABLED}" = "true" ]] ; then + echo -e "\e[94m Executing the ${FEEDER_NAME}-netcat_maint.sh script...\e[97m" + sudo nohup ${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-netcat_maint.sh > /dev/null 2>&1 & +fi + +# Start MLAT script. +if [[ "${FEEDER_MLAT_ENABLED}" = "true" ]] ; then + echo -e "\e[94m Executing the ${FEEDER_NAME}-mlat_maint.sh script...\e[97m" + sudo nohup ${COMPONENT_BUILD_DIRECTORY}/${FEEDER_NAME}-mlat_maint.sh > /dev/null 2>&1 & + echo -e "" +fi + +### SETUP COMPLETE + +# Return to the project root directory. +echo -e "\e[94m Entering the ${RECEIVER_PROJECT_TITLE} root directory...\e[97m" +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 + +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m ADS-B Exchange feed setup is complete.\e[39m" -echo "" -read -p "Press enter to continue..." CONTINUE +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi exit 0 diff --git a/bash/feeders/flightradar24.sh b/bash/feeders/flightradar24.sh index 83a2187..6bcf0be 100755 --- a/bash/feeders/flightradar24.sh +++ b/bash/feeders/flightradar24.sh @@ -9,7 +9,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Copyright (c) 2015-2016 Joseph A. Prochazka # +# Copyright (c) 2015-2017, 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,52 +31,87 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -## VARIABLES +### VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -FR24BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build/flightradar24" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" -## INCLUDE EXTERNAL SCRIPTS +# Component specific variables. +COMPONENT_NAME="FlightRadar24 feeder client" +COMPONENT_PROVIDER="FlightRadar24" +COMPONENT_PACKAGE_NAME="fr24feed" +COMPONENT_WEBSITE="https://www.flightradar24.com/share-your-data" +COMPONENT_GITHUB_URL="" +COMPONENT_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/flightradar24" -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +# Component service script variables. +COMPONENT_SERVICE_NAME="fr24feed" -## BEGIN SETUP +### INCLUDE EXTERNAL SCRIPTS -clear -echo -e "\n\e[91m $ADSB_PROJECTTITLE" -echo "" -echo -e "\e[92m Setting up the Flightradar24 feeder client..." -echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" -echo "" -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Flightradar24 Feeder Client Setup" --yesno "The Flightradar24's feeder client can track flights within 200-400 miles and will automatically share data with Flightradar24. You can track flights directly off your device or via Flightradar24.com.\n\n http://www.flightradar24.com/share-your-data\n\nContinue setup by installing the Flightradar24 feeder client?" 13 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 Flightradar24 feeder client setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +## SET INSTALLATION VARIABLES + +# Source the automated install configuration file if this is an automated installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "true" ]] && [[ -s "${RECEIVER_CONFIGURATION_FILE}" ]] ; then + source ${RECEIVER_CONFIGURATION_FILE} +fi + +### BEGIN SETUP + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +fi +echo -e "" +echo -e "\e[92m Setting up ${COMPONENT_NAME}..." +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" + +# Check for existing component install. +if [[ $(dpkg-query -W -f='${STATUS}' ${COMPONENT_PACKAGE_NAME} 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + COMPONENT_FIRST_INSTALL="true" +fi + +# Confirm component installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Interactive install. + CONTINUE_SETUP=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${COMPONENT_NAME} Setup" --yesno "The ${COMPONENT_NAME} takes data from a local dump1090 instance and shares this with ${COMPONENT_PROVIDER} using the ${COMPONENT_PACKAGE_NAME} package, for more information please see their website:\n\n ${COMPONENT_WEBSITE}\n\nContinue setup by installing the ${COMPONENT_NAME}?" 13 78 3>&1 1>&2 2>&3) + if [[ ${CONTINUE_SETUP} -eq 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 -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi +else + # Warn that automated installation is not supported. + echo -e "\e[92m Automated installation of this script is not yet supported...\e[39m" + echo -e "" exit 1 fi -## CHECK FOR PREREQUISITE PACKAGES +### CHECK FOR PREREQUISITE PACKAGES -echo -e "\e[95m Installing packages needed to build and fulfill dependencies...\e[97m" -echo "" -if [[ `uname -m` == "x86_64" ]]; then - if [ $(dpkg --print-foreign-architectures $1 2>/dev/null | grep -c "i386") -eq 0 ]; then +echo -e "\e[95m Installing packages needed to fulfill dependencies for ${COMPONENT_NAME}...\e[97m" +echo -e "" + +if [[ "${CPU_ARCHITECTURE}" = "x86_64" ]] ; then + if [[ $(dpkg --print-foreign-architectures $1 2>/dev/null | grep -c "i386") -eq 0 ]] ; then echo -e "\e[94m Adding the i386 architecture...\e[97m" - sudo dpkg --add-architecture i386 + sudo dpkg --add-architecture i386 2>&1 echo -e "\e[94m Downloading latest package lists for enabled repositories and PPAs...\e[97m" - echo "" + echo -e "" sudo apt-get update - echo "" + echo -e "" fi CheckPackage libc6:i386 CheckPackage libudev1:i386 @@ -93,75 +128,162 @@ fi CheckPackage wget CheckPackage dirmngr -## BEGIN INSTALLATION DEPENDING ON DEVICE ARCHITECTURE +### STOP ANY RUNNING SERVICES -echo "" -echo -e "\e[95m Begining the installation process...\e[97m" -echo "" -# Create the flightradar24 build directory if it does not exist. -if [ ! -d $FR24BUILDDIRECTORY ]; then - echo -e "\e[94m Creating the Flightradar24 feeder client build directory...\e[97m" - mkdir $FR24BUILDDIRECTORY +# Attempt to stop using systemd. +if [[ "`sudo systemctl status ${COMPONENT_SERVICE_NAME} 2>&1 | egrep -c "Active: active (running)"`" -gt 0 ]] ; then + echo -e "\e[94m Stopping the ${COMPONENT_NAME} service...\e[97m" + sudo systemctl stop ${COMPONENT_SERVICE_NAME} 2>&1 fi -echo -e "\e[94m Entering the Flightradar24 feeder client build directory...\e[97m" -cd $FR24BUILDDIRECTORY -if [[ `uname -m` == "armv7l" ]] || [[ `uname -m` == "armv6l" ]] || [[ `uname -m` == "aarch64" ]]; then - ## ARM INSTALLATION +### START INSTALLATION - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Plane Finder ADS-B Client Setup Instructions" --msgbox "This script will now download and execute the official Flightradar24 setup script. Follow the instructions provided and supply the required information when ask for by the script.\n\nOnce finished the ADS-B Receiver Project scripts will continue." 11 78 - echo -e "\e[94m Detected the device architecture as ARM...\e[97m" - echo -e "\e[94m Downloading the executing the Flightradar24 Pi24 installation script...\e[97m" - echo "" - sudo bash -c "$(wget -O - http://repo.feed.flightradar24.com/install_fr24_rpi.sh)" - echo "" +echo -e "" +echo -e "\e[95m Begining the ${COMPONENT_NAME} installation process...\e[97m" +echo -e "" + +# Create the component build directory if it does not exist. +if [[ ! -d "${COMPONENT_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Creating the ${COMPONENT_NAME} build directory...\e[97m" + mkdir -vp ${COMPONENT_BUILD_DIRECTORY} +fi + +# Change to the component build directory. +if [[ ! "${PWD}" = "${COMPONENT_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Entering the ${COMPONENT_NAME} build directory...\e[97m" + cd ${COMPONENT_BUILD_DIRECTORY} 2>&1 +fi + +## BUILD AND INSTALL THE COMPONENT PACKAGE + +echo -e "" +echo -e "\e[95m Building and installing the ${COMPONENT_NAME} package...\e[97m" +echo -e "" + +## DOWNLOAD OR UPDATE THE COMPONENT SOURCE + +# Download the appropriate package depending on the devices architecture. +if [[ "${CPU_ARCHITECTURE}" = "armv7l" ]] || [[ "${CPU_ARCHITECTURE}" = "armv6l" ]] || [[ "${CPU_ARCHITECTURE}" = "aarch64" ]] ; then + # ARM achitecture detected. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${COMPONENT_NAME} setup instructions" --msgbox "This script will now download and execute the official ${COMPONENT_NAME} setup script, please follow the instructions provided and supply the required information when ask for by the script.\n\nOnce finished the ADS-B Receiver Project scripts will continue." 11 78 + + echo -e "\e[94m Downloading the ${COMPONENT_NAME} installation script for ARM...\e[97m" + echo -e "" + wget --no-check-certificate https://repo.feed.flightradar24.com/install_fr24_rpi.sh -O ${COMPONENT_BUILD_DIRECTORY}/install_fr24_rpi.sh else + # Otherwise assume i386. + echo -e "\e[94m Downloading the ${COMPONENT_NAME} v${FLIGHTRADAR24_CLIENT_VERSION_I386} package for i386 devices...\e[97m" + echo -e "" + wget --no-check-certificate https://feed.flightradar24.com/linux/${COMPONENT_PACKAGE_NAME}_${FLIGHTRADAR24_CLIENT_VERSION_I386}_i386.deb -O ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_${FLIGHTRADAR24_CLIENT_VERSION_I386}_i386.deb +fi - ## I386 INSTALLATION +## INSTALL THE COMPONENT PACKAGE - echo -e "\e[94m Detected the device architecture as I386...\e[97m" - echo -e "\e[94m Downloading the Flightradar24 feeder client package...\e[97m" - echo "" - wget http://feed.flightradar24.com/linux/fr24feed_${FR24CLIENTVERSIONI386}_i386.deb -O $FR24BUILDDIRECTORY/fr24feed_${FR24CLIENTVERSIONI386}_i386.deb - echo -e "\e[94m Installing the Flightradar24 feeder client package...\e[97m" - if [[ `lsb_release -si` == "Debian" ]]; then +# Dummy test for consistency with other feeder install scripts. +if [[ -n "${COMPONENT_NAME}" ]] ; then + echo -e "\e[94m Installing the ${COMPONENT_NAME} package...\e[97m" + echo -e "" +fi + +# Install the proper package depending on the devices architecture. +if [[ "${CPU_ARCHITECTURE}" = "armv7l" ]] || [[ "${CPU_ARCHITECTURE}" = "armv6l" ]] || [[ "${CPU_ARCHITECTURE}" = "aarch64" ]] ; then + # ARM achitecture detected. + echo -e "\e[94m Executing the ${COMPONENT_NAME} installation script...\e[97m" + echo -e "" + sudo bash ${COMPONENT_BUILD_DIRECTORY}/install_fr24_rpi.sh +else + # Otherwise assume i386. + echo -e "\e[94m Installing the ${COMPONENT_NAME} v${FLIGHTRADAR24_CLIENT_VERSION_I386} package for i386 devices...\e[97m" + if [[ `lsb_release -si` = "Debian" ]] ; then # Force architecture if this is Debian. echo -e "\e[94m NOTE: dpkg executed with added flag --force-architecture.\e[97m" - echo "" - sudo dpkg -i --force-architecture $FR24BUILDDIRECTORY/fr24feed_${FR24CLIENTVERSIONI386}_i386.deb + echo -e "" + sudo dpkg -i --force-architecture ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_${FLIGHTRADAR24_CLIENT_VERSION_I386}_i386.deb 2>&1 else - echo "" - sudo dpkg -i $FR24BUILDDIRECTORY/fr24feed_${FR24CLIENTVERSIONI386}_i386.deb + echo -e "" + sudo dpkg -i ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_${FLIGHTRADAR24_CLIENT_VERSION_I386}_i386.deb 2>&1 fi - echo "" - echo -e "\e[94m Checking that the fr24feed package was installed properly...\e[97m" - if [ $(dpkg-query -W -f='${STATUS}' fr24feed 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - # If the fr24feed package could not be installed halt setup. - echo "" +fi + +# Dummy test for consistency with other feeder install scripts. +if [[ -n "${CPU_ARCHITECTURE}" ]] ; then + # Check that the component package was installed successfully. + echo -e "" + echo -e "\e[94m Checking that the ${COMPONENT_NAME} package was installed properly...\e[97m" + echo -e "" + + if [[ $(dpkg-query -W -f='${STATUS}' ${COMPONENT_PACKAGE_NAME} 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + # If the component package could not be installed halt setup. + echo -e "" echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." echo -e " SETUP HAS BEEN TERMINATED!" - echo "" - echo -e "\e[93mThe package \"fr24feed\" could not be installed.\e[39m" - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" - echo -e "\e[92m Flightradar24 feeder client setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE + echo -e "" + echo -e "\e[93mThe package \"${COMPONENT_PACKAGE_NAME}\" could not be installed.\e[39m" + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE + fi exit 1 + elif [[ ! "${CPU_ARCHITECTURE}" = "armv7l" ]] && [[ ! "${CPU_ARCHITECTURE}" = "armv6l" ]] && [[ ! "${CPU_ARCHITECTURE}" = "aarch64" ]] ; then + # Create binary package archive directory. + if [[ ! -d "${RECEIVER_BUILD_DIRECTORY}/package-archive" ]] ; then + echo -e "\e[94m Creating package archive directory...\e[97m" + echo -e "" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + fi + + # Archive binary package. + echo -e "\e[94m Moving the ${COMPONENT_NAME} binary package into the archive directory...\e[97m" + echo -e "" + mv -vf ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_*.deb ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + +## COMPONENT POST INSTALL ACTIONS + + # Check for component first install + if [[ "${COMPONENT_FIRST_INSTALL}" = "true" ]] ; then + # Run signup script if first install. + echo -e "\e[94m Starting ${COMPONENT_PACKAGE_NAME} signup wizard...\e[97m" + echo -e "" + ${COMPONENT_PACKAGE_NAME} --signup + echo -e "" + fi + + # Update config file permissions + echo -e "\e[94m Updating configuration file permissions...\e[97m" + echo -e "" + sudo chmod a+rw /etc/fr24feed.ini 2>&1 + echo -e "" + + # (re)start the component service. + if [[ "`sudo systemctl status ${COMPONENT_SERVICE_NAME} 2>&1 | egrep -c "Active: active (running)"`" -gt 0 ]] ; then + echo -e "\e[94m Restarting the ${COMPONENT_NAME} service...\e[97m" + sudo systemctl restart ${COMPONENT_SERVICE_NAME} 2>&1 + else + echo -e "\e[94m Starting the ${COMPONENT_NAME} service...\e[97m" + sudo systemctl start ${COMPONENT_SERVICE_NAME} 2>&1 + fi + echo -e "" fi fi -## FLIGHTRADAR24 FEEDER CLIENT SETUP COMPLETE +### SETUP COMPLETE -# Enter into the project root directory. -echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" -cd $PROJECTROOTDIRECTORY +# Return to the project root directory. +echo -e "\e[94m Returning to ${RECEIVER_PROJECT_TITLE} root directory...\e[97m" +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 -echo "" -echo -e "\e[93m-------------------------------------------------------------------------------------------------------" -echo -e "\e[92m Flightradar24 feeder client setup is complete.\e[39m" -echo "" -read -p "Press enter to continue..." CONTINUE +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" +echo -e "\e[92m ${COMPONENT_NAME} setup is complete.\e[39m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi exit 0 diff --git a/bash/feeders/piaware.sh b/bash/feeders/piaware.sh index 0cd4197..d4943c4 100755 --- a/bash/feeders/piaware.sh +++ b/bash/feeders/piaware.sh @@ -9,7 +9,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Copyright (c) 2015-2016 Joseph A. Prochazka # +# Copyright (c) 2015-2017, 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,46 +31,83 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -## VAARIABLES +### VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -PIAWAREBUILDDIRECTORY="$PROJECTROOTDIRECTORY/build/piaware_builder" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" -## INCLUDE EXTERNAL SCRIPTS +# Component specific variables. +COMPONENT_NAME="FlightAware PiAware client" +COMPONENT_PROVIDER="FlightAware" +COMPONENT_PACKAGE_NAME="piaware" +COMPONENT_WEBSITE="https://www.flightaware.com/adsb/piaware/" +COMPONENT_GITHUB_URL="https://github.com/flightaware/piaware_builder.git" +COMPONENT_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/piaware_builder" -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +# Component service script variables. +COMPONENT_SERVICE_NAME="piaware" -## BEGIN SETUP +### INCLUDE EXTERNAL SCRIPTS -clear -echo -e "\n\e[91m $ADSB_PROJECTTITLE" -echo "" -echo -e "\e[92m Setting up FlightAware's PiAware..." -echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" -echo "" -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "PiAware Setup" --yesno "PiAware is a package used to forward data read from an ADS-B receiver to FlightAware. It does this using a program, piaware, while aided by other support programs.\n\n https://github.com/flightaware/piaware\n\nContinue setup by installing FlightAware's PiAware?" 13 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 Dump1090-mutability setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +## SET INSTALLATION VARIABLES + +# Source the automated install configuration file if this is an automated installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "true" ]] && [[ -s "${RECEIVER_CONFIGURATION_FILE}" ]] ; then + source ${RECEIVER_CONFIGURATION_FILE} +fi + +### BEGIN SETUP + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +fi +echo -e "" +echo -e "\e[92m Setting up ${COMPONENT_NAME}..." +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" + +# Check for existing component install. +if [[ $(dpkg-query -W -f='${STATUS}' ${COMPONENT_PACKAGE_NAME} 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + COMPONENT_FIRST_INSTALL="true" +fi + +# Confirm component installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Interactive install. + CONTINUE_SETUP=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${COMPONENT_NAME} Setup" --yesno "The ${COMPONENT_NAME} takes data from a local dump1090 instance and shares this with ${COMPONENT_PROVIDER} using the ${COMPONENT_PACKAGE_NAME} package, for more information please see their website:\n\n ${COMPONENT_WEBSITE}\n\nContinue setup by installing the ${COMPONENT_NAME}?" 13 78 3>&1 1>&2 2>&3) + if [[ ${CONTINUE_SETUP} -eq 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 -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi +else + # Warn that automated installation is not supported. + echo -e "\e[92m Automated installation of this script is not yet supported...\e[39m" + echo -e "" exit 1 fi -## CHECK FOR PREREQUISITE PACKAGES +### CHECK FOR PREREQUISITE PACKAGES -echo -e "\e[95m Installing packages needed to build and fulfill dependencies...\e[97m" -echo "" +echo -e "\e[95m Installing packages needed to fulfill dependencies for ${COMPONENT_NAME}...\e[97m" +echo -e "" + +# Required by install script. CheckPackage git CheckPackage build-essential +# Required by component. CheckPackage debhelper CheckPackage tcl8.6-dev CheckPackage autoconf @@ -84,93 +121,134 @@ CheckPackage tcllib CheckPackage tcl-tls CheckPackage itcl3 -## DOWNLOAD OR UPDATE THE PIAWARE_BUILDER SOURCE +### STOP ANY RUNNING SERVICES -echo "" -echo -e "\e[95m Preparing the piaware_builder Git repository...\e[97m" -echo "" -if [ -d $PIAWAREBUILDDIRECTORY ] && [ -d $PIAWAREBUILDDIRECTORY/.git ]; then +# Attempt to stop using systemd. +if [[ "`sudo systemctl status ${COMPONENT_SERVICE_NAME} 2>&1 | egrep -c "Active: active (running)"`" -gt 0 ]] ; then + echo -e "\e[94m Stopping the ${COMPONENT_NAME} service...\e[97m" + sudo systemctl stop ${COMPONENT_SERVICE_NAME} 2>&1 +fi + +### START INSTALLATION + +echo -e "" +echo -e "\e[95m Begining the ${COMPONENT_NAME} installation process...\e[97m" +echo -e "" + +if [[ -d "${COMPONENT_BUILD_DIRECTORY}" ]] && [[ -d "${COMPONENT_BUILD_DIRECTORY}/.git" ]] ; then # A directory with a git repository containing the source code already exists. echo -e "\e[94m Entering the piaware_builder git repository directory...\e[97m" - cd $PIAWAREBUILDDIRECTORY + cd ${COMPONENT_BUILD_DIRECTORY} 2>&1 echo -e "\e[94m Updating the local piaware_builder git repository...\e[97m" - echo "" - git pull + echo -e "" + git pull 2>&1 else # A directory containing the source code does not exist in the build directory. echo -e "\e[94m Entering the ADS-B Receiver Project build directory...\e[97m" - cd $BUILDDIRECTORY + cd ${RECEIVER_BUILD_DIRECTORY} 2>&1 echo -e "\e[94m Cloning the piaware_builder git repository locally...\e[97m" - echo "" - git clone https://github.com/flightaware/piaware_builder.git + echo -e "" + git clone ${COMPONENT_GITHUB_URL} 2>&1 fi -## BUILD AND INSTALL THE PIAWARE PACKAGE +## BUILD AND INSTALL THE COMPONENT PACKAGE -echo "" -echo -e "\e[95m Building and installing the PiAware package...\e[97m" -echo "" -if [ ! $PWD = $PIAWAREBUILDDIRECTORY ]; then +echo -e "" +echo -e "\e[95m Building and installing the ${COMPONENT_NAME} package...\e[97m" +echo -e "" + +# Change to the component build directory. +if [[ ! "${PWD}" = "${COMPONENT_BUILD_DIRECTORY}" ]] ; then echo -e "\e[94m Entering the piaware_builder git repository directory...\e[97m" - cd $PIAWAREBUILDDIRECTORY + cd ${COMPONENT_BUILD_DIRECTORY} 2>&1 fi -echo -e "\e[94m Executing the PiAware build script...\e[97m" -echo "" -./sensible-build.sh jessie -echo "" -echo -e "\e[94m Entering the PiAware build directory...\e[97m" -cd $PIAWAREBUILDDIRECTORY/package-jessie -echo -e "\e[94m Building the PiAware package...\e[97m" -echo "" -dpkg-buildpackage -b -echo "" -echo -e "\e[94m Installing the PiAware package...\e[97m" -echo "" -sudo dpkg -i $PIAWAREBUILDDIRECTORY/piaware_*.deb -# Check that the PiAware package was installed successfully. -echo "" -echo -e "\e[94m Checking that the piaware package was installed properly...\e[97m" -if [ $(dpkg-query -W -f='${STATUS}' piaware 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - # If the piaware package could not be installed halt setup. - echo "" - echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" - echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." - echo -e " SETUP HAS BEEN TERMINATED!" - echo "" - echo -e "\e[93mThe package \"piaware\" could not be installed.\e[39m" - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" - echo -e "\e[92m PiAware setup halted.\e[39m" - echo "" +# Dummy test for consistency with other feeder install scripts. +if [[ -n "${CPU_ARCHITECTURE}" ]] ; then + # Execute build script. + echo -e "\e[94m Executing the ${COMPONENT_NAME} build script...\e[97m" + echo -e "" + ./sensible-build.sh jessie + echo -e "" + + # Change to build script directory. + echo -e "\e[94m Entering the ${COMPONENT_NAME} build directory...\e[97m" + cd ${COMPONENT_BUILD_DIRECTORY}/package-jessie 2>&1 + echo -e "" + + # Build binary package. + echo -e "\e[94m Building the ${COMPONENT_NAME} package...\e[97m" + echo -e "" + dpkg-buildpackage -b 2>&1 + echo -e "" + + # Install binary package. + echo -e "\e[94m Installing the ${COMPONENT_NAME} package...\e[97m" + echo -e "" + sudo dpkg -i ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_*.deb 2>&1 + echo -e "" + + # Check that the component package was installed successfully. + echo -e "" + echo -e "\e[94m Checking that the ${COMPONENT_NAME} package was installed properly...\e[97m" + echo -e "" + + if [[ $(dpkg-query -W -f='${STATUS}' ${COMPONENT_PACKAGE_NAME} 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + # If the component package could not be installed halt setup. + echo -e "" + echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" + echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." + echo -e " SETUP HAS BEEN TERMINATED!" + echo -e "" + echo -e "\e[93mThe package \"${COMPONENT_PACKAGE_NAME}\" could not be installed.\e[39m" + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE + fi + exit 1 + else + # Create binary package archive directory. + if [[ ! -d "${RECEIVER_BUILD_DIRECTORY}/package-archive" ]] ; then + echo -e "\e[94m Creating package archive directory...\e[97m" + echo -e "" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + fi + + # Archive binary package. + echo -e "\e[94m Moving the ${COMPONENT_NAME} binary package into the archive directory...\e[97m" + echo -e "" + mv -vf ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_*.deb ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + + # Archive changelog. + echo -e "\e[94m Moving the ${COMPONENT_NAME} changes file into the archive directory...\e[97m" + echo -e "" + mv -vf ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_*.changes ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + fi +fi + +## COMPONENT POST INSTALL ACTIONS + +# Instruct the user as to how they can claim their receiver online. +whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Claiming Your PiAware Device" --yesno "FlightAware now requires you claim your feeder online using the following page:\n\n http://flightaware.com/adsb/piaware/claim\n\nTo claim your device simply visit the address listed above to complete the process." 16 78 + +### SETUP COMPLETE + +# Return to the project root directory. +echo -e "\e[94m Returning to ${RECEIVER_PROJECT_TITLE} root directory...\e[97m" +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 + +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" +echo -e "\e[92m ${COMPONENT_NAME} setup is complete.\e[39m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then read -p "Press enter to continue..." CONTINUE - exit 1 fi -# Move the .deb package into another directory simply to keep it for historical reasons. -if [ ! -d $PIAWAREBUILDDIRECTORY/packages ]; then - echo -e "\e[94m Making the PiAware package archive directory...\e[97m" - mkdir $PIAWAREBUILDDIRECTORY/packages -fi -echo -e "\e[94m Moving the PiAware package into the package archive directory...\e[97m" -mv $PIAWAREBUILDDIRECTORY/piaware_*.deb $PIAWAREBUILDDIRECTORY/packages/ -echo -e "\e[94m Moving the PiAware package changes file into the package archive directory...\e[97m" -mv $PIAWAREBUILDDIRECTORY/piaware_*.changes $PIAWAREBUILDDIRECTORY/packages/ - -## INSTRUCTIONS TO CLAIM THE RECIEVER - -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Claim Your PiAware Device" --msgbox "IMPORTANT!!!/n/nYou will need to claim this PiAware device manually by visiting the following URL.\n\nhttp://flightaware.com/adsb/piaware/claim." 10 78 - -## PIAWARE 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 PiAware setup is complete.\e[39m" -echo "" -read -p "Press enter to continue..." CONTINUE - exit 0 diff --git a/bash/feeders/planefinder.sh b/bash/feeders/planefinder.sh index 0c5f595..a50ba60 100755 --- a/bash/feeders/planefinder.sh +++ b/bash/feeders/planefinder.sh @@ -9,7 +9,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Copyright (c) 2015-2016 Joseph A. Prochazka # +# Copyright (c) 2015-2017, 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,53 +31,87 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -## VARIABLES +### VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -PLANEFINDERBUILDDIRECTORY="$PROJECTROOTDIRECTORY/build/planefinder" -DEVICEIPADDRESS=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'` +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" -## INCLUDE EXTERNAL SCRIPTS +# Component specific variables. +COMPONENT_NAME="PlaneFinder ADS-B Client" +COMPONENT_PROVIDER="PlaneFinder" +COMPONENT_PACKAGE_NAME="pfclient" +COMPONENT_WEBSITE="https://planefinder.net/sharing/client" +COMPONENT_GITHUB_URL="" +COMPONENT_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/planefinder" +RECEIVER_IP_ADDRESS=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'` -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +# Component service script variables. -## BEGIN SETUP +### INCLUDE EXTERNAL SCRIPTS -clear -echo -e "\n\e[91m $ADSB_PROJECTTITLE" -echo "" -echo -e "\e[92m Setting up the Plane Finder ADS-B Client..." -echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" -echo "" -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Plane Finder ADS-B Client Setup" --yesno "The Plane Finder ADS-B Client is an easy and accurate way to share your ADS-B and MLAT data with Plane Finder. It comes with a beautiful user interface that helps you explore and interact with your data in realtime.\n\n https://planefinder.net/sharing/client\n\nContinue setup by installing the Plane Finder ADS-B Client?" 13 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 Plane Finder ADS-B Client setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +## SET INSTALLATION VARIABLES + +# Source the automated install configuration file if this is an automated installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "true" ]] && [[ -s "${RECEIVER_CONFIGURATION_FILE}" ]] ; then + source ${RECEIVER_CONFIGURATION_FILE} +fi + +### BEGIN SETUP + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +fi +echo -e "" +echo -e "\e[92m Setting up ${COMPONENT_NAME}..." +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" + +# Check for existing component install. +if [[ $(dpkg-query -W -f='${STATUS}' ${COMPONENT_PACKAGE_NAME} 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + COMPONENT_FIRST_INSTALL="true" +fi + +# Confirm component installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Interactive install. + CONTINUE_SETUP=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${COMPONENT_NAME} Setup" --yesno "The ${COMPONENT_NAME} is an easy and accurate way to share your ADS-B and MLAT data with Plane Finder. It comes with a beautiful user interface that helps you explore and interact with your data in realtime.\n\n ${COMPONENT_WEBSITE}\n\nContinue setup by installing ${COMPONENT_NAME}?" 13 78 3>&1 1>&2 2>&3) + if [[ ${CONTINUE_SETUP} -eq 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 -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi +else + # Warn that automated installation is not supported. + echo -e "\e[92m Automated installation of ${COMPONENT_NAME} is not yet supported...\e[39m" + echo -e "" exit 1 fi -## CHECK FOR PREREQUISITE PACKAGES +### CHECK FOR PREREQUISITE PACKAGES -echo -e "\e[95m Installing packages needed to build and fulfill dependencies...\e[97m" -echo "" -if [[ `uname -m` == "x86_64" ]]; then - if [ $(dpkg --print-foreign-architectures $1 2>/dev/null | grep -c "i386") -eq 0 ]; then +echo -e "\e[95m Installing packages needed to fulfill dependencies for ${COMPONENT_NAME}...\e[97m" +echo -e "" + +if [[ "${CPU_ARCHITECTURE}" = "x86_64" ]] ; then + if [[ $(dpkg --print-foreign-architectures $1 2>/dev/null | grep -c "i386") -eq 0 ]] ; then echo -e "\e[94m Adding the i386 architecture...\e[97m" - sudo dpkg --add-architecture i386 + sudo dpkg --add-architecture i386 2>&1 echo -e "\e[94m Downloading latest package lists for enabled repositories and PPAs...\e[97m" - echo "" + echo -e "" sudo apt-get update - echo "" + echo -e "" fi CheckPackage libc6:i386 else @@ -85,83 +119,132 @@ else fi CheckPackage wget -## DOWNLOAD THE PLANEFINDER ADS-B CLIENT PACKAGE +### STOP ANY RUNNING SERVICES -echo "" -echo -e "\e[95m Downloading the Plane Finder ADS-B Client package...\e[97m" -echo "" -# Create the planefinder build directory if it does not exist. -if [ ! -d $PLANEFINDERBUILDDIRECTORY ]; then - echo -e "\e[94m Creating the Plane Finder ADS-B Client build directory...\e[97m" - mkdir $PLANEFINDERBUILDDIRECTORY +### START INSTALLATION + +echo -e "" +echo -e "\e[95m Begining the ${COMPONENT_NAME} installation process...\e[97m" +echo -e "" + +# Create the component build directory if it does not exist. +if [[ ! -d "${COMPONENT_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Creating the ${COMPONENT_NAME} build directory...\e[97m" + mkdir -vp ${COMPONENT_BUILD_DIRECTORY} fi + +# Change to the component build directory. +if [[ ! "${PWD}" = "${COMPONENT_BUILD_DIRECTORY}" ]] ; then + echo -e "\e[94m Entering the ${COMPONENT_NAME} build directory...\e[97m" + cd ${COMPONENT_BUILD_DIRECTORY} 2>&1 +fi + +## BUILD AND INSTALL THE COMPONENT PACKAGE + +echo -e "" +echo -e "\e[95m Building and installing the ${COMPONENT_NAME} package...\e[97m" +echo -e "" + +## DOWNLOAD OR UPDATE THE COMPONENT SOURCE + # Download the appropriate package depending on the devices architecture. -if [[ `uname -m` == "armv7l" ]] || [[ `uname -m` == "armv6l" ]]; then - echo -e "\e[94m Downloading the Plane Finder ADS-B Client v$PFCLIENTVERSIONARM for ARM devices...\e[97m" - echo "" - wget http://client.planefinder.net/pfclient_${PFCLIENTVERSIONARM}_armhf.deb -O $PLANEFINDERBUILDDIRECTORY/pfclient_${PFCLIENTVERSIONARM}_armhf.deb +if [[ "${CPU_ARCHITECTURE}" = "armv7l" ]] || [[ "${CPU_ARCHITECTURE}" = "armv6l" ]] ; then + # ARM achitecture detected. + echo -e "\e[94m Downloading the ${COMPONENT_NAME} v${PLANEFINDER_CLIENT_VERSION_ARM} package for ARM devices...\e[97m" + echo -e "" + wget --no-check-certificate https://client.planefinder.net/${COMPONENT_PACKAGE_NAME}_${PLANEFINDER_CLIENT_VERSION_ARM}_armhf.deb -O ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_${PLANEFINDER_CLIENT_VERSION_ARM}_armhf.deb else - echo -e "\e[94m Downloading the Plane Finder ADS-B Client v$PFCLIENTVERSIONI386 for I386 devices...\e[97m" - echo "" - wget http://client.planefinder.net/pfclient_${PFCLIENTVERSIONI386}_i386.deb -O $PLANEFINDERBUILDDIRECTORY/pfclient_${PFCLIENTVERSIONI386}_i386.deb + # Otherwise assume i386. + echo -e "\e[94m Downloading the ${COMPONENT_NAME} v${PLANEFINDER_CLIENT_VERSION_I386} package for i386 devices...\e[97m" + echo -e "" + wget --no-check-certificate https://client.planefinder.net/${COMPONENT_PACKAGE_NAME}_${PLANEFINDER_CLIENT_VERSION_I386}_i386.deb -O ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_${PLANEFINDER_CLIENT_VERSION_I386}_i386.deb fi -## INSTALL THE PLANEFINDER ADS-B CLIENT PACKAGE +## INSTALL THE COMPONENT PACKAGE + +# Dummy test for consistency with other feeder install scripts. +if [[ -n "${COMPONENT_NAME}" ]] ; then + echo -e "\e[94m Installing the ${COMPONENT_NAME} package...\e[97m" + echo -e "" +fi -echo -e "\e[95m Installing the Plane Finder ADS-B Client package...\e[97m" -echo "" -echo -e "\e[94m Entering the Plane Finder ADS-B Client build directory...\e[97m" -cd $PLANEFINDERBUILDDIRECTORY # Install the proper package depending on the devices architecture. -if [[ `uname -m` == "armv7l" ]] || [[ `uname -m` == "armv6l" ]] || [[ `uname -m` == "aarch64" ]]; then - echo -e "\e[94m Installing the Plane Finder ADS-B Client v$PFCLIENTVERSIONARM for ARM devices package...\e[97m" - echo "" - sudo dpkg -i $PLANEFINDERBUILDDIRECTORY/pfclient_${PFCLIENTVERSIONARM}_armhf.deb +if [[ "${CPU_ARCHITECTURE}" = "armv7l" ]] || [[ "${CPU_ARCHITECTURE}" = "armv6l" ]] || [[ "${CPU_ARCHITECTURE}" = "aarch64" ]] ; then + # ARM achitecture detected. + echo -e "\e[94m Installing the ${COMPONENT_NAME} v${PLANEFINDER_CLIENT_VERSION_ARM} package for ARM devices...\e[97m" + echo -e "" + sudo dpkg -i ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_${PLANEFINDER_CLIENT_VERSION_ARM}_armhf.deb 2>&1 else - echo -e "\e[94m Installing the Plane Finder ADS-B Client v$PFCLIENTVERSIONI386 for I386 devices package...\e[97m" - if [[ `lsb_release -si` == "Debian" ]]; then + # Otherwise assume i386. + echo -e "\e[94m Installing the ${COMPONENT_NAME} v${PLANEFINDER_CLIENT_VERSION_I386} package for i386 devices...\e[97m" + if [[ `lsb_release -si` = "Debian" ]] ; then # Force architecture if this is Debian. echo -e "\e[94m NOTE: dpkg executed with added flag --force-architecture.\e[97m" - echo "" - sudo dpkg -i --force-architecture $PLANEFINDERBUILDDIRECTORY/pfclient_${PFCLIENTVERSIONI386}_i386.deb + echo -e "" + sudo dpkg -i --force-architecture ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_${PLANEFINDER_CLIENT_VERSION_I386}_i386.deb 2>&1 else - echo "" - sudo dpkg -i $PLANEFINDERBUILDDIRECTORY/pfclient_${PFCLIENTVERSIONI386}_i386.deb + echo -e "" + sudo dpkg -i ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_${PLANEFINDER_CLIENT_VERSION_I386}_i386.deb 2>&1 fi fi -# Check that the Plane Finder ADS-B Client package was installed successfully. -echo "" -echo -e "\e[94m Checking that the pfclient package was installed properly...\e[97m" -if [ $(dpkg-query -W -f='${STATUS}' pfclient 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - # If the pfclient package could not be installed halt setup. - echo "" - echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" - echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." - echo -e " SETUP HAS BEEN TERMINATED!" - echo "" - echo -e "\e[93mThe package \"pfclient\" could not be installed.\e[39m" - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" - echo -e "\e[92m Plane Finder ADS-B Client setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE - exit 1 + +# Dummy test for consistency with other feeder install scripts. +if [[ -n "${CPU_ARCHITECTURE}" ]] ; then + # Check that the component package was installed successfully. + echo -e "" + echo -e "\e[94m Checking that the ${COMPONENT_NAME} package was installed properly...\e[97m" + echo -e "" + + if [[ $(dpkg-query -W -f='${STATUS}' ${COMPONENT_PACKAGE_NAME} 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + # If the component package could not be installed halt setup. + echo -e "" + echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" + echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." + echo -e " SETUP HAS BEEN TERMINATED!" + echo -e "" + echo -e "\e[93mThe package \"${COMPONENT_PACKAGE_NAME}\" could not be installed.\e[39m" + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m ${COMPONENT_NAME} setup halted.\e[39m" + echo -e "" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE + fi + exit 1 + else + # Create binary package archive directory. + if [[ ! -d "${RECEIVER_BUILD_DIRECTORY}/package-archive" ]] ; then + echo -e "\e[94m Creating package archive directory...\e[97m" + echo -e "" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + fi + + # Archive binary package. + echo -e "\e[94m Moving the ${COMPONENT_NAME} binary package into the archive directory...\e[97m" + echo -e "" + mv -vf ${COMPONENT_BUILD_DIRECTORY}/${COMPONENT_PACKAGE_NAME}_*.deb ${RECEIVER_BUILD_DIRECTORY}/package-archive 2>&1 + echo -e "" + fi fi -## DISPLAY FINAL SETUP INSTRUCTIONS WHICH CONNOT BE HANDLED BY THIS SCRIPT +## COMPONENT POST INSTALL ACTIONS -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Plane Finder ADS-B Client Setup Instructions" --msgbox "At this point the Plane Finder ADS-B Client should be installed and running howeverThis script is only capable of installing the Plane Finder ADS-B Client. There are stilla few steps left which you must manually do through the Plane Finder ADS-B Client itself.\n\nVisit the following URL: http://${DEVICEIPADDRESS}:30053\n\nThe follow the instructions supplied by the Plane Finder ADS-B Client.\n\nUse the following settings when asked for them.\n\nData Format: Beast\nTcp Address: 127.0.0.1\nTcp Port: 30005" 20 78 +# Display final setup instructions which cannot be handled by this script. +whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${COMPONENT_NAME} Setup Instructions" --msgbox "At this point the ${COMPONENT_NAME} should be installed and running; however this script is only capable of installing the ${COMPONENT_NAME}. There are stilla few steps left which you must manually do through the ${COMPONENT_NAME} at the following URL:\n\n http://${RECEIVER_IP_ADDRESS}:30053\n\nThe follow the instructions supplied by the ${COMPONENT_NAME}.\n\nUse the following settings when asked for them.\n\nData Format: Beast\nTcp Address: 127.0.0.1\nTcp Port: 30005" 20 78 -## PLANE FINDER ADS-B CLIENT SETUP COMPLETE +### SETUP COMPLETE -# Enter into the project root directory. -echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" -cd $PROJECTROOTDIRECTORY +# Return to the project root directory. +echo -e "\e[94m Returning to ${RECEIVER_PROJECT_TITLE} root directory...\e[97m" +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 -echo "" -echo -e "\e[93m-------------------------------------------------------------------------------------------------------" -echo -e "\e[92m Plane Finder ADS-B Client setup is complete.\e[39m" -echo "" -read -p "Press enter to continue..." CONTINUE +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" +echo -e "\e[92m ${COMPONENT_NAME} setup is complete.\e[39m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi exit 0 diff --git a/bash/functions.sh b/bash/functions.sh index bfb206e..c79fa1b 100755 --- a/bash/functions.sh +++ b/bash/functions.sh @@ -9,7 +9,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Copyright (c) 2015 Joseph A. Prochazka # +# Copyright (c) 2016-2017, Joseph A. Prochazka & Romeo Golf # # # # 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,7 +31,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -####################################################################### +################################################################################# # Detect if a package is installed and if not attempt to install it. function CheckPackage { @@ -39,29 +39,29 @@ function CheckPackage { MAXATTEMPTS=5 WAITTIME=5 - while (( $ATTEMPT -le `(($MAXATTEMPTS + 1))` )); do + while (( ${ATTEMPT} -le `(($MAXATTEMPTS + 1))` )); do # If the maximum attempts has been reached... - if [ $ATTEMPT -gt $MAXATTEMPTS ]; then - echo "" + if [[ "${ATTEMPT}" -gt "${MAXATTEMPTS}" ]] ; then + echo -e "" echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m" echo -e " UNABLE TO INSTALL A REQUIRED PACKAGE." echo -e " SETUP HAS BEEN TERMINATED!" - echo "" - echo -e "\e[93mThe package \"$1\" could not be installed in $MAXATTEMPTS attempts.\e[39m" - echo "" + echo -e "" + echo -e "\e[93mThe package \"$1\" could not be installed in ${MAXATTEMPTS} attempts.\e[39m" + echo -e "" exit 1 fi # Check if the package is already installed. printf "\e[94m Checking if the package $1 is installed..." - if [ $(dpkg-query -W -f='${STATUS}' $1 2>/dev/null | grep -c "ok installed") -eq 0 ]; then + if [[ $(dpkg-query -W -f='${STATUS}' $1 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then # If this is not the first attempt at installing this package... - if [ $ATTEMPT -gt 1 ]; then + if [[ ${ATTEMPT} -gt 1 ]] ; then echo -e "\e[91m \e[5m[INSTALLATION ATTEMPT FAILED]\e[25m" - echo -e "\e[94m Attempting to Install the package $1 again in $WAITTIME seconds (ATTEMPT $ATTEMPT OF $MAXATTEMPTS)..." - sleep $WAITTIME + echo -e "\e[94m Attempting to Install the package $1 again in ${WAITTIME} seconds (ATTEMPT ${ATTEMPT} OF ${MAXATTEMPTS})..." + sleep ${WAITTIME} else echo -e "\e[91m [NOT INSTALLED]" echo -e "\e[94m Installing the package $1..." @@ -88,7 +88,7 @@ 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". - sudo sed -i "s/\($1 *= *\).*/\1\"$2\"/" $3 + sudo sed -i -e "s/\($1 *= *\).*/\1\"$2\"/" $3 } function GetConfig { @@ -106,3 +106,51 @@ function UncommentConfig { # Use sed to locate the "KEY" then uncomment the line containing it in the specified "FILE". sudo sed -i -e "/$1/s/^#//" $2 } + +################################################################################# +# The following function is used to clean up the log files by removing +# any color escaping sequences from the log file so it is easier to read. +# There are other lines not needed which can be removed as well. + +function CleanLogFile { + # Use sed to remove any color sequences from the specified "FILE". + sed -i "s,\x1B\[[0-9;]*[a-zA-Z],,g" $1 + # Remove the "Press enter to continue..." lines from the log file. + sed -i "/Press enter to continue.../d" $1 +} + +################################################################################# +# Detect CPU Architecture. + +function Check_CPU () { + if [[ -z "${CPU_ARCHITECTURE}" ]] ; then + echo -en "\e[94m Detecting CPU architecture...\e[97m" + export CPU_ARCHITECTURE=`uname -m | tr -d "\n\r"` + fi +} + +################################################################################# +# Detect Platform. + +function Check_Platform () { + if [[ -z "${HARDWARE_PLATFORM}" ]] ; then + echo -en "\e[94m Detecting hardware platform...\e[97m" + if [[ `egrep -c "^Hardware.*: BCM" /proc/cpuinfo` -gt 0 ]] ; then + export HARDWARE_PLATFORM="RPI" + elif [[ `egrep -c "^Hardware.*: Allwinner sun4i/sun5i Families$" /proc/cpuinfo` -gt 0 ]] ; then + export HARDWARE_PLATFORM="CHIP" + else + export HARDWARE_PLATFORM="unknown" + fi + fi +} + +################################################################################# +# Detect Hardware Revision. + +function Check_Hardware () { + if [[ -z "${HARDWARE_REVISION}" ]] ; then + echo -en "\e[94m Detecting Hardware revision...\e[97m" + export HARDWARE_REVISION=`grep "^Revision" /proc/cpuinfo | awk '{print $3}'` + fi +} diff --git a/bash/image.sh b/bash/image.sh index b6db137..8deae42 100755 --- a/bash/image.sh +++ b/bash/image.sh @@ -4,15 +4,12 @@ # ADS-B RECEIVER # ##################################################################################### # # -# A set of scripts created to automate the process of installing the software # -# needed to setup a Mode S decoder as well as feeders which are capable of # -# sharing your ADS-B results with many of the most popular ADS-B aggregate sites. # -# # -# Project Hosted On GitHub: https://github.com/jprochazka/adsb-receiver # +# This script is used to complete the setup of the Raspbian image files made # +# available to the public by the projects maintainer(s). # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Copyright (c) 2015 Joseph A. Prochazka # +# Copyright (c) 2015-2017, 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 # @@ -36,71 +33,80 @@ ## VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" ## INCLUDE EXTERNAL SCRIPTS -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh # Assign the Lighthttpd document root directory to a variable. RAWDOCUMENTROOT=`/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -p | grep server.document-root` -DOCUMENTROOT=`sed 's/.*"\(.*\)"[^"]*$/\1/' <<< $RAWDOCUMENTROOT` +DOCUMENTROOT=`sed 's/.*"\(.*\)"[^"]*$/\1/' <<< ${RAWDOCUMENTROOT}` ## WELCOME MESSAGE -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "ADS-B Receiver Project Image Setup" --msgbox "Thank you for choosing to use the ADS-B Receiver Project image.\n\nDuring this setup process the preinstalled dump1090-mutability installation will be configured and the ADS-B Project Web Portal will be installed. If you would like to add additional features to your receiver simply execute ./install.sh again after this initial setup process has been completed." 13 78 +whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "ADS-B Receiver Project Image Setup" --msgbox "Thank you for choosing to use the ADS-B Receiver Project image.\n\nDuring this setup process the preinstalled dump1090-mutability installation will be configured and the ADS-B Project Web Portal will be installed. If you would like to add additional features to your receiver simply execute ./install.sh again after this initial setup process has been completed." 13 78 ## ASK TO UPDATE THE OPERATING SYSTEM -if (whiptail --backtitle "$ADSB_PROJECTTITLE" --title "ADS-B Receiver Project Image Setup" --yesno "The image comes with the latest updates to Raspbian as of it's release. However updates may have been released for the operating system since the image was released. This being said it is highly recommended you allow the script to check for additional updates now in order to ensure you are in fact running the latest software available.\n\nWould you like the script to check for and install updates now?" 13 78) then +if (whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "ADS-B Receiver Project Image Setup" --yesno "The image comes with the latest updates to Raspbian as of it's release. However updates may have been released for the operating system since the image was released. This being said it is highly recommended you allow the script to check for additional updates now in order to ensure you are in fact running the latest software available.\n\nWould you like the script to check for and install updates now?" 13 78) then clear - echo -e "\n\e[91m $ADSB_PROJECTTITLE" - echo "" + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" + echo -e "" echo -e "\e[92m Downloading and installing the latest updates for your operating system..." - echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[97m" - echo "" + echo -e "\e[93m ------------------------------------------------------------------------------\e[97m" + echo -e "" sudo apt-get update sudo apt-get -y dist-upgrade - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" + echo -e "" + 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 + echo -e "" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE + fi fi ## CONFIGURE DUMP1090 clear -echo -e "\n\e[91m $ADSB_PROJECTTITLE" -echo "" +echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +echo -e "" echo -e "\e[92m Configure dump1090..." -echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" -echo "" +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" # If dump1090-mutability is installed... -if [ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]; then - # Set the receivers latitude and longitude. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Receiver Latitude and Longitude" --msgbox "Your receivers latitude and longitude 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 --backtitle "$ADSB_PROJECTTITLE" --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)" + +if [[ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then + # Explain to the user that the receiver's latitude and longitude is required. + RECEIVER_LATLON_DIALOG=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Receiver Latitude and Longitude" --msgbox "Your receivers latitude and longitude are required for distance calculations, you will now be asked to supply these values for your receiver.\n\nIf you do not have this information you can obtain it using the web based \"Geocode by Address\" utility hosted on another of the lead developers websites:\n\n https://www.swiftbyte.com/toolbox/geocode" 15 78 3>&1 1>&2 2>&3) + + # Ask the user for the receiver's latitude. + RECEIVER_LATITUDE_TITLE="Receiver Latitude" + while [[ -z "${RECEIVER_LATITUDE}" ]] ; do + RECEIVER_LATITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LATITUDE_TITLE}" --nocancel --inputbox "\nEnter your receiver's latitude.\n(Example: XX.XXXXXXX)" 9 78 3>&1 1>&2 2>&3) + RECEIVER_LATITUDE_TITLE="Receiver Latitude (REQUIRED)" done - RECEIVERLONGITUDE_TITLE="Receiver Longitude" - while [[ -z $RECEIVERLONGITUDE ]]; do - RECEIVERLONGITUDE=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --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)" + + # Ask the user for the receiver's longitude. + RECEIVER_LONGITUDE_TITLE="Receiver Longitude" + while [[ -z "${RECEIVER_LONGITUDE}" ]] ; do + RECEIVER_LONGITUDE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${RECEIVER_LONGITUDE_TITLE}" --nocancel --inputbox "\nEnter your receeiver's longitude.\n(Example: XX.XXXXXXX)" 9 78 3>&1 1>&2 2>&3) + RECEIVER_LONGITUDE_TITLE="Receiver Longitude (REQUIRED)" done - echo -e "\e[94m Setting the receiver's latitude to $RECEIVERLATITUDE...\e[97m" - ChangeConfig "LAT" $RECEIVERLATITUDE "/etc/default/dump1090-mutability" - echo -e "\e[94m Setting the receiver's longitude to $RECEIVERLONGITUDE...\e[97m" - ChangeConfig "LON" $RECEIVERLONGITUDE "/etc/default/dump1090-mutability" + + echo -e "\e[94m Setting the receiver's latitude to ${RECEIVER_LATITUDE}...\e[97m" + ChangeConfig "LAT" ${RECEIVER_LATITUDE} "/etc/default/dump1090-mutability" + echo -e "\e[94m Setting the receiver's longitude to ${RECEIVER_LONGITUDE}...\e[97m" + ChangeConfig "LON" ${RECEIVER_LONGITUDE} "/etc/default/dump1090-mutability" # Ask if dump1090-mutability should bind on all IP addresses. - if (whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Bind Dump1090-mutability To All IP Addresses" --defaultno --yesno "By default dump1090-mutability is bound only to the local loopback IP address(s) for security reasons. However some people wish to make dump1090-mutability's data accessable externally by other devices. To allow this dump1090-mutability can be configured to listen on all IP addresses bound to this device. It is recommended that unless you plan to access this device from an external source that dump1090-mutability remain bound only to the local loopback IP address(s).\n\nWould you like dump1090-mutability to listen on all IP addesses?" 15 78) then + if (whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Bind Dump1090-mutability To All IP Addresses" --defaultno --yesno "By default dump1090-mutability is bound only to the local loopback IP address(s) for security reasons. However some people wish to make dump1090-mutability's data accessable externally by other devices. To allow this dump1090-mutability can be configured to listen on all IP addresses bound to this device. It is recommended that unless you plan to access this device from an external source that dump1090-mutability remain bound only to the local loopback IP address(s).\n\nWould you like dump1090-mutability to listen on all IP addesses?" 15 78) then echo -e "\e[94m Binding dump1090-mutability to all available IP addresses...\e[97m" CommentConfig "NET_BIND_ADDRESS" "/etc/default/dump1090-mutability" else @@ -110,116 +116,126 @@ if [ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "o # Reload dump1090-mutability to ensure all changes take effect. echo -e "\e[94m Reloading dump1090-mutability...\e[97m" - echo "" + echo -e "" sudo /etc/init.d/dump1090-mutability force-reload fi # Download Heywhatsthat.com maximum range rings if the user wishes them to be displayed. -if [ ! -f /usr/share/dump1090-mutability/html/upintheair.json ] || [ ! -f /usr/share/dump1090-fa/html/upintheair.json ]; then - if (whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Heywhatsthat.com Maimum Range Rings" --yesno "Maximum range rings can be added to dump1090-mutability usings data obtained from Heywhatsthat.com. In order to add these rings to your dump1090-mutability map you will first need to visit http://www.heywhatsthat.com and generate a new panarama centered on the location of your receiver. Once your panarama has been generated a link to the panarama will be displayed in the up left hand portion of the page. You will need the view id which is the series of letters and/or numbers after \"?view=\" in this URL.\n\nWould you like to add heywhatsthat.com maximum range rings to your map?" 16 78); then - HEYWHATSTHATID_TITLE="Heywhatsthat.com Panarama ID" - while [[ -z $HEYWHATSTHATID ]]; do - HEYWHATSTHATID=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$HEYWHATSTHATID_TITLE" --nocancel --inputbox "\nEnter your Heywhatsthat.com panarama ID." 8 78 3>&1 1>&2 2>&3) - HEYWHATSTHATID_TITLE="Heywhatsthat.com Panarama ID (REQUIRED)" +if [[ ! -f "/usr/share/dump1090-mutability/html/upintheair.json" ]] || [[ ! -f "/usr/share/dump1090-fa/html/upintheair.json" ]] ; then + if (whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Heywhatsthat.com Maximum Range Rings" --yesno "Maximum range rings can be added to dump1090-mutability usings data obtained from Heywhatsthat.com. In order to add these rings to your dump1090-mutability map you will first need to visit http://www.heywhatsthat.com and generate a new panorama centered on the location of your receiver. Once your panorama has been generated a link to the panorama will be displayed in the top left hand portion of the page. You will need the view id which is the series of letters and/or numbers after \"?view=\" in this URL.\n\nWould you like to add heywhatsthat.com maximum range rings to your map?" 16 78); then + HEYWHATSTHATID_TITLE="Heywhatsthat.com Panorama ID" + while [[ -z "${HEYWHATSTHATID}" ]] ; do + HEYWHATSTHATID=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${HEYWHATSTHATID_TITLE}" --nocancel --inputbox "\nEnter your Heywhatsthat.com panorama ID." 8 78 3>&1 1>&2 2>&3) + HEYWHATSTHATID_TITLE="Heywhatsthat.com Panorama ID (REQUIRED)" done HEYWHATSTHATRINGONE_TITLE="Heywhatsthat.com First Ring Altitude" - while [[ -z $HEYWHATSTHATRINGONE ]]; do - HEYWHATSTHATRINGONE=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$HEYWHATSTHATRINGONE_TITLE" --nocancel --inputbox "\nEnter the first ring's altitude in meters.\n(default 3048 meters or 10000 feet)" 8 78 "3048" 3>&1 1>&2 2>&3) + while [[ -z "${HEYWHATSTHATRINGONE}" ]] ; do + HEYWHATSTHATRINGONE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${HEYWHATSTHATRINGONE_TITLE}" --nocancel --inputbox "\nEnter the first ring's altitude in meters.\n(default 3048 meters or 10000 feet)" 8 78 "3048" 3>&1 1>&2 2>&3) HEYWHATSTHATRINGONE_TITLE="Heywhatsthat.com First Ring Altitude (REQUIRED)" done HEYWHATSTHATRINGTWO_TITLE="Heywhatsthat.com Second Ring Altitude" - while [[ -z $HEYWHATSTHATRINGTWO ]]; do - HEYWHATSTHATRINGTWO=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$HEYWHATSTHATRINGTWO_TITLE" --nocancel --inputbox "\nEnter the second ring's altitude in meters.\n(default 12192 meters or 40000 feet)" 8 78 "12192" 3>&1 1>&2 2>&3) + while [[ -z "${HEYWHATSTHATRINGTWO}" ]] ; do + HEYWHATSTHATRINGTWO=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${HEYWHATSTHATRINGTWO_TITLE}" --nocancel --inputbox "\nEnter the second ring's altitude in meters.\n(default 12192 meters or 40000 feet)" 8 78 "12192" 3>&1 1>&2 2>&3) HEYWHATSTHATRINGTWO_TITLE="Heywhatsthat.com Second Ring Altitude (REQUIRED)" done echo -e "\e[94m Downloading JSON data pertaining to the supplied panorama ID...\e[97m" - echo "" - if [ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]; then + echo -e "" + if [[ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then HTMLPATH="/usr/share/dump1090-mutability/html/upintheair.json" else HTMLPATH="/usr/share/dump1090-fa/html/upintheair.json" fi - sudo wget -O $HTMLPATH "http://www.heywhatsthat.com/api/upintheair.json?id=${HEYWHATSTHATID}&refraction=0.25&alts=$HEYWHATSTHATRINGONE,$HEYWHATSTHATRINGTWO" + sudo wget -O ${HTMLPATH} "http://www.heywhatsthat.com/api/upintheair.json?id=${HEYWHATSTHATID}&refraction=0.25&alts=${HEYWHATSTHATRINGONE},${HEYWHATSTHATRINGTWO}" fi fi # Dump1090 configuration is now complete. -echo "" -echo -e "\e[93m----------------------------------------------------------------------------------------------------" +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m Dump1090 configuration complete.\e[39m" -echo "" -read -p "Press enter to continue..." CONTINUE +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi # CONFIGURE PIAWARE IF NEEDED -if [ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]; then +if [[ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then clear - echo -e "\n\e[91m $ADSB_PROJECTTITLE" - echo "" + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" + echo -e "" echo -e "\e[92m Configure PiAware..." - echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" - echo "" + echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" + echo -e "" - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Claim Your PiAware Device" --msgbox "Please supply your FlightAware login in order to claim this device. After supplying your login PiAware will ask you to enter your password for verification. If you decide not to supply a login and password at this time you should still be able to claim your feeder by visting the page http://flightaware.com/adsb/piaware/claim." 11 78 - # Ask for the users FlightAware login. - FLIGHTAWARELOGIN=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Your FlightAware Login" --nocancel --inputbox "\nEnter your FlightAware login.\nLeave this blank to manually claim your PiAware device." 9 78 3>&1 1>&2 2>&3) - if [ ! $FLIGHTAWARELOGIN = "" ]; then - # If the user supplied their FlightAware login continue with the device claiming process. - FLIGHTAWAREPASSWORD1_TITLE="Your FlightAware Password" - while [[ -z $FLIGHTAWAREPASSWORD1 ]]; do - FLIGHTAWAREPASSWORD1=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$FLIGHTAWAREPASSWORD1_TITLE" --nocancel --passwordbox "\nEnter your FlightAware password." 8 78 3>&1 1>&2 2>&3) - done - FLIGHTAWAREPASSWORD2_TITLE="Confirm Your FlightAware Password" - while [[ -z $FLIGHTAWAREPASSWORD2 ]]; do - FLIGHTAWAREPASSWORD2=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$FLIGHTAWAREPASSWORD2_TITLE" --nocancel --passwordbox "\nConfirm your FlightAware password." 8 78 3>&1 1>&2 2>&3) - done - while [ ! $FLIGHTAWAREPASSWORD1 = $FLIGHTAWAREPASSWORD2 ]; do - FLIGHTAWAREPASSWORD1="" - FLIGHTAWAREPASSWORD2="" - # Display an error message if the passwords did not match. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Claim Your PiAware Device" --msgbox "Passwords did not match.\nPlease enter your password again." 9 78 - FLIGHTAWAREPASSWORD1_TITLE="Your FlightAware Password (REQUIRED)" - while [[ -z $FLIGHTAWAREPASSWORD1 ]]; do - FLIGHTAWAREPASSWORD1=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$FLIGHTAWAREPASSWORD1_TITLE" --nocancel --passwordbox "\nEnter your FlightAware password." 8 78 3>&1 1>&2 2>&3) - done - FLIGHTAWAREPASSWORD2_TITLE="Confirm Your FlightAware Password (REQUIRED)" - while [[ -z $FLIGHTAWAREPASSWORD2 ]]; do - FLIGHTAWAREPASSWORD2=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$FLIGHTAWAREPASSWORD2_TITLE" --nocancel --passwordbox "\nConfirm your FlightAware password." 8 78 3>&1 1>&2 2>&3) - done - done + # Confirm if the user is able to claim their PiAware instance online. + FLIGHTAWARE_LOCAL_CREDENTIALS=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Claim Your PiAware Device" --yesno "Although it is possible to configure your FlightAware credentials locally, these will be stored in plaintext which represents a security risk that should be avoided.\n\nFlightAware recommends claiming your feeder online using the following page:\n\n http://flightaware.com/adsb/piaware/claim\n\nWill you be able to access the FlightAware website from the same public IP address as the feeder will be sending data from?" 16 78 3>&1 1>&2 2>&3) + if [[ "${FLIGHTAWARE_LOCAL_CREDENTIALS}" -eq "1" ]] ; then + # Ask for the users FlightAware login. + FLIGHTAWARE_LOGIN=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Your FlightAware Login" --nocancel --inputbox "\nEnter your FlightAware login.\nLeave this blank to manually claim your PiAware device." 9 78 3>&1 1>&2 2>&3) + if [[ ! "${FLIGHTAWARE_LOGIN}" = "" ]] ; then + # If the user supplied their FlightAware login continue with the device claiming process. + FLIGHTAWARE_PASSWORD1_TITLE="Your FlightAware Password" + while [[ -z "${FLIGHTAWARE_PASSWORD1}" ]] ; do + FLIGHTAWARE_PASSWORD1=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${FLIGHTAWARE_PASSWORD1_TITLE}" --nocancel --passwordbox "\nEnter your FlightAware password." 8 78 3>&1 1>&2 2>&3) + done + FLIGHTAWARE_PASSWORD2_TITLE="Confirm Your FlightAware Password" + while [[ -z "${FLIGHTAWARE_PASSWORD2}" ]] ; do + FLIGHTAWARE_PASSWORD2=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${FLIGHTAWARE_PASSWORD2_TITLE}" --nocancel --passwordbox "\nConfirm your FlightAware password." 8 78 3>&1 1>&2 2>&3) + done + while [[ ! "${FLIGHTAWARE_PASSWORD1}" = "${FLIGHTAWARE_PASSWORD2}" ]] ; do + FLIGHTAWARE_PASSWORD1="" + FLIGHTAWARE_PASSWORD2="" + # Display an error message if the passwords did not match. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Claim Your PiAware Device" --msgbox "Passwords did not match.\nPlease enter your password again." 9 78 + FLIGHTAWARE_PASSWORD1_TITLE="Your FlightAware Password (REQUIRED)" + while [[ -z "${FLIGHTAWARE_PASSWORD1}" ]] ; do + FLIGHTAWARE_PASSWORD1=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${FLIGHTAWARE_PASSWORD1_TITLE}" --nocancel --passwordbox "\nEnter your FlightAware password." 8 78 3>&1 1>&2 2>&3) + done + FLIGHTAWARE_PASSWORD2_TITLE="Confirm Your FlightAware Password (REQUIRED)" + while [[ -z "${FLIGHTAWARE_PASSWORD2}" ]] ; do + FLIGHTAWARE_PASSWORD2=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${FLIGHTAWARE_PASSWORD2_TITLE}" --nocancel --passwordbox "\nConfirm your FlightAware password." 8 78 3>&1 1>&2 2>&3) + done + done + else + # Display a message to the user stating they need to manually claim their device. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Claim Your PiAware Device" --msgbox "Please supply your FlightAware login in order to claim this device, after supplying this you will ask you to enter your password for verification.\n\nIf you decide not to provide a login and password at this time you should still be able to claim your feeder by visting the following site:\n\n http://flightaware.com/adsb/piaware/claim" 13 78 + fi + fi + + if [[ -n "${FLIGHTAWARE_LOGIN}" ]] && [[ -n "${FLIGHTAWARE_PASSWORD1}" ]] ; then # Set the supplied user name and password in the configuration. echo -e "\e[94m Setting the flightaware-user setting using piaware-config...\e[97m" - echo "" - sudo piaware-config flightaware-user $FLIGHTAWARELOGIN - echo "" + echo -e "" + sudo piaware-config flightaware-user ${FLIGHTAWARE_LOGIN} + echo -e "" echo -e "\e[94m Setting the flightaware-password setting using piaware-config...\e[97m" - echo "" - sudo piaware-config flightaware-password $FLIGHTAWAREPASSWORD1 - echo "" + echo -e "" + sudo piaware-config flightaware-password ${FLIGHTAWARE_PASSWORD1} + echo -e "" echo -e "\e[94m Restarting PiAware to ensure changes take effect...\e[97m" - echo "" + echo -e "" sudo /etc/init.d/piaware restart - echo "" - else - # Display a message to the user stating they need to manually claim their device. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Claim Your PiAware Device" --msgbox "Since you did not supply a login you will need to claim this PiAware device manually by visiting the following URL.\n\nhttp://flightaware.com/adsb/piaware/claim." 10 78 + echo -e "" fi # PiAware configuration is now complete. - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m PiAware configuration complete.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE + echo -e "" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE + fi fi -## SETUP THE ADS-B RECIEVER PROJECT WEB PORTAL +## SETUP THE ADS-B RECEIVER PROJECT WEB PORTAL -chmod +x $BASHDIRECTORY/portal/install.sh -$BASHDIRECTORY/portal/install.sh -if [ $? -ne 0 ]; then +chmod +x ${RECEIVER_BASH_DIRECTORY}/portal/install.sh +${RECEIVER_BASH_DIRECTORY}/portal/install.sh +if [[ $? -ne 0 ]] ; then exit 1 fi @@ -228,6 +244,6 @@ fi # remove the "image" file. rm -f image -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "ADS-B Receiver Project Image Setup" --msgbox "Image setup is now complete. If you have any questions or comments on the project let us know on our website.\n\n https://www.adsbreceiver.net\n\nRemember to install additional features simply run ./install.sh again." 12 78 +whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "ADS-B Receiver Project Image Setup" --msgbox "Image setup is now complete. If you have any questions or comments on the project let us know on our website.\n\n https://www.adsbreceiver.net\n\nRemember to install additional features simply run ./install.sh again." 12 78 exit 0 diff --git a/bash/init.sh b/bash/init.sh new file mode 100755 index 0000000..d698e80 --- /dev/null +++ b/bash/init.sh @@ -0,0 +1,251 @@ +#!/bin/bash + +##################################################################################### +# ADS-B RECEIVER # +##################################################################################### +# # +# This script is not meant to be executed directly. # +# Instead execute install.sh to begin the installation process. # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # +# 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 # +# in the Software without restriction, including without limitation the rights # +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # +# copies of the Software, and to permit persons to whom the Software is # +# furnished to do so, subject to the following conditions: # +# # +# The above copyright notice and this permission notice shall be included in all # +# copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # +# SOFTWARE. # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +## CHECK IF THIS IS THE FIRST RUN USING THE IMAGE RELEASE + +if [[ -f "${RECEIVER_ROOT_DIRECTORY}/image" ]] ; then + # Execute image setup script. + chmod +x ${RECEIVER_BASH_DIRECTORY}/image.sh + ${RECEIVER_BASH_DIRECTORY}/image.sh + if [[ $? -ne 0 ]] ; then + echo -e "" + echo -e " \e[91m IMAGE SETUP HAS BEEN TERMINISTED.\e[39m" + echo -e "" + exit 1 + fi + exit 0 +fi + +## INCLUDE EXTERNAL SCRIPTS + +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +## SET VARIABLES + +RECEIVER_PROJECT_TITLE="The ADS-B Receiver Project Preliminary Setup Process" + +## FUNCTIONS + +# Function to update the repository package lists. +function AptUpdate() { + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" + echo -e "" + echo -e "\e[92m Downloading the latest package lists for all enabled repositories and PPAs..." + echo -e "\e[93m ------------------------------------------------------------------------------\e[97m" + echo -e "" + sudo apt-get update + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m Finished downloading and updating package lists.\e[39m" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + echo -e "" + read -p "Press enter to continue..." CONTINUE + fi +} + +# Function to check that the packages required by this script are installed. +function CheckPrerequisites() { + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" + fi + echo -e "" + echo -e "\e[92m Checking to make sure the whiptail and git packages are installed..." + echo -e "\e[93m ------------------------------------------------------------------------------\e[97m" + echo -e "" + CheckPackage whiptail + CheckPackage git + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m The whiptail and git packages are installed.\e[39m" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + echo -e "" + read -p "Press enter to continue..." CONTINUE + fi +} + +# Function to update the local git repository. +function UpdateRepository() { + # Update lcoal branches which are set to track remote. + ACTION=$(git remote update 2>&1) + # Check if local branch is behind remote. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] && [[ `git status | grep -c "untracked files present"` -gt 0 ]] ; then + # Local branch has untracked files. + clear + # Ask if the user wishes to save any changes made to any core files before resetting them. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Backup Current ${RECEIVER_PROJECT_BRANCH} Branch State" --defaultno --yesno "This script will now reset your local copy of the ${RECEIVER_PROJECT_BRANCH} branch. Once this has been done any changes to the files making up this project will be replaced by untouched files from the project's repository.\n\nIf you would like to retain a copy of your current branch's state this script can do so now by migrating it to a new branch.\n\nCreate a new branch containing this branch's current state?" 14 78 + case $? in + 0) BACKUP_BRANCH_STATE="true" ;; + 1) BACKUP_BRANCH_STATE="false" ;; + esac + + if [[ "${BACKUP_BRANCH_STATE}" = "true" ]] ; then + # If the user wishes to create a new branch containing the current branches state ask for a name for this new branch. + BACKUP_BRANCH_NAME_TITLE="Name Of Backup Branch" + while [[ -z "${BACKUP_BRANCH_NAME}" ]] ; do + BACKUP_BRANCH_NAME=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${BACKUP_BRANCH_NAME_TITLE}" --nocancel --inputbox "\nPlease enter a name for this new branch." 10 78 3>&1 1>&2 2>&3) + BACKUP_BRANCH_NAME_TITLE="Name Of Backup Branch (REQUIRED)" + done + fi + fi + + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" + echo -e "" + echo -e "\e[92m Pulling the latest version of the ADS-B Receiver Project repository..." + echo -e "\e[93m ------------------------------------------------------------------------------\e[97m" + echo -e "" + echo -e "\e[94m Switching to branch ${RECEIVER_PROJECT_BRANCH}...\e[97m" + echo -e "" + git checkout ${RECEIVER_PROJECT_BRANCH} + echo -e "" + + # Save the current branch state if the user wished to do so. + if [[ "${BACKUP_BRANCH_STATE}" = "true" ]] ; then + echo -e "\e[94m Creating a new branch named ${NEW_BRANCH_NAME} containing the current state of the ${RECEIVER_PROJECT_BRANCH} branch...\e[97m" + echo -e "" + git commit -a -m "Saving current branch state." + git branch ${BACKUP_BRANCH_NAME} + echo -e "" + fi + + echo -e "\e[94m Fetching branch ${RECEIVER_PROJECT_BRANCH} from origin...\e[97m" + echo -e "" + git fetch origin + echo -e "" + echo -e "\e[94m Performing hard reset of branch ${RECEIVER_PROJECT_BRANCH} so it matches origin/${RECEIVER_PROJECT_BRANCH}...\e[97m" + echo -e "" + git reset --hard origin/${RECEIVER_PROJECT_BRANCH} + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m Finished pulling the latest version of the ADS-B Receiver Project repository....\e[39m" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + echo -e "" + read -p "Press enter to continue..." CONTINUE + fi +} + +# Function to update the operating system. +function UpdateOperatingSystem() { + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + clear + echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" + fi + echo -e "" + echo -e "\e[92m Downloading and installing the latest updates for your operating system..." + echo -e "\e[93m ------------------------------------------------------------------------------\e[97m" + echo -e "" + sudo apt-get -y dist-upgrade + echo -e "" + echo -e "\e[93m ------------------------------------------------------------------------------" + echo -e "\e[92m Your operating system should now be up to date.\e[39m" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + echo -e "" + read -p "Press enter to continue..." CONTINUE + fi +} + +## Update the repository packages and check that prerequisite packages are installed. + +# Only call AptUpdate if last update was more than ${APT_UPDATE_THRESHOLD} seconds ago. +APT_UPDATE_THRESHOLD="1800" +APT_UPDATE_CURRENT_EPOCH=`date +%s` +APT_UPDATE_LAST_EPOCH=`stat -c %Y /var/cache/apt/pkgcache.bin` +APT_UPDATE_DELTA=`echo $[${APT_UPDATE_CURRENT_EPOCH} - ${APT_UPDATE_LAST_EPOCH}]` +if [[ "${APT_UPDATE_DELTA}" -gt "${APT_UPDATE_THRESHOLD}" ]] ; then + AptUpdate +fi + +CheckPrerequisites + +## DISPLAY WELCOME SCREEN + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "The ADS-B Receiver Project" --yesno "Thanks for choosing The ADS-B Receiver Project to setup your receiver.\n\nMore information on this project as well as news, support, and discussions can be found on the projects official website located at:\n\n https://www.adsbreceiver.net\n\nWould you like to continue setup?" 14 78 + CONTINUE_SETUP=$? + if [[ "${CONTINUE_SETUP}" = 1 ]] ; then + # Setup has been halted by the user. + echo -e "" + echo -e "\e[91m \e[5mSETUP HALTED!\e[25m" + echo -e " Setup has been halted at the request of the user." + echo -e "" + read -p "Press enter to continue..." CONTINUE + exit 1 + fi +fi + +## UPDATE THE REPOSITORY + +UpdateRepository + +## ASK IF OPERATING SYSTEM SHOULD BE UPDATED + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Operating System Updates" --yesno "It is recommended that you update your system before building and/or installing any ADS-B receiver related packages. This script can do this for you at this time if you like.\n\nWould you like to update your operating system now?" 11 78 + case $? in + 0) UPDATE_OPERATING_SYSTEM="true" ;; + 1) UPDATE_OPERATING_SYSTEM="false" ;; + esac +fi +if [[ "${UPDATE_OPERATING_SYSTEM}" = "true" ]] ; then + UpdateOperatingSystem +fi + +# Use function to detect cpu architecture. +if [[ -z "${CPU_ARCHITECTURE}" ]] ; then + Check_CPU + echo -e "" +fi + +## EXECUTE BASH/MAIN.SH + +chmod +x ${RECEIVER_BASH_DIRECTORY}/main.sh +${RECEIVER_BASH_DIRECTORY}/main.sh +if [[ $? -ne 0 ]] ; then + echo -e " \e[91m ANY FURTHER SETUP AND/OR INSTALLATION REQUESTS HAVE BEEN TERMINIATED\e[39m" + echo -e "" + exit 1 +fi + +## INSTALLATION COMPLETE + +# Display the installation complete message box. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Software Installation Complete" --msgbox "INSTALLATION COMPLETE\n\nDO NOT DELETE THIS DIRECTORY!\n\nFiles needed for certain items to run properly are contained within this directory. Deleting this directory may result in your receiver not working properly.\n\nHopefully, these scripts and files were found useful while setting up your ADS-B Receiver. Feedback regarding this software is always welcome. If you have any issues or wish to submit feedback, feel free to do so on GitHub.\n\n https://github.com/jprochazka/adsb-receiver" 20 65 +fi + +echo -e "\e[32m" +echo -e "\e[91m Installation complete." +echo -e "\e[37m" + +exit 0 diff --git a/bash/main.sh b/bash/main.sh index 1f3017e..ccf0884 100755 --- a/bash/main.sh +++ b/bash/main.sh @@ -1,14 +1,11 @@ #!/bin/bash ##################################################################################### -# ADS-B RECEIVER # +# ADS-B RECEIVER # ##################################################################################### # # -# A set of scripts created to automate the process of installing the software # -# needed to setup a Mode S decoder as well as feeders which are capable of # -# sharing your ADS-B results with many of the most popular ADS-B aggregate sites. # -# # -# Project Hosted On GitHub: https://github.com/jprochazka/adsb-receiver # +# This script is not meant to be executed directly. # +# Instead execute install.sh to begin the installation process. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @@ -34,19 +31,24 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -## VARIABLES +### VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" ## INCLUDE EXTERNAL SCRIPTS -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh + +# Source the automated install configuration file if this is an automated installation. +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "true" ]] && [[ -s "${RECEIVER_CONFIGURATION_FILE}" ]] ; then + source ${RECEIVER_CONFIGURATION_FILE} +fi ## Set the project title variable. -export ADSB_PROJECTTITLE="The ADS-B Receiver Project v$PROJECTVERSION Installer" +export RECEIVER_PROJECT_TITLE="The ADS-B Receiver Project v${PROJECT_VERSION} Installer" ############### ## FUNCTIONS @@ -55,66 +57,74 @@ export ADSB_PROJECTTITLE="The ADS-B Receiver Project v$PROJECTVERSION Installer" # Execute the dump1090-mutability setup script. function InstallDump1090Mutability() { - chmod +x $BASHDIRECTORY/decoders/dump1090-mutability.sh - $BASHDIRECTORY/decoders/dump1090-mutability.sh - if [ $? -ne 0 ]; then + chmod +x ${RECEIVER_BASH_DIRECTORY}/decoders/dump1090-mutability.sh + ${RECEIVER_BASH_DIRECTORY}/decoders/dump1090-mutability.sh + if [[ $? -ne 0 ]] ; then exit 1 fi } # Execute the dump1090-fa setup script. function InstallDump1090Fa() { - chmod +x $BASHDIRECTORY/decoders/dump1090-fa.sh - $BASHDIRECTORY/decoders/dump1090-fa.sh - if [ $? -ne 0 ]; then + chmod +x ${RECEIVER_BASH_DIRECTORY}/decoders/dump1090-fa.sh + ${RECEIVER_BASH_DIRECTORY}/decoders/dump1090-fa.sh + if [[ $? -ne 0 ]] ; then exit 1 fi } - # Execute the dump978 setup script. function InstallDump978() { - chmod +x $BASHDIRECTORY/decoders/dump978.sh - $BASHDIRECTORY/decoders/dump978.sh - if [ $? -ne 0 ]; then + chmod +x ${RECEIVER_BASH_DIRECTORY}/decoders/dump978.sh + ${RECEIVER_BASH_DIRECTORY}/decoders/dump978.sh + if [[ $? -ne 0 ]] ; then + exit 1 + fi +} + +# Execute the RTL-SDR OGN setup script. +function InstallRtlsdrOgn() { + chmod +x ${RECEIVER_BASH_DIRECTORY}/decoders/rtlsdr-ogn.sh + ${RECEIVER_BASH_DIRECTORY}/decoders/rtlsdr-ogn.sh + if [[ $? -ne 0 ]] ; then exit 1 fi } ## FEEDERS -# Execute the PiAware setup script -function InstallPiAware() { - chmod +x $BASHDIRECTORY/feeders/piaware.sh - $BASHDIRECTORY/feeders/piaware.sh - if [ $? -ne 0 ]; then +# Execute the ADS-B Exchange setup script. +function InstallAdsbExchange() { + chmod +x ${RECEIVER_BASH_DIRECTORY}/feeders/adsbexchange.sh + ${RECEIVER_BASH_DIRECTORY}/feeders/adsbexchange.sh + if [[ $? -ne 0 ]] ; then exit 1 fi } -# Execute the Plane Finder ADS-B Client setup script. -function InstallPlaneFinder() { - chmod +x $BASHDIRECTORY/feeders/planefinder.sh - $BASHDIRECTORY/feeders/planefinder.sh - if [ $? -ne 0 ]; then +# Execute the PiAware setup script +function InstallPiAware() { + chmod +x ${RECEIVER_BASH_DIRECTORY}/feeders/piaware.sh + ${RECEIVER_BASH_DIRECTORY}/feeders/piaware.sh + if [[ $? -ne 0 ]] ; then exit 1 fi } # Execute the Flightradar24 Feeder client setup script. function InstallFlightradar24() { - chmod +x $BASHDIRECTORY/feeders/flightradar24.sh - $BASHDIRECTORY/feeders/flightradar24.sh - if [ $? -ne 0 ]; then + chmod +x ${RECEIVER_BASH_DIRECTORY}/feeders/flightradar24.sh + ${RECEIVER_BASH_DIRECTORY}/feeders/flightradar24.sh + if [[ $? -ne 0 ]] ; then exit 1 fi } -# Execute the ADS-B Exchange setup script. -function InstallAdsbExchange() { - chmod +x $BASHDIRECTORY/feeders/adsbexchange.sh - $BASHDIRECTORY/feeders/adsbexchange.sh - if [ $? -ne 0 ]; then +# Execute the Plane Finder Client setup script. +function InstallPlaneFinder() { + chmod +x ${RECEIVER_BASH_DIRECTORY}/feeders/planefinder.sh + ${RECEIVER_BASH_DIRECTORY}/feeders/planefinder.sh + if [[ $? -ne 0 ]] ; then exit 1 fi } @@ -123,9 +133,38 @@ function InstallAdsbExchange() { # Execute the ADS-B Receiver Project Web Portal setup script. function InstallWebPortal() { - chmod +x $BASHDIRECTORY/portal/install.sh - $BASHDIRECTORY/portal/install.sh - if [ $? -ne 0 ]; then + chmod +x ${RECEIVER_BASH_DIRECTORY}/portal/install.sh + ${RECEIVER_BASH_DIRECTORY}/portal/install.sh + if [[ $? -ne 0 ]] ; then + exit 1 + fi +} + +## Extras + +# Execute the AboveTustin setup script. +function InstallAboveTustin() { + chmod +x ${RECEIVER_BASH_DIRECTORY}/extras/abovetustin.sh + ${RECEIVER_BASH_DIRECTORY}/extras/abovetustin.sh + if [[ $? -ne 0 ]] ; then + exit 1 + fi +} + +# Execute the beast-splitter setup script. +function InstallBeastSplitter() { + chmod +x ${RECEIVER_BASH_DIRECTORY}/extras/beeastsplitter.sh + ${RECEIVER_BASH_DIRECTORY}/extras/beastsplitter.sh + if [[ $? -ne 0 ]] ; then + exit 1 + fi +} + +# Execute the Duck DNS setup script. +function InstallDuckDns() { + chmod +x ${RECEIVER_BASH_DIRECTORY}/extras/duckdns.sh + ${RECEIVER_BASH_DIRECTORY}/extras/duckdns.sh + if [[ $? -ne 0 ]] ; then exit 1 fi } @@ -136,224 +175,590 @@ function InstallWebPortal() { ## Decoders # Check if the dump1090-mutability package is installed. -DUMP1090MUTABILITY_INSTALLED=1 -DUMP1090MUTABILITY_INSTALL=1 -DUMP1090MUTABILITY_REINSTALL=1 -if [ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]; then - # The dump1090-mutability package appear to be installed. - DUMP1090MUTABILITY_INSTALLED=0 - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Dump1090-mutability Installed" --defaultno --yesno "The dump1090-mutability package appears to be installed on your device, however...\n\nThe dump1090-mutability v1.15~dev source code is regularly updated without a change made to the version numbering. To ensure you are running the latest version of dump1090-mutability you may opt to rebuild and reinstall this package.\n\nDownload, build, and reinstall this package?" 16 65 - DUMP1090MUTABILITY_REINSTALL=$? -fi - -# Check if the dump1090-fa package is installed. -DUMP1090FA_INSTALLED=1 -DUMP1090FA_INSTALL=1 -DUMP1090FA_UPGRADE=1 -if [ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]; then - # The dump1090-fa package appear to be installed. - DUMP1090FA_INSTALLED=0 - # Check if a newer version can be installed. - if [ $(sudo dpkg -s dump1090-fa 2>/dev/null | grep -c "Version: ${PIAWAREVERSION}") -eq 0 ]; then - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Dump1090-fa Upgrade Available" --defaultno --yesno "An updated version of dump1090-fa is available.\n\nWould you like to download, build, then install the new version?" 16 65 - DUMP1090FA_UPGRADE=$? +if [[ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then + DUMP1090_FORK="mutability" + DUMP1090_IS_INSTALLED="true" + # Skip over this dialog if this installation is set to be automated. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Ask if dump1090-mutability should be reinstalled. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump1090-mutability Installed" --defaultno --yesno "The dump1090-mutability package appears to be installed on your device, however...\n\nThe dump1090-mutability v1.15~dev source code is regularly updated without a change made to the version numbering.\n\nTo ensure you are running the latest version of dump1090-mutability you may opt to rebuild and reinstall this package.\n\nDownload, build, and reinstall this package?" 18 65 + case $? in + 0) + DUMP1090_DO_UPGRADE="true" + ;; + 1) + DUMP1090_DO_UPGRADE="false" + ;; + esac + else + # Refer to the installation configuration to decide if dump1090-mutability is to be reinstalled or not. + if [[ "${DUMP1090_UPGRADE}" = "true" ]] ; then + DUMP1090_DO_UPGRADE="true" + else + DUMP1090_DO_UPGRADE="false" + fi fi fi -# If any version of dump1090 is not installed ask which one to install. -if [ $DUMP1090MUTABILITY_INSTALLED = 1 ] && [ $DUMP1090FA_INSTALLED = 1 ]; then - DUMP1090OPTION=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Choose Dump1090 Version" --menu "The dump1090-mutability or dump1090-fa package does not appear to be installed on this device. In order to continue setup one of these two packages need to be installed. Please select your prefered dump1090 version from the list below.\n\nPlease note that in order to run dump1090-fa PiAware will need to be installed as well." 16 65 2 "dump1090-mutability" "(Mutability)" "dump1090-fa" "(FlightAware)" 3>&1 1>&2 2>&3) - case $DUMP1090OPTION in - "dump1090-mutability") - DUMP1090MUTABILITY_INSTALL=0 - ;; - "dump1090-fa") - DUMP1090FA_INSTALL=0 - ;; - *) - echo -e "\033[31m" - echo " A compatable dump1090 installation is required in order to continue setup." - exit 1 - ;; - esac +# Check if the dump1090-fa package is installed. +if [[ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then + DUMP1090_FORK="fa" + DUMP1090_IS_INSTALLED="true" + # Check if a newer version can be installed. + if [[ $(sudo dpkg -s dump1090-fa 2>/dev/null | grep -c "Version: ${PIAWARE_VERSION}") -eq 0 ]] ; then + # Skip over this dialog if this installation is set to be automated. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "RECEIVER_PROJECT_TITLE" --title "Dump1090-fa Upgrade Available" --defaultno --yesno "An updated version of dump1090-fa is available.\n\nWould you like to download, build, then install the new version?" 16 65 + case $? in + 0) + DUMP1090_DO_UPGRADE="true" + ;; + 1) + DUMP1090_DO_UPGRADE="false" + ;; + esac + else + # If a newer version of dump1090-fa is available refer to the installation configuration to decide if it should be upgraded or not. + if [[ "${DUMP1090_UPGRADE}" = "true" ]] ; then + DUMP1090_DO_UPGRADE="true" + else + DUMP1090_DO_UPGRADE="false" + fi + fi + fi fi -# Check if PiAware is required. -PIAWAREREQUIRED=1 -if [ $DUMP1090FA_INSTALL = 0 ]; then - PIAWAREREQUIRED=0 +# If no dump1090 fork is installed then attempt to install one. +if [[ ! "${DUMP1090_IS_INSTALLED}" = "true" ]] ; then + # If this is not an automated installation ask the user which one to install. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + DUMP1090_OPTION=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Choose Dump1090 Version To Install" --radiolist "The dump1090-mutability or dump1090-fa package does not appear to be installed on this device. In order to continue setup one of the following packages need to be installed. Please select your prefered dump1090 version from the list below.\n\nPlease note that in order to run dump1090-fa PiAware will need to be installed as well." 16 65 2 "dump1090-mutability" "(Mutability)" ON "dump1090-fa" "(FlightAware)" OFF 3>&1 1>&2 2>&3) + case ${DUMP1090_OPTION} in + "dump1090-mutability") + DUMP1090_FORK="mutability" + DUMP1090_DO_INSTALL="true" + ;; + "dump1090-fa") + DUMP1090_FORK="fa" + DUMP1090_DO_INSTALL="true" + ;; + *) + DUMP1090_DO_INSTALL="false" + ;; + esac + else + # Refer to the installation configuration to check if a dump1090 fork has been specified + if [[ "${DUMP1090_FORK}" = "mutability" ]] || [[ "${DUMP1090_FORK}" = "fa" ]] ; then + DUMP1090_DO_INSTALL="true" + else + DUMP1090_DO_INSTALL="false" + fi + fi fi -# Check that the dump978 binaries exist. -DUMP978_INSTALL=1 -DUMP978_REINSTALL=1 -if [ -f $BUILDDIRECTORY/dump978/dump978 ] && [ -f $BUILDDIRECTORY/dump978/uat2text ] && [ -f $BUILDDIRECTORY/dump978/uat2esnt ] && [ -f $BUILDDIRECTORY/dump978/uat2json ]; then +# If the FlightAware fork of dump1090 is or has been chosen to be installed PiAware must be installed. +if [[ "${DUMP1090_FORK}" = "fa" ]] ; then + if [[ "${DUMP1090_DO_INSTALL}" = "true" ]] || [[ "${DUMP1090_DO_UPGRADE}" = "true" ]] ; then + FORCE_PIAWARE_INSTALL="true" + fi +fi + +# Check if the dump978 binaries exist. +if [[ -f "${RECEIVER_BUILD_DIRECTORY}/dump978/dump978" ]] && [[ -f "${RECEIVER_BUILD_DIRECTORY}/dump978/uat2text" ]] && [[ -f "${RECEIVER_BUILD_DIRECTORY}/dump978/uat2esnt" ]] && [[ -f "${RECEIVER_BUILD_DIRECTORY}/dump978/uat2json" ]] ; then # Dump978 appears to have been built already. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Dump978 Installed" --defaultno --yesno "Dump978 appears to be installed on your device, however...\n\nThe dump978 source code may have been updated since it was built last. To ensure you are running the latest version of dump978 you may opt to rebuild the binaries making up dump978.\n\nDownload and rebuild the dump978 binaries?" 14 65 - DUMP978_REINSTALL=$? + DUMP978_IS_INSTALLED="true" + # Prompt user to confirm if a rebuild is required. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump978 Installed" --defaultno --yesno "Dump978 appears to be installed on your device, however...\n\nThe dump978 source code may have been updated since it was built last. To ensure you are running the latest version of dump978 you may opt to rebuild the binaries making up dump978.\n\nDownload and rebuild the dump978 binaries?" 14 65 + case $? in + 0) + DUMP978_DO_UPGRADE="true" + ;; + 1) + DUMP978_DO_UPGRADE="false" + ;; + esac + else + # Refer to the installation configuration to decide if dump978 is to be rebuilt from source or not. + if [[ "${DUMP978_UPGRADE}" = "true" ]] ; then + DUMP978_DO_UPGRADE="true" + else + DUMP978_DO_UPGRADE="false" + fi + fi else - # Dump978 does not appear to have been built yet. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Dump978 Not Installed" --defaultno --yesno "Dump978 is an experimental demodulator/decoder for 978MHz UAT signals. These scripts can setup dump978 for you. However keep in mind a second RTL-SDR device will be required to feed data to it.\n\nDo you wish to install dump978?" 10 65 - DUMP978_INSTALL=$? + # Dump978 does not appear to be present on this device. + DUMP978_IS_INSTALLED="false" + # Prompt user to confirm if installation is required. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Dump978 Not Installed" --defaultno --yesno "Dump978 is an experimental demodulator/decoder for 978MHz UAT signals. These scripts can setup dump978 for you. However keep in mind a second RTL-SDR device will be required to feed data to it.\n\nDo you wish to install dump978?" 10 65 + case $? in + 0) + DUMP978_DO_INSTALL="true" + ;; + 1) + DUMP978_DO_INSTALL="false" + ;; + esac + else + # Refer to the installation configuration to decide if dump978 is to be installed from source or not. + if [[ "${DUMP978_INSTALL}" = "true" ]] ; then + DUMP978_DO_INSTALL="true" + else + DUMP978_DO_INSTALL="false" + fi + + fi +fi + +# Check if the RTL-SDR OGN binaries exist on this device. +if [[ -f "/etc/init.d/rtlsdr-ogn" ]] ; then + RTLSDROGN_IS_INSTALLED="true" + # Check if a newer version of the binaries are available. + if [[ ! -d "${RECEIVER_BUILD_DIRECTORY}/rtlsdr-ogn/rtlsdr-ogn-${RTLSDROGN_VERSION}" ]] ; then + # Prompt user to confirm if a rebuild is required. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "RTL-SDR OGN Installed" --defaultno --yesno "A newer version of the RTL-SDR OGN binaries is available.\n\nWould you like to setup the newer binaries on this device?" 14 65 + case $? in + 0) + RTLSDROGN_DO_UPGRADE="true" + ;; + 1) + RTLSDROGN_DO_UPGRADE="false" + ;; + esac + else + # Refer to the installation configuration to decide if RTL-SDR OGN is to be rebuilt from source or not. + if [[ "${RTLSDROGN_UPGRADE}" = "true" ]] ; then + RTLSDROGN_DO_UPGRADE="true" + else + RTLSDROGN_DO_UPGRADE="false" + fi + fi + fi +else + # The RTL-SDR OGN binaries do not appear to exist on this device. + RTLSDROGN_IS_INSTALLED="false" + # Prompt user to confirm if installation is required. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "RTL-SDR OGN Not Installed" --defaultno --yesno "RTL-SDR OGN is a combined decoder and feeder for the Open Glider Network which focuses on tracking gilders and other GA aircraft equipped with FLARM, FLARM-compatible devices or OGN tracker.\n\nRTL-SDR OGN will require an additional RTL-SDR dongle to run.\nFLARM is most prevalent within Europe, but new receivers are welcome at any location.\n\nDo you wish to setup RTL-SDR OGN?" 10 65 + case $? in + 0) + RTLSDROGN_DO_INSTALL="true" + ;; + 1) + RTLSDROGN_DO_INSTALL="false" + ;; + esac + else + # Refer to the installation configuration to decide if RTL-SDR OGN is to be installed. + if [[ "${RTLSDROGN_INSTALL}" = "true" ]] ; then + RTLSDROGN_DO_INSTALL="true" + else + RTLSDROGN_DO_INSTALL="false" + fi + fi fi ## Feeder Selection Menu -# Declare the FEEDERLIST array which will store feeder installation choices for the feeder whiptail menu. -declare array FEEDERLIST +# Declare the FEEDER_LIST array and the FEEDER_CHOICES file which will store choices for feeders which are available for install. +declare array FEEDER_LIST +touch ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES -# Check for the PiAware package. -if [ $(dpkg-query -W -f='${STATUS}' piaware 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - # Do not show the PiAware install option if it is marked as required. - if [ $PIAWAREREQUIRED = 1 ]; then - # The PiAware package appears to not be installed. - FEEDERLIST=("${FEEDERLIST[@]}" 'FlightAware PiAware' '' OFF) +# Check if MLAT client has been installed to be used to feed ADS-B Exchange. +if [[ $(dpkg-query -W -f='${STATUS}' mlat-client 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then + # The mlat-client package appears to be installed. + MLAT_CLIENT_IS_INSTALLED="true" + MLAT_CLIENT_VERSION_AVAILABLE=$(echo ${MLAT_CLIENT_VERSION} | tr -cd '[:digit:]' | sed -e 's/^0//g') + MLAT_CLIENT_VERSION_INSTALLED=$(sudo dpkg -s mlat-client 2>/dev/null | grep "^Version:" | awk '{print $2}' | tr -cd '[:digit:]' | sed -e 's/^0//g') + # Check if installed mlat-client matches the available version. + if [[ ! "${MLAT_CLIENT_VERSION_AVAILABLE}" = "${MLAT_CLIENT_VERSION_INSTALLED}" ]] ; then + # Prompt user to confirm the upgrade. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the FEEDER_LIST array to be used by the whiptail menu. + FEEDER_LIST=("${FEEDER_LIST[@]}" 'ADS-B Exchange data export and MLAT Client (upgrade)' '' OFF) + else + # Check the installation configuration file to see if the Planefinder Client is to be upgraded. + if [[ -z "${ADSBEXCHANGE_INSTALL}" ]] && [[ "${ADSBEXCHANGE_INSTALL}" = "true" ]] && [[ -z "${ADSBEXCHANGE_UPGRADE}" ]] && [[ "${ADSBEXCHANGE_UPGRADE}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the FEEDER_CHOICES file. + echo "ADS-B Exchange data export and MLAT Client (upgrade)" >> ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES + fi + fi fi else - # Check if a newer version can be installed. - if [ $(sudo dpkg -s piaware 2>/dev/null | grep -c "Version: $PIAWAREVERSION") -eq 0 ]; then - FEEDERLIST=("${FEEDERLIST[@]}" 'FlightAware PiAware (upgrade)' '' OFF) + # The mlat-client package does not appear to be installed. + MLAT_CLIENT_IS_INSTALLED="false" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the FEEDER_LIST array to be used by the whiptail menu. + FEEDER_LIST=("${FEEDER_LIST[@]}" 'ADS-B Exchange data export and MLAT Client' '' OFF) + else + # Check the installation configuration file to see if ADS-B Exchange feeding is to be setup. + if [[ -z "${ADSBEXCHANGE_INSTALL}" ]] && [[ "${ADSBEXCHANGE_INSTALL}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the FEEDER_CHOICES file. + echo "ADS-B Exchange data export and MLAT Client" >> ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES + fi fi fi -# Check for the Planefinder ADS-B Client package. -if [ $(dpkg-query -W -f='${STATUS}' pfclient 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - # The Planefinder ADS-B Client package appears to be installed. - FEEDERLIST=("${FEEDERLIST[@]}" 'Plane Finder ADS-B Client' '' OFF) -else - # Set version depending on the device architecture. - PFCLIENTVERSION=$PFCLIENTVERSIONARM - if [[ `uname -m` != "armv7l" ]]; then - PFCLIENTVERSION=$PFCLIENTVERSIONI386 +# Check for the PiAware package. +if [[ $(dpkg-query -W -f='${STATUS}' piaware 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + # Do not show the PiAware install option if the FlightAware fork of dump1090 has been chosen. + if [[ "${DUMP1090_FORK}" != "fa" ]] ; then + # The PiAware package appears to not be installed. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the FEEDER_LIST array to be used by the whiptail menu. + FEEDER_LIST=("${FEEDER_LIST[@]}" 'FlightAware PiAware' '' OFF) + else + # Check the installation configuration file to see if PiAware is to be installed. + if [[ -z "${PIAWARE_INSTALL}" ]] && [[ "${PIAWARE_INSTALL}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the FEEDER_CHOICES file. + echo "FlightAware PiAware" >> ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES + fi + fi fi +else # Check if a newer version can be installed. - if [ $(sudo dpkg -s pfclient 2>/dev/null | grep -c "Version: ${PFCLIENTVERSION}") -eq 0 ]; then - FEEDERLIST=("${FEEDERLIST[@]}" 'Plane Finder ADS-B Client (upgrade)' '' OFF) + if [[ $(sudo dpkg -s piaware 2>/dev/null | grep -c "Version: ${PIAWARE_VERSION}") -eq 0 ]] ; then + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the FEEDER_LIST array to be used by the whiptail menu. + FEEDER_LIST=("${FEEDER_LIST[@]}" 'FlightAware PiAware (upgrade)' '' OFF) + else + # Check the installation configuration file to see if PiAware is to be upgraded. + if [[ -z "${PIAWARE_INSTALL}" ]] && [[ "${PIAWARE_INSTALL}" = "true" ]] && [[ -z "${PIAWARE_UPGRADE}" ]] && [[ "${PIAWARE_UPGRADE}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the FEEDER_CHOICES file. + echo "FlightAware PiAware (upgrade)" >> ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES + fi + fi fi fi # Check for the Flightradar24 Feeder Client package. -if [ $(dpkg-query -W -f='${STATUS}' fr24feed 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - # The Flightradar24 client package appears to be installed. - FEEDERLIST=("${FEEDERLIST[@]}" 'Flightradar24 Client' '' OFF) +if [[ $(dpkg-query -W -f='${STATUS}' fr24feed 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + # The Flightradar24 client package does not appear to be installed. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the FEEDER_LIST array to be used by the whiptail menu. + FEEDER_LIST=("${FEEDER_LIST[@]}" 'Flightradar24 Client' '' OFF) + else + # Check the installation configuration file to see if the Flightradar24 Client is to be installed. + if [[ -z "${FLIGHTRADAR_INSTALL}" ]] && [[ "${FLIGHTRADAR_INSTALL}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the FEEDER_CHOICES file. + echo "Flightradar24 Client" >> ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES + fi + fi else # Check if a newer version can be installed if this is not a Raspberry Pi device. - if [[ `uname -m` != "armv7l" ]]; then - if [ $(sudo dpkg -s fr24feed 2>/dev/null | grep -c "Version: ${FR24CLIENTVERSIONI386}") -eq 0 ]; then - FEEDERLIST=("${FEEDERLIST[@]}" 'Flightradar24 Client (upgrade)' '' OFF) + if [[ "${CPU_ARCHITECTURE}" != "armv7l" ]] ; then + if [[ $(sudo dpkg -s fr24feed 2>/dev/null | grep -c "Version: ${FLIGHTRADAR24_CLIENT_VERSION_I386}") -eq 0 ]] ; then + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the FEEDER_LIST array to be used by the whiptail menu. + FEEDER_LIST=("${FEEDER_LIST[@]}" 'Flightradar24 Client (upgrade)' '' OFF) + else + # Check the installation configuration file to see if the Flightradar24 Client is to be upgraded. + if [[ -z "${FLIGHTRADAR_INSTALL}" ]] && [[ "${FLIGHTRADAR_INSTALL}" = "true" ]] && [[ -z "${FLIGHTRADAR_UPGRADE}" ]] && [[ "${FLIGHTRADAR_UPGRADE}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the FEEDER_CHOICES file. + echo "Flightradar24 Client (upgrade)" >> ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES + fi + fi fi fi fi -# Check if ADS-B Exchange MLAT client has been set up. -if ! grep -q "$BUILDDIRECTORY/adsbexchange/adsbexchange-mlat_maint.sh &" /etc/rc.local; then - # The ADS-B Exchange maintenance script does not appear to be executed on startup. - FEEDERLIST=("${FEEDERLIST[@]}" 'ADS-B Exchange Script' '' OFF) +# Check for the Planefinder ADS-B Client package. +if [[ $(dpkg-query -W -f='${STATUS}' pfclient 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + # The Planefinder Client package does not appear to be installed. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the FEEDER_LIST array to be used by the whiptail menu. + FEEDER_LIST=("${FEEDER_LIST[@]}" 'Plane Finder Client' '' OFF) + else + # Check the installation configuration file to see if the Plane Finder Client is to be installed. + if [[ -z "${PLANEFINDER_INSTALL}" ]] && [[ "${PLANEFINDER_INSTALL}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the FEEDER_CHOICES file. + echo "Plane Finder Client" >> ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES + fi + fi +else + # Check if a newer version can be installed. + if [[ "${CPU_ARCHITECTURE}" = "armv7l" ]] ; then + if [[ $(sudo dpkg -s pfclient 2>/dev/null | grep -c "Version: ${PLANEFINDER_CLIENT_VERSION_ARM}") -eq 0 ]] ; then + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the FEEDER_LIST array to be used by the whiptail menu. + FEEDER_LIST=("${FEEDER_LIST[@]}" 'Plane Finder Client (upgrade)' '' OFF) + else + # Check the installation configuration file to see if the Planefinder Client is to be upgraded. + if [[ -z "${PLANEFINDER_INSTALL}" ]] && [[ "${PLANEFINDER_INSTALL}" = "true" ]] && [[ -z "${PLANEFINDER_UPGRADE}" ]] && [[ "${PLANEFINDER_UPGRADE}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the FEEDER_CHOICES file. + echo "Plane Finder Client (upgrade)" >> ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES + fi + fi + fi + else + if [[ $(sudo dpkg -s pfclient 2>/dev/null | grep -c "Version: ${PLANEFINDER_CLIENT_VERSION_I386}") -eq 0 ]] ; then + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the FEEDER_LIST array to be used by the whiptail menu. + FEEDER_LIST=("${FEEDER_LIST[@]}" 'Plane Finder Client (upgrade)' '' OFF) + else + # Check the installation configuration file to see if the Planefinder Client is to be upgraded. + if [[ -z "${PLANEFINDER_INSTALL}" ]] && [[ "${PLANEFINDER_INSTALL}" = "true" ]] && [[ -z "${PLANEFINDER_UPGRADE}" ]] && [[ "${PLANEFINDER_UPGRADE}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the FEEDER_CHOICES file. + echo "Plane Finder Client (upgrade)" >> ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES + fi + fi + fi + fi fi -declare FEEDERCHOICES - -if [[ -n "$FEEDERLIST" ]]; then - # Display a checklist containing feeders that are not installed if any. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Feeder Installation Options" --checklist --nocancel --separate-output "The following feeders are available for installation.\nChoose the feeders you wish to install." 13 65 4 "${FEEDERLIST[@]}" 2>FEEDERCHOICES -else - # Since all available feeders appear to be installed inform the user of the fact. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "All Feeders Installed" --msgbox "It appears that all the optional feeders available for installation by this script have been installed already." 8 65 +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + if [[ -n "${FEEDER_LIST}" ]] ; then + # Display a checklist containing feeders that are not installed if any. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Feeder Installation Options" --checklist --nocancel --separate-output "The following feeders are available for installation.\nChoose the feeders you wish to install." 13 65 4 "${FEEDER_LIST[@]}" 2>${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES + else + # Since all available feeders appear to be installed inform the user of the fact. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "All Feeders Installed" --msgbox "It appears that all the optional feeders available for installation by this script have been installed already." 8 65 + fi fi ## ADS-B Receiver Project Web Portal -# Ask if the web portal should be installed. -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Install The ADS-B Receiver Project Web Portal" --yesno "The ADS-B Receiver Project Web Portal is a lightweight web interface for dump-1090-mutability installations.\n\nCurrent features include the following:\n Unified navigation between all web pages.\n System and dump1090 performance graphs.\n\nWould you like to install the ADS-B Receiver Project web portal on this device?" 8 78 -PORTAL_INSTALL=$? +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Ask if the web portal should be installed. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Install The ADS-B Receiver Project Web Portal" --yesno "The ADS-B Receiver Project Web Portal is a lightweight web interface for dump-1090-mutability installations.\n\nCurrent features include the following:\n Unified navigation between all web pages.\n System and dump1090 performance graphs.\n\nWould you like to install the ADS-B Receiver Project web portal on this device?" 8 78 + case $? in + 0) + WEBPORTAL_DO_INSTALL="true" + ;; + 1) + WEBPORTAL_DO_INSTALL="false" + ;; + esac +fi + +## Extras + +# Declare the EXTRAS_LIST array and the EXTRAS_CHOICES file which will store choices for extras which are available for install. +declare array EXTRAS_LIST +touch ${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES + +# Check if the AboveTustin repository has been cloned. +if [[ -d "${RECEIVER_BUILD_DIRECTORY}/AboveTustin" ]] && [[ -d "${RECEIVER_BUILD_DIRECTORY}/AboveTustin/.git" ]] ; then + # The AboveTustin repository has been cloned to this device. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the EXTRAS_LIST array to be used by the whiptail menu. + EXTRAS_LIST=("${EXTRAS_LIST[@]}" 'AboveTustin (reinstall)' '' OFF) + else + # Check the installation configuration file to see if AboveTustin is to be upgraded. + if [[ -z "${ABOVETUSTIN_INSTALL}" ]] && [[ "${ABOVETUSTIN_INSTALL}" = "true" ]] && [[ -z "${ABOVETUSTIN_UPGRADE}" ]] && [[ "${ABOVETUSTIN_UPGRADE}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the EXTRAS_CHOICES file. + echo "AboveTustin (reinstall)" >> ${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES + fi + fi +else + # The AboveTustin repository has not been cloned to this device. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the EXTRAS_LIST array to be used by the whiptail menu. + EXTRAS_LIST=("${EXTRAS_LIST[@]}" 'AboveTustin' '' OFF) + else + # Check the installation configuration file to see if AboveTustin is to be installed. + if [[ -z "${ABOVETUSTIN_INSTALL}" ]] && [[ "${ABOVETUSTIN_INSTALL}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the EXTRAS_CHOICES file. + echo "AboveTustin" >> ${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES + fi + fi +fi + +# Check if the beast-splitter package is installed. +if [[ $(dpkg-query -W -f='${STATUS}' beast-splitter 2>/dev/null | grep -c "ok installed") -eq 0 ]] ; then + # The beast-splitter package appears to not be installed. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the EXTRAS_LIST array to be used by the whiptail menu. + EXTRAS_LIST=("${EXTRAS_LIST[@]}" 'beast-splitter' '' OFF) + else + # Check the installation configuration file to see if beast-splitter is to be installed. + if [[ -z "${BEASTSPLITTER_INSTALL}" ]] && [[ "${BEASTSPLITTER_INSTALL}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the EXTRAS_CHOICES file. + echo "beast-splitter" >> ${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES + fi + fi +else + # Offer the option to build then reinstall the beast-splitter package. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the EXTRAS_LIST array to be used by the whiptail menu. + EXTRAS_LIST=("${EXTRAS_LIST[@]}" 'beast-splitter (reinstall)' '' OFF) + else + if [[ -z "${BEASTSPLITTER_INSTALL}" ]] && [[ "${BEASTSPLITTER_INSTALL}" = "true" ]] && [[ -z "${BEASTSPLITTER_UPGRADE}" ]] && [[ "${BEASTSPLITTER_UPGRADE}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the EXTRAS_CHOICES file. + echo "beast-splitter (reinstall)" >> ${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES + fi + fi +fi + +# Check if the Duck DNS update script exists. +if [[ ! -f "${RECEIVER_BUILD_DIRECTORY}/duckdns/duck.sh" ]] ; then + # Duck DNS does not appear to be set up on this device. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the EXTRAS_LIST array to be used by the whiptail menu. + EXTRAS_LIST=("${EXTRAS_LIST[@]}" 'Duck DNS Free Dynamic DNS Hosting' '' OFF) + else + # Check the installation configuration file to see if Duck DNS dynamic DNS support is to be added. + if [[ -z "${DUCKDNS_INSTALL}" ]] && [[ "${DUCKDNS_INSTALL}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the EXTRAS_CHOICES file. + echo "Duck DNS Free Dynamic DNS Hosting" >> ${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES + fi + fi +else + # Offer the option to install/setup Duck DNS once more. + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Add this choice to the EXTRAS_LIST array to be used by the whiptail menu. + EXTRAS_LIST=("${EXTRAS_LIST[@]}" 'Duck DNS Free Dynamic DNS Hosting (reinstall)' '' OFF) + else + if [[ -z "${DUCKDNS_INSTALL}" ]] && [[ "${DUCKDNS_INSTALL}" = "true" ]] && [[ -z "${DUCKDNS_UPGRADE}" ]] && [[ "${DUCKDNS_UPGRADE}" = "true" ]] ; then + # Since the menu will be skipped add this choice directly to the EXTRAS_CHOICES file. + echo "Duck DNS Free Dynamic DNS Hosting (reinstall)" >> ${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES + fi + fi +fi + + +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Display a menu the user can use to pick extras to be installed. + if [[ -n "${EXTRAS_LIST}" ]] ; then + # Display a checklist containing feeders that are not installed if any. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Feeder Installation Options" --checklist --nocancel --separate-output "The following extras are available for installation, please select any which you wish to install." 13 65 4 "${EXTRAS_LIST[@]}" 2>${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES + else + # Since all available extras appear to be installed inform the user of the fact. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "All Extras Installed" --msgbox "It appears that all the optional extras available for installation by this script have been installed already." 8 65 + fi +fi ## Setup Confirmation -# Check if anything is to be done before moving on. -if [ $DUMP1090MUTABILITY_INSTALL = 1 ] && [ $DUMP1090MUTABILITY_REINSTALL = 1 ] && [ $DUMP1090FA_INSTALL = 1 ] && [ $DUMP1090FA_UPGRADE = 1 ] && [ $DUMP978_INSTALL = 1 ] && [ $DUMP978_REINSTALL = 1 ] && [ $PORTAL_INSTALL = 1 ] && [ ! -s FEEDERCHOICES ]; then - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Nothing to be done" --msgbox "Nothing has been selected to be installed so the script will exit now." 10 65 - echo -e "\033[31m" - echo "Nothing was selected to do or be installed." - echo -e "\033[37m" - exit 1 -fi - declare CONFIRMATION -# If the user decided to install software... -if [ $DUMP1090MUTABILITY_INSTALL = 0 ] || [ $DUMP1090MUTABILITY_REINSTALL = 0 ] || [ $DUMP1090FA_INSTALL = 0 ] || [ $DUMP1090FA_UPGRADE = 0 ] || [ $DUMP978_INSTALL = 0 ] || [ $DUMP978_REINSTALL = 0 ] || [ $PORTAL_INSTALL = 0 ] || [ -s FEEDERCHOICES ]; then - CONFIRMATION="$The following software will be installed:\n" +# Check if anything is to be done before moving on. +if [[ "${DUMP1090_DO_INSTALL}" = "false" ]] && [[ "${DUMP1090_DO_UPGRADE}" = "false" ]] && [[ "${DUMP978_DO_INSTALL}" = "false" ]] && [[ "${DUMP978_DO_UPGRADE}" = "false" ]] && [[ "${RTLSDROGN_DO_INSTALL}" = "false" ]] && [[ "${RTLSDROGN_DO_UPGRADE}" = "false" ]] && [[ "${WEBPORTAL_DO_INSTALL}" = "false" ]] && [[ ! -s "${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES" ]] && [[ ! -s "${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES" ]] ; then + # Nothing was chosen to be installed. + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Nothing to be done" --msgbox "Nothing has been selected to be installed so the script will exit now." 10 65 + echo -e "\e[31m" + echo -e " Nothing was selected to do or be installed." + echo -e "\e[37m" + exit 1 +else + # The user decided to install software. + CONFIRMATION="The following software will be installed:\n" - if [ $DUMP1090MUTABILITY_INSTALL = 0 ] || [ $DUMP1090MUTABILITY_REINSTALL = 0 ]; then - if [ $DUMP1090MUTABILITY_REINSTALL = 0 ]; then - CONFIRMATION="$CONFIRMATION\n * dump1090-mutability (reinstall)" - else - CONFIRMATION="$CONFIRMATION\n * dump1090-mutability" - fi + # dump1090 + if [[ "${DUMP1090_DO_UPGRADE}" = "true" ]] ; then + case ${DUMP1090_FORK} in + "mutability") + CONFIRMATION="${CONFIRMATION}\n * dump1090-mutability (reinstall)" + ;; + "fa") + CONFIRMATION="${CONFIRMATION}\n * dump1090-fa (upgrade)" + ;; + esac + elif [[ "${DUMP1090_DO_INSTALL}" = "true" ]] ; then + case ${DUMP1090_FORK} in + "mutability") + CONFIRMATION="${CONFIRMATION}\n * dump1090-mutability" + ;; + "fa") + CONFIRMATION="${CONFIRMATION}\n * dump1090-fa" + ;; + esac fi - if [ $DUMP1090FA_INSTALL = 0 ] || [ $DUMP1090FA_UPGRADE = 0 ]; then - if [ $DUMP1090FA_UPGRADE = 0 ]; then - CONFIRMATION="$CONFIRMATION\n * dump1090-fa (upgrade)" - else - CONFIRMATION="$CONFIRMATION\n * dump1090-fa" - fi + # dump978 + if [[ "${DUMP978_DO_UPGRADE}" = "true" ]] ; then + CONFIRMATION="${CONFIRMATION}\n * dump978 (rebuild)" + elif [[ "${DUMP978_DO_INSTALL}" = "true" ]] ; then + CONFIRMATION="${CONFIRMATION}\n * dump978" fi - if [ $DUMP978_INSTALL = 0 ] || [ $DUMP978_REINSTALL = 0 ]; then - if [ $DUMP978_REINSTALL = 0 ]; then - CONFIRMATION="$CONFIRMATION\n * dump978 (rebuild)" - else - CONFIRMATION="$CONFIRMATION\n * dump978" - fi + # RTL-SDR OGN + if [[ "${RTLSDROGN_DO_UPGRADE}" = "true" ]] ; then + CONFIRMATION="${CONFIRMATION}\n * RTL-SDR OGN (upgrade)" + elif [[ "${RTLSDROGN_DO_INSTALL}" = "true" ]] ; then + CONFIRMATION="${CONFIRMATION}\n * RTL-SDR OGN" fi # If PiAware is required add it to the list. - if [ $PIAWAREREQUIRED = 0 ]; then - CONFIRMATION="$CONFIRMATION\n * FlightAware PiAware" + if [[ "${DUMP1090_FORK}" = "fa" ]] ; then + CONFIRMATION="${CONFIRMATION}\n * FlightAware PiAware" fi - if [ -s FEEDERCHOICES ]; then - while read FEEDERCHOICE + if [[ -s "${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES" ]] ; then + while read FEEDER_CHOICE do - case $FEEDERCHOICE in + case ${FEEDER_CHOICE} in "FlightAware PiAware") - CONFIRMATION="$CONFIRMATION\n * FlightAware PiAware" - ;; + CONFIRMATION="${CONFIRMATION}\n * FlightAware PiAware" + ;; "FlightAware PiAware (upgrade)") - CONFIRMATION="$CONFIRMATION\n * FlightAware PiAware (upgrade)" + CONFIRMATION="${CONFIRMATION}\n * FlightAware PiAware (upgrade)" ;; - "Plane Finder ADS-B Client") - CONFIRMATION="$CONFIRMATION\n * Plane Finder ADS-B Client" + "Plane Finder Client") + CONFIRMATION="${CONFIRMATION}\n * Plane Finder Client" ;; - "Plane Finder ADS-B Client (upgrade)") - CONFIRMATION="$CONFIRMATION\n * Plane Finder ADS-B Client (upgrade)" + "Plane Finder Client (upgrade)") + CONFIRMATION="${CONFIRMATION}\n * Plane Finder Client (upgrade)" ;; "Flightradar24 Client") - CONFIRMATION="$CONFIRMATION\n * Flightradar24 Client" - ;; + CONFIRMATION="${CONFIRMATION}\n * Flightradar24 Client" + ;; "Flightradar24 Client (upgrade)") - CONFIRMATION="$CONFIRMATION\n * Flightradar24 Client (upgrade)" - ;; - "ADS-B Exchange Script") - CONFIRMATION="$CONFIRMATION\n * ADS-B Exchange Script" + CONFIRMATION="${CONFIRMATION}\n * Flightradar24 Client (upgrade)" + ;; + "ADS-B Exchange data export and MLAT Client") + CONFIRMATION="${CONFIRMATION}\n * ADS-B Exchange data export and MLAT Client" + ;; + "ADS-B Exchange data export and MLAT Client (upgrade)") + CONFIRMATION="${CONFIRMATION}\n * ADS-B Exchange data export and MLAT Client (upgrade)" ;; esac - done < FEEDERCHOICES + done < ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES fi - if [ $PORTAL_INSTALL = 0 ]; then - CONFIRMATION="$CONFIRMATION\n * ADS-B Receiver Project Web Portal" + if [[ "${WEBPORTAL_DO_INSTALL}" = "true" ]] ; then + CONFIRMATION="${CONFIRMATION}\n * ADS-B Receiver Project Web Portal" fi - CONFIRMATION="$CONFIRMATION\n\n" + + if [[ -s "${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES" ]] ; then + while read EXTRAS_CHOICE + do + case ${EXTRAS_CHOICE} in + "AboveTustin") + CONFIRMATION="${CONFIRMATION}\n * AboveTustin" + ;; + "AboveTustin (reinstall)") + CONFIRMATION="${CONFIRMATION}\n * AboveTustin (reinstall)" + ;; + "beast-splitter") + CONFIRMATION="${CONFIRMATION}\n * beast-splitter" + ;; + "beast-splitter (reinstall)") + CONFIRMATION="${CONFIRMATION}\n * beast-splitter (reinstall)" + ;; + "Duck DNS Free Dynamic DNS Hosting") + CONFIRMATION="${CONFIRMATION}\n * Duck DNS Free Dynamic DNS Hosting" + ;; + "Duck DNS Free Dynamic DNS Hosting (reinstall)") + CONFIRMATION="${CONFIRMATION}\n * Duck DNS Free Dynamic DNS Hosting (reinstall)" + ;; + esac + done < ${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES + fi + + CONFIRMATION="${CONFIRMATION}\n\n" fi -# Ask for confirmation before moving on. -CONFIRMATION="${CONFIRMATION}Do you wish to continue setup?" -if ! (whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Confirm You Wish To Continue" --yesno "$CONFIRMATION" 17 78) then - echo -e "\033[31m" - echo " Installation canceled by user." - exit 1 +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + # Ask for confirmation before moving on. + CONFIRMATION="${CONFIRMATION}Do you wish to continue setup?" + if ! (whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Confirm You Wish To Continue" --yesno "${CONFIRMATION}" 21 78) then + echo -e "\e[31m" + echo " Installation canceled by user." + exit 1 + fi fi ################# @@ -361,68 +766,111 @@ fi ## Decoders -if [ $DUMP1090MUTABILITY_INSTALL = 0 ] || [ $DUMP1090MUTABILITY_REINSTALL = 0 ]; then - InstallDump1090Mutability +if [[ "${DUMP1090_DO_INSTALL}" = "true" ]] || [[ "${DUMP1090_DO_UPGRADE}" = "true" ]] ; then + case ${DUMP1090_FORK} in + "mutability") + InstallDump1090Mutability + ;; + "fa") + InstallDump1090Fa + ;; + esac fi -if [ $DUMP1090FA_INSTALL = 0 ] || [ $DUMP1090FA_UPGRADE = 0 ]; then - InstallDump1090Fa -fi - -if [ $DUMP978_INSTALL = 0 ] || [ $DUMP978_REINSTALL = 0 ]; then +if [[ "${DUMP978_DO_INSTALL}" = "true" ]] || [[ "${DUMP978_DO_UPGRADE}" = "true" ]] ; then InstallDump978 fi +if [[ "${RTLSDROGN_DO_INSTALL}" = "true" ]] || [[ "${RTLSDROGN_DO_UPGRADE}" = "true" ]] ; then + InstallRtlsdrOgn +fi + ## Feeders # Moved execution of functions outside of while loop. # Inside the while loop the installation scripts are not stopping at reads. -RUNPIAWARESCRIPT=1 -RUNPLANEFINDERSCRIPT=1 -RUNFLIGHTRADAR24SCRIPT=1 -RUNADSBEXCHANGESCRIPT=1 +RUN_PIAWARE_SCRIPT="false" +RUN_PLANEFINDER_SCRIPT="false" +RUN_FLIGHTRADAR24_SCRIPT="false" +RUN_ADSBEXCHANGE_SCRIPT="false" -if [ -s FEEDERCHOICES ]; then - while read FEEDERCHOICE +if [[ -s "${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES" ]] ; then + while read FEEDER_CHOICE do - case $FEEDERCHOICE in + case ${FEEDER_CHOICE} in "FlightAware PiAware"|"FlightAware PiAware (upgrade)") - RUNPIAWARESCRIPT=0 - ;; - "Plane Finder ADS-B Client"|"Plane Finder ADS-B Client (upgrade)") - RUNPLANEFINDERSCRIPT=0 - ;; + RUN_PIAWARE_SCRIPT="true" + ;; + "Plane Finder Client"|"Plane Finder Client (upgrade)") + RUN_PLANEFINDER_SCRIPT="true" + ;; "Flightradar24 Client"|"Flightradar24 Client (upgrade)") - RUNFLIGHTRADAR24SCRIPT=0 - ;; - "ADS-B Exchange Script") - RUNADSBEXCHANGESCRIPT=0 - ;; + RUN_FLIGHTRADAR24_SCRIPT="true" + ;; + "ADS-B Exchange data export and MLAT Client"|"ADS-B Exchange data export and MLAT Client (upgrade)") + RUN_ADSBEXCHANGE_SCRIPT="true" + ;; esac - done < FEEDERCHOICES + done < ${RECEIVER_ROOT_DIRECTORY}/FEEDER_CHOICES fi -if [ $RUNPIAWARESCRIPT = 0 ] || [ $PIAWAREREQUIRED = 0 ]; then +if [[ "${RUN_PIAWARE_SCRIPT}" = "true" ]] || [[ "${FORCE_PIAWARE_INSTALL}" = "true" ]] ; then InstallPiAware fi -if [ $RUNPLANEFINDERSCRIPT = 0 ]; then +if [[ "${RUN_PLANEFINDER_SCRIPT}" = "true" ]] ; then InstallPlaneFinder fi -if [ $RUNFLIGHTRADAR24SCRIPT = 0 ]; then +if [[ "${RUN_FLIGHTRADAR24_SCRIPT}" = "true" ]] ; then InstallFlightradar24 fi -if [ $RUNADSBEXCHANGESCRIPT = 0 ]; then +if [[ "${RUN_ADSBEXCHANGE_SCRIPT}" = "true" ]] ; then InstallAdsbExchange fi ## ADS-B Receiver Project Web Portal -if [ $PORTAL_INSTALL = 0 ]; then +if [[ "${WEBPORTAL_DO_INSTALL}" = "true" ]] ; then InstallWebPortal fi +# Moved execution of functions outside of while loop. +# Inside the while loop the installation scripts are not stopping at reads. + +RUN_ABOVETUSTIN_SCRIPT="false" +RUN_BEASTSPLITTER_SCRIPT="false" +RUN_DUCKDNS_SCRIPT="false" + +if [[ -s "${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES" ]] ; then + while read EXTRAS_CHOICE + do + case ${EXTRAS_CHOICE} in + "AboveTustin"|"AboveTustin (reinstall)") + RUN_ABOVETUSTIN_SCRIPT="true" + ;; + "beast-splitter"|"beast-splitter (reinstall)") + RUN_BEASTSPLITTER_SCRIPT="true" + ;; + "Duck DNS Free Dynamic DNS Hosting"|"Duck DNS Free Dynamic DNS Hosting (reinstall)") + RUN_DUCKDNS_SCRIPT="true" + ;; + esac + done < ${RECEIVER_ROOT_DIRECTORY}/EXTRAS_CHOICES +fi + +if [[ "${RUN_ABOVETUSTIN_SCRIPT}" = "true" ]] ; then + InstallAboveTustin +fi + +if [[ "${RUN_BEASTSPLITTER_SCRIPT}" = "true" ]] ; then + InstallBeastSplitter +fi + +if [[ "${RUN_DUCKDNS_SCRIPT}" = "true" ]] ; then + InstallDuckDns +fi + exit 0 diff --git a/bash/portal/core.sh b/bash/portal/core.sh index 82b2eee..d44dddb 100755 --- a/bash/portal/core.sh +++ b/bash/portal/core.sh @@ -33,45 +33,45 @@ ## VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -PORTALBUILDDIRECTORY="$BUILDDIRECTORY/portal" -PORTALPYTHONDIRECTORY="$PORTALBUILDDIRECTORY/python" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" +PORTAL_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/portal" +PORTAL_PYTHON_DIRECTORY="${PORTAL_BUILD_DIRECTORY}/python" -DATABASEENGINE=$ADSB_DATABASEENGINE -DATABASEHOSTNAME=$ADSB_DATABASEHOSTNAME -DATABASEUSER=$ADSB_DATABASEUSER -DATABASEPASSWORD1=$ADSB_DATABASEPASSWORD1 -DATABASENAME=$ADSB_DATABASENAME +DATABASEENGINE=${ADSB_DATABASEENGINE} +DATABASEHOSTNAME=${ADSB_DATABASEHOSTNAME} +DATABASEUSER=${ADSB_DATABASEUSER} +DATABASEPASSWORD1=${ADSB_DATABASEPASSWORD1} +DATABASENAME=${ADSB_DATABASENAME} ## SETUP FLIGHT LOGGING -echo "" +echo -e "" echo -e "\e[95m Setting up core advanced portal features...\e[97m" -echo "" +echo -e "" -case $DATABASEENGINE in +case ${DATABASEENGINE} in "MySQL") echo -e "\e[94m Creating the flight Python configuration file for MySQL...\e[97m" - tee $PORTALPYTHONDIRECTORY/config.json > /dev/null < /dev/null < /dev/null < /dev/null </dev/null | grep -c "ok installed") -eq 1 ]] ; then + DUMP1090_FORK="mutability" + DUMP1090_INSTALLED="true" + fi + if [[ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then + DUMP1090_FORK="fa" + DUMP1090_INSTALLED="true" + fi + echo -e "" +fi +if [[ -f "/etc/init.d/rtlsdr-ogn" ]] ; then + RTLSDROGN_INSTALLED="true" +fi + +## CONFIRM HARDWARE PLATFORM + +if [[ -z "${HARDWARE_PLATFORM}" ]] ; then + Check_Platform + echo -e "" +fi ## MODIFY THE DUMP1090-MUTABILITY INIT SCRIPT TO MEASURE AND RETAIN NOISE DATA -if [ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]; then +if [[ "${DUMP1090_INSTALLED}" = "true" ]] && [[ "${DUMP1090_FORK}" = "mutability" ]] ; then echo -e "\e[94m Modifying the dump1090-mutability init script to add noise measurements...\e[97m" - sudo sed -i 's/ARGS=""/ARGS="--measure-noise "/g' /etc/init.d/dump1090-mutability + sudo sed -i 's/ARGS=""/ARGS="--measure-noise "/g' /etc/init.d/dump1090-mutability 2>&1 + # echo -e "\e[94m Reloading the systemd manager configuration...\e[97m" - sudo systemctl daemon-reload + sudo systemctl daemon-reload 2>&1 + # echo -e "\e[94m Reloading dump1090-mutability...\e[97m" - echo "" - sudo /etc/init.d/dump1090-mutability force-reload - echo "" + sudo /etc/init.d/dump1090-mutability force-reload 2>&1 + echo -e "" fi ## BACKUP AND REPLACE COLLECTD.CONF -# Check if the file /etc/collectd/collectd.conf exists and if so back it up. -if [ -f /etc/collectd/collectd.conf ]; then +# Check if the collectd config file exists and if so back it up. +if [[ -f "${COLLECTD_CONFIG}" ]] ; then echo -e "\e[94m Backing up the current collectd.conf file...\e[97m" - sudo mv /etc/collectd/collectd.conf /etc/collectd/collectd.conf.back + sudo cp ${COLLECTD_CONFIG} ${COLLECTD_CONFIG}.bak 2>&1 + echo -e "" fi + +# Generate new collectd config. echo -e "\e[94m Replacing the current collectd.conf file...\e[97m" -sudo tee -a /etc/collectd/collectd.conf > /dev/null < /dev/null < /dev/null < /dev/null < /dev/null < Globals true @@ -124,24 +177,33 @@ LoadPlugin disk DataDir "/var/lib/collectd/rrd" -#----------------------------------------------------------------------------# -# Configure the dump1090 python module. # -# # -# Each Instance block collects statistics from a separate named dump1090. # -# The URL should be the base URL of the webmap, i.e. in the examples below, # -# statistics will be loaded from http://localhost/dump1090/data/stats.json # -#----------------------------------------------------------------------------# - - ModulePath "$PORTALBUILDDIRECTORY/graphs" - LogTraces true - Import "dump1090" - - - URL "http://localhost/dump1090" - - + + + Plugin "cpu" + Type "cpu" + GroupBy "Host" + GroupBy "TypeInstance" + CalculateAverage true + + + MountPoint "/" + IgnoreSelected false + ReportReserved true + ReportInodes true + + + + Interface "eth0" + Interface "wlan0" + + +EOF + +# Raspberry Pi specific values. +if [[ "${HARDWARE_PLATFORM}" = "RPI" ]] ; then + sudo tee -a ${COLLECTD_CONFIG} > /dev/null < Instance localhost @@ -154,33 +216,117 @@ LoadPlugin disk
- - Interface "eth0" - Interface "wlan0" - - - - - Plugin "cpu" - Type "cpu" - GroupBy "Host" - GroupBy "TypeInstance" - CalculateAverage true - - - - - MountPoint "/" - IgnoreSelected false - ReportReserved true - ReportInodes true - - Disk "mmcblk0" IgnoreSelected false +EOF +# CHIP specific values. +elif [[ "${HARDWARE_PLATFORM}" = "CHIP" ]] ; then + sudo tee -a ${COLLECTD_CONFIG} > /dev/null < + + Instance localhost + Separator " " + + Type gauge + InstancePrefix "cpu_temp" + ValuesFrom 0 + +
+ + + + Disk "ubi0:rootfs" + IgnoreSelected false + + +EOF +fi + +# Dump1090 specific values. +if [[ "${DUMP1090_INSTALLED}" = "true" ]] ; then + sudo tee -a ${COLLECTD_CONFIG} > /dev/null < + ModulePath "${PORTAL_BUILD_DIRECTORY}/graphs" + LogTraces true + Import "dump1090" + + + URL "http://localhost/dump1090" + + + + +EOF +fi + +# RTLSDR-OGN specific values. +if [[ "${RTLSDROGN_INSTALLED}" = "true" ]] ; then + sudo tee -a ${COLLECTD_CONFIG} > /dev/null < + + URL "http://localhost:8080/" + # OGN center Frequency + + Regex "RF.OGN.CenterFreq([0-9]*\\.[0-9]+) MHz" + DSType "GaugeLast" + Type "frequency" + Instance "Center-Frequency-OGN" + + # GSM center Frequency + + Regex "RF.GSM.CenterFreq([0-9]*\\.[0-9]+) MHz" + DSType "GaugeLast" + Type "frequency" + Instance "Center-Frequency-GSM" + + # OGN Frequency Correction + + Regex "Frequency correction([\+\-][0-9]*\\.[0-9]+) ppm" + DSType "GaugeLast" + Type "frequency_offset" + Instance "Frequency-Correction-OGN" + + # NTP Frequency Correction + + Regex "NTP freq. corr.([\+\-][0-9]*\\.[0-9]+) ppm" + DSType "GaugeLast" + Type "frequency_offset" + Instance "Frequency-Correction-NTP" + + # OGN Gain + + Regex "RF.OGN.Gain([0-9]*\\.[0-9]+) dB" + DSType "GaugeLast" + Type "gauge" + Instance "Gain-OGN" + + # GSM Gain + + Regex "RF.GSM.Gain([0-9]*\\.[0-9]+) dB" + DSType "GaugeLast" + Type "gauge" + Instance "Gain-GSM" + + + +EOF +fi + +# Remaining config for all installations. +sudo tee -a ${COLLECTD_CONFIG} > /dev/null < @@ -195,33 +341,39 @@ LoadPlugin disk Target "write" EOF +echo -e "" ## RELOAD COLLECTD echo -e "\e[94m Reloading collectd so the new configuration is used...\e[97m" -echo "" -sudo /etc/init.d/collectd force-reload -echo "" +echo -e "" +sudo /etc/init.d/collectd force-reload 2>&1 +echo -e "" ## EDIT CRONTAB -echo -e "\e[94m Making the make-collectd-graphs.sh script executable...\e[97m" -chmod +x $PORTALBUILDDIRECTORY/graphs/make-collectd-graphs.sh +if [[ ! -x "${PORTAL_BUILD_DIRECTORY}/graphs/make-collectd-graphs.sh" ]] ; then + echo -e "\e[94m Making the make-collectd-graphs.sh script executable...\e[97m" + chmod +x ${PORTAL_BUILD_DIRECTORY}/graphs/make-collectd-graphs.sh 2>&1 + echo -e "" +fi # The next block is temporary in order to insure this file is # deleted on older installation before the project renaming. -if [ -f /etc/cron.d/adsb-feeder-performance-graphs ]; then +if [[ -f "/etc/cron.d/adsb-feeder-performance-graphs" ]] ; then echo -e "\e[94m Removing outdated performance graphs cron file...\e[97m" - sudo rm -f /etc/cron.d/adsb-feeder-performance-graphs + sudo rm -f /etc/cron.d/adsb-feeder-performance-graphs 2>&1 + echo -e "" fi -if [ -f /etc/cron.d/adsb-receiver-performance-graphs ]; then +if [[ -f "${COLLECTD_CRON_FILE}" ]] ; then echo -e "\e[94m Removing previously installed performance graphs cron file...\e[97m" - sudo rm -f /etc/cron.d/adsb-receiver-performance-graphs + sudo rm -f ${COLLECTD_CRON_FILE} 2>&1 + echo -e "" fi echo -e "\e[94m Adding performance graphs cron file...\e[97m" -sudo tee -a /etc/cron.d/adsb-receiver-performance-graphs > /dev/null < /dev/null < /dev/null </dev/null 2>&1 -*/10 * * * * root bash $PORTALBUILDDIRECTORY/graphs/make-collectd-graphs.sh 6h >/dev/null 2>&1 -2,12,22,32,42,52 * * * * root bash $PORTALBUILDDIRECTORY/graphs/make-collectd-graphs.sh 24h >/dev/null 2>&1 -4,24,44 * * * * root bash $PORTALBUILDDIRECTORY/graphs/make-collectd-graphs.sh 7d >/dev/null 2>&1 -6 * * * * root bash $PORTALBUILDDIRECTORY/graphs/make-collectd-graphs.sh 30d >/dev/null 2>&1 -8 */12 * * * root bash $PORTALBUILDDIRECTORY/graphs/make-collectd-graphs.sh 365d >/dev/null 2>&1 +*/5 * * * * root bash ${PORTAL_BUILD_DIRECTORY}/graphs/make-collectd-graphs.sh 1h >/dev/null 2>&1 +*/10 * * * * root bash ${PORTAL_BUILD_DIRECTORY}/graphs/make-collectd-graphs.sh 6h >/dev/null 2>&1 +2,12,22,32,42,52 * * * * root bash ${PORTAL_BUILD_DIRECTORY}/graphs/make-collectd-graphs.sh 24h >/dev/null 2>&1 +4,24,44 * * * * root bash ${PORTAL_BUILD_DIRECTORY}/graphs/make-collectd-graphs.sh 7d >/dev/null 2>&1 +6 * * * * root bash ${PORTAL_BUILD_DIRECTORY}/graphs/make-collectd-graphs.sh 30d >/dev/null 2>&1 +8 */12 * * * root bash ${PORTAL_BUILD_DIRECTORY}/graphs/make-collectd-graphs.sh 365d >/dev/null 2>&1 EOF +echo -e "" + +# Update max_range.rrd to remove the 500 km / ~270 nmi limit. +if [[ `rrdinfo ${DUMP1090_MAX_RANGE_RRD} | grep -c "ds\[value\].max = 1.0000000000e+06"` -eq 0 ]] ; then + sudo rrdtool tune ${DUMP1090_MAX_RANGE_RRD} --maximum "value:1000000" 2>&1 +fi + +### SETUP COMPLETE + +# Return to the project root directory. +echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 + +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" +echo -e "\e[92m Graphing setup is complete.\e[39m" +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi exit 0 diff --git a/bash/portal/install.sh b/bash/portal/install.sh index 8f6980b..82ab65b 100755 --- a/bash/portal/install.sh +++ b/bash/portal/install.sh @@ -33,35 +33,37 @@ ## VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -PORTALBUILDDIRECTORY="$BUILDDIRECTORY/portal" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" +PORTAL_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/portal" ## INCLUDE EXTERNAL SCRIPTS -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh ## BEGIN SETUP clear -echo -e "\n\e[91m $ADSB_PROJECTTITLE" -echo "" +echo -e "\n\e[91m ${RECEIVER_PROJECT_TITLE}" +echo -e "" echo -e "\e[92m Setting up the ADS-B Receiver Project Portal..." -echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" -echo "" -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "ADS-B ADS-B Receiver Project Portal Setup" --yesno "The ADS-B ADS-B Receiver Project Portal adds a web accessable portal to your receiver. The portal contains allows you to view performance graphs, system information, and live maps containing the current aircraft being tracked.\n\nBy enabling the portal's advanced features you can also view historical data on flight that have been seen in the past as well as view more detailed information on each of these aircraft.\n\nTHE ADVANCED PORTAL FEATURES ARE STILL IN DEVELOPMENT\n\nIt is recomended that only those wishing to contribute to the development of these features or those wishing to test out the new features enable them. Do not be surprised if you run into any major bugs after enabling the advanced features at this time!\n\nDo you wish to continue with the ADS-B Receiver Project Portal setup?" 23 78 -CONTINUESETUP=$? -if [ $CONTINUESETUP = 1 ]; then +echo -e "\e[93m ------------------------------------------------------------------------------\e[96m" +echo -e "" +whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "ADS-B ADS-B Receiver Project Portal Setup" --yesno "The ADS-B ADS-B Receiver Project Portal adds a web accessable portal to your receiver. The portal contains allows you to view performance graphs, system information, and live maps containing the current aircraft being tracked.\n\nBy enabling the portal's advanced features you can also view historical data on flight that have been seen in the past as well as view more detailed information on each of these aircraft.\n\nTHE ADVANCED PORTAL FEATURES ARE STILL IN DEVELOPMENT\n\nIt is recomended that only those wishing to contribute to the development of these features or those wishing to test out the new features enable them. Do not be surprised if you run into any major bugs after enabling the advanced features at this time!\n\nDo you wish to continue with the ADS-B Receiver Project Portal setup?" 23 78 +CONTINUE_SETUP=$? +if [[ "${CONTINUE_SETUP}" = 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 "" + echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m ADS-B Receiver Project Portal setup halted.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE + echo -e "" + if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE + fi exit 1 fi @@ -69,162 +71,162 @@ fi # We will need to make sure Lighttpd is installed first before we go any further. echo -e "\e[95m Installing packages needed to fulfill dependencies...\e[97m" -echo "" +echo -e "" CheckPackage lighttpd # Assign the Lighthttpd document root directory to a variable. -RAWDOCUMENTROOT=`/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -p | grep server.document-root` -LIGHTTPDDOCUMENTROOT=`sed 's/.*"\(.*\)"[^"]*$/\1/' <<< $RAWDOCUMENTROOT` +RAW_DOCUMENT_ROOT=`/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -p | grep server.document-root` +LIGHTTPD_DOCUMENT_ROOT=`sed 's/.*"\(.*\)"[^"]*$/\1/' <<< ${RAW_DOCUMENT_ROOT}` # Check if there is already an existing portal installation. -if [ -f $LIGHTTPDDOCUMENTROOT/classes/settings.class.php ]; then - PORTALINSTALLED=TRUE +if [[ -f "${LIGHTTPD_DOCUMENT_ROOT}/classes/settings.class.php" ]] ; then + RECEIVER_PORTAL_INSTALLED="true" else - PORTALINSTALLED=FALSE + RECEIVER_PORTAL_INSTALLED="false" fi -if [ $PORTALINSTALLED = TRUE ]; then +if [[ "${RECEIVER_PORTAL_INSTALLED}" = "true" ]] ; then # Assign needed variables using the driver setting in settings.class.php. - DATABASEENGINE=`grep 'db_driver' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2` - if [ $DATABASEENGINE = "xml" ]; then - ADVANCED=FALSE + DATABASEENGINE=`grep 'db_driver' ${LIGHTTPD_DOCUMENT_ROOT}/classes/settings.class.php | tail -n1 | cut -d\' -f2` + if [[ "${DATABASEENGINE}" = "xml" ]] ; then + ADVANCED="false" else - ADVANCED=TRUE + ADVANCED="true" fi - if [ $ADVANCED = TRUE ]; then - case $DATABASEENGINE in - "mysql") DATABASEENGINE="MySQL";; - "sqlite") DATABASEENGINE="SQLite";; + if [[ "${ADVANCED}" = "true" ]] ; then + case "${DATABASEENGINE}" in + "mysql") DATABASEENGINE="MySQL" ;; + "sqlite") DATABASEENGINE="SQLite" ;; esac - DATABASEHOSTNAME=`grep 'db_host' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2` - DATABASEUSER=`grep 'db_username' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2` - DATABASEPASSWORD1=`grep 'db_password' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2` - DATABASENAME=`grep 'db_database' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2` + DATABASEHOSTNAME=`grep 'db_host' ${LIGHTTPD_DOCUMENT_ROOT}/classes/settings.class.php | tail -n1 | cut -d\' -f2` + DATABASEUSER=`grep 'db_username' ${LIGHTTPD_DOCUMENT_ROOT}/classes/settings.class.php | tail -n1 | cut -d\' -f2` + DATABASEPASSWORD1=`grep 'db_password' ${LIGHTTPD_DOCUMENT_ROOT}/classes/settings.class.php | tail -n1 | cut -d\' -f2` + DATABASENAME=`grep 'db_database' ${LIGHTTPD_DOCUMENT_ROOT}/classes/settings.class.php | tail -n1 | cut -d\' -f2` fi else # Ask if advanced features should be enabled. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "ADS-B Receiver Portal Selection" --defaultno --yesno "NOTE THAT THE ADVANCED FEATURES ARE STILL IN DEVELOPMENT AT THIS TIME\nADVANCED FEATURES SHOULD ONLY BE ENABLED BY DEVELOPERS AND TESTERS ONLY\n\nBy enabling advanced features the portal will log all flights seen as well as the path of the flight. This data is stored in either a MySQL or SQLite database. This will result in a lot more data being stored on your devices hard drive. Keep this and your devices hardware capabilities in mind before selecting to enable these features.\n\nENABLING ADVANCED FEATURES ON DEVICES USING SD CARDS CAN SHORTEN THE LIFE OF THE SD CARD IMMENSELY\n\nDo you wish to enable the portal advanced features?" 19 78 + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "ADS-B Receiver Portal Selection" --defaultno --yesno "NOTE THAT THE ADVANCED FEATURES ARE STILL IN DEVELOPMENT AT THIS TIME\nADVANCED FEATURES SHOULD ONLY BE ENABLED BY DEVELOPERS AND TESTERS ONLY\n\nBy enabling advanced features the portal will log all flights seen as well as the path of the flight. This data is stored in either a MySQL or SQLite database. This will result in a lot more data being stored on your devices hard drive. Keep this and your devices hardware capabilities in mind before selecting to enable these features.\n\nENABLING ADVANCED FEATURES ON DEVICES USING SD CARDS CAN SHORTEN THE LIFE OF THE SD CARD IMMENSELY\n\nDo you wish to enable the portal advanced features?" 19 78 RESPONSE=$? - case $RESPONSE in - 0) ADVANCED=TRUE;; - 1) ADVANCED=FALSE;; + case ${RESPONSE} in + 0) ADVANCED="true" ;; + 1) ADVANCED="false" ;; esac - if [ $ADVANCED = TRUE ]; then + if [[ "${ADVANCED}" = "true" ]] ; then # Ask which type of database to use. - DATABASEENGINE=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Choose Database Type" --nocancel --menu "\nChoose which type of database to use." 11 80 2 "MySQL" "" "SQLite" "" 3>&1 1>&2 2>&3) + DATABASEENGINE=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Choose Database Type" --nocancel --menu "\nChoose which type of database to use." 11 80 2 "MySQL" "" "SQLite" "" 3>&1 1>&2 2>&3) - if [ $DATABASEENGINE = "MySQL" ]; then + if [[ "${DATABASEENGINE}" = "MySQL" ]] ; then # Ask if the database server will be installed locally. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "MySQL Database Location" --yesno "Will the database be hosted locally on this device?" 7 80 + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "MySQL Database Location" --yesno "Will the database be hosted locally on this device?" 7 80 RESPONSE=$? - case $RESPONSE in - 0) LOCALMYSQLSERVER=TRUE;; - 1) LOCALMYSQLSERVER=FALSE;; + case ${RESPONSE} in + 0) LOCALMYSQLSERVER="true" ;; + 1) LOCALMYSQLSERVER="false" ;; esac - if [ $LOCALMYSQLSERVER = FALSE ]; then + if [[ "${LOCALMYSQLSERVER}" = "false" ]] ; then # Ask for the remote MySQL servers hostname. DATABASEHOSTNAME_TITLE="MySQL Database Server Hostname" - while [[ -z $DATABASEHOSTNAME ]]; do - DATABASEHOSTNAME=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEHOSTNAME_TITLE" --nocancel --inputbox "\nWhat is the remote MySQL server's hostname?" 10 60 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEHOSTNAME}" ]] ; do + DATABASEHOSTNAME=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEHOSTNAME_TITLE}" --nocancel --inputbox "\nWhat is the remote MySQL server's hostname?" 10 60 3>&1 1>&2 2>&3) DATABASEHOSTNAME_TITLE="MySQL Database Server Hostname (REQUIRED)" done # Ask if the remote MySQL database already exists. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Does MySQL Database Exist" --yesno "Has the database already been created?" 7 80 + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Does MySQL Database Exist" --yesno "Has the database already been created?" 7 80 RESPONSE=$? - case $RESPONSE in - 0) DATABASEEXISTS=TRUE;; - 1) DATABASEEXISTS=FALSE;; + case ${RESPONSE} in + 0) DATABASEEXISTS="true" ;; + 1) DATABASEEXISTS="false" ;; esac else # Install the MySQL serer now if it does not already exist. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "MySQL Server Setup" --msgbox "This script will now check for the MySQL server package. If the MySQL server package is not installed it will be installed at this time." 8 78 + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "MySQL Server Setup" --msgbox "This script will now check for the MySQL server package. If the MySQL server package is not installed it will be installed at this time." 8 78 CheckPackage mysql-server # Since this is a local installation assume the MySQL database does not already exist. - DATABASEEXISTS=FALSE + DATABASEEXISTS="false" # Since the MySQL database server will run locally assign localhost as it's hostname. DATABASEHOSTNAME="localhost" fi # Ask for the MySQL administrator credentials if the database does not already exist. - if [ $LOCALMYSQLSERVER = TRUE ] || [ $DATABASEEXISTS = FALSE ]; then - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Create Remote MySQL Database" --msgbox "This script can attempt to create the MySQL database for you.\nYou will now be asked for the credentials for a MySQL user who has the ability to create a database on the MySQL server." 9 78 + if [[ "${LOCALMYSQLSERVER}" = "true" ]] || [[ "${DATABASEEXISTS}" = "false" ]] ; then + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Create Remote MySQL Database" --msgbox "This script can attempt to create the MySQL database for you.\nYou will now be asked for the credentials for a MySQL user who has the ability to create a database on the MySQL server." 9 78 DATABASEADMINUSER_TITLE="MySQL Administrator User" - while [ -z "$DATABASEADMINUSER" ]; do - DATABASEADMINUSER=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEADMINUSER_TITLE" --nocancel --inputbox "\nEnter the MySQL administrator user." 8 78 "root" 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEADMINUSER}" ]] ; do + DATABASEADMINUSER=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEADMINUSER_TITLE}" --nocancel --inputbox "\nEnter the MySQL administrator user." 8 78 "root" 3>&1 1>&2 2>&3) DATABASEADMINUSER_TITLE="MySQL Administrator User (REQUIRED)" done DATABASEADMINPASSWORD1_TITLE="MySQL Administrator Password" DATABASEADMINPASSWORD1_MESSAGE="\nEnter the password for the MySQL adminitrator user." - while [ -z "$DATABASEADMINPASSWORD1" ]; do - DATABASEADMINPASSWORD1=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEADMINPASSWORD1_TITLE" --nocancel --passwordbox "$DATABASEADMINPASSWORD1_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEADMINPASSWORD1}" ]] ; do + DATABASEADMINPASSWORD1=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEADMINPASSWORD1_TITLE}" --nocancel --passwordbox "${DATABASEADMINPASSWORD1_MESSAGE}" 8 78 3>&1 1>&2 2>&3) DATABASEADMINPASSWORD1_TITLE="MySQL Administrator Password (REQUIRED)" done DATABASEADMINPASSWORD2_TITLE="Confirm The MySQL Administrator Password" DATABASEADMINPASSWORD2_MESSAGE="\nConfirm the password for the MySQL adminitrator user." - while [ -z "$DATABASEADMINPASSWORD2" ]; do - DATABASEADMINPASSWORD2=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEADMINPASSWORD2_TITLE" --nocancel --passwordbox "$DATABASEADMINPASSWORD2_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEADMINPASSWORD2}" ]] ; do + DATABASEADMINPASSWORD2=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEADMINPASSWORD2_TITLE}" --nocancel --passwordbox "${DATABASEADMINPASSWORD2_MESSAGE}" 8 78 3>&1 1>&2 2>&3) DATABASEADMINPASSWORD2_TITLE="Confirm The MySQL Administrator Password (REQUIRED)" done - while [ ! $DATABASEADMINPASSWORD1 = $DATABASEADMINPASSWORD2 ]; do + while [[ ! "${DATABASEADMINPASSWORD1}" = "${DATABASEADMINPASSWORD2}" ]] ; do DATABASEADMINPASSWORD1="" DATABASEADMINPASSWORD2="" - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Passwords Did Not Match" --msgbox "Passwords did not match.\nPlease enter your password again." 9 78 + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Passwords Did Not Match" --msgbox "Passwords did not match.\nPlease enter your password again." 9 78 DATABASEADMINPASSWORD1_TITLE="MySQL Administrator Password" - while [ -z "$DATABASEADMINPASSWORD1" ]; do - DATABASEADMINPASSWORD1=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEADMINPASSWORD1_TITLE" --nocancel --passwordbox "DATABASEADMINPASSWORD1_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEADMINPASSWORD1}" ]] ; do + DATABASEADMINPASSWORD1=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEADMINPASSWORD1_TITLE}" --nocancel --passwordbox "DATABASEADMINPASSWORD1_MESSAGE" 8 78 3>&1 1>&2 2>&3) DATABASEADMINPASSWORD1_TITLE="MySQL Administrator Password (REQUIRED)" done DATABASEADMINPASSWORD2_TITLE="Confirm The MySQL Administrator Password" - while [ -z "$DATABASEADMINPASSWORD2" ]; do - DATABASEADMINPASSWORD2=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEADMINPASSWORD2_TITLE" --nocancel --passwordbox "DATABASEADMINPASSWORD2_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEADMINPASSWORD2}" ]] ; do + DATABASEADMINPASSWORD2=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEADMINPASSWORD2_TITLE}" --nocancel --passwordbox "DATABASEADMINPASSWORD2_MESSAGE" 8 78 3>&1 1>&2 2>&3) DATABASEADMINPASSWORD2_TITLE="Confirm The MySQL Administrator Password (REQUIRED)" done done fi # Get the login information pertaining to the MySQL database itself. - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Create Remote MySQL Database" --msgbox "You will now be asked to supply the name of the database which will store the portal data as well as the login credentials for the MySQL user that has access to this database." 9 78 + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Create Remote MySQL Database" --msgbox "You will now be asked to supply the name of the database which will store the portal data as well as the login credentials for the MySQL user that has access to this database." 9 78 DATABASENAME_TITLE="ADS-B Receiver Portal Database Name" - while [ -z "$DATABASENAME" ]; do - DATABASENAME=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASENAME_TITLE" --nocancel --inputbox "\nEnter your ADS-B Receiver Portal database name." 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASENAME}" ]] ; do + DATABASENAME=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASENAME_TITLE}" --nocancel --inputbox "\nEnter your ADS-B Receiver Portal database name." 8 78 3>&1 1>&2 2>&3) DATABASENAME_TITLE="ADS-B Receiver Portal Database Name (REQUIRED)" done DATABASEUSER_TITLE="ADS-B Receiver Portal Database User" - while [ -z "$DATABASEUSER" ]; do - DATABASEUSER=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEUSER_TITLE" --nocancel --inputbox "\nEnter the user for the ADS-B Receiver Portal database." 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEUSER}" ]] ; do + DATABASEUSER=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEUSER_TITLE}" --nocancel --inputbox "\nEnter the user for the ADS-B Receiver Portal database." 8 78 3>&1 1>&2 2>&3) DATABASEUSER_TITLE="ADS-B Receiver Portal Database User (REQUIRED)" done DATABASEPASSWORD1_TITLE="ADS-B Receiver Portal Password" DATABASEPASSWORD1_MESSAGE="\nEnter your ADS-B Receiver Portal database password." - while [ -z "$DATABASEPASSWORD1" ]; do - DATABASEPASSWORD1=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEPASSWORD1_TITLE" --nocancel --passwordbox "$DATABASEPASSWORD1_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEPASSWORD1}" ]] ; do + DATABASEPASSWORD1=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEPASSWORD1_TITLE}" --nocancel --passwordbox "${DATABASEPASSWORD1_MESSAGE}" 8 78 3>&1 1>&2 2>&3) DATABASEPASSWORD1_TITLE="ADS-B Receiver Portal Password (REQUIRED)" done DATABASEPASSWORD2_TITLE="Confirm The ADS-B Receiver Portal Password" DATABASEPASSWORD2_MESSAGE="\nConfirm your ADS-B Receiver Portal database password." - while [ -z "$DATABASEPASSWORD2" ]; do - DATABASEPASSWORD2=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEPASSWORD2_TITLE" --nocancel --passwordbox "$DATABASEPASSWORD2_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEPASSWORD2}" ]] ; do + DATABASEPASSWORD2=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEPASSWORD2_TITLE}" --nocancel --passwordbox "${DATABASEPASSWORD2_MESSAGE}" 8 78 3>&1 1>&2 2>&3) DATABASEPASSWORD2_TITLE="Confirm The ADS-B Receiver Portal Password (REQUIRED)" done - while [ ! $DATABASEPASSWORD1 = $DATABASEPASSWORD2 ]; do + while [[ ! "${DATABASEPASSWORD1}" = "${DATABASEPASSWORD2}" ]] ; do DATABASEPASSWORD1="" DATABASEPASSWORD2="" - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Passwords Did Not Match" --msgbox "Passwords did not match.\nPlease enter your password again." 9 78 + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Passwords Did Not Match" --msgbox "Passwords did not match.\nPlease enter your password again." 9 78 DATABASEPASSWORD1_TITLE="ADS-B Receiver Portal Password" - while [ -z "$DATABASEPASSWORD1" ]; do - DATABASEPASSWORD1=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEPASSWORD1_TITLE" --nocancel --passwordbox "$DATABASEPASSWORD1_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEPASSWORD1}" ]] ; do + DATABASEPASSWORD1=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEPASSWORD1_TITLE}" --nocancel --passwordbox "${DATABASEPASSWORD1_MESSAGE}" 8 78 3>&1 1>&2 2>&3) DATABASEPASSWORD1_TITLE="ADS-B Receiver Portal Password (REQUIRED)" done DATABASEPASSWORD2_TITLE="Confirm The ADS-B Receiver Portal Password" - while [ -z "$DATABASEPASSWORD2" ]; do - DATABASEPASSWORD2=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEPASSWORD2_TITLE" --nocancel --passwordbox "$DATABASEPASSWORD2_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEPASSWORD2}" ]] ; do + DATABASEPASSWORD2=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEPASSWORD2_TITLE}" --nocancel --passwordbox "${DATABASEPASSWORD2_MESSAGE}" 8 78 3>&1 1>&2 2>&3) DATABASEPASSWORD2_TITLE="Confirm The ADS-B Receiver Portal Password (REQUIRED)" done done @@ -234,6 +236,46 @@ fi ## CHECK FOR PREREQUISITE PACKAGES +# Attempt to detect Debian and derivative distros such as Ubuntu. +if [[ -s "/etc/lsb-release" ]] ; then + source /etc/lsb-release +elif [[ -x "`which lsb_release`" ]] ; then + DISTRIB_ID=`lsb_release -a 2>&1 | grep "^Distributor ID:" | awk -F ":" '{print $2}' | awk '{print $1}'` + DISTRIB_RELEASE=`lsb_release -a 2>&1 | grep "^Release:" | awk -F ":" '{print $2}' | awk '{print $1}'` +fi + +# Check for existing PHP installation. +if [[ -x `which php` ]] && [[ `php -v | grep -c "^PHP [0-9]"` -gt 0 ]] ; then + # Detect installed PHP version. + RECEIVER_PHP_INSTALLED=`php -v | grep "^PHP [0-9]" | awk '{print $2}'` + if [[ `echo ${RECEIVER_PHP_INSTALLED} | grep -c "^7\.0\."` -gt 0 ]] ; then + # Found php7.0 install. + RECEIVER_PHP_VERSION="7.0" + elif [[ `echo ${RECEIVER_PHP_INSTALLED} | grep -c "^5\."` -gt 0 ]] ; then + # Found php5 install. + RECEIVER_PHP_VERSION="5" + else + # Otherwise assume php5. + RECEIVER_PHP_VERSION="5" + fi +else + # Otherwise determine required PHP version based on distribution version. + if [[ "${DISTRIB_ID}" = "Ubuntu" ]] && [[ "$(echo ${DISTRIB_RELEASE} | tr -cd '[:digit:]')" -ge "1604" ]] ; then + # Use phpp7.0 for Ubuntu 16.04 LTS and above, which we detect based on version string format of yymm. + RECEIVER_PHP_VERSION="7.0" + elif [[ "${DISTRIB_ID}" = "Debian" ]] && [[ "${DISTRIB_RELEASE}" = "testing" ]] ; then + # Use php7.0 for Debian 9.0 'Strech' which is currently identified as the "testing" release. + RECEIVER_PHP_VERSION="7.0" + else + # Use php5 for all other platforms and distributions. + RECEIVER_PHP_VERSION="5" + fi +fi + +# Install correct PHP version for the platform. +CheckPackage php${RECEIVER_PHP_VERSION}-cgi +CheckPackage php${RECEIVER_PHP_VERSION}-json + # Performance graph dependencies. CheckPackage collectd-core CheckPackage rrdtool @@ -241,133 +283,87 @@ CheckPackage rrdtool # Portal dependencies. CheckPackage libpython2.7 -# Check if this is Ubuntu 16.04 LTS (or later) -# Since Ubuntu versions are always in the format yy.mm, we can simply -# remove the decimal and treat the resultant string as an integer -if [ -f /etc/lsb-release ]; then - . /etc/lsb-release - temp=$(echo $DISTRIB_RELEASE | sed "s/\.//g") - if [ $DISTRIB_ID == "Ubuntu" ] && [ $temp -ge 1604 ]; then - CheckPackage php7.0-cgi - CheckPackage php7.0-json # was php7.0-xml - maybe a typo? - else - CheckPackage php5-cgi - CheckPackage php5-json - fi -else - CheckPackage php5-cgi - CheckPackage php5-json -fi - # Install packages needed for advanced portal setups. -if [ $ADVANCED = TRUE ]; then +if [[ "${ADVANCED}" = "true" ]] ; then CheckPackage python-pyinotify - case $DATABASEENGINE in + case "${DATABASEENGINE}" in "MySQL") CheckPackage mysql-client CheckPackage python-mysqldb - - # Check if this is Ubuntu 16.04 LTS (or later) - # Since Ubuntu versions are always in the format yy.mm we can simply - # remove the decimal and treat the resultant string as an integer - if [ -f /etc/lsb-release ]; then - . /etc/lsb-release - temp=$(echo $DISTRIB_RELEASE | sed "s/\.//g") - if [ $DISTRIB_ID == "Ubuntu" ] && [ $temp -ge 1604 ]; then - CheckPackage php7.0-mysql - else - CheckPackage php5-mysql - fi - else - CheckPackage php5-mysql - fi + CheckPackage php${RECEIVER_PHP_VERSION}-mysql ;; "SQLite") CheckPackage sqlite3 - - # Check if this is Ubuntu 16.04 LTS (or later) - # Since Ubuntu versions are always in the format yy.mm we can simply - # remove the decimal and treat the resultant string as an integer - if [ -f /etc/lsb-release ]; then - . /etc/lsb-release - temp=$(echo $DISTRIB_RELEASE | sed "s/\.//g") - if [ $DISTRIB_ID == "Ubuntu" ] && [ $temp -ge 1604 ]; then - CheckPackage php7.0-sqlite - else - CheckPackage php5-sqlite - fi - else - CheckPackage php5-sqlite - fi + CheckPackage php${RECEIVER_PHP_VERSION}-sqlite ;; esac fi # Reload Lighttpd after installing the prerequisite packages. echo -e "\e[94m Reloading Lighttpd...\e[97m" -echo "" +echo -e "" sudo /etc/init.d/lighttpd force-reload ## SETUP THE PORTAL WEBSITE -echo "" +echo -e "" echo -e "\e[95m Setting up the web portal...\e[97m" -echo "" +echo -e "" # If this is an existing Lite installation being upgraded backup the XML data files. -if [ $PORTALINSTALLED = TRUE ] && [ $ADVANCED = FALSE ]; then - echo -e "\e[94m Backing up the file $LIGHTTPDDOCUMENTROOT/data/administrators.xml...\e[97m" - sudo mv $LIGHTTPDDOCUMENTROOT/data/administrators.xml $LIGHTTPDDOCUMENTROOT/data/administrators.backup.xml - echo -e "\e[94m Backing up the file $LIGHTTPDDOCUMENTROOT/data/blogPosts.xml...\e[97m" - sudo mv $LIGHTTPDDOCUMENTROOT/data/blogPosts.xml $LIGHTTPDDOCUMENTROOT/data/blogPosts.backup.xml - echo -e "\e[94m Backing up the file $LIGHTTPDDOCUMENTROOT/data/flightNotifications.xml...\e[97m" - sudo mv $LIGHTTPDDOCUMENTROOT/data/flightNotifications.xml $LIGHTTPDDOCUMENTROOT/data/flightNotifications.backup.xml - echo -e "\e[94m Backing up the file $LIGHTTPDDOCUMENTROOT/data/settings.xml...\e[97m" - sudo mv $LIGHTTPDDOCUMENTROOT/data/settings.xml $LIGHTTPDDOCUMENTROOT/data/settings.backup.xml +if [[ "${RECEIVER_PORTAL_INSTALLED}" = "true" ]] && [[ "${ADVANCED}" = "false" ]] ; then + echo -e "\e[94m Backing up the file ${LIGHTTPD_DOCUMENT_ROOT}/data/administrators.xml...\e[97m" + sudo mv ${LIGHTTPD_DOCUMENT_ROOT}/data/administrators.xml ${LIGHTTPD_DOCUMENT_ROOT}/data/administrators.backup.xml + echo -e "\e[94m Backing up the file ${LIGHTTPD_DOCUMENT_ROOT}/data/blogPosts.xml...\e[97m" + sudo mv ${LIGHTTPD_DOCUMENT_ROOT}/data/blogPosts.xml ${LIGHTTPD_DOCUMENT_ROOT}/data/blogPosts.backup.xml + echo -e "\e[94m Backing up the file ${LIGHTTPD_DOCUMENT_ROOT}/data/flightNotifications.xml...\e[97m" + sudo mv ${LIGHTTPD_DOCUMENT_ROOT}/data/flightNotifications.xml ${LIGHTTPD_DOCUMENT_ROOT}/data/flightNotifications.backup.xml + echo -e "\e[94m Backing up the file ${LIGHTTPD_DOCUMENT_ROOT}/data/settings.xml...\e[97m" + sudo mv ${LIGHTTPD_DOCUMENT_ROOT}/data/settings.xml ${LIGHTTPD_DOCUMENT_ROOT}/data/settings.backup.xml fi echo -e "\e[94m Placing portal files in Lighttpd's root directory...\e[97m" -sudo cp -R $PORTALBUILDDIRECTORY/html/* $LIGHTTPDDOCUMENTROOT +sudo cp -R ${PORTAL_BUILD_DIRECTORY}/html/* ${LIGHTTPD_DOCUMENT_ROOT} # If this is an existing installation being upgraded restore the original XML data files. -if [ $PORTALINSTALLED = TRUE ] && [ $ADVANCED = FALSE ]; then - echo -e "\e[94m Restoring the backup copy of the file $LIGHTTPDDOCUMENTROOT/data/administrators.xml...\e[97m" - sudo mv $LIGHTTPDDOCUMENTROOT/data/administrators.backup.xml $LIGHTTPDDOCUMENTROOT/data/administrators.xml - echo -e "\e[94m Restoring the backup copy of the file $LIGHTTPDDOCUMENTROOT/data/blogPosts.xml...\e[97m" - sudo mv $LIGHTTPDDOCUMENTROOT/data/blogPosts.backup.xml $LIGHTTPDDOCUMENTROOT/data/blogPosts.xml - echo -e "\e[94m Restoring the backup copy of the file $LIGHTTPDDOCUMENTROOT/data/flightNotifications.xml...\e[97m" - sudo mv $LIGHTTPDDOCUMENTROOT/data/flightNotifications.backup.xml $LIGHTTPDDOCUMENTROOT/data/flightNotifications.xml - echo -e "\e[94m Restoring the backup copy of the file $LIGHTTPDDOCUMENTROOT/data/settings.xml...\e[97m" - sudo mv $LIGHTTPDDOCUMENTROOT/data/settings.backup.xml $LIGHTTPDDOCUMENTROOT/data/settings.xml +if [[ "${RECEIVER_PORTAL_INSTALLED}" = "true" ]] && [[ "${ADVANCED}" = "false" ]] ; then + echo -e "\e[94m Restoring the backup copy of the file ${LIGHTTPD_DOCUMENT_ROOT}/data/administrators.xml...\e[97m" + sudo mv ${LIGHTTPD_DOCUMENT_ROOT}/data/administrators.backup.xml ${LIGHTTPD_DOCUMENT_ROOT}/data/administrators.xml + echo -e "\e[94m Restoring the backup copy of the file ${LIGHTTPD_DOCUMENT_ROOT}/data/blogPosts.xml...\e[97m" + sudo mv ${LIGHTTPD_DOCUMENT_ROOT}/data/blogPosts.backup.xml ${LIGHTTPD_DOCUMENT_ROOT}/data/blogPosts.xml + echo -e "\e[94m Restoring the backup copy of the file ${LIGHTTPD_DOCUMENT_ROOT}/data/flightNotifications.xml...\e[97m" + sudo mv ${LIGHTTPD_DOCUMENT_ROOT}/data/flightNotifications.backup.xml ${LIGHTTPD_DOCUMENT_ROOT}/data/flightNotifications.xml + echo -e "\e[94m Restoring the backup copy of the file ${LIGHTTPD_DOCUMENT_ROOT}/data/settings.xml...\e[97m" + sudo mv ${LIGHTTPD_DOCUMENT_ROOT}/data/settings.backup.xml ${LIGHTTPD_DOCUMENT_ROOT}/data/settings.xml fi # Set the proper permissions on certain portal directories. -echo -e "\e[94m Making the directory $LIGHTTPDDOCUMENTROOT/graphs/ writable...\e[97m" -sudo chmod 777 $LIGHTTPDDOCUMENTROOT/graphs/ -echo -e "\e[94m Making the directory $LIGHTTPDDOCUMENTROOT/classes/ writable...\e[97m" -sudo chmod 777 $LIGHTTPDDOCUMENTROOT/classes/ -echo -e "\e[94m Making the directory $LIGHTTPDDOCUMENTROOT/data/ writable...\e[97m" -sudo chmod 777 $LIGHTTPDDOCUMENTROOT/data/ -echo -e "\e[94m Making the files contained within the directory $LIGHTTPDDOCUMENTROOT/data/ writable...\e[97m" -sudo chmod 666 $LIGHTTPDDOCUMENTROOT/data/* +echo -e "\e[94m Making the directory ${LIGHTTPD_DOCUMENT_ROOT}/graphs/ writable...\e[97m" +sudo chmod 777 ${LIGHTTPD_DOCUMENT_ROOT}/graphs/ +echo -e "\e[94m Making the directory ${LIGHTTPD_DOCUMENT_ROOT}/classes/ writable...\e[97m" +sudo chmod 777 ${LIGHTTPD_DOCUMENT_ROOT}/classes/ +echo -e "\e[94m Making the directory ${LIGHTTPD_DOCUMENT_ROOT}/data/ writable...\e[97m" +sudo chmod 777 ${LIGHTTPD_DOCUMENT_ROOT}/data/ +echo -e "\e[94m Making the files contained within the directory ${LIGHTTPD_DOCUMENT_ROOT}/data/ writable...\e[97m" +sudo chmod 666 ${LIGHTTPD_DOCUMENT_ROOT}/data/* # Check if dump978 was setup. echo -e "\e[94m Checking if dump978 was set up...\e[97m" -if ! grep -q "$BUILDDIRECTORY/dump978/dump978-maint.sh &" /etc/rc.local; then +if [[ `grep -cFx "${RECEIVER_BUILD_DIRECTORY}/dump978/dump978-maint.sh &" /etc/rc.local` -eq 0 ]] ; then # Check if a heywhatsthat.com range file exists in the dump1090 HTML folder. echo -e "\e[94m Checking for the file upintheair.json in the dump1090 HTML folder...\e[97m" - if [ -f /usr/share/dump1090-mutability/html/upintheair.json ] || [ -f /usr/share/dump1090-fa/html/upintheair.json ]; then + if [[ -f "/usr/share/dump1090-mutability/html/upintheair.json" ]] || [[ -f "/usr/share/dump1090-fa/html/upintheair.json" ]] ; then echo -e "\e[94m Copying the file upintheair.json from the dump1090 HTML folder to the dump978 HTML folder...\e[97m" - if [ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]; then - sudo cp /usr/share/dump1090-mutability/html/upintheair.json $LIGHTTPDDOCUMENTROOT/dump978/ + if [[ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then + sudo cp /usr/share/dump1090-mutability/html/upintheair.json ${LIGHTTPD_DOCUMENT_ROOT}/dump978/ fi - if [ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]; then - sudo cp /usr/share/dump1090-fa/html/upintheair.json $LIGHTTPDDOCUMENTROOT/dump978/ + if [[ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then + sudo cp /usr/share/dump1090-fa/html/upintheair.json ${LIGHTTPD_DOCUMENT_ROOT}/dump978/ fi fi fi -if [ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]; then +if [[ $(dpkg-query -W -f='${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then echo -e "\e[94m Removing conflicting redirects from the Lighttpd dump1090.conf file...\e[97m" # Remove this line completely. sudo sed -i "/$(echo ' "^/dump1090$" => "/dump1090/gmap.html"' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/&/\\\&/g')/d" /etc/lighttpd/conf-available/89-dump1090.conf @@ -377,11 +373,11 @@ fi # Add to the Lighttpd configuration. echo -e "\e[94m Adding the Lighttpd portal configuration file...\e[97m" -if [ -f /etc/lighttpd/conf-available/89-adsb-portal.conf ]; then +if [[ -f "/etc/lighttpd/conf-available/89-adsb-portal.conf" ]] ; then sudo rm -f /etc/lighttpd/conf-available/89-adsb-portal.conf fi sudo touch /etc/lighttpd/conf-available/89-adsb-portal.conf -if [ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]; then +if [[ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then sudo tee -a /etc/lighttpd/conf-available/89-adsb-portal.conf > /dev/null < /dev/null < /dev/null; then echo -e "\e[94m Reloading Lighttpd...\e[97m" - echo "" + echo -e "" sudo /etc/init.d/lighttpd force-reload else echo -e "\e[94m Starting Lighttpd...\e[97m" - echo "" + echo -e "" sudo /etc/init.d/lighttpd start fi ## SETUP THE MYSQL DATABASE -if [ $PORTALINSTALLED = FALSE ] && [ $ADVANCED = TRUE ] && [ $DATABASEENGINE = "MySQL" ] && [ $DATABASEEXISTS = FALSE ]; then +if [[ "${RECEIVER_PORTAL_INSTALLED}" = "false" ]] && [[ "${ADVANCED}" = "true" ]] && [[ "${DATABASEENGINE}" = "MySQL" ]] && [[ "${DATABASEEXISTS}" = "false" ]] ; then # Attempt to login with the supplied MySQL administrator credentials. echo -e "\e[94m Attempting to log into the MySQL server using the supplied administrator credentials...\e[97m" - while ! mysql -u$DATABASEADMINUSER -p$DATABASEADMINPASSWORD1 -h $DATABASEHOSTNAME -e ";" ; do + while ! mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD1} -h ${DATABASEHOSTNAME} -e ";" ; do echo -e "\e[94m Unable to log into the MySQL server using the supplied administrator credentials...\e[97m" - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Create Remote MySQL Database" --msgbox "The script was not able to log into the MySQL server using the administrator credentials you supplied. You will now be asked to reenter the MySQL server administrator credentials." 9 78 + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Create Remote MySQL Database" --msgbox "The script was not able to log into the MySQL server using the administrator credentials you supplied. You will now be asked to reenter the MySQL server administrator credentials." 9 78 DATABASEADMINPASSWORD1="" DATABASEADMINPASSWORD2="" DATABASEADMINUSER_TITLE="MySQL Administrator User" - while [ -z "$DATABASEADMINUSER" ]; do - DATABASEADMINUSER=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEADMINUSER_TITLE" --nocancel --inputbox "\nEnter the MySQL administrator user." 8 78 "$DATABASEADMINUSER" 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEADMINUSER}" ]] ; do + DATABASEADMINUSER=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEADMINUSER_TITLE}" --nocancel --inputbox "\nEnter the MySQL administrator user." 8 78 "${DATABASEADMINUSER}" 3>&1 1>&2 2>&3) DATABASEADMINUSER_TITLE="MySQL Administrator User (REQUIRED)" done DATABASEADMINPASSWORD1_TITLE="MySQL Administrator Password" DATABASEADMINPASSWORD1_MESSAGE="\nEnter the password for the MySQL adminitrator user." - while [ -z "$DATABASEADMINPASSWORD1" ]; do - DATABASEADMINPASSWORD1=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEADMINPASSWORD1_TITLE" --nocancel --passwordbox "$DATABASEADMINPASSWORD1_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEADMINPASSWORD1}" ]] ; do + DATABASEADMINPASSWORD1=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEADMINPASSWORD1_TITLE}" --nocancel --passwordbox "${DATABASEADMINPASSWORD1_MESSAGE}" 8 78 3>&1 1>&2 2>&3) DATABASEADMINPASSWORD1_TITLE="MySQL Administrator Password (REQUIRED)" done DATABASEADMINPASSWORD2_TITLE="Confirm The MySQL Administrator Password" DATABASEADMINPASSWORD2_MESSAGE="\nConfirm the password for the MySQL adminitrator user." - while [ -z "$DATABASEADMINPASSWORD2" ]; do - DATABASEADMINPASSWORD2=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEADMINPASSWORD2_TITLE" --nocancel --passwordbox "$DATABASEADMINPASSWORD2_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEADMINPASSWORD2}" ]] ; do + DATABASEADMINPASSWORD2=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEADMINPASSWORD2_TITLE}" --nocancel --passwordbox "${DATABASEADMINPASSWORD2_MESSAGE}" 8 78 3>&1 1>&2 2>&3) DATABASEADMINPASSWORD2_TITLE="Confirm The MySQL Administrator Password (REQUIRED)" done - while [ ! $DATABASEADMINPASSWORD1 = $DATABASEADMINPASSWORD2 ]; do + while [[ ! "${DATABASEADMINPASSWORD1}" = "${DATABASEADMINPASSWORD2}" ]] ; do DATABASEADMINPASSWORD1="" DATABASEADMINPASSWORD2="" - whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Passwords Did Not Match" --msgbox "Passwords did not match.\nPlease enter your password again." 9 78 + whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Passwords Did Not Match" --msgbox "Passwords did not match.\nPlease enter your password again." 9 78 DATABASEADMINPASSWORD1_TITLE="MySQL Administrator Password" - while [ -z "$DATABASEADMINPASSWORD1" ]; do - DATABASEADMINPASSWORD1=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEADMINPASSWORD1_TITLE" --nocancel --passwordbox "DATABASEADMINPASSWORD1_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEADMINPASSWORD1}" ]] ; do + DATABASEADMINPASSWORD1=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEADMINPASSWORD1_TITLE}" --nocancel --passwordbox "DATABASEADMINPASSWORD1_MESSAGE" 8 78 3>&1 1>&2 2>&3) DATABASEADMINPASSWORD1_TITLE="MySQL Administrator Password (REQUIRED)" done DATABASEADMINPASSWORD2_TITLE="Confirm The MySQL Administrator Password" - while [ -z "$DATABASEADMINPASSWORD2" ]; do - DATABASEADMINPASSWORD2=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "$DATABASEADMINPASSWORD2_TITLE" --nocancel --passwordbox "DATABASEADMINPASSWORD2_MESSAGE" 8 78 3>&1 1>&2 2>&3) + while [[ -z "${DATABASEADMINPASSWORD2}" ]] ; do + DATABASEADMINPASSWORD2=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "${DATABASEADMINPASSWORD2_TITLE}" --nocancel --passwordbox "DATABASEADMINPASSWORD2_MESSAGE" 8 78 3>&1 1>&2 2>&3) DATABASEADMINPASSWORD2_TITLE="Confirm The MySQL Administrator Password (REQUIRED)" done done @@ -478,36 +474,36 @@ if [ $PORTALINSTALLED = FALSE ] && [ $ADVANCED = TRUE ] && [ $DATABASEENGINE = " done # Create the database use and database using the information supplied by the user. - echo -e "\e[94m Creating the MySQL database \"$DATABASENAME\"...\e[97m" - mysql -u$DATABASEADMINUSER -p$DATABASEADMINPASSWORD1 -h $DATABASEHOSTNAME -e "CREATE DATABASE $DATABASENAME;" - echo -e "\e[94m Creating the MySQL user \"$DATABASEUSER\"...\e[97m" - mysql -u$DATABASEADMINUSER -p$DATABASEADMINPASSWORD1 -h $DATABASEHOSTNAME -e "CREATE USER '$DATABASEUSER'@'localhost' IDENTIFIED BY \"$DATABASEPASSWORD1\";" - echo -e "\e[94m Granting priviledges on the MySQL database \"DATABASENAME\" to the user \"$DATABASEUSER\"...\e[97m" - mysql -u$DATABASEADMINUSER -p$DATABASEADMINPASSWORD1 -h $DATABASEHOSTNAME -e "GRANT ALL PRIVILEGES ON $DATABASENAME.* TO '$DATABASEUSER'@'localhost';" + echo -e "\e[94m Creating the MySQL database \"${DATABASENAME}\"...\e[97m" + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD1} -h ${DATABASEHOSTNAME} -e "CREATE DATABASE ${DATABASENAME};" + echo -e "\e[94m Creating the MySQL user \"${DATABASEUSER}\"...\e[97m" + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD1} -h ${DATABASEHOSTNAME} -e "CREATE USER '${DATABASEUSER}'@'localhost' IDENTIFIED BY \"${DATABASEPASSWORD1}\";" + echo -e "\e[94m Granting priviledges on the MySQL database \"DATABASENAME\" to the user \"${DATABASEUSER}\"...\e[97m" + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD1} -h ${DATABASEHOSTNAME} -e "GRANT ALL PRIVILEGES ON ${DATABASENAME}.* TO '${DATABASEUSER}'@'localhost';" echo -e "\e[94m Flushing priviledges on the MySQL database server...\e[97m" - mysql -u$DATABASEADMINUSER -p$DATABASEADMINPASSWORD1 -h $DATABASEHOSTNAME -e "FLUSH PRIVILEGES;" + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD1} -h ${DATABASEHOSTNAME} -e "FLUSH PRIVILEGES;" fi ## SETUP THE PERFORMANCE GRAPHS USING THE SCRIPT GRAPHS.SH -chmod +x $BASHDIRECTORY/portal/graphs.sh -$BASHDIRECTORY/portal/graphs.sh -if [ $? -ne 0 ]; then - echo "" +chmod +x ${RECEIVER_BASH_DIRECTORY}/portal/graphs.sh +${RECEIVER_BASH_DIRECTORY}/portal/graphs.sh +if [[ $? -ne 0 ]] ; then + echo -e "" echo -e "\e[91m THE SCRIPT GRAPHS.SH ENCOUNTERED AN ERROR" - echo "" + echo -e "" exit 1 fi ## SETUP COMMON PORTAL FEATURES # Export variables needed by logging.sh. -if [ "$DATABASEENGINE" = "MySQL" ] || [ "$DATABASEENGINE" = "SQLite" ]; then - export ADSB_DATABASEENGINE=$DATABASEENGINE - export ADSB_DATABASEHOSTNAME=$DATABASEHOSTNAME - export ADSB_DATABASEUSER=$DATABASEUSER - export ADSB_DATABASEPASSWORD1=$DATABASEPASSWORD1 - export ADSB_DATABASENAME=$DATABASENAME +if [[ "${DATABASEENGINE}" = "MySQL" ]] || [[ "${DATABASEENGINE}" = "SQLite" ]] ; then + export ADSB_DATABASEENGINE=${DATABASEENGINE} + export ADSB_DATABASEHOSTNAME=${DATABASEHOSTNAME} + export ADSB_DATABASEUSER=${DATABASEUSER} + export ADSB_DATABASEPASSWORD1=${DATABASEPASSWORD1} + export ADSB_DATABASENAME=${DATABASENAME} else export ADSB_DATABASEENGINE="xml" export ADSB_DATABASEHOSTNAME="" @@ -517,29 +513,29 @@ else fi # Execute the core setup script. -chmod +x $BASHDIRECTORY/portal/core.sh -$BASHDIRECTORY/portal/core.sh -if [ $? -ne 0 ]; then - echo "" +chmod +x ${RECEIVER_BASH_DIRECTORY}/portal/core.sh +${RECEIVER_BASH_DIRECTORY}/portal/core.sh +if [[ $? -ne 0 ]] ; then + echo -e "" echo -e " \e[91m THE SCRIPT CORE.SH ENCOUNTERED AN ERROR" - echo "" + echo -e "" exit 1 fi ## SETUP ADVANCED PORTAL FEATURES -if [ $ADVANCED = TRUE ]; then +if [[ "${ADVANCED}" = "true" ]] ; then # If SQLite is being used and the path is not already set to the variable $DATABASENAME set it to the default path. - if [ $DATABASEENGINE = "SQLite" ] && [ -z "$DATABASENAME" ]; then - $DATABASENAME="$LIGHTTPDDOCUMENTROOT/data/portal.sqlite" + if [[ "${DATABASEENGINE}" = "SQLite" ]] && [[ -z "${DATABASENAME}" ]] ; then + DATABASENAME="${LIGHTTPD_DOCUMENT_ROOT}/data/portal.sqlite" fi - chmod +x $BASHDIRECTORY/portal/logging.sh - $BASHDIRECTORY/portal/logging.sh - if [ $? -ne 0 ]; then - echo "" + chmod +x ${RECEIVER_BASH_DIRECTORY}/portal/logging.sh + ${RECEIVER_BASH_DIRECTORY}/portal/logging.sh + if [[ $? -ne 0 ]] ; then + echo -e "" echo -e " \e[91m THE SCRIPT LOGGING.SH ENCOUNTERED AN ERROR" - echo "" + echo -e "" exit 1 fi fi @@ -557,16 +553,20 @@ unset ADSB_DATABASENAME IPADDRESS=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'` # Display final portal setup instructions to the user. -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "ADS-B Receiver Project Portal Setup" --msgbox "NOTE THAT PORTAL SETUP IS NOT YET COMPLETE!\n\nIn order to complete the portal setup process visit the following URL in your favorite web browser.\n\nhttp://${IPADDRESS}/install/\n\nFollow the instructions and enter the requested information to complete the ADS-B Receiver Project Portal setup." 12 78 +whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "ADS-B Receiver Project Portal Setup" --msgbox "NOTE THAT PORTAL SETUP IS NOT YET COMPLETE!\n\nIn order to complete the portal setup process visit the following URL in your favorite web browser.\n\nhttp://${IPADDRESS}/install/\n\nFollow the instructions and enter the requested information to complete the ADS-B Receiver Project Portal setup." 12 78 -# Enter into the project root directory. +### SETUP COMPLETE + +# Return to the project root directory. echo -e "\e[94m Entering the ADS-B Receiver Project root directory...\e[97m" -cd $PROJECTROOTDIRECTORY +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 -echo "" -echo -e "\e[93m-------------------------------------------------------------------------------------------------------" +echo -e "" +echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m ADS-B Receiver Project Portal setup is complete.\e[39m" -echo "" -read -p "Press enter to continue..." CONTINUE +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi exit 0 diff --git a/bash/portal/logging.sh b/bash/portal/logging.sh index b5d54fc..3e280c8 100755 --- a/bash/portal/logging.sh +++ b/bash/portal/logging.sh @@ -33,85 +33,85 @@ ## VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" -PORTALBUILDDIRECTORY="$BUILDDIRECTORY/portal" -PORTALPYTHONDIRECTORY="$PORTALBUILDDIRECTORY/python" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" +PORTAL_BUILD_DIRECTORY="${RECEIVER_BUILD_DIRECTORY}/portal" +PORTAL_PYTHON_DIRECTORY="${PORTAL_BUILD_DIRECTORY}/python" PYTHONPATH=`which python` ## SETUP FLIGHT LOGGING -echo "" +echo -e "" echo -e "\e[95m Setting up flight logging...\e[97m" -echo "" +echo -e "" # Create and set permissions on the flight logging and maintenance maintenance scripts. echo -e "\e[94m Creating the flight logging maintenance script...\e[97m" -tee $PORTALPYTHONDIRECTORY/flights-maint.sh > /dev/null < /dev/null < /dev/null < /dev/null <0)) && sudo sed -i "${LINENUMBER[$((${#LINENUMBER[@]}-1))]}i $PORTALPYTHONDIRECTORY/flights-maint.sh &\n" /etc/rc.local + ((LINENUMBER>0)) && sudo sed -i "${LINENUMBER[$((${#LINENUMBER[@]}-1))]}i ${PORTAL_PYTHON_DIRECTORY}/flights-maint.sh &\n" /etc/rc.local fi # Remove old maintenance-maint.sh start up line from /etc/rc.local. sudo sed -i '/build\/portal\/logging\/maintenance-maint.sh/d' /etc/rc.local # Add maintenance maintenance script to rc.local. -if ! grep -Fxq "$PORTALPYTHONDIRECTORY/maintenance-maint.sh &" /etc/rc.local; then +if [[ `grep -cFx "${PORTAL_PYTHON_DIRECTORY}/maintenance-maint.sh &" /etc/rc.local` -eq 0 ]] ; then echo -e "\e[94m Adding the maintenance maintenance script startup line to /etc/rc.local...\e[97m" LINENUMBER=($(sed -n '/exit 0/=' /etc/rc.local)) - ((LINENUMBER>0)) && sudo sed -i "${LINENUMBER[$((${#LINENUMBER[@]}-1))]}i $PORTALPYTHONDIRECTORY/maintenance-maint.sh &\n" /etc/rc.local + ((LINENUMBER>0)) && sudo sed -i "${LINENUMBER[$((${#LINENUMBER[@]}-1))]}i ${PORTAL_PYTHON_DIRECTORY}/maintenance-maint.sh &\n" /etc/rc.local fi # Kill any previously running maintenance scripts. echo -e "\e[94m Checking for any running flights-maint.sh processes...\e[97m" PIDS=`ps -efww | grep -w "flights-maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'` -if [ ! -z "$PIDS" ]; then +if [[ -n "${PIDS}" ]] ; then echo -e "\e[94m Killing any running flights-maint.sh processes...\e[97m" - sudo kill $PIDS - sudo kill -9 $PIDS + sudo kill ${PIDS} + sudo kill -9 ${PIDS} fi PIDS=`ps -efww | grep -w "maintenance-maint.sh" | awk -vpid=$$ '$2 != pid { print $2 }'` -if [ ! -z "$PIDS" ]; then +if [[ -n "${PIDS}" ]] ; then echo -e "\e[94m Killing any running maintenance-maint.sh processes...\e[97m" - sudo kill $PIDS - sudo kill -9 $PIDS + sudo kill ${PIDS} + sudo kill -9 ${PIDS} fi # Start flight logging. echo -e "\e[94m Executing the flight logging maintenance script...\e[97m" -nohup $PORTALPYTHONDIRECTORY/flights-maint.sh > /dev/null 2>&1 & +nohup ${PORTAL_PYTHON_DIRECTORY}/flights-maint.sh > /dev/null 2>&1 & # Start maintenance. echo -e "\e[94m Executing the maintenance maintenance script...\e[97m" -nohup $PORTALPYTHONDIRECTORY/maintenance-maint.sh > /dev/null 2>&1 & +nohup ${PORTAL_PYTHON_DIRECTORY}/maintenance-maint.sh > /dev/null 2>&1 & exit 0 diff --git a/bash/tools/image_setup.sh b/bash/tools/image_setup.sh index 688f045..da9c0f9 100755 --- a/bash/tools/image_setup.sh +++ b/bash/tools/image_setup.sh @@ -4,15 +4,11 @@ # ADS-B RECEIVER # ##################################################################################### # # -# A set of scripts created to automate the process of installing the software # -# needed to setup a Mode S decoder as well as feeders which are capable of # -# sharing your ADS-B results with many of the most popular ADS-B aggregate sites. # -# # -# Project Hosted On GitHub: https://github.com/jprochazka/adsb-feeder # +# This script is meant only to create offical Raspbian releases for this project. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# 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 # @@ -50,31 +46,31 @@ clear ## VARIABLES -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" +RECEIVER_ROOT_DIRECTORY="${PWD}" +RECEIVER_BASH_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/bash" +RECEIVER_BUILD_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/build" ## INCLUDE EXTERNAL SCRIPTS -source $BASHDIRECTORY/variables.sh -source $BASHDIRECTORY/functions.sh +source ${RECEIVER_BASH_DIRECTORY}/variables.sh +source ${RECEIVER_BASH_DIRECTORY}/functions.sh -echo "" +echo -e "" echo -e "\e[91m The ADS-B Receiver Project Image Preparation Script\e[97m" -echo "" +echo -e "" ## UPDATE REPOSITORY LISTS AND OPERATING SYSTEM echo -e "\e[95m Updating repository lists and operating system...\e[97m" -echo "" +echo -e "" sudo apt-get update sudo apt-get -y dist-upgrade ## INSTALL DUMP1090 -echo "" +echo -e "" echo -e "\e[95m Installing prerequisite packages...\e[97m" -echo "" +echo -e "" CheckPackage git CheckPackage curl CheckPackage build-essential @@ -88,32 +84,32 @@ CheckPackage lighttpd CheckPackage fakeroot # Ask which version of dump1090 to install. -DUMP1090OPTION=$(whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Choose Dump1090 Version" --menu "Which version of dump1090 is to be installed?" 12 65 2 "dump1090-mutability" "(Mutability)" "dump1090-fa" "(FlightAware)" 3>&1 1>&2 2>&3) +DUMP1090OPTION=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" --title "Choose Dump1090 Version" --menu "Which version of dump1090 is to be installed?" 12 65 2 "dump1090-mutability" "(Mutability)" "dump1090-fa" "(FlightAware)" 3>&1 1>&2 2>&3) -case $DUMP1090OPTION in +case ${DUMP1090OPTION} in "dump1090-mutability") echo -e "\e[95m Installing dump1090-mutability...\e[97m" - echo "" + echo -e "" # Dump1090-mutability - echo "" + echo -e "" echo -e "\e[95m Installing dump1090-mutability...\e[97m" - echo "" - mkdir -p $BUILDDIRECTORY/dump1090-mutability - cd $BUILDDIRECTORY/dump1090-mutability + echo -e "" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY}/dump1090-mutability + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090-mutability 2>&1 git clone https://github.com/mutability/dump1090.git - cd $BUILDDIRECTORY/dump1090-mutability/dump1090 + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090-mutability/dump1090 2>&1 dpkg-buildpackage -b - cd $BUILDDIRECTORY/dump1090-mutability + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090-mutability 2>&1 sudo dpkg -i dump1090-mutability_1.15~dev_*.deb ;; "dump1090-fa") echo -e "\e[95m Installing dump1090-fa and PiAware...\e[97m" - echo "" + echo -e "" # Install prerequisite packages. echo -e "\e[95m Installing additional dump1090-fa and PiAware prerequisite packages...\e[97m" - echo "" + echo -e "" CheckPackage tcl8.6-dev CheckPackage autoconf CheckPackage python3-dev @@ -127,25 +123,25 @@ case $DUMP1090OPTION in CheckPackage itcl3 # Dump1090-fa - echo "" + echo -e "" echo -e "\e[95m Installing dump1090-fa...\e[97m" - echo "" - mkdir -p $BUILDDIRECTORY/dump1090-fa - cd $BUILDDIRECTORY/dump1090-fa + echo -e "" + mkdir -vp ${RECEIVER_BUILD_DIRECTORY}/dump1090-fa + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090-fa 2>&1 git clone https://github.com/flightaware/dump1090.git - cd $BUILDDIRECTORY/dump1090-fa/dump1090 + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090-fa/dump1090 2>&1 dpkg-buildpackage -b - cd $BUILDDIRECTORY/dump1090-fa + cd ${RECEIVER_BUILD_DIRECTORY}/dump1090-fa 2>&1 sudo dpkg -i dump1090-fa_*.deb # PiAware - cd $BUILDDIRECTORY + cd ${RECEIVER_BUILD_DIRECTORY} 2>&1 git clone https://github.com/flightaware/piaware_builder.git - cd $BUILDDIRECTORY/piaware_builder + cd ${RECEIVER_BUILD_DIRECTORY}/piaware_builder 2>&1 ./sensible-build.sh jessie - cd $BUILDDIRECTORY/piaware_builder/package-jessie + cd ${RECEIVER_BUILD_DIRECTORY}/piaware_builder/package-jessie 2>&1 dpkg-buildpackage -b - sudo dpkg -i $BUILDDIRECTORY/piaware_builder/piaware_*.deb + sudo dpkg -i ${RECEIVER_BUILD_DIRECTORY}/piaware_builder/piaware_*.deb ;; *) # Nothing selected. @@ -155,9 +151,9 @@ esac ## INSTALL THE BASE PORTAL PREREQUISITES PACKAGES -echo "" +echo -e "" echo -e "\e[95m Installing packages needed by the ADS-B Receiver Project Web Portal...\e[97m" -echo "" +echo -e "" CheckPackage lighttpd CheckPackage collectd-core CheckPackage rrdtool @@ -167,9 +163,9 @@ CheckPackage php5-json ## SET LOCALE -echo "" +echo -e "" echo -e "\e[95m Setting the locale to en_US.UTF-8...\e[97m" -echo "" +echo -e "" sudo su -c "sed --regexp-extended --expression=' 1 { @@ -206,7 +202,7 @@ sudo update-locale LC_IDENTIFICATION='en_US.UTF-8' ## CHANGE THE KEYBOARD LAYOUT -echo "" +echo -e "" echo -e "\e[95m Changing the default keyboard layout to US/PC105...\e[97m" ChangeConfig "XKBMODEL" "pc105" "/etc/default/keyboard" ChangeConfig "XKBLAYOUT" "us" "/etc/default/keyboard" @@ -233,16 +229,16 @@ echo "pi:adsbreceiver" | sudo chpasswd ## CLEAN UP THE SYSTEM TO MAKE THE IMAGE SMALLER echo -e "\e[95m Removing packages which are no longer needed...\e[97m" -echo "" +echo -e "" sudo apt-get -y clean sudo apt-get -y autoclean sudo apt-get -y autoremove -echo "" +echo -e "" ## TOUCH THE IMAGE FILE echo -e "\e[95m Touching the \"image\" file...\e[97m" -cd $PROJECTROOTDIRECTORY +cd ${RECEIVER_ROOT_DIRECTORY} 2>&1 touch image ## CLEAR BASH HISTORY @@ -251,10 +247,10 @@ history -c && history -w ## DONE -echo "" +echo -e "" echo -e "\e[91m Image preparation completed.)\e[39m" echo -e "\e[91m Device will be shut down in 5 seconds.\e[39m" -echo "" +echo -e "" sleep 5 sudo halt diff --git a/bash/tools/portal_backup.sh b/bash/tools/portal_backup.sh index a89a930..009e57d 100644 --- a/bash/tools/portal_backup.sh +++ b/bash/tools/portal_backup.sh @@ -4,15 +4,14 @@ # ADS-B RECEIVER # ##################################################################################### # # -# A set of scripts created to automate the process of installing the software # -# needed to setup a Mode S decoder as well as feeders which are capable of # -# sharing your ADS-B results with many of the most popular ADS-B aggregate sites. # -# # -# Project Hosted On GitHub: https://github.com/jprochazka/adsb-feeder # +# This script was created to allow users to backup their portal data. At this # +# time this script has not been integrated into the current collection of # +# scripts. However this script, possibly in a modified form, will be integrated # +# for simplified use by those who set up their receivers using this project. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# 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 # @@ -37,103 +36,103 @@ ## VARIABLES BACKUPDATE=$(date +"%Y-%m-%d-%H%M%S") -PROJECTROOTDIRECTORY="$PWD" -BACKUPSDIRECTORY="$PROJECTROOTDIRECTORY/backups" -TEMPORARYDIRECTORY="$PROJECTROOTDIRECTORY/backup_$BACKUPDATE" +RECEIVER_ROOT_DIRECTORY="${PWD}" +BACKUPSDIRECTORY="${RECEIVER_ROOT_DIRECTORY}/backups" +TEMPORARY_DIRECTORY="${RECEIVER_ROOT_DIRECTORY}/backup_${BACKUPDATE}" RAWDOCUMENTROOT=`/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -p | grep server.document-root` -LIGHTTPDDOCUMENTROOT=`sed 's/.*"\(.*\)"[^"]*$/\1/' <<< $RAWDOCUMENTROOT` +LIGHTTPDDOCUMENTROOT=`sed 's/.*"\(.*\)"[^"]*$/\1/' <<< ${RAWDOCUMENTROOT}` ## BEGIN THE BACKUP PROCESS clear -echo -e "\n\e[91m ADSB Reciever Project Maintenance" -echo "" +echo -e "\n\e[91m ADSB Receiver Project Maintenance" +echo -e "" echo -e "\e[92m Backing up portal data..." -echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[97m" +echo -e "\e[93m ------------------------------------------------------------------------------\e[97m" -echo "" +echo -e "" echo -e "\e[95m Backing up current portal data...\e[97m" -echo "" +echo -e "" ## PREPARE TO BEGIN CREATING BACKUPS # Get the database type used. echo -e "\e[94m Declare the database engine being used...\e[97m" -DATABASEENGINE=`grep 'db_driver' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2` +DATABASEENGINE=`grep 'db_driver' ${LIGHTTPDDOCUMENTROOT}/classes/settings.class.php | tail -n1 | cut -d\' -f2` echo -e "\e[94m Declare whether or not the advnaced portal features were installed...\e[97m" # Decide if the advanced portal features were installed or not. echo -e "\e[94m Declare whether or not the advnaced portal features were installed...\e[97m" -if [ $DATABASEENGINE = "xml" ]; then +if [[ "${DATABASEENGINE}" = "xml" ]] ; then ADVANCED=FALSE else ADVANCED=TRUE fi # Get the path to the SQLite database if SQLite is used for the database. -if [ $DATABASEENGINE = "sqlite" ]; then - DATABASEPATH=`grep 'db_host' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2` +if [[ "${DATABASEENGINE}" = "sqlite" ]] ; then + DATABASEPATH=`grep 'db_host' ${LIGHTTPDDOCUMENTROOT}/classes/settings.class.php | tail -n1 | cut -d\' -f2` fi # Assign the MySQL login credentials to variables if a MySQL database is being used. -if [ $DATABASEENGINE = "mysql" ]; then - MYSQLDATABASE=`grep 'db_database' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2` - MYSQLUSERNAME=`grep 'db_username' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2` - MYSQLPASSWORD=`grep 'db_password' $LIGHTTPDDOCUMENTROOT/classes/settings.class.php | tail -n1 | cut -d\' -f2` +if [[ "${DATABASEENGINE}" = "mysql" ]] ; then + MYSQLDATABASE=`grep 'db_database' ${LIGHTTPDDOCUMENTROOT}/classes/settings.class.php | tail -n1 | cut -d\' -f2` + MYSQLUSERNAME=`grep 'db_username' ${LIGHTTPDDOCUMENTROOT}/classes/settings.class.php | tail -n1 | cut -d\' -f2` + MYSQLPASSWORD=`grep 'db_password' ${LIGHTTPDDOCUMENTROOT}/classes/settings.class.php | tail -n1 | cut -d\' -f2` fi # Check that the backup directory exists. -echo -e "\e[94m Checking that the directory $BACKUPSDIRECTORY exists...\e[97m" -if [ ! -d "$BACKUPSDIRECTORY" ]; then +echo -e "\e[94m Checking that the directory ${BACKUPSDIRECTORY} exists...\e[97m" +if [[ ! -d "${BACKUPSDIRECTORY}" ]] ; then # Create the backups directory. - echo -e "\e[94m Creating the directory $BACKUPSDIRECTORY...\e[97m" - mkdir -p $BACKUPSDIRECTORY + echo -e "\e[94m Creating the directory ${BACKUPSDIRECTORY}...\e[97m" + mkdir -vp ${BACKUPSDIRECTORY} fi # Check that the temporary directory exists. -echo -e "\e[94m Checking that the directory $TEMPORARYDIRECTORY exists...\e[97m" -if [ ! -d "$TEMPORARYDIRECTORY" ]; then +echo -e "\e[94m Checking that the directory ${TEMPORARY_DIRECTORY} exists...\e[97m" +if [[ ! -d "${TEMPORARY_DIRECTORY}" ]] ; then # Create the tmp directory. - echo -e "\e[94m Creating the directory $TEMPORARYDIRECTORY...\e[97m" - mkdir -p $TEMPORARYDIRECTORY + echo -e "\e[94m Creating the directory ${TEMPORARY_DIRECTORY}...\e[97m" + mkdir -vp ${TEMPORARY_DIRECTORY} fi ## BACKUP THE FILES COMMON TO ALL PORTAL INSTALLATION SCENARIOS # Copy the collectd round robin database files to the temporary directory. -echo -e "\e[94m Checking that the directory $TEMPORARYDIRECTORY/var/lib/collectd/rrd/ exists...\e[97m" -if [ ! -d "$TEMPORARYDIRECTORY/var/lib/collectd/rrd/" ]; then - mkdir -p $TEMPORARYDIRECTORY/var/lib/collectd/rrd/ +echo -e "\e[94m Checking that the directory ${TEMPORARY_DIRECTORY}/var/lib/collectd/rrd/ exists...\e[97m" +if [[ ! -d "${TEMPORARY_DIRECTORY}/var/lib/collectd/rrd/" ]] ; then + mkdir -vp ${TEMPORARY_DIRECTORY}/var/lib/collectd/rrd/ fi echo -e "\e[94m Backing up the directory /var/lib/collectd/rrd/...\e[97m" -sudo cp -R /var/lib/collectd/rrd/ $TEMPORARYDIRECTORY/var/lib/collectd/rrd/ +sudo cp -R /var/lib/collectd/rrd/ ${TEMPORARY_DIRECTORY}/var/lib/collectd/rrd/ ## BACKUP PORTAL USING LITE FEATURES AND XML FILES -if [ ADVANCED = "FALSE" ]; then +if [[ "${ADVANCED}" = "FALSE" ]] ; then # Copy the portal XML data files to the temporary directory. - echo -e "\e[94m Checking that the directory $TEMPORARYDIRECTORY/var/www/html/data/ exists...\e[97m" - if [ ! -d "$TEMPORARYDIRECTORY/var/www/html/data/" ]; then - mkdir -p $TEMPORARYDIRECTORY/var/www/html/data/ + echo -e "\e[94m Checking that the directory ${TEMPORARY_DIRECTORY}/var/www/html/data/ exists...\e[97m" + if [[ ! -d "${TEMPORARY_DIRECTORY}/var/www/html/data/" ]] ; then + mkdir -vp ${TEMPORARY_DIRECTORY}/var/www/html/data/ fi - echo -e "\e[94m Backing up all XML data files to $TEMPORARYDIRECTORY/var/www/html/data/...\e[97m" - sudo cp -R /var/www/html/data/*.xml $TEMPORARYDIRECTORY/var/www/html/data/ + echo -e "\e[94m Backing up all XML data files to ${TEMPORARY_DIRECTORY}/var/www/html/data/...\e[97m" + sudo cp -R /var/www/html/data/*.xml ${TEMPORARY_DIRECTORY}/var/www/html/data/ else ## BACKUP PORTAL USING ADVANCED FEATURES AND A SQLITE DATABASE - if [ $DATABASEENGINE = "sqlite" ]; then + if [[ "${DATABASEENGINE}" = "sqlite" ]] ; then # Copy the portal SQLite database file to the temporary directory. - echo -e "\e[94m Backing up the SQLite database file to $TEMPORARYDIRECTORY/var/www/html/data/portal.sqlite...\e[97m" - sudo cp -R $DATABASEPATH $TEMPORARYDIRECTORY/var/www/html/data/portal.sqlite + echo -e "\e[94m Backing up the SQLite database file to ${TEMPORARY_DIRECTORY}/var/www/html/data/portal.sqlite...\e[97m" + sudo cp -R ${DATABASEPATH} ${TEMPORARY_DIRECTORY}/var/www/html/data/portal.sqlite fi ## BACKUP PORTAL USING ADVANCED FEATURES AND A MYSQL DATABASE - if [ $DATABASEENGINE = "mysql" ]; then + if [[ "${DATABASEENGINE}" = "mysql" ]] ; then # Dump the current MySQL database to a .sql text file. - echo -e "\e[94m Dumping the MySQL database $MYSQLDATABASE to the file $TEMPORARYDIRECTORY/$MYSQLDATABASE.sql...\e[97m" - mysqldump -u$MYSQLUSERNAME -p$MYSQLPASSWORD $MYSQLDATABASE > $TEMPORARYDIRECTORY/$MYSQLDATABASE.sql + echo -e "\e[94m Dumping the MySQL database ${MYSQLDATABASE} to the file ${TEMPORARY_DIRECTORY}/${MYSQLDATABASE}.sql...\e[97m" + mysqldump -u${MYSQLUSERNAME} -p${MYSQLPASSWORD} ${MYSQLDATABASE} > ${TEMPORARY_DIRECTORY}/${MYSQLDATABASE}.sql fi fi @@ -141,26 +140,28 @@ fi # Create the backup archive. echo -e "\e[94m Compressing the backed up files...\e[97m" -echo "" -tar -zcvf $BACKUPSDIRECTORY/adsb-receiver_data_$BACKUPDATE.tar.gz $TEMPORARYDIRECTORY -echo "" +echo -e "" +tar -zcvf ${BACKUPSDIRECTORY}/adsb-receiver_data_${BACKUPDATE}.tar.gz ${TEMPORARY_DIRECTORY} +echo -e "" # Remove the temporary directory. echo -e "\e[94m Removing the temporary backup directory...\e[97m" -sudo rm -rf $TEMPORARYDIRECTORY +sudo rm -rf ${TEMPORARY_DIRECTORY} ## BACKUP PROCESS COMPLETE echo -e "\e[32m" echo -e " BACKUP PROCESS COMPLETE\e[93m" -echo "" +echo -e "" echo -e " An archive containing the data just backed up can be found at:" -echo -e " $TEMPORARYDIRECTORY/adsb-receiver_data_$BACKUPDATE.tar.gz\e[97m" -echo "" +echo -e " ${TEMPORARY_DIRECTORY}/adsb-receiver_data_${BACKUPDATE}.tar.gz\e[97m" +echo -e "" -echo -e "\e[93m----------------------------------------------------------------------------------------------------" +echo -e "\e[93m ------------------------------------------------------------------------------" echo -e "\e[92m Finished backing up portal data.\e[39m" -echo "" -read -p "Press enter to exit..." CONTINUE +echo -e "" +if [[ "${RECEIVER_AUTOMATED_INSTALL}" = "false" ]] ; then + read -p "Press enter to continue..." CONTINUE +fi exit 0 diff --git a/bash/variables.sh b/bash/variables.sh index 0b8fd9a..71ab724 100644 --- a/bash/variables.sh +++ b/bash/variables.sh @@ -9,7 +9,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Copyright (c) 2015 Joseph A. Prochazka # +# Copyright (c) 2015-2017, 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 # @@ -34,21 +34,25 @@ ## SOFTWARE VERSIONS # The ADS-B Receiver Project -PROJECTVERSION="2.6.0" +PROJECT_VERSION="2.6.0" + +# RTL-SDR OGN +RTLSDROGN_VERSION="0.2.5" # FlightAware PiAware -PIAWAREVERSION="3.5.1" +PIAWARE_VERSION="3.5.1" -# PlaneFinder ADS-B Client -PFCLIENTVERSIONARM="3.7.20" -PFCLIENTVERSIONI386="3.7.1" +# PlaneFinder Client +PLANEFINDER_CLIENT_VERSION_ARM="3.7.20" +PLANEFINDER_CLIENT_VERSION_I386="3.7.1" -# Flightradar24 Linux Debian package -FR24CLIENTVERSIONI386="1.0.18-5" +# Flightradar24 Client +FLIGHTRADAR24_CLIENT_VERSION_ARM="1.0.18-7" +FLIGHTRADAR24_CLIENT_VERSION_I386="1.0.18-5" # mlat-client -MLATCLIENTVERSION="0.2.6" -MLATCLIENTTAG="v0.2.6" +MLAT_CLIENT_VERSION="0.2.9" +MLAT_CLIENT_TAG="v0.2.9" # PhantomJS -PHANTOMJSVERSION="2.1.1" +PHANTOMJS_VERSION="2.1.1" diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..7a7f2dd --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,15 @@ +# exclude build directories +AboveTustin/ +adsbexchange/ +acarsdec/ +dump1090* +gps/ +hab/ +mlat-client/ +mlat-client* +ogn/ +phantomjs* +piaware_builder/ +planefinder/ +portal/graphs/dump1090.pyc +portal/logging/ diff --git a/build/portal/graphs/dump1090.db b/build/portal/graphs/dump1090.db index 1e933ad..e3617bf 100644 --- a/build/portal/graphs/dump1090.db +++ b/build/portal/graphs/dump1090.db @@ -2,6 +2,6 @@ dump1090_messages value:DERIVE:0:8000 dump1090_cpu value:DERIVE:0:1200 dump1090_dbfs value:GAUGE:U:0 dump1090_aircraft total:GAUGE:0:500, positions:GAUGE:0:500 -dump1090_range value:GAUGE:0:500000 +dump1090_range value:GAUGE:0:1000000 dump1090_tracks value:DERIVE:0:500 dump1090_mlat value:GAUGE:0:500 diff --git a/build/portal/html/admin/index.php b/build/portal/html/admin/index.php index 119827e..5581edb 100644 --- a/build/portal/html/admin/index.php +++ b/build/portal/html/admin/index.php @@ -296,7 +296,7 @@
  • Notifications
  • Navigation
  • -
  • Measurements
  • +
  • Measurements
  • System
  • Maintenance
  • @@ -496,7 +496,7 @@ -
    +
    Unit of Measurement (Range)
    diff --git a/build/portal/html/classes/common.class.php b/build/portal/html/classes/common.class.php index fc77e36..38437e1 100644 --- a/build/portal/html/classes/common.class.php +++ b/build/portal/html/classes/common.class.php @@ -294,7 +294,7 @@ } // Get the size of the database. - function getDatabaseSize($measurment = "") { + function getDatabaseSize($measurement = "") { require_once($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."classes".DIRECTORY_SEPARATOR."settings.class.php"); $settings = new settings(); @@ -311,7 +311,7 @@ } else { $databaseSize = 0; } - switch ($measurment) { + switch ($measurement) { case "kb": return round($databaseSize / 1024, 2); break; diff --git a/build/portal/html/flights.php b/build/portal/html/flights.php index 3068fc8..d534317 100644 --- a/build/portal/html/flights.php +++ b/build/portal/html/flights.php @@ -95,7 +95,13 @@ $pageData['flights'] = $flights; // Calculate the number of pagination links to show. - $pageData['pageLinks'] = ceil($totalFlights / $itemsPerPage); + $pageData['pageLinks'] = ceil($totalFlights / $itemsPerPage - 1); + + // Pass the current page number being viewed to the template. + $pageData['pageNumber'] = 1; + if (isset($_GET['page'])) { + $pageData['pageNumber'] = $_GET['page']; + } $template->display($pageData); ?> diff --git a/build/portal/html/templates/default/flights.tpl b/build/portal/html/templates/default/flights.tpl index a282547..b43dae0 100644 --- a/build/portal/html/templates/default/flights.tpl +++ b/build/portal/html/templates/default/flights.tpl @@ -43,12 +43,29 @@ {/foreach} -
      - {for pageNumber eq 1 to page:pageLinks} -
    • {pageNumber}
    • - {/for} -
    +
    {/area} -{area:scripts/} - +{area:scripts} + + +{/area} diff --git a/build/portal/python/maintenance.py b/build/portal/python/maintenance.py index 678769d..8218b5c 100644 --- a/build/portal/python/maintenance.py +++ b/build/portal/python/maintenance.py @@ -32,7 +32,7 @@ import json import os import datetime -while True: +while true: ## Read the configuration file. with open(os.path.dirname(os.path.realpath(__file__)) + '/config.json') as config_file: diff --git a/example.config b/example.config new file mode 100644 index 0000000..1fe4b04 --- /dev/null +++ b/example.config @@ -0,0 +1,438 @@ +#!/bin/bash + +##################################################################################### +# ADS-B RECEIVER # +##################################################################################### +# # +# This script is not meant to be executed directly. # +# Instead execute install.sh to begin the installation process. # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # +# 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 # +# in the Software without restriction, including without limitation the rights # +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # +# copies of the Software, and to permit persons to whom the Software is # +# furnished to do so, subject to the following conditions: # +# # +# The above copyright notice and this permission notice shall be included in all # +# copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # +# SOFTWARE. # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +## RECEIVER AND OPERATING SYSTEM + +# Allow scipts to update the operating system software installed on your device. + +UPDATE_OPERATING_SYSTEM="true" + +# You can save the current branch state if you altered any of the core files within +# the ADS-B Receiver Project respository cloned to your device by copying it to a +# new branch. You will need to specify an name for this new branch if you do decide +# to backup your changes to another branch. + +BACKUP_BRANCH_STATE="false" +BACKUP_BRANCH_NAME="" + +# Specify the receivers latitude and longitude as well as its altitude. This +# information can be obtained from https://www.swiftbyte.com/toolbox/geocode by +# simply supplying an address for this receiver. + +RECEIVER_LATITUDE="" +RECEIVER_LONGITUDE="" +RECEIVER_ALTITUDE="" + + +## DECODERS + +# --------------------------------------------------------------------------------- +# DUMP1090 +# --------------------------------------------------------------------------------- +# +# One of two dump1090 forks must be installed by these scripts. You are required to +# specify one of the compatably forks in order to complete setup. The two available +# options at this time are the following: +# +# mutability : dump1090-mutability : https://github.com/mutability/dump1090 +# fa : dump1090-fa : https://github.com/flightaware/dump1090 +# +# If dump1090-fa (fa) is selected PiAware must be installed as +# well in order for dump1090-fa to run properly. + +DUMP1090_FORK="mutability" + +# If set to true dump1090 will be upgraded to the latest available version. +# +# Some forks such as dump1090-mutability are not released by version but instead +# changes to made to the software are commited to the projects master branch with +# no release being made. With no way to gage whether or not improvments or +# additions have been made to the software you may from time to time have to +# download, build, and install the source in order to ensure you are running +# an up to date version of the software. Set this variable to true if you wish to +# force the reinstallation of dump1090 on your device. + +DUMP1090_UPGRADE="true" + +# Some setups will require you to specify the USB device dump1090 will be using. +# In particular when you are setting up more than one decoder on a single device. +# If you are only running the dump1090 decoder and not in cujunction with say +# dump978 on the same device then it is safe to leave this variable empty. +# +# This variable will be ignored if dump1090 is the only decoder installed. + +DUMP1090_DEVICE_ID="0" + +# OPTIONAL: You can optionally specify a Bing Maps API key in order to use maps +# provided by the Bing Maps service within the dump1090 map page. You can sign up +# for a Bing Maps API key at https://www.bingmapsportal.com. + +DUMP1090_BING_MAPS_KEY="" + +# OPTIONAL: You can optionally specify a Mapzen API key in order to use maps +# provided by the Mapzen Maps service within the dump1090 map page. You can sign up +# for a Mapzen API key at https://mapzen.com. + +DUMP1090_MAPZEN_KEY="" + +# OPTIONAL: Maximum range rings can be added to the dump109 map usings data +# obtained from Heywhatsthat.com. You will need to generate a new panorama for +# the receivers location before begining the installation. Note that the ability +# to download the JSON file making up the rings may expire over time on the +# Heywhatsthat.com website. + +DUMP1090_HEYWHATSTHAT_INSTALL="false" + +# In order to add these rings to your dump1090 map you will first need to visit +# http://www.heywhatsthat.com and generate a new panorama centered on the location +# of your receiver. You will need to supply the view id which is the series of +# letters and/or numbers after ?view= in the URL located near the top left hand +# corner of the page the panorama is displayed. + +DUMP1090_HEYWHATSTHAT_ID="" + +# Set the following variables to the altitude in meters for each Heywhatsthat.com +# maximum range ring which will be displayed on the dump1090 map. +# +# 3048 meters equals 10000 feet. +# 12192 meters equals 40000 feet. + +DUMP1090_HEYWHATSTHAT_RING_ONE="3048" +DUMP1090_HEYWHATSTHAT_RING_TWO="12192" + +# MUTABILITY ONLY: You can specify if dump1090-mutability will be allowed to listen +# on all IP addresses assigned to the device or only on the loopback address.' + +DUMP1090_BIND_TO_ALL_IPS="true" + +# MUTABILITY ONLY: You can specify the unit of measure used by dump1090-mutability. +# This can be set to either "metric" or "imperial". + +DUMP1090_UNIT_OF_MEASUREMENT="imperial" + +# --------------------------------------------------------------------------------- +# DUMP978 +# --------------------------------------------------------------------------------- + +DUMP978_INSTALL="false" + +# The dump978 source code is not versioned with fixes and changes to the source +# code directly commited to the master branch of the repoisitory when added. Since +# there is no version to go off of to judge whether or not changes have been made +# you must rebuild the binaries from source each time a change is made which you +# may need. Setting this option to true will download and rebuild the source code +# each time the installation is ran. + +DUMP978_UPGRADE="true" + +# When setting up dump978 along with another decoder such as dump978 on the same +# device you will be required specify the USB device dump1090 as well as dump978 +# will be using. +# +# If installing dump978 on a device running dump1090 as well as dump978 the +# variable named DUMP1090_DEVICE_ID must be set as well. + +DUMP978_DEVICE_ID="1" + +# --------------------------------------------------------------------------------- +# RTLSDR-OGN +# --------------------------------------------------------------------------------- + +RTLSDROGN_INSTALL="false" + +# + +RTLSDROGN_UPGRADE="true" + +# + +RTLSDROGN_DEVICE_ID="" + +# Device ID Device index of the USB RTL-SDR device to be selected + +OGN_DEVICE_ID="" + +# DeviceSerial Serial number of the USB RTL-SDR device to be selected + +OGN_DEVICE_SERIAL="" + +# FreqCorr [ppm] Some R820T sticks have 40-80ppm correction factors, measure it with gsm_scan + +OGN_FREQ_CORR="" + +# CenterFreq [MHz] Use gsm_scan to find the best GSM frequency + +OGN_GSM_FREQ="" + +# Gain [0.1dB] RF input gain for frequency calibration (beware that GSM signals are very strong) + +OGN_GSM_GAIN="" + +# Latitude [deg] Antenna latitude in decimal degrees + +OGN_LAT="" + +# Longitude [deg] Antenna longitude in decimal degrees + +OGN_LON="" + +# Altitude [m] Antenna altitude above sea leavel + +OGN_ALT="" + +# GeoidSepar [m] Geoid separation: FLARM transmits GPS altitude, APRS uses means Sea level altitude + +OGN_GEOID="" + +# Callsign [char9] APRS callsign (max. 9 characters) + +OGN_RECEIVER_NAME="" + +# Whitelist [0|1] OGN Whitelist + +OGN_WHITELIST="" + + +## FEEDERS + +# --------------------------------------------------------------------------------- +# ADS-B Exchange +# --------------------------------------------------------------------------------- + +ADSBEXCHANGE_INSTALL="false" +ADSBEXCHANGE_UPGRADE="false" + +# The receiver name should be a unique name specific to this receiver which you can +# use to identify your receiver on the ADS-B Exchange MLAT status pages. This +# variable is required in order to setup the MLAT client to feed ADS-B Exchange +# properly. + +ADSBEXCHANGE_RECEIVER_USERNAME="I_DID_NOT_READ_THE_COMMENTS" + +# --------------------------------------------------------------------------------- +# FLIGHTRADAR24 FEEDER CLIENT +# --------------------------------------------------------------------------------- +# +# The Flightradar24 Feeder Client requires the user to interact physically with the +# device during installation. If you are to choose to set this installation option +# to true then the interactive installation mode will be automatically enabled +# for the entire installation process. + +FLIGHTRADAR24_INSTALL="false" + +# --------------------------------------------------------------------------------- +# PIAWARE +# --------------------------------------------------------------------------------- +# +# Please note that if the FlightAware fork of dump1090 is chosen to be installed +# PiAware will be installed reguardless of the option set here. + +PIAWARE_INSTALL="false" +PIAWARE_UPGRADE="true" + +# The variables PIAWARE_FLIGHTAWARE_LOGIN and PIAWARE_FLIGHTAWARE_PASSWORD are +# optional and may be left empty. If you decide to leave these values empty you +# will need to manual claim this device as your on FlightAwares website. +# Information on claiming your device can be found at the following address: +# +# http://flightaware.com/adsb/piaware/claim + +PIAWARE_FLIGHTAWARE_LOGIN="" +PIAWARE_FLIGHTAWARE_PASSWORD="" + +# --------------------------------------------------------------------------------- +# PLANEFINDER ADS-B CLIENT +# --------------------------------------------------------------------------------- +# +# After setup has completed the Plane Finder ADS-B Client should be installed and +# running however this script is only capable of installing the Plane Finder ADS-B +# Client. There are still a few steps left which you must manually do through the +# Plane Finder ADS-B Client itself after the setup process is complete. +# +# Visit the following URL: http://127.0.0.1:30053 +# +# Use the following settings when asked for them. +# +# Data Format: Beast +# Tcp Address: 127.0.0.1 +# Tcp Port: 30005 + +PLANEFINDER_INSTALL="false" +PLANEFINDER_UPGRADE="true" + +# --------------------------------------------------------------------------------- +# WEB PORTAL +# --------------------------------------------------------------------------------- +# +# If you wish to install the ADS-B Receiver Project portal set the following +# variable to true if not then set this variable to false. +# +# In order to complete the portal setup process you will still be required to visit +# the URL http://127.0.0.1/install/ in your favorite web browser. If the portal is +# ever updated you will need to visit the same URL to complete the upgrade as well. + +WEBPORTAL_INSTALL="true" + +# Set the following variable to true to keep your portal up to date each time the +# script are ran on this device. + +WEBPORTAL_UPDATE="true" + +# It is highly recomended that any device using a SD card for data storage does +# not enable the portal's advanced featires. Doing so may shorten the life of your +# storage device greatly. + +WEBPORTAL_ADVANCED="false" + +# If WEBPORTAL_ADVANCED is set to "true" the variable WEBPORTAL_DATABASE_ENGINE +# must be set as well. There are currently two database engine options available. +# +# mysql : MySQL : http://www.mysql.com/ +# sqlite : SQLite : http://sqlite.org/ + +WEBPORTAL_DATABASE_ENGINE="" + +# If you are using MySQL as your database engine you must specify if the database +# server will be hosted locally on this device or at a remote location. + +WEBPORTAL_MYSQL_SERVER_LOCAL="true" + +# If you are using MySQL you will also need to specify the hostname or address of +# the MySQL server you are going to use. If the MySQL server will be running +# locally on this device then the WEBPORTAL_MYSQL_SERVER_HOSTNAME value should +# be set to "localhost". + +WEBPORTAL_MYSQL_SERVER_HOSTNAME="localhost" + +# If the database to be used by the portal already exists set you will want to set +# the value of the variable WEBPORTAL_DATABASE_EXISTS to "true" in order to skip +# the database creation process. + +WEBPORTAL_DATABASE_EXISTS="false" + +# If the database which will be used by the portal does not exist you will need to +# supply administrative credentials the script can use to log into the database +# eengine in order to create the database. + +WEBPORTAL_DATABASE_ADMIN_USER="" +WEBPORTAL_DATABASE_ADMIN_PASSWORD="" + +# You will need to supply both the database name as well as the credentials needed +# to log into the database server even if the database does or does not exist yet. + +WEBPORTAL_DATABASE_NAME="" +WEBPORTAL_DATABASE_USER="" +WEBPORTAL_DATABASE_PASSWORD="" + + +## EXTRAS + +# --------------------------------------------------------------------------------- +# ABOVETUSTIN +# --------------------------------------------------------------------------------- +# +# AboveTustin is a twitter bot which can be installed using these scripts. In order +# for AboveTustin to work properly make sure to fill in all of the following +# variables including proper working twitter keys, secrets, and tokens. + +ABOVETUSTIN_INSTALL="false" + +# Setting the following variable to true will download the latest copy of the files +# making up AboveTustin from the project's Git repository on GitHub. + +ABOVETUSTIN_UPGRADE="true" + +# If no precompiled PhantomJS binary is available for download for use on your +# device the scripts are capable of building a binary from source. However doing so +# may take quite some time measurable in hours. Set this variable to true if you +# wish to allow the scripts to compile a binary if one is not available. + +ABOVETUSTIN_COMPILE_IF_NEEDED="false" + +# You will need to obtain tokens and keys from the Twitter developers site in order +# to send tweets to your Twitter account via the AboveTustin Twitter bot. You can +# sign up for a free Twitter developer account at https://dev.twitter.com. + +TWITTER_ACCESS_TOKEN="" +TWITTER_ACCESS_TOKEN_SECRET="" +TWITTER_CONSUMER_KEY="" +TWITTER_CONSUMER_SECRET="" + +# --------------------------------------------------------------------------------- +# BEAST-SPLITTER +# --------------------------------------------------------------------------------- +# +# It is possible to allow these scripts to install the beast-splitter application +# on this device. The beast-splitter package makes it possible to feed data from +# devices such as the Mode-S Beast into dump1090. If you are not using a device +# such as the Mode-S Beast there is no reason to install this package. + +BEASTSPLITTER_INSTALL="false" + +# The beast-splitter source code is not versioned so setting the this variable to +# true will reinstall beast-splitter insuring that the most recent code commited +# to the master branch of the project is built and installed on this device. + +BEASTSPLITTER_UPGRADE="false" + +# If you decide to install beast-splitter you must specify the ports the +# application will both listen on and send data on while running. Be sure to set +# the listen port to one not already being used. The dump1090 application generally +# listens on port 30005 so this port should be changed in order not to conflict +# with dump1090. The majority of the time the connect port should be set to the +# port dump1090 listens for external data on by default being port 30104. + +BEASTSPLITTER_LISTEN_PORT="30005" +BEASTSPLITTER_CONNECT_PORT="30104" + +# --------------------------------------------------------------------------------- +# DUCK DNS FREE DYNAMIC DNS HOSTING +# --------------------------------------------------------------------------------- +# +# These scripts are capable of setting up your receiver to use Duck DNS for dynamic +# DNS hosting. The script requires setting up an account on the Duck DNS website +# found at http://www.duckdns.org. You will need to setup a sub domain as well as +# obtain a key and supply it here in order to complete the setup process. +# +# Set the following variable to true in order to setup this option. + +DUCKDNS_INSTALL="false" + +# Set the following variable to true only if you wish to modify the current setup. + +DUCKDNS_UPGRADE="false" + +# supply the subdomain and key supplied to you by duckdns.org. + +DUCKDNS_DOMAIN="" +DUCKDNS_TOKEN="" diff --git a/install.sh b/install.sh index ee2e152..e5573e8 100755 --- a/install.sh +++ b/install.sh @@ -36,143 +36,146 @@ ## VARIABLES -PROJECTBRANCH="master" -PROJECTROOTDIRECTORY="$PWD" -BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" -BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" +AUTOMATED_INSTALL="false" +PROJECT_BRANCH="master" +CONFIGURATION_FILE="default" +ENABLE_LOGGING="false" -## INCLUDE EXTERNAL SCRIPTS +export RECEIVER_ROOT_DIRECTORY="${PWD}" +export RECEIVER_BASH_DIRECTORY="${PWD}/bash" +export RECEIVER_BUILD_DIRECTORY="${PWD}/build" -source $BASHDIRECTORY/functions.sh +## SOURCE EXTERNAL SCRIPTS -## MORE VARIABLES - -export ADSB_PROJECTTITLE="The ADS-B Receiver Project Installer" -TERMINATEDMESSAGE=" \e[91m ANY FURTHER SETUP AND/OR INSTALLATION REQUESTS HAVE BEEN TERMINIATED\e[39m" - -## CHECK IF THIS IS THE FIRST RUN USING THE IMAGE RELEASE - -if [ -f $PROJECTROOTDIRECTORY/image ]; then - # Execute image setup script.. - chmod +x $BASHDIRECTORY/image.sh - $BASHDIRECTORY/image.sh - if [ $? -ne 0 ]; then - echo "" - echo -e $TERMINATEDMESSAGE - echo "" - exit 1 - fi - exit 0 -fi +source ${RECEIVER_BASH_DIRECTORY}/functions.sh ## FUNCTIONS -# UPDATE REPOSITORY PACKAGE LISTS -function AptUpdate() { - clear - echo -e "\n\e[91m $ADSB_PROJECTTITLE" - echo "" - echo -e "\e[92m Downloading the latest package lists for all enabled repositories and PPAs..." - echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[97m" - echo "" - sudo apt-get update - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" - echo -e "\e[92m Finished downloading and updating package lists.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE +# Display the help message. +function DisplayHelp() { + echo -e "" + echo -e "Usage: $0 [OPTIONS] [ARGUMENTS]" + echo -e "" + echo -e "Option GNU long option Meaning" + echo -e "-a --automated-install Use a configuration file to automate the install process somewhat." + echo -e "-b --branch= Specifies the repository branch to be used." + echo -e "-c --config-file= The configuration file to be use for an unattended installation." + echo -e "-h --help Shows this message." + echo -e "-l --log-output Logs all output to a file in the logs directory." + echo -e "-v --verbose Provides extra confirmation at each stage of the install." + echo -e "" } -function CheckPrerequisites() { - clear - echo -e "\n\e[91m $ADSB_PROJECTTITLE" - echo "" - echo -e "\e[92m Checking to make sure the whiptail and git packages are installed..." - echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[97m" - echo "" - CheckPackage whiptail - CheckPackage git - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" - echo -e "\e[92m The whiptail and git packages are installed.\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE -} +## CHECK FOR OPTIONS AND ARGUMENTS +while [[ $# -gt 0 ]] ; do + case "$1" in + -h|--help) + # Display a help message. + DisplayHelp + exit 0 + ;; + -a|--automated-install) + # Automated install. + AUTOMATED_INSTALL="true" + shift 1 + ;; + -b) + # The specified branch of github. + PROJECT_BRANCH="$2" + shift 2 + ;; + --branch*) + # The specified branch of github. + PROJECT_BRANCH=`echo $1 | sed -e 's/^[^=]*=//g'` + shift 1 + ;; + -c) + # The specified installation configuration file. + CONFIGURATION_FILE="$2" + shift 2 + ;; + --config-file*) + # The specified installation configuration file. + CONFIGURATION_FILE=`echo $1 | sed -e 's/^[^=]*=//g'` + shift 1 + ;; + -l|--log-output) + # Enable logging to a file in the logs directory. + ENABLE_LOGGING="true" + shift 1 + ;; + -v|--verbose) + # Provides extra confirmation at each stage of the install. + VERBOSE="true" + shift 1 + ;; + *) + # Unknown options were set so exit. + echo -e "Error: Unknown option: $1" >&2 + DisplayHelp + exit 1 + ;; + esac +done -function UpdateRepository() { -## UPDATE THIS REPOSITORY - clear - echo -e "\n\e[91m $ADSB_PROJECTTITLE" - echo "" - echo -e "\e[92m Pulling the latest version of the ADS-B Receiver Project repository..." - echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[97m" - echo "" - echo -e "\e[94m Switching to branch $PROJECTBRANCH...\e[97m" - echo "" - git checkout $PROJECTBRANCH - echo "" - echo -e "\e[94m Pulling the latest git repository...\e[97m" - echo "" - git pull - echo "" - echo -e "\e[93m----------------------------------------------------------------------------------------------------" - echo -e "\e[92m Finished pulling the latest version of the ADS-B Receiver Project repository....\e[39m" - echo "" - read -p "Press enter to continue..." CONTINUE -} +## AUTOMATED INSTALL -# UPDATE THE OPERATING SYSTEM -function UpdateOperatingSystem() { - clear - echo -e "\n\e[91m $ADSB_PROJECTTITLE" - echo "" - echo -e "\e[92m Downloading and installing the latest updates for your operating system..." - echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[97m" - echo "" - sudo apt-get -y dist-upgrade - echo "" - 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 -} - -AptUpdate -CheckPrerequisites -UpdateRepository - -## DISPLAY WELCOME SCREEN - -## ASK IF OPERATING SYSTEM SHOULD BE UPDATED - -if (whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Operating System Updates" --yesno "It is recommended that you update your system before building and/or installing any ADS-B receiver related packages. This script can do this for you at this time if you like.\n\nWould you like to update your operating system now?" 11 78) then - UpdateOperatingSystem +# If the automated installation option was selected set the needed environmental variables. +if [[ "${AUTOMATED_INSTALL}" = "true" ]] ; then + # If no configuration file was specified use the default configuration file path and name. + if [[ -n "${CONFIGURATION_FILE}" ]] || [[ "${CONFIGURATION_FILE}" = "default" ]] ; then + CONFIGURATION_FILE="${RECEIVER_ROOT_DIRECTORY}/install.config" + # If either the -c or --config-file= flags were set a valid file must reside there. + elif [[ ! -f "${CONFIGURATION_FILE}" ]] ; then + echo "Unable to locate the installation configuration file." + exit 1 + fi fi -## EXECUTE BASH/MAIN.SH +# Add any environmental variables needed by any child scripts. +export RECEIVER_AUTOMATED_INSTALL=${AUTOMATED_INSTALL} +export RECEIVER_PROJECT_BRANCH=${PROJECT_BRANCH} +export RECEIVER_CONFIGURATION_FILE=${CONFIGURATION_FILE} +export RECEIVER_VERBOSE=${VERBOSE} -chmod +x $BASHDIRECTORY/main.sh -$BASHDIRECTORY/main.sh -if [ $? -ne 0 ]; then - echo -e $TERMINATEDMESSAGE - echo "" +## EXECUTE BASH/INIT.SH + +chmod +x ${RECEIVER_BASH_DIRECTORY}/init.sh +if [[ -n "${ENABLE_LOGGING}" ]] && [[ "${ENABLE_LOGGING}" = "true" ]] ; then + # Execute init.sh logging all output to the log drectory as the file name specified. + LOG_FILE="${RECEIVER_ROOT_DIRECTORY}/logs/install_$(date +"%m_%d_%Y_%H_%M_%S").log" + ${RECEIVER_BASH_DIRECTORY}/init.sh 2>&1 | tee -a "${LOG_FILE}" + echo -e "\e[95m Cleaning up log file...\e[97m" + CleanLogFile "${LOG_FILE}" +else + # Execute init.sh without logging any output to the log directory. + ${RECEIVER_BASH_DIRECTORY}/init.sh +fi + +## CLEAN UP + +# Remove any files created by whiptail. +for WHIPTAIL in FEEDER_CHOICES EXTRAS_CHOICES ; do + if [[ -f "${RECEIVER_ROOT_DIRECTORY}/${WHIPTAIL}" ]] ; then + rm -f ${RECEIVER_ROOT_DIRECTORY}/${WHIPTAIL} + fi +done + +# Remove any global variables assigned by this script. +unset RECEIVER_ROOT_DIRECTORY +unset RECEIVER_BASH_DIRECTORY +unset RECEIVER_BUILD_DIRECTORY +unset RECEIVER_PROJECT_BRANCH +unset RECEIVER_AUTOMATED_INSTALL +unset RECEIVER_CONFIGURATION_FILE +unset RECEIVER_VERBOSE +unset RECEIVER_PROJECT_TITLE + +# Check if any errors were encountered by any child scripts. +# If no errors were encountered then exit this script cleanly. +if [[ $? -ne 0 ]] ; then exit 1 +else + exit 0 fi - -## INSTALLATION COMPLETE - -# Display the installation complete message box. -whiptail --backtitle "$ADSB_PROJECTTITLE" --title "Software Installation Complete" --msgbox "INSTALLATION COMPLETE\n\nDO NOT DELETE THIS DIRECTORY!\n\nFiles needed for certain items to run properly are contained within this directory. Deleting this directory may result in your receiver not working properly.\n\nHopefully, these scripts and files were found useful while setting up your ADS-B Receiver. Feedback regarding this software is always welcome. If you have any issues or wish to submit feedback, feel free to do so on GitHub.\n\nhttps://github.com/jprochazka/adsb-receiver" 20 65 - -# Unset any exported variables. -unset ADSB_PROJECTTITLE - -# Remove the FEEDERCHOICES file created by whiptail. -rm -f FEEDERCHOICES - -echo -e "\033[32m" -echo "Installation complete." -echo -e "\033[37m" - -exit 0 diff --git a/logs/placeholder.txt b/logs/placeholder.txt new file mode 100644 index 0000000..fcad817 --- /dev/null +++ b/logs/placeholder.txt @@ -0,0 +1 @@ +Placeholder file to make sure the logs folder is created