2016-01-15 21:22:14 +00:00
#!/bin/bash
#####################################################################################
2016-02-18 15:41:39 +00:00
# ADS-B RECEIVER #
2016-01-15 21:22:14 +00:00
#####################################################################################
# #
# This script is not meant to be executed directly. #
# Instead execute install.sh to begin the installation process. #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
2016-09-02 19:17:31 +00:00
# Copyright (c) 2015-2016 Joseph A. Prochazka #
2016-01-15 21:22:14 +00:00
# #
# 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. #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2016-09-02 19:17:31 +00:00
### VARIABLES
2016-01-15 21:22:14 +00:00
2016-09-02 19:17:31 +00:00
PROJECTROOTDIRECTORY = " $PWD "
BASHDIRECTORY = " $PROJECTROOTDIRECTORY /bash "
BUILDDIRECTORY = " $PROJECTROOTDIRECTORY /build "
2016-12-19 17:50:20 +00:00
BUILDDIRECTORY_DUMP978 = " $BUILDDIRECTORY /dump978 "
DECODER_NAME = "Dump978"
DECODER_WEBSITE = "https://github.com/mutability/dump978"
2016-01-15 21:22:14 +00:00
2016-09-02 19:17:31 +00:00
### INCLUDE EXTERNAL SCRIPTS
2016-01-15 21:22:14 +00:00
2016-09-02 19:17:31 +00:00
source $BASHDIRECTORY /variables.sh
source $BASHDIRECTORY /functions.sh
### BEGIN SETUP
clear
2016-12-19 17:50:20 +00:00
echo -e ""
echo -e " \e[91m $ADSB_PROJECTTITLE "
echo -e ""
echo -e " \e[92m Setting up ${ DECODER_NAME } .... "
2016-09-02 19:17:31 +00:00
echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m"
2016-12-19 17:50:20 +00:00
echo -e ""
whiptail --backtitle " $ADSB_PROJECTTITLE " --title " ${ DECODER_NAME } Setup " --yesno " ${ DECODER_NAME } is an experimental demodulator/decoder for 978MHz UAT signals.\n\n $DECODER_WEBSITE \n\nWould you like to continue setup by installing ${ DECODER_NAME } ? " 9 78
2016-09-02 19:17:31 +00:00
CONTINUESETUP = $?
2016-12-19 17:50:20 +00:00
if [ [ $CONTINUESETUP = 1 ] ] ; then
2016-09-02 19:17:31 +00:00
# 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."
2016-12-19 17:50:20 +00:00
echo -e ""
echo -e "\e[93m----------------------------------------------------------------------------------------------------"
echo -e " \e[92m ${ DECODER_NAME } setup halted.\e[39m "
echo -e ""
if [ [ ! -z ${ VERBOSE } ] ] ; then
2016-12-14 01:42:31 +00:00
read -p "Press enter to continue..." CONTINUE
fi
2016-09-02 19:17:31 +00:00
exit 1
fi
2016-01-15 21:22:14 +00:00
2016-12-19 17:50:20 +00:00
### CHECK FOR PREREQUISITE PACKAGES
2016-01-15 21:22:14 +00:00
2016-12-19 17:50:20 +00:00
echo -e " \e[95m Installing packages needed to build and fulfill dependencies for ${ DECODER_NAME } ...\e[97m "
echo -e ""
2016-01-15 21:22:14 +00:00
CheckPackage git
CheckPackage make
CheckPackage rtl-sdr
CheckPackage librtlsdr-dev
CheckPackage libusb-1.0-0-dev
CheckPackage gcc
2016-01-24 05:10:30 +00:00
CheckPackage netcat
2016-09-02 19:17:31 +00:00
CheckPackage lighttpd
2016-12-19 17:50:20 +00:00
### DOWNLOAD THE DUMP978 SOURCE CODE
2016-09-02 19:17:31 +00:00
2016-12-19 17:50:20 +00:00
echo -e ""
echo -e " \e[95m Preparing the ${ DECODER_NAME } Git repository...\e[97m "
echo -e ""
2016-09-02 19:17:31 +00:00
# Remove the existing dumpp978 build directory if it exists.
2016-12-19 17:50:20 +00:00
if [ [ -d $BUILDDIRECTORY_DUMP978 ] ] ; then
2016-09-02 19:17:31 +00:00
# Delete the current dump978 build directory if it already exists.
2016-12-19 17:50:20 +00:00
echo -e " \e[94m Deleting the existing ${ DECODER_NAME } Git repository directory...\e[97m "
rm -rf $BUILDDIRECTORY_DUMP978
2016-09-02 19:17:31 +00:00
fi
# Clone the dump978 Git repository.
2016-12-19 17:50:20 +00:00
echo -e " \e[94m Entering the $ADSB_PROJECTTITLE build directory...\e[97m "
2016-09-02 19:17:31 +00:00
cd $BUILDDIRECTORY
2016-12-19 17:50:20 +00:00
echo -e " \e[94m Cloning the ${ DECODER_NAME } Git repository locally...\e[97m "
echo -e ""
2016-09-02 19:17:31 +00:00
git clone https://github.com/mutability/dump978.git
2016-12-19 17:50:20 +00:00
### BUILD THE DUMP978 BINARIES
2016-09-02 19:17:31 +00:00
2016-12-19 17:50:20 +00:00
echo -e ""
echo -e " \e[95m Building the ${ DECODER_NAME } binaries...\e[97m "
echo -e ""
if [ [ ! $PWD = $BUILDDIRECTORY_DUMP978 ] ] ; then
echo -e " \e[94m Entering the ${ DECODER_NAME } Git repository directory...\e[97m "
cd $BUILDDIRECTORY_DUMP978
2016-09-02 19:17:31 +00:00
fi
2016-12-19 17:50:20 +00:00
echo -e " \e[94m Building the ${ DECODER_NAME } binaries...\e[97m "
echo -e ""
2016-09-02 19:17:31 +00:00
make all
2016-12-19 17:50:20 +00:00
echo -e ""
2016-09-02 19:17:31 +00:00
# Check that the dump978 binaries were built.
2016-12-19 17:50:20 +00:00
echo -e " \e[94m Checking that the ${ DECODER_NAME } binaries were built...\e[97m "
if [ [ ! -f $BUILDDIRECTORY_DUMP978 /dump978 ] ] || [ [ ! -f $BUILDDIRECTORY_DUMP978 /uat2esnt ] || [ ! -f $BUILDDIRECTORY_DUMP978 /uat2json ] || [ ! -f $BUILDDIRECTORY_DUMP978 /uat2text ] ] ; then
2016-09-02 19:17:31 +00:00
# If the dump978 binaries could not be found halt setup.
2016-12-19 17:50:20 +00:00
echo -e ""
2016-09-02 19:17:31 +00:00
echo -e "\e[91m \e[5mINSTALLATION HALTED!\e[25m"
2016-12-19 17:50:20 +00:00
echo -e " UNABLE TO LOCATE THE ${ DECODER_NAME } BINARIES. "
2016-09-02 19:17:31 +00:00
echo -e " SETUP HAS BEEN TERMINATED!"
2016-12-19 17:50:20 +00:00
echo -e ""
echo -e " \e[93mThe ${ DECODER_NAME } binaries appear to have not been built successfully..\e[39m "
echo -e ""
2016-09-02 19:17:31 +00:00
echo -e "\e[93m-------------------------------------------------------------------------------------------------------"
2016-12-19 17:50:20 +00:00
echo -e " \e[92m ${ DECODER_NAME } setup halted.\e[39m "
echo -e ""
if [ [ ! -z ${ VERBOSE } ] ] ; then
2016-12-14 01:42:31 +00:00
read -p "Press enter to continue..." CONTINUE
fi
2016-09-02 19:17:31 +00:00
exit 1
fi
2016-12-19 17:50:20 +00:00
### SETUP AND CONFIGURE THE DEVICE TO UTILIZE THE DDUMP978 BINARIES
2016-01-15 21:22:14 +00:00
2016-12-19 17:50:20 +00:00
echo -e ""
echo -e " \e[95m Configuring the device to utilize the ${ DECODER_NAME } binaries...\e[97m "
echo -e ""
2016-01-27 04:32:29 +00:00
2016-09-02 19:17:31 +00:00
# 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"
2016-01-27 05:30:20 +00:00
sudo tee /etc/modprobe.d/rtlsdr-blacklist.conf > /dev/null <<EOF
2016-01-27 04:32:29 +00:00
blacklist dvb_usb_rtl28xxu
blacklist dvb_usb_v2
blacklist rtl_2830
blacklist rtl_2832
blacklist r820t
EOF
2016-09-02 19:17:31 +00:00
echo -e "\e[94m Removing the kernel module dvb_usb_rtl28xxu...\e[97m"
2016-12-19 17:50:20 +00:00
echo -e ""
2016-01-27 04:32:29 +00:00
sudo rmmod dvb_usb_rtl28xxu
2016-12-19 17:50:20 +00:00
echo -e ""
2016-01-15 21:22:14 +00:00
# Check if the dump1090-mutability package is installed.
2016-09-02 19:17:31 +00:00
echo -e "\e[94m Checking if the dump1090-mutability package is installed...\e[97m"
2016-12-19 17:50:20 +00:00
if [ [ $( dpkg-query -W -f= '${STATUS}' dump1090-mutability 2>/dev/null | grep -c "ok installed" ) -eq 1 ] ] ; then
2016-01-15 21:22:14 +00:00
# The dump1090-mutability package appear to be installed.
2016-12-19 17:50:20 +00:00
whiptail --backtitle " $ADSB_PROJECTTITLE " --title "RTL-SDR Device Assignments" --msgbox " It appears the dump1090-mutability package is installed on this device. In order to run ${ DECODER_NAME } in tandem with dump1090-mutability you will need to specifiy which RTL-SDR device 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
DUMP1090_DEVICE_TITLE = "Dump1090 RTL-SDR Device"
while [ [ -z $DUMP1090_DEVICE_ID ] ] ; do
DUMP1090_DEVICE_ID = $( whiptail --backtitle " $ADSB_PROJECTTITLE " --title " $DUMP1090_DEVICE_TITLE " --nocancel --inputbox "\nEnter the ID for your dump1090 RTL-SDR device." 8 78 3>& 1 1>& 2 2>& 3)
DUMP1090_DEVICE_TITLE = "Dump1090 RTL-SDR Device (REQUIRED)"
2016-09-02 19:17:31 +00:00
done
2016-12-19 17:50:20 +00:00
DUMP978_DEVICE_TITLE = "Dump978 RTL-SDR Device"
while [ [ -z $DUMP978_DEVICE_ID ] ] ; do
DUMP978_DEVICE_ID = $( whiptail --backtitle " $ADSB_PROJECTTITLE " --title " $DUMP978_DEVICE_TITLE " --nocancel --inputbox "\nEnter the ID for your dump978 RTL-SDR device." 8 78 3>& 1 1>& 2 2>& 3)
DUMP978_DEVICE_TITLE = "Dump978 RTL-SDR Device (REQUIRED)"
2016-09-02 19:17:31 +00:00
done
2016-12-19 17:50:20 +00:00
# Assign the specified RTL-SDR device to dump1090-mutability.
echo -e " \e[94m Assigning RTL-SDR device \" $DUMP1090_DEVICE_ID \" to dump1090-mutability...\e[97m "
ChangeConfig "DEVICE" $DUMP1090_DEVICE_ID "/etc/default/dump1090-mutability"
2016-09-02 19:17:31 +00:00
echo -e "\e[94m Restarting dump1090-mutability...\e[97m"
2016-12-19 17:50:20 +00:00
echo -e ""
2016-01-15 21:22:14 +00:00
sudo /etc/init.d/dump1090-mutability restart
2016-12-19 17:50:20 +00:00
echo -e ""
2016-11-15 20:36:08 +00:00
# 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"
2016-12-21 14:14:00 +00:00
RECEIVER_LATITUDE = ` GetConfig "LAT" "/etc/default/dump1090-mutability" `
2016-11-15 20:36:08 +00:00
echo -e "\e[94m Retrieving the receiver's longitude from /etc/default/dump1090-mutability...\e[97m"
RECIEVERLONGITUDE = ` GetConfig "LON" "/etc/default/dump1090-mutability" `
2016-01-15 21:22:14 +00:00
fi
2016-12-19 17:50:20 +00:00
# If a device has not yet been assigned to ${DECODER_NAME} assign the first available.
if [ [ -z $DUMP978_DEVICE_ID ] ] ; then
echo -e " \e[94m Assigning RTL-SDR device \"0\" to ${ DECODER_NAME } ...\e[97m "
DUMP978_DEVICE_ID = "0"
2016-09-02 19:17:31 +00:00
fi
2016-01-15 21:22:14 +00:00
2016-11-15 20:36:08 +00:00
# Declare the LIGHTTPDDOCUMENTROOTDIRECTORY variable.
2016-09-02 19:17:31 +00:00
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 `
2016-11-15 20:36:08 +00:00
2016-12-21 13:01:42 +00:00
# Confirm the receivers latitude and longitude, if not already known.
2016-12-21 14:14:00 +00:00
if [ [ -z $RECEIVER_LATITUDE ] ] || [ [ -z $RECEIVER_LONGITUDE ] ] ; then
2016-11-15 20:36:08 +00:00
# If dump1090-mutability is not installed ask for the latitude and longitude of this receiver.
2016-12-21 14:14:00 +00:00
RECEIVER_LATITUDE_TITLE = "Receiver Latitude (OPTIONAL)"
# while [[ -z $RECEIVER_LATITUDE ]] ; do
RECEIVER_LATITUDE = $( whiptail --backtitle " $ADSB_PROJECTTITLE " --title " $RECEIVER_LATITUDE_TITLE " --nocancel --inputbox "\nEnter your receiver's latitude.\n(Example: XX.XXXXXXX)\n\nLeave blank and select <Ok> to skip." 12 78 3>& 1 1>& 2 2>& 3)
RECEIVER_LONGITUDE_TITLE = "Receiver Longitude"
2016-12-21 13:01:42 +00:00
# done
2016-12-21 14:14:00 +00:00
while [ [ -z $RECEIVER_LONGITUDE ] ] ; do
RECEIVER_LONGITUDE = $( whiptail --backtitle " $ADSB_PROJECTTITLE " --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)"
2016-11-15 20:36:08 +00:00
done
fi
2016-12-21 13:01:42 +00:00
# Now set the receivers latitude and longitude.
2016-12-21 14:14:00 +00:00
if [ [ ! -z $RECEIVER_LATITUDE ] ] && [ [ ! -z $RECEIVER_LONGITUDE ] ] ; then
echo -e " \e[94m Setting the receiver's latitude to $RECEIVER_LATITUDE ...\e[97m "
ChangeConfig "SiteLat" " $RECEIVER_LATITUDE " " $LIGHTTPDDOCUMENTROOTDIRECTORY /dump978/config.js "
echo -e " \e[94m Setting the receiver's longitude to $RECEIVER_LONGITUDE ...\e[97m "
ChangeConfig "SiteLon" " $RECEIVER_LONGITUDE " " $LIGHTTPDDOCUMENTROOTDIRECTORY /dump978/config.js "
2016-11-15 20:36:08 +00:00
fi
# Create the dump978 JSON directory in Lighttpd's document root.
2016-12-19 17:50:20 +00:00
echo -e " \e[94m Creating the ${ DECODER_NAME } JSON data directory within Lighttpd's document root...\e[97m "
2016-09-02 19:17:31 +00:00
sudo mkdir -p $LIGHTTPDDOCUMENTROOTDIRECTORY /dump978/data
echo -e "\e[94m Setting permissions for the dump978 JSON data directory within Lighttpd's document root...\e[97m"
sudo chmod +w $LIGHTTPDDOCUMENTROOTDIRECTORY /dump978/data
# Create the dump978 maintenance script.
2016-12-19 17:50:20 +00:00
echo -e " \e[94m Creating the ${ DECODER_NAME } maintenance script...\e[97m "
tee $BUILDDIRECTORY_DUMP978 /dump978-maint.sh > /dev/null <<EOF
2016-01-15 21:22:14 +00:00
#! /bin/sh
2016-01-18 20:50:19 +00:00
2016-09-02 19:17:31 +00:00
# Start dump978 without logging.
2016-01-22 18:39:38 +00:00
while true; do
2016-12-19 17:50:20 +00:00
rtl_sdr -d $DUMP978_DEVICE_ID -f 978000000 -s 2083334 -g 48 - | $BUILDDIRECTORY_DUMP978 /dump978 | $BUILDDIRECTORY_DUMP978 /uat2json $LIGHTTPDDOCUMENTROOTDIRECTORY /dump978/data | $BUILDDIRECTORY_DUMP978 /uat2esnt | /bin/nc -q1 127.0.0.1 30001 &
2016-01-27 03:34:43 +00:00
sleep 15
2016-01-22 18:39:38 +00:00
done
2016-01-15 21:22:14 +00:00
EOF
2016-12-19 17:50:20 +00:00
echo -e " \e[94m Setting permissions on the ${ DECODER_NAME } maintenance script...\e[97m "
chmod +x $BUILDDIRECTORY_DUMP978 /dump978-maint.sh
2016-09-02 19:17:31 +00:00
# Add the dump978 maintenance script to /etc/rc.local.
2016-12-19 17:50:20 +00:00
echo -e " \e[94m Checking if the file /etc/rc.local is already set to execute the ${ DECODER_NAME } maintenance script...\e[97m "
if ! grep -Fxq " $BUILDDIRECTORY_DUMP978 /dump978-maint.sh & " /etc/rc.local; then
echo -e " \e[94m Adding a line to execute the ${ DECODER_NAME } maintenance script to the file /etc/rc.local...\e[97m "
2016-09-02 19:17:31 +00:00
LINENUMBER = ( $( sed -n '/exit 0/=' /etc/rc.local) )
2016-12-19 17:50:20 +00:00
( ( LINENUMBER>0) ) && sudo sed -i " ${ LINENUMBER [ $(( ${# LINENUMBER [@] } - 1 )) ] } i ${ BUILDDIRECTORY_DUMP978 } /dump978-maint.sh &\n " /etc/rc.local
2016-01-27 01:00:42 +00:00
fi
2016-01-15 21:22:14 +00:00
2016-12-19 17:50:20 +00:00
### EXECUTE THE MAINTAINANCE SCRIPT TO START DUMP978
2016-01-15 21:22:14 +00:00
2016-12-19 17:50:20 +00:00
echo -e ""
echo -e " \e[95m Starting ${ DECODER_NAME } ...\e[97m "
echo -e ""
echo -e " \e[94m Starting ${ DECODER_NAME } by executing the ${ DECODER_NAME } maintenance script...\e[97m "
sudo nohup $BUILDDIRECTORY_DUMP978 /dump978-maint.sh > /dev/null 2>& 1 &
2016-09-02 19:17:31 +00:00
2016-12-19 17:50:20 +00:00
### SETUP COMPLETE
2016-09-02 19:17:31 +00:00
# Enter into the project root directory.
2016-12-19 17:50:20 +00:00
echo -e " \e[94m Entering the $ADSB_PROJECTTITLE root directory...\e[97m "
2016-09-02 19:17:31 +00:00
cd $PROJECTROOTDIRECTORY
2016-01-15 21:22:14 +00:00
2016-12-19 17:50:20 +00:00
echo -e ""
2016-09-02 19:17:31 +00:00
echo -e "\e[93m-------------------------------------------------------------------------------------------------------"
2016-12-19 17:50:20 +00:00
echo -e " \e[92m ${ DECODER_NAME } setup is complete.\e[39m "
echo -e ""
if [ [ ! -z ${ VERBOSE } ] ] ; then
2016-12-14 01:42:31 +00:00
read -p "Press enter to continue..." CONTINUE
fi
2016-09-02 19:17:31 +00:00
exit 0