adsb-receiver/install.sh

176 wiersze
7.2 KiB
Bash
Czysty Zwykły widok Historia

2015-11-04 04:48:08 +00:00
#!/bin/bash
#####################################################################################
# ADS-B RECEIVER #
2015-11-04 04:48:08 +00:00
#####################################################################################
# #
# 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 #
2015-11-04 04:48:08 +00:00
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
2016-09-01 21:06:18 +00:00
# Copyright (c) 2015-2016 Joseph A. Prochazka #
2015-11-04 04:48:08 +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-12-29 17:01:06 +00:00
## VARIABLES
2015-12-17 04:38:06 +00:00
2016-12-29 17:01:06 +00:00
AUTOMATED_INSTALL="true"
PROJECT_BRANCH="master"
CONFIGURATION_FILE="default"
2016-12-29 17:01:06 +00:00
ENABLE_LOGGING="false"
export RECEIVER_ROOT_DIRECTORY="$PWD"
export RECEIVER_BASH_DIRECTORY="$PWD/bash"
export RECEIVER_BUILD_DIRECTORY="$PWD/build"
2016-12-29 17:01:06 +00:00
## SOURCE EXTERNAL SCRIPTS
source $RECEIVER_ROOT_DIRECTORY/bash/functions.sh
2016-12-29 17:01:06 +00:00
## FUNCTIONS
# Display the help message.
function DisplayHelp() {
echo ""
echo "Usage: $0 [OPTIONS] [ARGUMENTS]"
echo ""
echo "Option GNU long option Meaning"
echo "-a --automated-install Use a configuration file to automate the install process somewhat."
echo "-b <BRANCH> --branch=<BRANCH> Specifies the repository branch to be used."
echo "-c <FILE> --config-file=<FILE> The configuration file to be use for an unattended installation."
echo "-h --help Shows this message."
echo "-l --log-output Logs all output to a file in the logs directory."
echo "-v --verbose Provides extra confirmation at each stage of the install."
echo ""
}
2016-12-29 17:01:06 +00:00
## CHECK FOR OPTIONS AND ARGUMENTS
2016-12-08 22:10:13 +00:00
while [[ $# -gt 0 ]]; do
2016-12-08 22:10:13 +00:00
case "$1" in
-h|--help)
# Display a help message.
2016-12-29 17:01:06 +00:00
DisplayHelp
2016-12-08 22:10:13 +00:00
exit 0
;;
2016-12-29 17:01:06 +00:00
-a|--automated-install)
AUTOMATED_INSTALL="true"
2016-12-29 17:01:06 +00:00
;;
-b)
# The specified installation configuration file.
PROJECT_BRANCH="$2"
shift 2
;;
--branch*)
# The specified installation configuration file.
PROJECT_BRANCH=`echo $1 | sed -e 's/^[^=]*=//g'`
shift 1
;;
-c)
2016-12-21 11:10:17 +00:00
# The specified installation configuration file.
CONFIGURATION_FILE="$2"
2016-12-21 11:10:17 +00:00
shift 2
;;
--config-file*)
# The specified installation configuration file.
CONFIGURATION_FILE=`echo $1 | sed -e 's/^[^=]*=//g'`
shift 1
;;
2016-12-08 22:10:13 +00:00
-l|--log-output)
# Enable logging to a file in the logs directory.
2016-12-08 22:10:13 +00:00
ENABLE_LOGGING="true"
shift 1
2016-12-08 22:10:13 +00:00
;;
-v|--verbose)
# Provides extra confirmation at each stage of the install.
2016-12-29 17:01:06 +00:00
VERBOSE="true"
shift 1
;;
2016-12-08 22:10:13 +00:00
*)
# Unknown options were set so exit.
echo -e "Error: Unknown option: $1" >&2
DisplayHelp
exit 1
2016-12-08 22:10:13 +00:00
;;
esac
done
2016-12-29 17:01:06 +00:00
## AUTOMATED INSTALL
# 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
2016-12-29 17:01:06 +00:00
echo "Unable to locate the installation configuration file."
exit 1
fi
2016-12-21 11:10:17 +00:00
fi
# Add any environmental variables needed by any child scripts.
2016-12-29 17:01:06 +00:00
export RECEIVER_AUTOMATED_INSTALL=$AUTOMATED_INSTALL
2016-12-31 02:24:45 +00:00
export RECEIVER_PROJECT_BRANCH=$PROJECT_BRANCH
2016-12-29 17:01:06 +00:00
export RECEIVER_CONFIGURATION_FILE=$CONFIGURATION_FILE
export RECEIVER_VERBOSE=$VERBOSE
2016-12-29 17:01:06 +00:00
## EXECUTE BASH/INIT.SH
2016-09-23 21:10:29 +00:00
chmod +x $RECEIVER_BASH_DIRECTORY/init.sh
if [[ -z "$ENABLE_LOGGING" ]] && [[ "$ENABLE_LOGGING" = "true" ]] ; then
2016-12-08 22:10:13 +00:00
# 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"
CleanLogFile "$LOG_FILE"
2016-12-08 22:10:13 +00:00
else
# Execute init.sh without logging any output to the log directory.
$RECEIVER_BASH_DIRECTORY/init.sh
2016-09-23 21:10:29 +00:00
fi
2016-12-29 17:01:06 +00:00
## CLEAN UP
# Remove any files created by whiptail.
rm -f $RECEIVER_ROOT_DIRECTORY/FEEDER_CHOICES
rm -f $RECEIVER_ROOT_DIRECTORY/EXTRAS_CHOICES
2016-12-21 11:10:17 +00:00
# Remove any global variables assigned by this script.
unset RECEIVER_ROOT_DIRECTORY
unset RECEIVER_BASH_DIRECTORY
unset RECEIVER_BUILD_DIRECTORY
unset RECEIVER_PROJECT_BRANCH
2016-12-29 17:01:06 +00:00
unset RECEIVER_AUTOMATED_INSTALL
unset RECEIVER_CONFIGURATION_FILE
unset RECEIVER_VERBOSE
2016-12-29 17:01:06 +00:00
unset RECEIVER_PROJECT_TITLE
2015-11-04 04:48:08 +00:00
2016-12-21 11:10:17 +00:00
# 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
2016-12-21 11:10:17 +00:00
else
exit 0
fi