Allow remote MySQL setup.

pull/186/head
Joe Prochazka 2016-04-29 23:25:14 -04:00
rodzic 6e74ee0812
commit 6e4b3e830a
1 zmienionych plików z 91 dodań i 78 usunięć

Wyświetl plik

@ -159,7 +159,8 @@ if [[ $ADVANCED =~ ^[yY]$ ]]; then
fi fi
fi fi
# Check for prerequisite packages. ## CHECK FOR PREREQUISITE PACKAGES
echo -e "\033[33m" echo -e "\033[33m"
echo "Installing packages needed to build and fulfill dependencies..." echo "Installing packages needed to build and fulfill dependencies..."
echo -e "\033[37m" echo -e "\033[37m"
@ -172,84 +173,95 @@ if [[ $ADVANCED =~ ^[yY]$ ]]; then
if [[ $LOCALDATABASE != 2 ]]; then if [[ $LOCALDATABASE != 2 ]]; then
# Install MySQL locally. # Install MySQL locally.
CheckPackage mysql-server CheckPackage mysql-server
CheckPackage mysql-client
fi fi
CheckPackage mysql-client
CheckPackage php5-mysql CheckPackage php5-mysql
CheckPackage python-mysqldb CheckPackage python-mysqldb
fi fi
fi fi
# Create the database If advanced features was selected if [[ $INSTALLED == "n" ]]; then
if [[ $ADVANCED =~ ^[yY]$ ]]; then
if [[ $DATABASEENGINE != 2 ]]; then ## CREATE THE DATABASE IF ADVANCED FEATURES WAS SELECTED
echo -e "\033[31m"
echo "Gathering Database Information" if [[ $ADVANCED =~ ^[yY]$ ]]; then
echo -e "\033[33m" if [[ $DATABASEENGINE != 2 ]]; then
echo "Please supply the information pertaining to the new password when asked." echo -e "\033[31m"
echo "" echo "Gathering Database Information"
echo "If the database will be hosted locally on this device a database will be" echo -e "\033[33m"
echo "created automatically for you. If you are hosting your database remotely" echo "Please supply the information pertaining to the new password when asked."
echo "you will need to manually create the database and user on the remote device." echo ""
echo -e "\033[37m" echo "If the database will be hosted locally on this device a database will be"
if [[ $LOCALDATABASE == 2 ]]; then echo "created automatically for you. If you are hosting your database remotely"
# Ask for remote MySQL address if the database is hosted remotely. echo "you will need to manually create the database and user on the remote device."
read -p "Remote MySQL Server Address: " DATABASEHOST echo -e "\033[37m"
else
DATABASEHOST="localhost" DATABASEHOST="localhost"
fi if [[ $LOCALDATABASE == 2 ]]; then
read -p "Password for MySQL root user: " MYSQLROOTPASSWORD # Ask for remote MySQL address if the database is hosted remotely.
read -p "New Database Name: " DATABASENAME read -p "Remote MySQL Server Address: " DATABASEHOST
read -p "New Database User Name: " DATABASEUSER
read -p "New Database User Password: " DATABASEPASSWORD
# Database creation can only be handled locally.
if [[ $LOCALDATABASE != 2 ]]; then
if [[ $DATABASEENGINE == 1 ]] || [[ $DATABASEENGINE == "" ]]; then
echo -e "\033[33m"
echo -e "Creating MySQL database and user...\033[37m"
mysql -uroot -p${MYSQLROOTPASSWORD} -e "CREATE DATABASE ${DATABASENAME};"
mysql -uroot -p${MYSQLROOTPASSWORD} -e "CREATE USER '${DATABASEUSER}'@'localhost' IDENTIFIED BY \"${DATABASEPASSWORD}\";";
mysql -uroot -p${MYSQLROOTPASSWORD} -e "GRANT ALL PRIVILEGES ON ${DATABASENAME}.* TO '${DATABASEUSER}'@'localhost';"
mysql -uroot -p${MYSQLROOTPASSWORD} -e "FLUSH PRIVILEGES;"
fi fi
fi read -p "Password for MySQL root user: " MYSQLROOTPASSWORD
echo -e "\033[31m" # Check that the supplied password is correct.
echo "BE SURE TO WRITE THIS INFORMATION DOWN." while ! mysql -u root -p$MYSQLROOTPASSWORD -h $DATABASEHOST -e ";" ; do
echo -e "\033[33m" echo -e "\033[31m"
echo "This information will be needed in order to complete the installation of the portal." echo -e "Unable to connect to the MySQL server using the supplied password.\033[37m"
echo "" read -p "Password for MySQL root user: " MYSQLROOTPASSWORD
if [[ $LOCALDATABASE == 2 ]]; then done
echo -e "\033[31mNOTE:"
echo "Being you are hosting your database remotely you will need this information to create" read -p "New Database Name: " DATABASENAME
echo "both the database and database user on your remote database server." read -p "New Database User Name: " DATABASEUSER
read -p "New Database User Password: " DATABASEPASSWORD
# Create the database and user as well as assign permissions.
if [[ $DATABASEENGINE == 1 ]] || [[ $DATABASEENGINE == "" ]]; then
echo -e "\033[33m"
echo -e "Creating MySQL database and user...\033[37m"
mysql -uroot -p${MYSQLROOTPASSWORD} -h $DATABASEHOST -e "CREATE DATABASE ${DATABASENAME};"
mysql -uroot -p${MYSQLROOTPASSWORD} -h $DATABASEHOST -e "CREATE USER '${DATABASEUSER}'@'localhost' IDENTIFIED BY \"${DATABASEPASSWORD}\";";
mysql -uroot -p${MYSQLROOTPASSWORD} -h $DATABASEHOST -e "GRANT ALL PRIVILEGES ON ${DATABASENAME}.* TO '${DATABASEUSER}'@'localhost';"
mysql -uroot -p${MYSQLROOTPASSWORD} -h $DATABASEHOST -e "FLUSH PRIVILEGES;"
fi
echo -e "\033[31m"
echo "BE SURE TO WRITE THIS INFORMATION DOWN."
echo -e "\033[33m" echo -e "\033[33m"
fi echo "This information will be needed in order to complete the installation of the portal."
echo "Database Server: ${DATABASEHOST}" echo ""
echo "Database User: ${DATABASEUSER}" if [[ $LOCALDATABASE == 2 ]]; then
echo "Database Password: ${DATABASEPASSWORD}" echo -e "\033[31mNOTE:"
echo "Database Name: ${DATABASENAME}" echo "Being you are hosting your database remotely you will need this information to create"
echo -e "\033[37m" echo "both the database and database user on your remote database server."
read -p "Press enter to continue..." CONTINUE echo -e "\033[33m"
fi fi
echo "Database Server: ${DATABASEHOST}"
echo "Database User: ${DATABASEUSER}"
echo "Database Password: ${DATABASEPASSWORD}"
echo "Database Name: ${DATABASENAME}"
echo -e "\033[37m"
read -p "Press enter to continue..." CONTINUE
# Setup the flight logging script. fi
echo -e "\033[33m"
echo -e "Creating configuration file...\033[37m" ## SETUP FLIGHT LOGGING SCRIPT
case $DATABASEENGINE in
"2") echo -e "\033[33m"
tee ~/adsb-receiver/build/portal/logging/config.json > /dev/null <<EOF echo -e "Creating configuration file...\033[37m"
case $DATABASEENGINE in
"2")
tee $BUILDDIR/portal/logging/config.json > /dev/null <<EOF
{ {
"database":{"type":"sqlite", "database":{"type":"sqlite",
"host":"", "host":"",
"user":"", "user":"",
"passwd":"", "passwd":"",
"db":"${HTMLDIR}/data/portal.sqlite"} "db":"${DOCUMENTROOT}/data/portal.sqlite"}
} }
EOF EOF
;; ;;
*) *)
tee ~/adsb-receiver/build/portal/logging/config.json > /dev/null <<EOF tee $BUILDDIR/portal/logging/config.json > /dev/null <<EOF
{ {
"database":{"type":"mysql", "database":{"type":"mysql",
"host":"${DATABASEHOST}", "host":"${DATABASEHOST}",
@ -258,33 +270,34 @@ EOF
"db":"${DATABASENAME}"} "db":"${DATABASENAME}"}
} }
EOF EOF
;; ;;
esac esac
# Create and set permissions on the flight logging maintainance script. # Create and set permissions on the flight logging maintainance script.
PYTHONPATH=`which python` PYTHONPATH=`which python`
tee ~/adsb-receiver/build/portal/logging/flights-maint.sh > /dev/null <<EOF tee $BUILDDIR/portal/logging/flights-maint.sh > /dev/null <<EOF
#!/bin/sh #!/bin/sh
while true while true
do do
sleep 30 sleep 30
${PYTHONPATH} ~/adsb-receiver/build/portal/logging/flights.py ${PYTHONPATH} ${BUILDDIR}/portal/logging/flights.py
done done
EOF EOF
chmod +x ~/adsb-receiver/build/portal/logging/flights-maint.sh chmod +x $BUILDDIR/portal/logging/flights-maint.sh
# Add flight logging maintainance script to rc.local. # Add flight logging maintainance script to rc.local.
if ! grep -Fxq "${BUILDDIR}/portal/logging/flights-maint.sh &" /etc/rc.local; then if ! grep -Fxq "${BUILDDIR}/portal/logging/flights-maint.sh &" /etc/rc.local; then
echo -e "\033[33m"
echo -e "Adding startup line to rc.local...\033[37m"
lnum=($(sed -n '/exit 0/=' /etc/rc.local))
((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i ${BUILDDIR}/portal/logging/flights-maint.sh &\n" /etc/rc.local
fi
# Start flight logging.
echo -e "\033[33m" echo -e "\033[33m"
echo -e "Adding startup line to rc.local...\033[37m" echo -e "Starting flight logging...\033[37m"
lnum=($(sed -n '/exit 0/=' /etc/rc.local)) nohup ${BUILDDIR}/portal/logging/flights-maint.sh > /dev/null 2>&1 &
((lnum>0)) && sudo sed -i "${lnum[$((${#lnum[@]}-1))]}i ${BUILDDIR}/portal/logging/flights-maint.sh &\n" /etc/rc.local
fi fi
# Start flight logging.
echo -e "\033[33m"
echo -e "Starting flight logging...\033[37m"
~/adsb-receiver/build/portal/logging/flights-maint.sh &
fi fi
## FINISH CONFIGURATION ## FINISH CONFIGURATION