More merge changes.

portal
Joseph Prochazka 2024-08-24 03:43:12 -04:00
rodzic 529946436d
commit 4957427459
3 zmienionych plików z 0 dodań i 769 usunięć

Wyświetl plik

@ -1,33 +0,0 @@
#!/bin/bash
## INCLUDE EXTERNAL SCRIPTS
source ${RECEIVER_BASH_DIRECTORY}/variables.sh
source ${RECEIVER_BASH_DIRECTORY}/functions.sh
## VARIABLES
python_path=`which python3`
## SETUP ADVANCED PORTAL FEATURES
log_heading "Setting up advanced portal features"
log_message "Creating the Python configuration file needed for logging"
tee ${RECEIVER_BUILD_DIRECTORY}/portal/python/config.json > /dev/null <<EOF
{
"database":{"type":"${ADSB_PORTAL_DATABASE_ENGINE,,}",
"host":"${ADSB_PORTAL_DATABASE_HOSTNAME}",
"user":"${ADSB_PORTAL_DATABASE_USER}",
"passwd":"${ADSB_PORTAL_DATABASE_PASSWORD1}",
"db":"${ADSB_PORTAL_DATABASE_NAME}"}
}
EOF
# Create the cron jobs responsible for logging and maintenance.
log_message "Creating cron file needed to run the Python logging scripts"
sudo tee /etc/cron.d/adsb-receiver-flight-logging > /dev/null <<EOF
* * * * * root ${python_path} ${RECEIVER_BUILD_DIRECTORY}/portal/python/flights.py
0 0 * * * root ${python_path} ${RECEIVER_BUILD_DIRECTORY}/portal/python/maintenance.py
EOF

Wyświetl plik

@ -1,332 +0,0 @@
#!/bin/bash
<<<<<<< HEAD
### VARIABLES
collectd_config="/etc/collectd/collectd.conf"
collectd_cron_file="/etc/cron.d/adsb-receiver-performance-graphs"
dump1090_max_range_rrd_database="/var/lib/collectd/rrd/localhost/dump1090-localhost/dump1090_range-max_range.rrd"
dump1090_messages_local_rrd_database="/var/lib/collectd/rrd/localhost/dump1090-localhost/dump1090_messages-local_accepted.rrd"
### INCLUDE EXTERNAL SCRIPTS
=======
## INCLUDE EXTERNAL SCRIPTS
>>>>>>> master
source ${RECEIVER_BASH_DIRECTORY}/variables.sh
source ${RECEIVER_BASH_DIRECTORY}/functions.sh
<<<<<<< HEAD
=======
### VARIABLES
collectd_config="/etc/collectd/collectd.conf"
collectd_cron_file="/etc/cron.d/adsb-receiver-performance-graphs"
dump1090_max_range_rrd="/var/lib/collectd/rrd/localhost/dump1090-localhost/dump1090_range-max_range.rrd"
dump1090_messages_local_rrd="/var/lib/collectd/rrd/localhost/dump1090-localhost/dump1090_messages-local_accepted.rrd"
>>>>>>> master
### BEGIN SETUP
log_heading "Setting up collectd performance graphs"
CheckPackage collectd-core
CheckPackage rrdtool
## CONFIRM INSTALLED PACKAGES
<<<<<<< HEAD
echo -e "\e[94m Checking which dump1090 fork is installed...\e[97m"
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"
=======
if [[ -z "${dump1090_installed}" || -z "${dump1090_fork}" ]] ; then
log_message "Checking which dump1090 fork is installed"
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
>>>>>>> master
fi
## BACKUP AND REPLACE COLLECTD.CONF
# Check if the collectd config file exists and if so back it up.
if [[ -f "${collectd_config}" ]] ; then
<<<<<<< HEAD
echo -e "\e[94m Backing up the current collectd.conf file...\e[97m"
=======
log_message "Backing up the current collectd.conf file"
>>>>>>> master
sudo cp ${collectd_config} ${collectd_config}.bak
fi
# Generate new collectd config.
<<<<<<< HEAD
echo -e "\e[94m Replacing the current collectd.conf file...\e[97m"
=======
log_message "Replacing the current collectd.conf file"
>>>>>>> master
sudo tee ${collectd_config} > /dev/null <<EOF
# Config file for collectd(1).
##############################################################################
# Global #
##############################################################################
Hostname "localhost"
#----------------------------------------------------------------------------#
# Interval at which to query values. This may be overwritten on a per-plugin #
# base by using the 'Interval' option of the LoadPlugin block: #
# <LoadPlugin foo> #
# Interval 60 #
# </LoadPlugin> #
#----------------------------------------------------------------------------#
Interval 60
Timeout 2
ReadThreads 5
WriteThreads 1
EOF
# Dump1090 specific values.
<<<<<<< HEAD
if [[ "${dump1090_is_installed}" = "true" ]] ; then
=======
if [[ "${dump1090_installed}" == "true" ]] ; then
>>>>>>> master
sudo tee -a ${collectd_config} > /dev/null <<EOF
#----------------------------------------------------------------------------#
# Added types for dump1090. #
# Make sure the path to dump1090.db is correct. #
#----------------------------------------------------------------------------#
TypesDB "${RECEIVER_BUILD_DIRECTORY}/portal/graphs/dump1090.db" "/usr/share/collectd/types.db"
EOF
fi
# Config for all installations.
sudo tee -a ${collectd_config} > /dev/null <<EOF
##############################################################################
# Logging #
##############################################################################
LoadPlugin syslog
<Plugin syslog>
LogLevel info
</Plugin>
##############################################################################
# LoadPlugin section #
#----------------------------------------------------------------------------#
# Specify what features to activate. #
##############################################################################
LoadPlugin rrdtool
LoadPlugin table
LoadPlugin interface
LoadPlugin memory
LoadPlugin cpu
LoadPlugin cpufreq
LoadPlugin thermal
LoadPlugin aggregation
LoadPlugin match_regex
LoadPlugin df
LoadPlugin disk
LoadPlugin curl
<LoadPlugin python>
Globals true
</LoadPlugin>
##############################################################################
# Plugin configuration #
##############################################################################
<Plugin rrdtool>
DataDir "/var/lib/collectd/rrd"
</Plugin>
<Plugin "aggregation">
<Aggregation>
Plugin "cpu"
Type "cpu"
GroupBy "Host"
GroupBy "TypeInstance"
CalculateAverage true
</Aggregation>
</Plugin>
<Plugin "df">
MountPoint "/"
IgnoreSelected false
ReportInodes true
</Plugin>
<Plugin "interface">
Interface "eth0"
Interface "wlan0"
</Plugin>
EOF
# Device specific values.
# Raspberry Pi: b03112
if [[ "${RECEIVER_CPU_REVISION}" = "b03112" ]] ; then
sudo tee -a ${collectd_config} > /dev/null <<EOF
<Plugin table>
<Table "/sys/class/thermal/thermal_zone0/temp">
Instance localhost
Separator " "
<Result>
Type gauge
InstancePrefix "cpu_temp"
ValuesFrom 0
</Result>
</Table>
</Plugin>
<Plugin "disk">
Disk "mmcblk0"
IgnoreSelected false
</Plugin>
EOF
fi
# Dump1090 specific values.
<<<<<<< HEAD
if [[ "${dump1090_is_installed}" = "true" ]] ; then
=======
if [[ "${dump1090_installed}" == "true" ]] ; then
>>>>>>> master
sudo tee -a ${collectd_config} > /dev/null <<EOF
#----------------------------------------------------------------------------#
# Configure the dump1090-tools 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 #
#----------------------------------------------------------------------------#
<Plugin python>
ModulePath "${RECEIVER_BUILD_DIRECTORY}/portal/graphs"
LogTraces true
Import "dump1090"
<Module dump1090>
<Instance localhost>
URL "http://localhost/dump1090"
</Instance>
</Module>
</Plugin>
EOF
fi
# Remaining config for all installations.
sudo tee -a ${collectd_config} > /dev/null <<EOF
<Chain "PostCache">
<Rule>
<Match regex>
Plugin "^cpu\$"
PluginInstance "^[0-9]+\$"
</Match>
<Target write>
Plugin "aggregation"
</Target>
Target stop
</Rule>
Target "write"
</Chain>
EOF
## RELOAD COLLECTD
log_message "Reloading collectd so the new configuration is used"
sudo service collectd force-reload
## EDIT CRONTAB
<<<<<<< HEAD
echo -e "\e[94m Making the make-collectd-graphs.sh script executable...\e[97m"
chmod +x ${RECEIVER_BUILD_DIRECTORY}/portal/graphs/make-collectd-graphs.sh
if [[ -f "${collectd_cron_file}" ]] ; then
echo -e "\e[94m Removing previously installed performance graphs cron file...\e[97m"
sudo rm -f ${collectd_cron_file}
fi
echo -e "\e[94m Adding performance graphs cron file...\e[97m"
=======
if [[ ! -x "${RECEIVER_BUILD_DIRECTORY}/portal/graphs/make-collectd-graphs.sh" ]] ; then
log_message "Making the make-collectd-graphs.sh script executable"
chmod +x ${RECEIVER_BUILD_DIRECTORY}/portal/graphs/make-collectd-graphs.sh
fi
if [[ -f "${collectd_cron_file}" ]] ; then
log_message "Removing previously installed performance graphs cron file"
sudo rm -f ${collectd_cron_file}
fi
log_message "Adding performance graphs cron file"
>>>>>>> master
sudo tee ${collectd_cron_file} > /dev/null <<EOF
# Updates the portal's performance graphs.
#
# Every 5 minutes new hourly graphs are generated.
# Every 10 minutes new six hour graphs are generated.
# At 2, 12, 22, 32, 42, and 52 minutes past the hour new 24 hour graphs are generated.
# At 4, 24, and 44 minuites past the hour new 7 day graphs are generated.
# At 6 minutes past the hour new 30 day graphs are generated.
# At 8 minutes past every 12th hour new 365 day graphs are generated.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
*/5 * * * * root bash ${RECEIVER_BUILD_DIRECTORY}/portal/graphs/make-collectd-graphs.sh 1h >/dev/null 2>&1
*/10 * * * * root bash ${RECEIVER_BUILD_DIRECTORY}/portal/graphs/make-collectd-graphs.sh 6h >/dev/null 2>&1
2,12,22,32,42,52 * * * * root bash ${RECEIVER_BUILD_DIRECTORY}/portal/graphs/make-collectd-graphs.sh 24h >/dev/null 2>&1
4,24,44 * * * * root bash ${RECEIVER_BUILD_DIRECTORY}/portal/graphs/make-collectd-graphs.sh 7d >/dev/null 2>&1
6 * * * * root bash ${RECEIVER_BUILD_DIRECTORY}/portal/graphs/make-collectd-graphs.sh 30d >/dev/null 2>&1
8 */12 * * * root bash ${RECEIVER_BUILD_DIRECTORY}/portal/graphs/make-collectd-graphs.sh 365d >/dev/null 2>&1
EOF
# Update max_range.rrd to remove the 500 km / ~270 nmi limit.
if [ -f "/var/lib/collectd/rrd/localhost/dump1090-localhost/dump1090_range-max_range.rrd" ]; then
<<<<<<< HEAD
if [[ `rrdinfo ${dump1090_max_range_rrd_database} | grep -c "ds\[value\].max = 1.0000000000e+06"` -eq 0 ]] ; then
echo -e "\e[94m Removing 500km/270mi limit from max_range.rrd...\e[97m"
sudo rrdtool tune ${dump1090_max_range_rrd_database} --maximum "value:1000000"
=======
if [[ `rrdinfo ${dump1090_max_range_rrd} | grep -c "ds\[value\].max = 1.0000000000e+06"` -eq 0 ]] ; then
log_message "Removing 500km/270mi limit from max_range.rrd"
sudo rrdtool tune ${dump1090_max_range_rrd} --maximum "value:1000000"
>>>>>>> master
fi
fi
# Increase size of weekly messages table to 8 days
<<<<<<< HEAD
if [ -f ${dump1090_messages_local_rrd_database} ]; then
if [[ `rrdinfo ${dump1090_messages_local_rrd_database} | grep -c "rra\[6\]\.rows = 1260"` -eq 1 ]] ; then
echo -e "\e[94m Increasing weekly table size to 8 days in messages-local_accepted.rrd...\e[97m"
sudo rrdtool tune ${dump1090_messages_local_rrd_database} 'RRA#6:=1440' 'RRA#7:=1440' 'RRA#8:=1440'
fi
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}
=======
if [[ -f ${dump1090_messages_local_rrd} ]]; then
if [[ `rrdinfo ${dump1090_messages_local_rrd} | grep -c "rra\[6\]\.rows = 1260"` -eq 1 ]] ; then
log_message "Increasing weekly table size to 8 days in messages-local_accepted.rrd"
sudo rrdtool tune ${dump1090_messages_local_rrd} 'RRA#6:=1440' 'RRA#7:=1440' 'RRA#8:=1440'
fi
fi
>>>>>>> master

Wyświetl plik

@ -1,404 +0,0 @@
#!/bin/bash
## INCLUDE EXTERNAL SCRIPTS
source ${RECEIVER_BASH_DIRECTORY}/variables.sh
source ${RECEIVER_BASH_DIRECTORY}/functions.sh
## BEGIN SETUP
clear
log_project_title ${RECEIVER_PROJECT_TITLE}
log_title_heading "Setting up the ADS-B Portal"
log_title_message "------------------------------------------------------------------------------"
if ! whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "ADS-B Portal Setup" \
--yesno "The ADS-B Portal 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 has been seen in the past as well as view more detailed information on each of these aircraft.\n\nDo you wish to continue setting up the ADS-B Portal?" \
23 78; then
echo ""
log_alert_heading "INSTALLATION HALTED"
log_alert_message "Setup has been halted at the request of the user"
echo ""
log_title_message "------------------------------------------------------------------------------"
log_title_heading "ADS-B Receiver Portal setup halted"
echo ""
exit 1
fi
## GATHER INSTALLATION INFORMATION FROM THE USER
# -----------------------------------------------------------------
# TODO: CHECK IF THE ADS-B PORTAL BACKEND AND FRONTEND IS INSTALLED
# -----------------------------------------------------------------
portal_installed = "false"
if [[ -f "" ]] ; then
portal_installed = "true"
fi
## EXECUTE THE PROPER ADS-B PORTAL DATABASE CREATION SCRIPT
if [[ "${portal_installed}" = "false" ]]
log_heading "Performing database setup"
log_message "Asking the user which type of database engine should be used"
database_engine = $(whiptail \
--backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "Choose Database Engine" \
--nocancel \
--menu "Choose which database engine to use" \
11 80 2 \
"MySQL" "" "PostgreSQL" "" "SQLite" "")
log_message "Database engine set to ${database_engine}"
check_package collectd-core
check_package rrdtool
check_package libpython3-stdlib
if [[ "$RECEIVER_MTA" == "POSTFIX" || -z "$RECEIVER_MTA" ]]; then
check_package postfix
fi
case $RECEIVER_OS_DISTRIBUTION in
ubuntu)
php_version=""
;;
debian)
if [[ "${RECEIVER_OS_CODE_NAME}" == "bookworm" ]]; then php_version="8.2"; fi
if [[ "${RECEIVER_OS_CODE_NAME}" == "bullseye" ]]; then php_version="7.4"; fi
;;
esac
check_package php${php_version}-cgi
if [[ ! "${php_version}" == "" && "${php_version}" < "8" ]]; then
check_package php${php_version}-json
fi
if [[ "${advanced_installation}" = "true" ]]; then
check_package python3-pyinotify
check_package python3-apt
case "${database_engine}" in
"MySQL")
check_package mariadb-client
check_package python3-mysqldb
check_package php${php_version}-mysql
;;
"SQLite")
check_package sqlite3
check_package php${php_version}-sqlite3
;;
esac
else
check_package php${php_version}-xml
fi
log_message "Reloading the Lighttpd server"
sudo service lighttpd force-reload
echo ""
## SETUP THE ADS-B PORTAL
log_heading "Begining ADS-B Portal setup"
if [[ "${portal_installed}" = "true" && "${advanced_installation}" = "false" ]]; then
log_message "Backing up the file ${lighttpd_document_root}/data/administrators.xml"
sudo mv $lighttpd_document_root/data/administrators.xml $lighttpd_document_root/data/administrators.backup.xml
log_message "Backing up the file ${lighttpd_document_root}/data/blogPosts.xml"
sudo mv $lighttpd_document_root/data/blogPosts.xml $lighttpd_document_root/data/blogPosts.backup.xml
log_message "Backing up the file ${lighttpd_document_root}/data/flightNotifications.xml"
sudo mv $lighttpd_document_root/data/flightNotifications.xml $lighttpd_document_root/data/flightNotifications.backup.xml
log_message "Backing up the file ${lighttpd_document_root}/data/settings.xml"
sudo mv $lighttpd_document_root/data/settings.xml $lighttpd_document_root/data/settings.backup.xml
log_message "Backing up the file ${lighttpd_document_root}/data/links.xml"
sudo mv $lighttpd_document_root/data/links.xml $lighttpd_document_root/data/links.backup.xml
log_message "Backing up the file ${lighttpd_document_root}/data/notifications.xml"
sudo mv $lighttpd_document_root/data/notifications.xml $lighttpd_document_root/data/notifications.backup.xml
fi
if [ -f $lighttpd_document_root/index.lighttpd.html ]; then
log_message "Removing default Lighttpd index file from document root"
sudo rm $lighttpd_document_root/index.lighttpd.html
fi
log_message "Placing portal files in Lighttpd's root directory"
sudo cp -R $RECEIVER_BUILD_DIRECTORY/portal//html/* $lighttpd_document_root
if [[ "${portal_installed}" = "true" && "${advanced_installation}" = "false" ]]; then
log_message "Restoring the backup copy of the file ${lighttpd_document_root}/data/administrators.xml"
sudo mv $lighttpd_document_root/data/administrators.backup.xml $lighttpd_document_root/data/administrators.xml
log_message "Restoring the backup copy of the file ${lighttpd_document_root}/data/blogPosts.xml"
sudo mv $lighttpd_document_root/data/blogPosts.backup.xml $lighttpd_document_root/data/blogPosts.xml
log_message "Restoring the backup copy of the file ${lighttpd_document_root}/data/flightNotifications.xml"
sudo mv $lighttpd_document_root/data/flightNotifications.backup.xml $lighttpd_document_root/data/flightNotifications.xml
log_message "Restoring the backup copy of the file ${lighttpd_document_root}/data/settings.xml"
sudo mv $lighttpd_document_root/data/settings.backup.xml $lighttpd_document_root/data/settings.xml
log_message "Restoring the backup copy of the file ${lighttpd_document_root}/data/links.xml"
sudo mv $lighttpd_document_root/data/links.backup.xml $lighttpd_document_root/data/links.xml
log_message "Restoring the backup copy of the file ${lighttpd_document_root}/data/notifications.xml"
sudo mv $lighttpd_document_root/data/notifications.backup.xml $lighttpd_document_root/data/notifications.xml
fi
log_message "Making the directory ${lighttpd_document_root}/graphs/ writable"
sudo chmod 777 $lighttpd_document_root/graphs/
log_message "Making the directory ${lighttpd_document_root}/classes/ writable"
sudo chmod 777 $lighttpd_document_root/classes/
log_message "Making the directory ${lighttpd_document_root}/data/ writable"
sudo chmod 777 $lighttpd_document_root/data/
log_message "Making the files contained within the directory ${lighttpd_document_root}/data/ writable"
sudo chmod 666 $lighttpd_document_root/data/*
if [[ $(dpkg-query -W -f='${STATUS}' dump1090-fa 2>/dev/null | grep -c "ok installed") -eq 1 ]]; then
log_message "Checking for the file upintheair.json in the dump1090 HTML folder"
if [[ -f "/usr/share/dump1090-mutability/html/upintheair.json" || -f "/usr/share/dump1090-fa/html/upintheair.json" ]]; then
log_message "Copying the file upintheair.json from the dump1090 HTML folder to the dump978 HTML folder"
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 $lighttpd_document_root/dump978/
fi
fi
fi
if [[ -f "/etc/lighttpd/conf-available/87-adsb-portal.conf" ]] ; then
log_message "Removing the existing Lighttpd ADS-B Portal configuration file"
sudo rm -f /etc/lighttpd/conf-available/87-adsb-portal.conf
fi
log_message "Adding the Lighttpd portal configuration file"
sudo touch /etc/lighttpd/conf-available/87-adsb-portal.conf
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/87-adsb-portal.conf > /dev/null <<EOF
# Add dump1090 as an alias to the dump1090-fa HTML folder.
alias.url += (
"/dump1090/data/" => "/run/dump1090-fa/",
"/dump1090/" => "/usr/share/skyaware/html/"
)
# Redirect the slash-less dump1090 URL
url.redirect += (
"^/dump1090$" => "/dump1090/"
)
# Add CORS header
\$HTTP["url"] =~ "^/dump1090/data/.*\.json$" {
setenv.add-response-header = ( "Access-Control-Allow-Origin" => "*" )
}
EOF
fi
if [[ ! -L "/etc/lighttpd/conf-enabled/87-adsb-portal.conf" ]] ; then
log_message "Enabling the Lighttpd portal configuration file"
sudo ln -s /etc/lighttpd/conf-available/87-adsb-portal.conf /etc/lighttpd/conf-enabled/87-adsb-portal.conf
fi
if [[ "${portal_installed}" = "false" ]] ; then
log_message "Enabling the Lighttpd fastcgi-php module"
echo ""
sudo lighty-enable-mod fastcgi-php
echo ""
fi
if pgrep "lighttpd" > /dev/null; then
log_message "Reloading Lighttpd"
sudo service lighttpd force-reload
else
log_message "Starting Lighttpd"
sudo service lighttpd start
fi
## SETUP THE ADS-B PORTAL MYSQL DATABASE
if [[ "${portal_installed}" = "false" && "${advanced_installation}" = "true" && "${database_engine}" = "MySQL" && "${database_exists}" = "false" ]]; then
if [[ $(dpkg-query -W -f='${STATUS}' mariadb-server-10.1 2>/dev/null | grep -c "ok installed") -eq 1 ]] ; then
log_message "Switching the default MySQL plugin from unix_socket to mysql_native_password"
sudo mysql -u${database_admin_user} -p${database_admin_password1} -h ${database_hostname} -e "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'unix_socket';"
log_message "Flushing privileges on the MySQL (MariaDB) server"
sudo mysql -u${database_admin_user} -p${database_admin_password1} -h ${database_hostname} -e "FLUSH PRIVILEGES;"
log_message "Reloading MySQL (MariaDB)"
sudo service mysql force-reload
fi
log_message "Attempting to log into the MySQL server using the supplied administrator credentials"
while ! sudo mysql -u${database_admin_user} -p${database_admin_password1} -h ${database_hostname} -e ";"; do
log_message "Unable to log into the MySQL server using the supplied administrator credentials"
whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "Create 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
database_admin_password1=""
database_admin_password2=""
log_message "Asking for the MySQL administrator username"
database_admin_user_title="MySQL Administrator User"
while [[ -z $database_admin_user ]]; do
database_admin_user=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "${database_admin_user_title}" \
--nocancel \
--inputbox "Enter the MySQL administrator user." \
8 78 \
"${database_admin_user}" 3>&1 1>&2 2>&3)
database_admin_user_title="MySQL Administrator User (REQUIRED)"
done
log_message "Asking for the MySQL administrator password"
database_admin_password1_title="MySQL Administrator Password"
while [[ -z $database_admin_password1 ]]; do
database_admin_password1=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "${database_admin_password1_title}" \
--nocancel \
--passwordbox "Enter the password for the MySQL adminitrator user." \
8 78 3>&1 1>&2 2>&3)
database_admin_password1_title="MySQL Administrator Password (REQUIRED)"
done
log_message "Asking to confirm the MySQL administrator password"
database_admin_password2_title="Confirm The MySQL Administrator Password"
while [[ -z $database_admin_password2 ]] ; do
database_admin_password2=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "${database_admin_password2_title}" \
--nocancel \
--passwordbox "Confirm the password for the MySQL adminitrator user." \
8 78 3>&1 1>&2 2>&3)
database_admin_password2_title="Confirm The MySQL Administrator Password (REQUIRED)"
done
while [[ ! "${database_admin_password1}" == "${database_admin_password2}" ]]; do
log_message "Failed to log into MySQL using the supplied credentials"
database_admin_password1=""
database_admin_password2=""
whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "Passwords Did Not Match" \
--msgbox "Passwords did not match.\nPlease enter your password again." \
9 78
log_message "Asking for the MySQL administrator password"
database_admin_password1_title="MySQL Administrator Password"
while [[ -z $database_admin_password1 ]] ; do
database_admin_password1=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "${database_admin_password1_title}" \
--nocancel \
--passwordbox "Enter the password for the MySQL adminitrator user." \
8 78 3>&1 1>&2 2>&3)
database_admin_password1_title="MySQL Administrator Password (REQUIRED)"
done
log_message "Asking to confirm the MySQL administrator password"
database_admin_password2_title="Confirm The MySQL Administrator Password"
while [[ -z $database_admin_password2 ]] ; do
database_admin_password2=$(whiptail --backtitle "${RECEIVER_PROJECT_TITLE}" \
--title "${database_admin_password2_title}" \
--nocancel \
--passwordbox "Confirm the password for the MySQL adminitrator user." \
8 78 3>&1 1>&2 2>&3)
database_admin_password2_title="Confirm The MySQL Administrator Password (REQUIRED)"
done
done
log_message "Attempting to log into the MySQL server using the new administrator credentials"
done
log_message "Successfully logged into the MySQL server using the new administrator credentials"
log_message "Creating the MySQL database ${database_name}"
sudo mysql -u${database_admin_user} -p${database_admin_password1} -h ${database_hostname} -e "CREATE DATABASE ${database_name};"
log_message "Creating the MySQL user ${database_user}"
if [[ "${local_mysql_server}" = "false" ]] ; then
sudo mysql -u${database_admin_user} -p${database_admin_password1} -h ${database_hostname} -e "CREATE USER '${database_user}'@'%' IDENTIFIED BY \"${database_password1}\";"
else
sudo mysql -u${database_admin_user} -p${database_admin_password1} -h ${database_hostname} -e "CREATE USER '${database_user}'@'localhost' IDENTIFIED BY \"${database_password1}\";"
fi
log_message "Granting priviledges on the MySQL database ${database_name} to the user ${database_user}"
sudo mysql -u${database_admin_user} -p${database_admin_password1} -h ${database_hostname} -e "GRANT ALL PRIVILEGES ON ${database_name}.* TO '${database_user}'@'localhost';"
log_message "Flushing priviledges on the MySQL database server"
sudo mysql -u${database_admin_user} -p${database_admin_password1} -h ${database_hostname} -e "FLUSH PRIVILEGES;"
fi
## SETUP THE PERFORMANCE GRAPHS USING THE SCRIPT GRAPHS.SH
chmod +x $RECEIVER_BASH_DIRECTORY/portal/graphs.sh
$RECEIVER_BASH_DIRECTORY/portal/graphs.sh
if [[ $? -ne 0 ]] ; then
echo ""
log_alert_message "THE SCRIPT GRAPHS.SH ENCOUNTERED AN ERROR"
echo ""
exit 1
fi
## SETUP COMMON PORTAL FEATURES
if [ "${database_engine}" = "MySQL" ]; then
export ADSB_PORTAL_DATABASE_ENGINE=$database_engine
export ADSB_PORTAL_DATABASE_HOSTNAME=$database_hostname
export ADSB_PORTAL_DATABASE_USER=$database_user
export ADSB_PORTAL_DATABASE_PASSWORD1=$database_password1
export ADSB_PORTAL_DATABASE_NAME=$database_name
elif [ "${database_engine}" = "SQLite" ]; then
if [ -z $database_name ] ; then
if [ ! -f $lighttpd_document_root/data/portal.sqlite ]; then
log_message "Creating an empty SQLite database file"
sudo touch $lighttpd_document_root/data/portal.sqlite
log_message "Setting write permissions on the empty SQLite database file"
sudo chmod 666 $lighttpd_document_root/data/portal.sqlite
fi
database_name="${lighttpd_document_root}/data/portal.sqlite"
fi
export ADSB_PORTAL_DATABASE_ENGINE=$database_engine
export ADSB_PORTAL_DATABASE_HOSTNAME=""
export ADSB_PORTAL_DATABASE_USER=""
export ADSB_PORTAL_DATABASE_PASSWORD1=""
export ADSB_PORTAL_DATABASE_NAME=$database_name
else
export ADSB_PORTAL_DATABASE_ENGINE="xml"
export ADSB_PORTAL_DATABASE_HOSTNAME=""
export ADSB_PORTAL_DATABASE_USER=""
export ADSB_PORTAL_DATABASE_PASSWORD1=""
export ADSB_PORTAL_DATABASE_NAME=""
fi
## SETUP ADVANCED PORTAL FEATURES
if [[ "${advanced_installation}" == "true" ]] ; then
chmod +x ${RECEIVER_BASH_DIRECTORY}/portal/advanced.sh
${RECEIVER_BASH_DIRECTORY}/portal/advanced.sh
if [[ $? -ne 0 ]] ; then
echo ""
log_alert_message "THE SCRIPT ADVANCED.SH ENCOUNTERED AN ERROR"
echo ""
exit 1
fi
fi
## SETUP ADS-B PORTAL BACKEND
## SETUP ADS-B PORTAL FRONTEND
## EXECUTE THE PERFORMANCE GRAPHS SETUP SCRIPT
log_heading "Performing performance graphs setup"
log_message "Executing the performance graphs setup script"
chmod +x ${RECEIVER_BASH_DIRECTORY}/portal/graphs.sh
${RECEIVER_BASH_DIRECTORY}/portal/graphs.sh
if [[ $? -ne 0 ]] ; then
log_alert_heading "THE SCRIPT GRAPHS.SH ENCOUNTERED AN ERROR"
log_alert_message "Setup has been halted due to error reported by the graphs.sh script"
echo ""
log_title_message "------------------------------------------------------------------------------"
log_title_heading "ADS-B Portal setup has been halted"
exit 1
fi
## SETUP COMPLETE
log_heading "Performing post setup steps"
echo ""
log_message "Entering the ADS-B Receiver Project root directory"
cd ${RECEIVER_ROOT_DIRECTORY}
echo ""
log_title_message "------------------------------------------------------------------------------"
log_title_heading "ADS-B Portal setup is complete"
echo ""
exit 0