#!/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 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. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ### VARIABLES PROJECTROOTDIRECTORY="$PWD" BASHDIRECTORY="$PROJECTROOTDIRECTORY/bash" BUILDDIRECTORY="$PROJECTROOTDIRECTORY/build" BUILDDIRECTORY_RTLSDROGN="$BUILDDIRECTORY/rtlsdr-ogn" DECODER_NAME="RTLSDR-OGN" DECODER_DESC="is the Open Glider Network decoder which focuses on tracking aircraft equipped with FLARM, FLARM-compatible devices or OGN tracker" DECODER_WEBSITE="http://wiki.glidernet.org" ### INCLUDE EXTERNAL SCRIPTS source $BASHDIRECTORY/variables.sh source $BASHDIRECTORY/functions.sh ### BEGIN SETUP clear echo -e "" echo -e "\e[91m $ADSB_PROJECTTITLE" echo -e "" echo -e "\e[92m Setting up ${DECODER_NAME} ...." echo -e "\e[93m----------------------------------------------------------------------------------------------------\e[96m" echo -e "" whiptail --backtitle "$ADSB_PROJECTTITLE" --title "${DECODER_NAME} Setup" --yesno "${DECODER_NAME} ${DECODER_DESC}. \n\n Please note that ${DECODER_NAME} requests a dedicated SDR tuner. \n\n $DECODER_WEBSITE \n\nContinue setup by installing ${DECODER_NAME} ?" 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 -e "" echo -e "\e[93m----------------------------------------------------------------------------------------------------" echo -e "\e[92m ${DECODER_NAME} setup halted.\e[39m" echo -e "" if [[ ! -z ${VERBOSE} ]] ; then read -p "Press enter to continue..." CONTINUE fi exit 1 fi ### CHECK FOR PREREQUISITE PACKAGES echo -e "\e[95m Installing packages needed to build and fulfill dependencies for ${DECODER_NAME} ...\e[97m" echo -e "" CheckPackage git CheckPackage rtl-sdr CheckPackage librtlsdr-dev CheckPackage libusb-1.0-0-dev CheckPackage libconfig-dev CheckPackage libfftw3-dev CheckPackage libjpeg8 CheckPackage libjpeg-dev CheckPackage libconfig9 CheckPackage procserv CheckPackage telnet CheckPackage wget CheckPackage lynx ### BLACKLIST UNWANTED RTL-SDR MODULES FROM BEING LOADED echo -e "\033[33m Stopping unwanted kernel modules from being loaded..." echo -e "\033[37m" sudo tee /etc/modprobe.d/rtlsdr-blacklist.conf > /dev/null <&1 | grep -c ", SN: "` if [[ ${TUNER_COUNT} -gt 1 ]] ; then # Multiple tuners found, check if device specified for this decoder is present. if [[ ${OGN_DEVICE_SERIAL} ]] ; then if [[ `rtl_test 2>&1 | grep -c "SN: ${OGN_DEVICE_SERIAL}" ` -eq 1 ]] ; then OGN_DEVICE_ID=`rtl_test 2>&1 | grep "SN: ${OGN_DEVICE_SERIAL}" | awk -F ":" '{print $1}' | sed -e 's/\ //g' ` echo -e "\e [94m RTL-SDR with Serial \"${OGN_DEVICE_SERIAL}\" found at device \"${OGN_DEVICE_ID}\" and will be assigned to ${DECODER_NAME} ...\e [97m" else echo -e "\e [94m RTL-SDR with Serial \"${OGN_DEVICE_SERIAL}\" not found, assigning device \"0\" to ${DECODER_NAME} ...\e [97m" fi elif [[ ${OGN_DEVICE_ID} ]] ; then if [[ `rtl_test 2>&1 | grep "SN: " | grep -c "^\ *${OGN_DEVICE_ID}:"` -eq 1 ]] ; then echo -e "\e [94m RTL-SDR device \"${OGN_DEVICE_ID}\" found and will be assigned to ${DECODER_NAME} ...\e [97m" else echo -e "\e [94m RTL-SDR device \"${OGN_DEVICE_ID}\" not found, assigning device \"0\" to ${DECODER_NAME} ...\e [97m" fi else if [[ -z ${OGN_DEVICE_ID} ]] ; then echo -e "\e [94m No RTL-SDR device specified, assigning device \"0\" to ${DECODER_NAME} ...\e [97m" OGN_DEVICE_ID="0" fi fi elif [[ ${TUNER_COUNT} -eq 1 ]] ; then # Single tuner present so we must stop any other running decoders, or at least dump1090-mutablity for a default install... echo -e "\e [94m Single RTL-SDR device \"0\" detected and assigned to ${DECODER_NAME} ...\e [97m" OGN_DEVICE_ID="0" sudo /etc/init.d/dump1090-mutability stop elif [[ ${TUNER_COUNT} -lt 1 ]] ; then # No tuner found. echo -e "\e [94m No RTL-SDR device detected so ${DECODER_NAME} will be assigned device \"0\" ...\e [97m" OGN_DEVICE_ID="0" sudo /etc/init.d/dump1090-mutability stop fi ### CREATE THE CONFIGURATION FILE OGN_WHITELIST="0" OGN_GSM_FREQ="957.800" OGN_GSM_GAIN="35" # Use receiver coordinates if already know, otherwise populate with dummy values to generate a valid config file. if [[ -n ${OGN_LAT} ]] ; then if [[ -n ${RECEIVER_LATITUDE} ]] ; then OGN_LAT="${RECEIVER_LATITUDE}" else OGN_LAT="0.0000000" fi fi if [[ -n ${OGN_LON} ]] ; then if [[ -n ${RECEIVER_LONGITUDE} ]] ; then OGN_LON="${ECEIVER_LONGITUDE}" else OGN_LON="0.0000000" fi fi if [[ -n ${OGN_ALT} ]] ; then if [[ -n ${RECIEVER_ALTITUDE} ]] ; then OGN_ALT="${RECIEVER_ALTITUDE}" else OGN_ALT="0" fi fi # Geoid separation: FLARM transmits GPS altitude, APRS uses means Sea level altitude # To find value you can check: http://geographiclib.sourceforge.net/cgi-bin/GeoidEval # Need to derive from co-ords but will set to altitude as a placeholders if [[ -z ${RECIEVER_ALTITUDE} ]] ; then OGN_GEOID="" else OGN_GEOID="0" fi # Callsign should be between 3 and 9 alphanumeric charactors, with no punctuation # Please see: http://wiki.glidernet.org/receiver-naming-convention if [[ -n ${OGN_RECEIVER_NAME} ]] ; then OGN_CALLSIGN=`echo ${OGN_RECEIVER_NAME} | tr -cd '[:alnum:]' | cut -c -9` else OGN_CALLSIGN=`hostname -s | tr -cd '[:alnum:]' | cut -c -9` fi # Test if config file exists, if not create it. if [[ -s $BUILDDIRECTORY_RTLSDROGN/${OGN_CALLSIGN}.conf ]] ; then echo -e "\e [94m Existing ${DECODER_NAME} config file \"${OGN_CALLSIGN}.conf\" found...\e [97m" else sudo tee $BUILDDIRECTORY_RTLSDROGN/${OGN_CALLSIGN}.conf > /dev/null < /dev/null < #Syntax: #port user directory command args 50000 pi ${BUILDDIRECTORY_RTLSDROGN}/rtlsdr-ogn ./ogn-rf ${OGN_CALLSIGN}.conf 50001 pi ${BUILDDIRECTORY_RTLSDROGN}/rtlsdr-ogn ./ogn-decode ${OGN_CALLSIGN}.conf EOF if [[ ${TUNER_COUNT} -lt 2 ]] ; then # Less than 2 tuners present so we must stop the dump1090-mutability before starting this decoder. echo -e "\033[33m Less than 2 RTL-SDR devices present so dump1090-mutability service will be disabled..." echo -e "\033[37m" sudo /etc/init.d/dump1090-mutability disable fi echo -e "\033[33m Setting up ${DECODER_NAME} as a service..." echo -e "\033[37m" sudo update-rc.d rtlsdr-ogn defaults echo -e "\033[33m Starting the ${DECODER_NAME} service..." echo -e "\033[37m" sudo service rtlsdr-ogn start ### ARCHIVE SETUP PACKAGES ### SETUP COMPLETE # Return to the project root directory. echo -e "\e[94m Entering the $ADSB_PROJECTTITLE root directory...\e[97m" cd $PROJECTROOTDIRECTORY echo -e "" echo -e "\e[93m-------------------------------------------------------------------------------------------------------" echo -e "\e[92m ${DECODER_NAME} setup is complete.\e[39m" echo -e "" if [[ ! -z ${VERBOSE} ]] ; then read -p "Press enter to continue..." CONTINUE fi exit 0