-
Notifications
You must be signed in to change notification settings - Fork 127
/
install.sh
executable file
·214 lines (171 loc) · 6.53 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
## ASSIGN VARIABLE
project_version="2.8.8"
printf -v date_time '%(%Y-%m-%d_%H-%M-%S)T' -1
log_file="adsb-installer_${date_time}.log"
logging_enabled="true"
project_branch="master"
## FUNCTIONS
# Display the help message
function DisplayHelp() {
echo " "
echo "Usage: $0 [OPTION] [ARGUMENT] "
echo " "
echo "-------------------------------------------------------------------------------------------"
echo "Option GNU long option Description "
echo "-------------------------------------------------------------------------------------------"
echo "-b <BRANCH> --branch=<BRANCH> Specifies the repository branch to be used. "
echo "-d --development Skips local repository update so changes are not overwrote."
echo "-h --help Shows this message. "
echo "-m <MTA> --mta=<MTA> Specify which email MTA to use currently Exim or Postfix. "
echo "-n --no-logging Disables writing output to a log file. "
echo "-v --version Displays the version being used. "
echo "-------------------------------------------------------------------------------------------"
echo " "
}
## CHECK FOR OPTIONS AND ARGUMENTS
while [[ $# > 0 ]] ; do
case $1 in
--branch*)
project_branch=`echo $1 | sed -e 's/^[^=]*=//g'`
shift 1
;;
-b)
project_branch=$2
shift 2
;;
--development | -d)
development_mode="true"
shift 1
;;
--help | -h)
DisplayHelp
exit 0
;;
--mta*)
mta=`echo ${1^^} | sed -e 's/^[^=]*=//g'`
if [[ "${mta}" != "EXIM" && "${mta}" != "POSTFIX" ]]; then
echo "MTA can only be either EXIM or POSTFIX."
exit 1
fi
shift 1
;;
--no-logging | -n)
logging_enabled="false"
shift 1
;;
-m)
# The MTA to use
mta=${2^^}
if [[ "${mta}" != "EXIM" && "${mta}" != "POSTFIX" ]]; then
echo "MTA can only be either EXIM or POSTFIX."
exit 1
fi
shift 2
;;
--version | -v)
# Display the version
echo $project_version
exit 0
;;
*)
# Unknown options were set so exit
echo -e "Error: Unknown option: $1" >&2
DisplayHelp
exit 1
;;
esac
done
export RECEIVER_PROJECT_BRANCH=$project_branch
export RECEIVER_DEVELOPMENT_MODE=$development_mode
export RECEIVER_LOGGING_ENABLED=$logging_enabled
export RECEIVER_MTA=$mta
## SET PROJECT VARIABLES
export RECEIVER_PROJECT_TITLE="ADS-B Receiver Installer v${project_version}"
export RECEIVER_ROOT_DIRECTORY=$PWD
export RECEIVER_BASH_DIRECTORY=$PWD/bash
export RECEIVER_BUILD_DIRECTORY=$PWD/build
## SOURCE EXTERNAL SCRIPTS
source $RECEIVER_BASH_DIRECTORY/functions.sh
source $RECEIVER_BASH_DIRECTORY/variables.sh
## CREATE THE LOG DIRECTORY
if [[ "${RECEIVER_LOGGING_ENABLED}" == "true" ]]; then
export RECEIVER_LOG_FILE=$PWD/logs/$log_file
if [ ! -d "$DIRECTORY" ]; then
log_message "Creating logs directory"
mkdir $PWD/logs
fi
fi
## UPDATE PACKAGE LISTS AND INSTALL DEPENDENCIES
clear
log_project_title
log_title_heading "Starting ADS-B Receiver Installer package dependency check"
log_title_message "------------------------------------------------------------------------------"
log_heading "Updating package lists for all enabled repositories and PPAs"
log_message "Downloading the latest package lists for all enabled repositories and PPAs"
echo ""
sudo apt-get update 2>&1 | tee -a $RECEIVER_LOG_FILE
log_heading "Ensuring that all required packages are installed"
check_package bc
check_package git
check_package lsb-base
check_package lsb-release
check_package whiptail
echo ""
log_title_message "------------------------------------------------------------------------------"
log_title_heading "ADS-B Receiver Installer package dependency check complete"
echo ""
read -p "Press enter to continue..." discard
## SET OS VARIABLES
export RECEIVER_OS_CODE_NAME=`lsb_release -c -s`
export RECEIVER_OS_DISTRIBUTION=`. /etc/os-release; echo ${ID/*, /}`
export RECEIVER_OS_RELEASE=`. /etc/os-release; echo ${VERSION_ID/*, /}`
## SET HANDWARE VARIABLES
export RECIEVER_CPU_ARCHITECTURE=`uname -m | tr -d "\n\r"`
export RECEIVER_CPU_REVISION=`grep "^Revision" /proc/cpuinfo | awk '{print $3}'`
## INIT DECODER DEVICE ASSIGNMENT VARIABLES
export RECEIVER_DEVICE_ASSIGNED_TO_ACARS_DECODER
export RECEIVER_DEVICE_ASSIGNED_TO_ADSB_DECODER
export RECEIVER_DEVICE_ASSIGNED_TO_UAT_DECODER
export RECEIVER_DEVICE_ASSIGNED_TO_VDLM2_DECODER
export RECEIVER_ACARS_DECODER_SOFTWARE
export RECEIVER_ADSB_DECODER_SOFTWARE
export RECEIVER_UAT_DECODER_SOFTWARE
export RECEIVER_VDLM2_DECODER_SOFTWARE
## EXECUTE BASH/INIT.SH
chmod +x $RECEIVER_BASH_DIRECTORY/init.sh
$RECEIVER_BASH_DIRECTORY/init.sh
## CLEAN UP
for choice in FEEDER_CHOICES EXTRAS_CHOICES ; do
if [[ -f ${RECEIVER_ROOT_DIRECTORY}/${choice} ]] ; then
rm -f ${RECEIVER_ROOT_DIRECTORY}/${choice}
fi
done
unset RECEIVER_PROJECT_TITLE
unset RECEIVER_ROOT_DIRECTORY
unset RECEIVER_BASH_DIRECTORY
unset RECEIVER_BUILD_DIRECTORY
unset RECEIVER_OS_CODE_NAME
unset RECEIVER_OS_DISTRIBUTION
unset RECEIVER_OS_RELEASE
unset RECIEVER_CPU_ARCHITECTURE
unset RECEIVER_CPU_REVISION
unset RECEIVER_DEVICE_ASSIGNED_TO_ACARS_DECODER
unset RECEIVER_DEVICE_ASSIGNED_TO_ADSB_DECODER
unset RECEIVER_DEVICE_ASSIGNED_TO_UAT_DECODER
unset RECEIVER_DEVICE_ASSIGNED_TO_VDLM2_DECODER
unset RECEIVER_ACARS_DECODER_SOFTWARE
unset RECEIVER_ADSB_DECODER_SOFTWARE
unset RECEIVER_UAT_DECODER_SOFTWARE
unset RECEIVER_VDLM2_DECODER_SOFTWARE
unset RECEIVER_PROJECT_BRANCH
unset RECEIVER_DEVELOPMENT_MODE
unset RECEIVER_LOGGING_ENABLED
unset RECEIVER_LOG_FILE
unset RECEIVER_MTA
# Check if any errors were encountered by any child scripts
if [[ $? != 0 ]] ; then
exit 1
else
exit 0
fi