Incorporate changes made for old version 5.2.4.3
This commit is contained in:
308
install.sh
308
install.sh
@@ -8,21 +8,26 @@
|
||||
|
||||
APP_NAME="OpenLog"
|
||||
DEFAULT_DB_NAME="openlog"
|
||||
APP_VERSION="5.2.4.2"
|
||||
APP_VERSION="5.2.4.3"
|
||||
DOC_ROOT="/var/www"
|
||||
INSTALL_LOC="openlog"
|
||||
APACHE_USER="www-data"
|
||||
APACHE_GROUP="www-data"
|
||||
APACHE_CONF_DIR="/etc/apache2/conf-available"
|
||||
BACKUP_DIR="openlog-previous-installation"
|
||||
INDEX_FILE="lognotes.php"
|
||||
LANDING_PAGE="lognotes.php"
|
||||
CONFIG_TABLE="configs"
|
||||
CONFIG_NAME_COLUMN="confname"
|
||||
CONFIG_VALUE_COLUMN="confvalue"
|
||||
CONFIG_DEFAULT_COLUMN=""
|
||||
OFFER_OPTIONAL_PKGS=false
|
||||
|
||||
|
||||
function privilege_check() {
|
||||
# test for superuser rights
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run with superuser privileges. Try sudo $0"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function get_new_password() {
|
||||
# Stores new password in the variable $newpassword
|
||||
pwgood=false
|
||||
@@ -105,11 +110,22 @@ function abort_exit() {
|
||||
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"
|
||||
abort_exit
|
||||
fi
|
||||
privilege_check
|
||||
|
||||
|
||||
echo ""
|
||||
@@ -122,182 +138,28 @@ 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
|
||||
|
||||
apt-get update
|
||||
apt-get update -qq
|
||||
|
||||
# Check for prerequisites and prompt to install
|
||||
echo "Checking for required packages..."
|
||||
echo ""
|
||||
install_required_packages "apache2" "php" "mysql-server or mariadb-server" "uuid-runtime"
|
||||
install_required_packages "apache2" "php" "mysql-server or mariadb-server" "php-mysql" "uuid-runtime"
|
||||
echo ""
|
||||
echo "Finished required package installation."
|
||||
echo ""
|
||||
|
||||
if $OFFER_OPTIONAL_PKGS
|
||||
then
|
||||
# Check for optional packages and prompt to install
|
||||
echo "Checking for optional packages..."
|
||||
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 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 "Proceeding with phpmyadmin installation"
|
||||
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 "In order to log in to the database using phpmyadmin, there must be a"
|
||||
echo "database user with a password set who has administrator privileges."
|
||||
echo "After a fresh installation of the MySQL or MariaDB server, the root"
|
||||
echo "user doesn't have a password, and is unable to log in to the phpmyadmin"
|
||||
echo "web GUI. You should create a new user with administrative rights now."
|
||||
echo ""
|
||||
read -p "New MySQL/MariaDB administrator username: " -r newdbadminuser
|
||||
echo ""
|
||||
get_new_password
|
||||
newdbadminpass=$newpassword
|
||||
unset newpassword
|
||||
mysql -e "CREATE USER '$newdbadminuser'@'localhost'
|
||||
IDENTIFIED VIA mysql_native_password USING password('$newdbadminpass');
|
||||
GRANT ALL PRIVILEGES ON *.* TO '$newdbadminuser'@'localhost'
|
||||
REQUIRE NONE WITH GRANT OPTION
|
||||
MAX_QUERIES_PER_HOUR 0
|
||||
MAX_CONNECTIONS_PER_HOUR 0
|
||||
MAX_UPDATES_PER_HOUR 0
|
||||
MAX_USER_CONNECTIONS 0;
|
||||
flush privileges"
|
||||
echo ""
|
||||
echo ""
|
||||
echo "You can now access phpmyadmin using a web browser pointed to:"
|
||||
echo ""
|
||||
echo " http://$HOSTNAME/phpmyadmin"
|
||||
echo ""
|
||||
echo "*** WARNING!! this url is accessible via unencrypted (http) connections."
|
||||
echo "This is a huge security risk since the username and password you enter"
|
||||
echo "on the phpmyadmin login page can be sent in the clear for any potential"
|
||||
echo "attacker to sniff! You should enable redirection to https for phpmyadmin"
|
||||
echo "in your apache2 configuration if your site is reachable from the internet."
|
||||
echo ""
|
||||
echo -n "Press enter to continue."
|
||||
read continueok
|
||||
echo ""
|
||||
echo "Finished with phpmyadmin installation"
|
||||
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 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 "Proceeding with webmin installation"
|
||||
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 "Finished with webmin installation"
|
||||
echo ""
|
||||
sleep 3
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Finished optional package installation."
|
||||
fi
|
||||
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 $APP_NAME? This should"
|
||||
@@ -322,6 +184,7 @@ 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
|
||||
@@ -329,7 +192,6 @@ then
|
||||
if grep -q -e "$APP_NAME" $install_path/db.php
|
||||
then
|
||||
# the db.php file is part of a previous installation
|
||||
echo "The installation path you chose already exists."
|
||||
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] :"
|
||||
@@ -337,23 +199,49 @@ 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 < database-update.sql >/dev/null 2>&1
|
||||
# apply updates to existing db.php
|
||||
bash ./db.php_update $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
|
||||
@@ -365,21 +253,14 @@ then
|
||||
# set symlink for index.php
|
||||
if [ ! -L "$install_path/index.php" ]
|
||||
then
|
||||
ln -s $install_path/$INDEX_FILE $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 $APP_NAME 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
|
||||
@@ -396,8 +277,21 @@ then
|
||||
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 $APP_NAME was found. Please investigate the situation. Aborting now."
|
||||
abort_exit
|
||||
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
|
||||
@@ -486,21 +380,14 @@ else
|
||||
fi
|
||||
if [ ! -L "$install_path/index.php" ]
|
||||
then
|
||||
ln -s $install_path/lognotes.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 $APP_NAME 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
|
||||
@@ -521,6 +408,7 @@ then
|
||||
echo "Alias /$base_url $doc_root_in/$base_url" >> $APACHE_CONF_DIR/$base_url.conf
|
||||
echo "" >> $APACHE_CONF_DIR/$base_url.conf
|
||||
echo "<Directory $doc_root_in/$base_url>" >> $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 "</Directory>" >> $APACHE_CONF_DIR/$base_url.conf
|
||||
|
||||
Reference in New Issue
Block a user