From 0bc6d684c1397042ffe4038c89ff7de5126fc37e Mon Sep 17 00:00:00 2001 From: Rod Wright Date: Tue, 24 Feb 2026 21:09:59 -0500 Subject: [PATCH] Incorporated changes for release 1.4.5 --- CHANGELOG | 19 + opendrs-initial.sql => database-initial.sql | 2 +- database-update.sh | 31 + opendrs-update.sql => database-update.sql | 6 + db.php.template | 3 +- distfiles/CHANGELOG | 19 + distfiles/create.php | 5 +- distfiles/groups.php | 4 - distfiles/search.php | 4 +- distfiles/settings.php | 4 + distfiles/writeupdetail.php | 3 - distfiles/writeups.php | 7 +- opendrs-update.sh => files-update.sh | 19 +- install.sh | 698 +++++++------------- 14 files changed, 350 insertions(+), 474 deletions(-) rename opendrs-initial.sql => database-initial.sql (99%) create mode 100644 database-update.sh rename opendrs-update.sql => database-update.sql (97%) rename opendrs-update.sh => files-update.sh (75%) diff --git a/CHANGELOG b/CHANGELOG index 331f63f..259e40c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -187,3 +187,22 @@ Changelog trying to insert a null value into the action_reason field of the writeups table (you left the action reason dropdown blank). Previous versions just left it as is without complaint. + +1.4.5 - 2025-12-16 + - Various problems were noted resulting from php's use of UTC as the + default timezone. Now, on installation or upgrade, the installer + gets the correct timezone from the system and sets it as a php + option in a .htaccess file in the install location. This solves + multiple problems and allows today's date and the current time + to be determined from the php date() function as part of the + settings.php once per page load instead of having to query the + database multiple times per page load. Also added the option to + allow apache to read the .htaccess file to the + section of the application's conf file in + /etc/apache2/conf-available + - Renamed the installer's opendrs-update.sh script to files_update.sh + to align with the standardized installation process used by + other applications. + - Changed the install.sh script to align with the standardized + installation process used by other applications. + diff --git a/opendrs-initial.sql b/database-initial.sql similarity index 99% rename from opendrs-initial.sql rename to database-initial.sql index 4fc09c1..da4ba51 100644 --- a/opendrs-initial.sql +++ b/database-initial.sql @@ -69,7 +69,7 @@ CREATE TABLE `config` ( LOCK TABLES `config` WRITE; /*!40000 ALTER TABLE `config` DISABLE KEYS */; INSERT INTO `config` VALUES -(1,'drs_version','1.4.4','1.4.4'), +(1,'drs_version','1.4.5','1.4.5'), (5,'app_name','OpenDRS - Discrepancy Reporting System','OpenDRS Discrepancy Reporting System'), (6,'banner','1','1'), (7,'background_color','0B3144','0B3144'), diff --git a/database-update.sh b/database-update.sh new file mode 100644 index 0000000..9daf2e1 --- /dev/null +++ b/database-update.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# database-update.sh +# OpenLog Online Logbook +# Copyright (C) 2025 Rod Wright + +# SPDX-License-Identifier: GPL-2.0 + + +if [[ $1 == "" ]] +then + echo "This script requires a mysql options file, but none was specified. Aborting." + exit 1 +fi + +mysql_opt_file=$1 +if [[ ! -f $mysql_opt_file ]] +then + echo "The mysql options file specified does not exist. Aborting." + exit 1 +fi + +margs="--defaults-extra-file=$mysql_opt_file" + +# ---------- version x.x.x ---------- +# Nothing to be done for versions prior to 1.4.5 +# ----------------------------------- + +# ---------- version 1.4.5 ---------- +# Nothing to be done +# ----------------------------------- diff --git a/opendrs-update.sql b/database-update.sql similarity index 97% rename from opendrs-update.sql rename to database-update.sql index 5d57bf9..d1fbbe3 100644 --- a/opendrs-update.sql +++ b/database-update.sql @@ -270,3 +270,9 @@ UPDATE config SET value="1.4.3",defaultvalue="1.4.3" WHERE name="drs_version"; -- Update version number UPDATE config SET value="1.4.4",defaultvalue="1.4.4" WHERE name="drs_version"; -- -------------------------------------- + +-- ---------- version 1.4.5 ------------- +-- Update version number +UPDATE config SET value="1.4.5",defaultvalue="1.4.5" WHERE name="drs_version"; +-- -------------------------------------- + diff --git a/db.php.template b/db.php.template index 968032e..fb4974d 100644 --- a/db.php.template +++ b/db.php.template @@ -14,6 +14,7 @@ ** DO NOT EDIT ** ************************************************************************ */ +$appname="APPNAME"; $dbname="DBNAME"; $username="DBUSER"; $dbpass="DBPASS"; @@ -26,7 +27,7 @@ function dberrmsg($dbname) { Could not connect to the $dbname database. Please ensure the MySQL server is running. If this is - the first time you have used OpenDRS, please consult the INSTALL file included in the distribution. + the first time you have used $appname, please consult the INSTALL file included in the distribution. "; diff --git a/distfiles/CHANGELOG b/distfiles/CHANGELOG index 331f63f..259e40c 100644 --- a/distfiles/CHANGELOG +++ b/distfiles/CHANGELOG @@ -187,3 +187,22 @@ Changelog trying to insert a null value into the action_reason field of the writeups table (you left the action reason dropdown blank). Previous versions just left it as is without complaint. + +1.4.5 - 2025-12-16 + - Various problems were noted resulting from php's use of UTC as the + default timezone. Now, on installation or upgrade, the installer + gets the correct timezone from the system and sets it as a php + option in a .htaccess file in the install location. This solves + multiple problems and allows today's date and the current time + to be determined from the php date() function as part of the + settings.php once per page load instead of having to query the + database multiple times per page load. Also added the option to + allow apache to read the .htaccess file to the + section of the application's conf file in + /etc/apache2/conf-available + - Renamed the installer's opendrs-update.sh script to files_update.sh + to align with the standardized installation process used by + other applications. + - Changed the install.sh script to align with the standardized + installation process used by other applications. + diff --git a/distfiles/create.php b/distfiles/create.php index fb5f9cb..6a774a6 100644 --- a/distfiles/create.php +++ b/distfiles/create.php @@ -93,9 +93,6 @@ framework("begin","$appname","New Writeup",$print); // ******** begin database manipulation ******** -// determine today's date and make it the default -$today=date("Y-m-d"); -$now=date("H:i:s"); if (!isset($report_date) || $report_date=="automatic") $report_date=$today; if (!isset($report_time) || $report_time=="automatic") $report_time=$now; @@ -133,7 +130,7 @@ echo "
"; // display the form if (isset($create)) { if ($discrepancy_text!=NULL && $reported_by!=NULL) { - format_message(0,"Writeup created. You may create another writeup or return to Open Writeups page."); + format_message(0,"Writeup created. You may create another writeup or return to View Writeups page."); $preserve=false; } if ($device==NULL) { diff --git a/distfiles/groups.php b/distfiles/groups.php index 3b94d67..4da5865 100644 --- a/distfiles/groups.php +++ b/distfiles/groups.php @@ -113,10 +113,6 @@ framework("begin","$appname","Writeup Groups",$print); // ******** begin database manipulation ******** -// determine today's date and make it the default -$today=date("Y-m-d"); -$now=date("H:i:s"); - // get max report date from writeups table, validate input dates/times and set defaults $maxrepdate_qry=mysqli_query($drs_db,"select max(report_date) from writeups"); $maxrepdate=mysqli_fetch_row($maxrepdate_qry)[0]; diff --git a/distfiles/search.php b/distfiles/search.php index 1ea48fe..74344ad 100644 --- a/distfiles/search.php +++ b/distfiles/search.php @@ -38,10 +38,10 @@ if (array_key_exists('exportcsv',$_REQUEST)) { $exportcsv=true; $csv_filename="{$appname}_Search_Results_" . date("Y-m-d_His") . ".csv"; // disable caching - $now = gmdate("D, d M Y H:i:s"); + $lastmodified = gmdate("D, d M Y H:i:s"); header("Expires: Tue, 03 Jul 2001 06:00:00 GMT"); header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate"); - header("Last-Modified: {$now} GMT"); + header("Last-Modified: {$lastmodified} GMT"); // force download header("Content-Type: application/force-download"); diff --git a/distfiles/settings.php b/distfiles/settings.php index faa1385..bfe3f74 100644 --- a/distfiles/settings.php +++ b/distfiles/settings.php @@ -7,6 +7,10 @@ SPDX-License-Identifier: GPL-2.0 */ +// determine today's date and time and assign them to variables +$today = date("Y-m-d"); +$now = date("H:i:s"); + $sttl=mysqli_fetch_row(mysqli_query($drs_db,"select value from config where name=\"session_ttl_days\""))[0]; $ostype=strtoupper(substr(php_uname('s'), 0, 3)); if ($ostype == 'WIN') { diff --git a/distfiles/writeupdetail.php b/distfiles/writeupdetail.php index 17ac3f2..8b6e5c1 100644 --- a/distfiles/writeupdetail.php +++ b/distfiles/writeupdetail.php @@ -97,9 +97,6 @@ framework("begin","$appname","Writeup Detail",$print); // ******** begin database manipulation ******** -// determine today's date and make it the default -$today=date("Y-m-d"); -$now=date("H:i:s"); if ($usersave) { // user parameters diff --git a/distfiles/writeups.php b/distfiles/writeups.php index 9e3b87c..197f6bb 100644 --- a/distfiles/writeups.php +++ b/distfiles/writeups.php @@ -130,7 +130,7 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol } $writeup=mysqli_query($drs_db,"select * from writeups where report_date between \"$start_date\" and \"$end_date\" order by report_date desc,report_time desc"); if (mysqli_num_rows($writeup)) { - $now=date("H:i l"); + $as_of=date("H:i l"); if ($viewtype == "summary") { if ($role) { $selcol="Sel"; @@ -138,7 +138,7 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol $selcol=""; } echo " - As of $now      Newest at top
+ As of $as_of      Newest at top
$selcol @@ -231,7 +231,7 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol echo "
\n"; } elseif ($viewtype == "detail") { echo " - As of $now      Newest at top

+ As of $as_of      Newest at top

"; while ($tablerow = mysqli_fetch_assoc($writeup)) { @@ -272,7 +272,6 @@ function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$rol } // use default date values if not supplied -$today = date("Y-m-d"); if (!isset($start_date)) $start_date=$today; if (!isset($end_date)) $end_date=$today; if (isset($showtoday)) { diff --git a/opendrs-update.sh b/files-update.sh similarity index 75% rename from opendrs-update.sh rename to files-update.sh index 9103caf..8f545f5 100644 --- a/opendrs-update.sh +++ b/files-update.sh @@ -1,5 +1,11 @@ #!/bin/bash -# opendrs-update.sh +# files-update.sh + +if [[ $1 == "" ]] +then + echo "This script requires an install path, but none was specified. Aborting." + exit 1 +fi install_path=$1 @@ -60,3 +66,14 @@ sed -i "s/mts_db/drs_db/g" $install_path/db.php # Nothing to do for this version # -------------------------------------- +# ---------- version 1.4.5 ------------- +# Add AllowOverride Options to the apache conf-available file +install_loc=$(basename $install_path) +if ! grep -q "AllowOverride Options" /etc/apache2/conf-available/$install_loc.conf +then + sed -i '/^/dev/null 2>&1 + then + echo "$prereq is installed. Continuing." + else + echo "$APP_NAME requires $prereq, but it doesn't seem to be installed. " + echo -n "Install $preferred_pkg now? [Y/n]: " + read reqinstall + if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ] + then + echo "$APP_NAME requires $prereq, but you have elected not to install it." + echo "Installation cannot continue." + abort_exit + else + echo "" + echo "Proceeding with $preferred_pkg installation" + echo "" + sleep 3 + apt-get install -y $preferred_pkg + echo "" + echo "Finished with $preferred_pkg installation" + echo "" + sleep 3 + + fi + fi + done +} + +function clean_exit() { + # Re-enable unattended-upgrades + if $restart_uu; then systemctl start unattended-upgrades; fi + exit 0 +} + +function abort_exit() { + # Re-enable unattended-upgrades + if $restart_uu; then systemctl start unattended-upgrades; fi + exit 1 +} + +function spinner() { + local pid="$1" + local delay="0.1" + local spinstr='|/-\\' + local i=0 + + while ps -p "$pid" > /dev/null; do + i=$(( (i+1) % 4 )) + printf "\r[%c]" "${spinstr:$i:1}" + sleep "$delay" + done + printf "\r \r" # Clear the spinner line +} # test for superuser rights -if [[ $EUID -ne 0 ]]; then - echo "This script must be run with superuser privileges. Try sudo ./install.sh" - exit 1 -fi +privilege_check -echo "Preparing for OpenDRS installation or upgrade. Please stand by..." + +echo "" +echo "" +echo "* * * * * Welcome to $APP_NAME $APP_VERSION Installation * * * * *" +echo "" +echo "" +sleep 3 +echo "Preparing for installation. Please wait..." # Prevent unattended-upgrades from interfering restart_uu=false -while systemctl status unattended-upgrades >/dev/null 2>&1 +while dpkg -l|grep unattended-upgrades >/dev/null 2>&1 do systemctl stop unattended-upgrades sleep 5 restart_uu=true done -echo "" -echo "" -echo "* * * * * Welcome to OpenDRS $DRS_VERSION Installation * * * * *" -echo "" -echo "" -echo "Just press enter at the prompts to accept the defaults shown." -echo "" + +apt-get update -qq + # Check for prerequisites and prompt to install -echo "Checking for prerequisites..." +echo "Checking for required packages..." echo "" +install_required_packages "apache2" "php" "mysql-server or mariadb-server" "php-mysql" "uuid-runtime" echo "" -echo " Checking for apache2 installation..." -echo "" -if dpkg -l|grep apache2 >/dev/null 2>&1 -then - echo "" - echo "apache2 is installed. Continuing." - echo "" -else - echo "OpenDRS requires the apache2 http server, but it doesn't seem" - echo -n "to be installed. Install it now? [Y/n]: " - read reqinstall - if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ] - then - echo "OpenDRS requires apache2, but you have elected not to install it." - echo "Installation cannot continue." - exit 1 - else - echo "" - echo "###################################################################" - echo "" - echo "Proceeding with apache2 installation" - echo "" - echo "###################################################################" - sleep 3 - apt-get install -y apache2 - echo "" - echo "###################################################################" - echo "" - echo "Finished with apache2 installation" - echo "" - echo "###################################################################" - sleep 3 - - fi -fi - -echo "" -echo " Checking for php installation..." -echo "" -if dpkg -l|grep php >/dev/null 2>&1 -then - echo "" - echo "php is installed. Continuing." - echo "" -else - echo "" - echo "" - echo "OpenDRS requires php, but it doesn't seem to be installed." - echo -n "Install it now? [Y/n]: " - read reqinstall - if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ] - then - echo "OpenDRS requires php, but you have elected not to install it." - echo "Installation cannot continue." - exit 1 - else - echo "" - echo "###################################################################" - echo "" - echo "Proceeding with php installation" - echo "" - echo "###################################################################" - sleep 3 - apt-get install -y php - echo "" - echo "###################################################################" - echo "" - echo "Finished with php installation" - echo "" - echo "###################################################################" - sleep 3 - fi -fi - -echo "" -echo " Checking for mariadb or mysql installation..." +echo "Finished required package installation." echo "" -if dpkg -l|grep mariadb-server >/dev/null 2>&1 -then - echo "" - echo "mariadb-server is installed. Continuing." - echo "" -elif dpkg -l|grep mysql-server >/dev/null 2>&1 -then - echo "" - echo "mysql-server is installed. Continuing." - echo "" -else - echo "" - echo "" - echo "OpenDRS requires either mariadb or mysql server, but neither seem" - echo -n "to be installed. Install mariadb-server now? [Y/n]: " - read reqinstall - if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ] - then - echo "OpenDRS requires either mariadb or mysql server, but you have elected not to install it." - echo "Installation cannot continue." - exit 1 - else - echo "" - echo "###################################################################" - echo "" - echo "Proceeding with mariadb-server installation" - echo "" - echo "###################################################################" - sleep 3 - apt-get install -y mariadb-server - echo "" - echo "###################################################################" - echo "" - echo "Finished with mariadb-server installation" - echo "" - echo "###################################################################" - sleep 3 - echo "" - echo "###################################################################" - echo "" - echo "Proceeding with mariadb configuration" - echo "" - echo "###################################################################" - sleep 3 - echo "" - echo "Configuring the MariaDB installation. There will be some more prompts:" - echo "" - echo "- You'll be prompted for the current password for the root user. You've" - echo " just installed MariaDB and you haven't set one yet, so just press enter." - echo "" - echo "- You'll be prompted to switch to unix_socket authentication. Answer Y." - echo "" - echo "- You'll be prompted to change the root password. Answer Y and enter a password." - echo " Note that this is just the password for the MariaDB root user, not the root login." - echo " DO NOT FORGET THIS PASSWORD. You'll need it later during OpenDRS install." - echo "" - echo "- Answer Y to remove anonymous users, disallow root login remotely, remove" - echo " test database and access, and reload privilege tables." - echo "" - echo -n "Press enter to proceed." - read continueok - echo "" - mysql_secure_installation - echo "" - echo "###################################################################" - echo "" - echo "Finished with mariadb configuration." - echo "" - echo "###################################################################" - sleep 3 - fi -fi -echo "" -echo " Checking for phpmyadmin installation..." -echo "" -if dpkg -l|grep phpmyadmin >/dev/null 2>&1 -then - echo "" - echo "phpmyadmin is installed. Continuing." - echo "" -else - echo "phpmyadmin is optional, but doesn't seem to be installed." - echo "It is an optional package that enables administration of the mysql/mariadb" - echo "database server using a friendly GUI. It is highly recommended." - echo "Note that this has the potential to be a security risk, especially" - echo "if your passwords aren't sufficiently strong." - echo -n "Install it now? [Y/n]: " - read reqinstall - if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ] - then - echo "Proceeding without installing phpmyadmin. Database administration" - echo "will require the use of the mysql/mariadb command line tools." - else - echo "" - echo "###################################################################" - echo "" - echo "Proceeding with phpmyadmin installation" - echo "" - echo "###################################################################" - sleep 3 - echo "" - echo "During the following installation of phpmyadmin:" - echo "" - echo "- Select apache2 as the web server to configure automatically." - echo "" - echo "- Choose Yes when prompted to install phpmyadmin database and allow it to" - echo " generate a random password(leave the field blank)." - echo "" - echo -n "Press enter to continue." - read continueok - echo "" - apt-get install -y phpmyadmin - echo "" - echo "" - echo "You can now access phpmyadmin using a web browser pointed to:" - echo "http://$HOSTNAME/phpmyadmin" - echo "*** WARNING!! this url is accessible via unencrypted (http), not" - echo "encrypted SSL (https) connections. This is a huge security risk" - echo "since the username and password you enter will be sent in the" - echo "clear for any potential attacker to sniff! You should enable" - echo "redirection to https for phpmyadmin in your apache2 configuration." - echo "" - echo -n "Press enter to continue." - read continueok - echo "" - echo "###################################################################" - echo "" - echo "Finished with phpmyadmin installation" - echo "" - echo "###################################################################" - sleep 3 - fi -fi -echo "" -echo " Checking for webmin installation..." -echo "" -if dpkg -l|grep webmin >/dev/null 2>&1 -then - echo "" - echo "webmin is installed. Continuing." - echo "" -else - echo "webmin is optional, but doesn't seem to be installed." - echo "It is an optional package that enables system administration" - echo "using a friendly GUI. It is highly recommended, especially for" - echo "headless servers without any way to log in directly on the machine." - echo "Note that this has the potential to be a security risk, especially" - echo "if your passwords aren't sufficiently strong." - echo -n "Install it now? [Y/n]: " - read reqinstall - if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ] - then - echo "Proceeding without installing webmin. System administration" - echo "will require login to the server either directly or via ssh." - else - echo "" - echo "###################################################################" - echo "" - echo "Proceeding with webmin installation" - echo "" - echo "###################################################################" - sleep 3 - echo "Installing webmin..." - skipwebmin="false" - if ! curl -o setup-repos.sh https://raw.githubusercontent.com/webmin/webmin/master/setup-repos.sh - then - echo "Warning: failed to download Webmin repo setup script." - echo -n "Ignore and [c]ontinue or [A]bort? [c/A]: " - read wmfailchoice - if [ "$wmfailchoice" = "C" -o "$wmfailchoice" = "c" ] - then - skipwebmin="true" - echo "Continuing without installing Webmin. You should investigate the failure" - echo "and install Webmin manually after the server is set up if you would like" - echo "to be able to manage the server from another computer with a GUI instead" - echo "of through ssh only." - echo -n "Press enter to continue." - read continueok - echo "" - fi - fi - if [ "$skipwebmin" = "false" ] - then - sh setup-repos.sh -f - apt-get install -y --install-recommends webmin - fi - echo "...done." - echo "" - echo "You can now access webmin using a web browser pointed to:" - echo "https://$HOSTNAME:10000" - echo "Unless you have obtained valid ssl certificates, your server is" - echo "using self-signed certs. This is not necessarily a problem, but" - echo "your browser will complain. You can tell the browser to accept the" - echo "self signed certificates and the traffic will still be encrypted," - echo "however you may be vulnerable to man-in-the-middle attacks. You can" - echo "get free valid certificates through LetsEncrypt." - echo "See http://letsencrypt.org for more information." - echo "" - echo -n "Press enter to continue." - read continueok - echo "" - echo "###################################################################" - echo "" - echo "Finished with webmin installation" - echo "" - echo "###################################################################" - sleep 3 - - fi -fi -echo "" -echo " Checking for uuidgen installation..." -echo "" -if uuidgen 2>&1 -then - echo "" - echo "uuidgen is installed. Continuing." - echo "" -else - echo "" - echo "" - echo "OpenDRS requires uuidgen, but it doesn't seem to be installed." - echo -n "Install it now? [Y/n]: " - read reqinstall - if [ "$reqinstall" = "N" -o "$reqinstall" = "n" ] - then - echo "OpenDRS requires uuidgen, but you have elected not to install it." - echo "Installation cannot continue." - exit 1 - else - echo "" - echo "###################################################################" - echo "" - echo "Proceeding with uuidgen installation" - echo "" - echo "###################################################################" - sleep 3 - apt-get install -y uuid-runtime - echo "" - echo "###################################################################" - echo "" - echo "Finished with uuidgen installation" - echo "" - echo "###################################################################" - sleep 3 - fi -fi -echo "" -echo "" -echo "Finished checking for and installing prerequisites..." -echo "" -echo "" +# Determine the correct Apache2 user and group +APACHE_USER=$(grep APACHE_RUN_USER /etc/apache2/envvars | cut -d= -f2) +APACHE_GROUP=$(grep APACHE_RUN_GROUP /etc/apache2/envvars | cut -d= -f2) +httpd_user_group="$APACHE_USER:$APACHE_GROUP" + sleep 3 # prompt for install location -echo "Where would you like to install this version of OpenDRS? This should" +echo "Where would you like to install this version of $APP_NAME? This should" echo "be somewhere the webserver can find it. If you don't know, refer to the" echo "webserver's documentation and check the server's configuration files." -echo "Note that this is where the directory containing OpenDRS's files will be" +echo "Note that this is where the directory containing $APP_NAME's files will be" echo "created." echo -n "Enter the webserver's install location [$DOC_ROOT]:" read doc_root_in echo "" -echo -n "Enter name of OpenDRS installation directory [$INSTALL_LOC] :" +echo -n "Enter name of $APP_NAME installation directory [$INSTALL_LOC] :" read install_loc_in echo "" if [ "$doc_root_in" = "" ] @@ -396,14 +184,14 @@ fi install_path="$doc_root_in/$install_loc_in" if [ -d "$install_path" ] then + echo "The installation path you chose already exists." # Install path exists. if [ -e "$install_path/db.php" ] then # A db.php file was found in the install path - if grep -q -e "OpenDRS" -e "OpenMTS" $install_path/db.php + if grep -q -e "$APP_NAME" $install_path/db.php then - # the db.php file is part of an OpenDRS/OpenMTS installation - echo "The installation path you chose already exists." + # the db.php file is part of a previous installation echo "Would you like to upgrade an existing installation or cancel " echo "and restart the install using a new installation location." echo -n "[U]pgrade or [C]ancel? [C] :" @@ -411,106 +199,113 @@ then if [ "$upgrade_choice" = "U" -o "$upgrade_choice" = "u" ] # Upgrade chosen then # proceed with upgrade + mkdir -p backups operation="upgraded" + curr_dbname=$(grep dbname $install_path/db.php | head -1 | cut -d\" -f2) + + # create mysql option file with data for this installation + mysql_opt_file=$(mktemp --tmpdir=/run/shm/) + echo "[client]" > $mysql_opt_file + echo "user = $(grep username $install_path/db.php | head -1 | cut -d\" -f2)" >> $mysql_opt_file + echo "password = $(grep dbpass $install_path/db.php | head -1 | cut -d\" -f2)" >> $mysql_opt_file + echo "" >> $mysql_opt_file + echo "[mysql]" > $mysql_opt_file + echo "database = $curr_dbname" >> $mysql_opt_file + echo "batch" >> $mysql_opt_file + echo "disable-column-names" >> $mysql_opt_file + # back up existing database echo "Backing up the current database to the package directory." - curr_dbname=`grep dbname $install_path/db.php | head -1 | cut -d "\"" -f2` - curr_username=`grep username $install_path/db.php | head -1 | cut -d "\"" -f2` - curr_dbpass=`grep dbpass $install_path/db.php | head -1 | cut -d "\"" -f2` - export MYSQL_PWD="$curr_dbpass" - mysqldump --no-tablespaces -u"$curr_username" $curr_dbname > $curr_dbname-`date +%Y-%m-%d_%H:%M:%S`-backup.sql + mysqldump --defaults-extra-file=$mysql_opt_file --no-tablespaces $curr_dbname > backups/$curr_dbname-$(date +%Y-%m-%d_%H:%M:%S)-backup.sql + # back up existing installation echo "Backing up current installation to the package directory." - cp -R $install_path $install_loc_in-`date +%Y-%m-%d_%H:%M:%S`-backup + cp -R $install_path backups/$install_loc_in-`date +%Y-%m-%d_%H:%M:%S`-backup + # delete all existing installation files except db.php find $install_path/ -mindepth 1 -not -name 'db.php' -delete - # apply database updates - mysql -u"$curr_username" -f -D $curr_dbname < opendrs-update.sql >/dev/null 2>&1 - # apply updates to existing db.php - bash ./opendrs-update.sh $install_path + + echo "Performing database updates. This may take a while..." + # apply database updates from sql file + (mysql --defaults-extra-file=$mysql_opt_file --force < database-update.sql >/dev/null 2>&1) & + task_pid=$! + spinner $task_pid + + # apply database updates via script + (bash ./database-update.sh $mysql_opt_file) & + task_pid=$! + spinner $task_pid + + echo "... finished with database updates." + rm -f $mysql_opt_file + + # apply updates to other files + bash ./files-update.sh $install_path + # copy distribution to install location echo "Installing distribution . . ." cp -R distfiles/* $install_path + # set symlink for jquery-ui if [ ! -L "$install_path/jquery-ui" ] then ln -s $install_path/jquery-ui* $install_path/jquery-ui fi + # set symlink for index.php if [ ! -L "$install_path/index.php" ] then - ln -s $install_path/writeups.php $install_path/index.php + ln -s $install_path/$LANDING_PAGE $install_path/index.php fi + # add the local timezone to .htaccess + local_tz=$(timedatectl show -p Timezone|cut -d= -f2) + echo "Your local timezone is $local_tz" + echo "php_value date.timezone \"$local_tz\"">$install_path/.htaccess + # set ownership - echo "In order to set the ownership correctly, we need to know the user and" - echo "group that the webserver expects its files to be owned by. This is" - echo "usually not the root account. Refer to the ownership of other files in" - echo "your webserver's document tree to see what this should be." - echo "Enter the user and group separated by a colon (username:groupname)." - echo "Enter the user:group of the OpenDRS installation" - echo -n "directory [$APACHE_USER:$APACHE_GROUP] :" - read httpd_user_group - if [ "$httpd_user_group" = "" ] - then - httpd_user_group="$APACHE_USER:$APACHE_GROUP" - fi echo "" echo "Setting file ownership . . ." chown -R $httpd_user_group $install_path else echo "Cancelling installation" - exit + abort_exit fi else # This was a mistake. Exit now to avoid clobbering another app. echo "The installation directory you chose exists, but no previous installation" - echo "of OpenDRS was found. Please investigate the situation. Aborting now." - exit 1 + echo "of $APP_NAME was found. Please investigate the situation. Aborting now." + abort_exit fi else # This was a mistake. Exit now to avoid clobbering another app. echo "The installation directory you chose exists, but no previous installation" - echo "of OpenDRS was found. Please investigate the situation. Aborting now." - exit 1 + echo "of $APP_NAME was found." + echo "" + echo " CAUTION: If there is anything else in this directory, it will be deleted!" + echo "" + echo "Would you like to use this location for a fresh installation or quit and" + echo "investigate further? It's probably safest to quit and investigate." + proceed="" + while [[ $proceed != "P" && $proceed != "p" && $proceed != "Q" && $proceed != "q" ]] + do + read proceed -p "[P]roceed with new install or [Q]uit? : " + done + if [[ $proceed == "Q" || $proceed == "q" ]] + then + abort_exit + fi fi else # This is a fresh install operation="installed" - # prompt for mysql information - bad_mysql_adm=true - while $bad_mysql_adm - do - admintestdb="drsadm`date +%Y%m%d`" - echo "We need to know the username and password of a MySQL administrator" - echo "to be able to create the database and user for OpenDRS. Note that this" - echo "is not necessarily the same as the login and password for the computer." - echo -n "MySQL admin username: " - read mysql_adm_user - echo "" - echo -n "MySQL admin password: " - read -s mysql_adm_pass - export MYSQL_PWD="$mysql_adm_pass" - if mysql -u"$mysql_adm_user" -e "create database $admintestdb;drop database $admintestdb" - then - bad_mysql_adm=false - else - echo "ERROR: Either the username/password you supplied were incorrect or the user" - echo -n "is not a MySQL administrator. Try again? [Y/N]: " - read admtry - if [ "$admtry" != "Y" -o "$admtry" != "y" ] - then - exit - fi - fi - done echo "" - echo "What would you like to call this installation of OpenDRS? If you accept" - echo "the default, it will be called OpenDRS. If you will be running multiple" - echo "instances of OpenDRS on this server, you should choose a distinctive name." + echo "What would you like to call this installation of $APP_NAME? If you accept" + echo "the default, it will be called $APP_NAME. If you will be running multiple" + echo "instances of $APP_NAME on this server, you should choose a distinctive name." echo "This can be changed later in the application itself." - echo -n "Installation name [OpenDRS]: " + echo -n "Installation name [$APP_NAME]: " read new_inst_name if [ "$new_inst_name" = "" ] then - new_inst_name="OpenDRS" + new_inst_name="$APP_NAME" fi echo "" @@ -518,20 +313,19 @@ else db_create_fail=true while $db_create_fail do - echo "What would you like to call the database for this installation of OpenDRS?" - echo "If you accept the default, it will be called opendrs. Again, this is fine" + echo "What would you like to call the database for this installation of $APP_NAME?" + echo "If you accept the default, it will be called $DEFAULT_DB_NAME. Again, this is fine" echo "if you will only be running this one instance, but if you will be running" - echo "multiple instances of OpenDRS on this server, you should choose a " + echo "multiple instances of $APP_NAME on this server, you should choose a " echo "distinctive name." - echo -n "database name [opendrs]: " + echo -n "database name [$DEFAULT_DB_NAME]: " read new_db_name if [ "$new_db_name" = "" ] then - new_db_name=opendrs + new_db_name=$DEFAULT_DB_NAME fi echo "" - export MYSQL_PWD="$mysql_adm_pass" - if mysql -u"$mysql_adm_user" -e "create database $new_db_name" + if mysql -e "create database $new_db_name" then db_create_fail=false else @@ -541,26 +335,28 @@ else read dbcreatetry if [ "$dbcreatetry" != "Y" -o "$dbcreatetry" != "y" ] then - exit + abort_exit fi fi done # Create user and give rights to database - drs_user="$new_db_name`date +%Y%m%d%H%M%S`" - drs_pass=`uuidgen` - export MYSQL_PWD="$mysql_adm_pass" - mysql -u"$mysql_adm_user" -e "create user if not exists '$drs_user'@'localhost' identified by '$drs_pass'" - mysql -u"$mysql_adm_user" -e "grant all on $new_db_name.* to '$drs_user'@'localhost'" - mysql -u"$mysql_adm_user" -e "flush privileges" + db_user="$new_db_name`date +%Y%m%d%H%M%S`" + db_pass=`uuidgen` + mysql -e "create user if not exists '$db_user'@'localhost' identified by '$db_pass'" + mysql -e "grant all on $new_db_name.* to '$db_user'@'localhost'" + mysql -e "flush privileges" # Populate initial database - mysql -u"$mysql_adm_user" $new_db_name < opendrs-initial.sql + mysql $new_db_name < database-initial.sql # Set the installation name - export MYSQL_PWD="$drs_pass" - mysql -u"$drs_user" $new_db_name -e "update config set value=\"$new_inst_name\",defaultvalue=\"$new_inst_name\" where name=\"app_name\"" - + export MYSQL_PWD="$db_pass" + mysql -u"$db_user" $new_db_name -e "update $CONFIG_TABLE set $CONFIG_VALUE_COLUMN=\"$new_inst_name\" where $CONFIG_NAME_COLUMN=\"app_name\"" + if [ "$CONFIG_DEFAULT_COLUMN" != "" ] + then + mysql -u"$db_user" $new_db_name -e "update $CONFIG_TABLE set $CONFIG_DEFAULT_COLUMN=\"$new_inst_name\" where $CONFIG_NAME_COLUMN=\"app_name\"" + fi # Create install path echo "Creating installation directory . . ." mkdir $install_path @@ -570,8 +366,9 @@ else then cp db.php.template $install_path/db.php sed -i "s/DBNAME/$new_db_name/g" $install_path/db.php - sed -i "s/DBUSER/$drs_user/g" $install_path/db.php - sed -i "s/DBPASS/$drs_pass/g" $install_path/db.php + sed -i "s/DBUSER/$db_user/g" $install_path/db.php + sed -i "s/DBPASS/$db_pass/g" $install_path/db.php + sed -i "s/APPNAME/$APP_NAME/g" $install_path/db.php fi # copy distribution to install location @@ -583,21 +380,14 @@ else fi if [ ! -L "$install_path/index.php" ] then - ln -s $install_path/writeups.php $install_path/index.php + ln -s $install_path/$LANDING_PAGE $install_path/index.php fi + # add the local timezone to .htaccess + local_tz=$(timedatectl show -p Timezone|cut -d= -f2) + echo "Your local timezone is $local_tz" + echo "php_value date.timezone \"$local_tz\"">$install_path/.htaccess + # set ownership - echo "In order to set the ownership correctly, we need to know the user and" - echo "group that the webserver expects its files to be owned by. This is" - echo "usually not the root account. Refer to the ownership of other files in" - echo "your webserver's document tree to see what this should be." - echo "Enter the user and group separated by a colon (username:groupname)." - echo "Enter the user:group of the OpenDRS installation" - echo -n "directory [$APACHE_USER:$APACHE_GROUP] :" - read httpd_user_group - if [ "$httpd_user_group" = "" ] - then - httpd_user_group="$APACHE_USER:$APACHE_GROUP" - fi echo "" echo "Setting file ownership . . ." chown -R $httpd_user_group $install_path @@ -609,26 +399,27 @@ echo "" echo "" echo "" echo "" -echo "OpenDRS has been $operation." +echo "$APP_NAME has been $operation." base_url=$install_loc_in if [ "$operation" = "installed" ] then - echo "# OpenDRS default Apache configuration" > $APACHE_CONF_DIR/$base_url.conf + echo "# $APP_NAME default Apache configuration" > $APACHE_CONF_DIR/$base_url.conf echo "" >> $APACHE_CONF_DIR/$base_url.conf echo "Alias /$base_url $doc_root_in/$base_url" >> $APACHE_CONF_DIR/$base_url.conf echo "" >> $APACHE_CONF_DIR/$base_url.conf echo "" >> $APACHE_CONF_DIR/$base_url.conf + echo " AllowOverride Options" >> $APACHE_CONF_DIR/$base_url.conf echo " Options FollowSymLinks" >> $APACHE_CONF_DIR/$base_url.conf echo " DirectoryIndex index.php" >> $APACHE_CONF_DIR/$base_url.conf echo "" >> $APACHE_CONF_DIR/$base_url.conf - echo -n "The apache2 $base_url configuration must be enabled. Would you like to do that now? [Y] :" + echo -n "The apache2 $base_url configuration must be enabled. Would you like to do that now? [Y/n] :" read enconf if [ "$enconf" = "" -o "$enconf" = "Y" -o "$enconf" = "y" ] then a2enconf $base_url.conf >/dev/null service apache2 reload echo "You can now point a web browser to $base_url on your web server " - echo "to set up and configure OpenDRS." + echo "to set up and configure $APP_NAME." echo "" echo "IMPORTANT: The default login credentials for the initial admin user are:" echo "" @@ -642,13 +433,12 @@ then else echo "You will need to manually enable the configuration by executing:" echo " a2enconf $base_url.conf" - echo " service apache2 reload" + echo " systemctl reload apache2" echo "as a superuser before it can be accessed." fi else - echo "You can now point a web browser to $base_url on your web server " - echo "to use your upgraded OpenDRS." + echo "You can now point a web browser to http://$HOSTNAME/$base_url " + echo "to use your upgraded $APP_NAME." fi -# Re-enable unattended-upgrades -if $restart_uu; then systemctl start unattended-upgrades; fi +clean_exit