From 9e509cf641232e070f03a5d74a324710eb47e064 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sat, 4 Dec 2021 14:24:08 +0100 Subject: [PATCH] check_encryption_scan_legacy-format, check_for_old_files.sh: some minor changes. --- check_encryption_scan_legacy-format | 421 ++++++++++++++++++++++------ check_for_old_files.sh | 209 +++++++++++--- 2 files changed, 505 insertions(+), 125 deletions(-) diff --git a/check_encryption_scan_legacy-format b/check_encryption_scan_legacy-format index e14b30c..6c0bbee 100755 --- a/check_encryption_scan_legacy-format +++ b/check_encryption_scan_legacy-format @@ -139,6 +139,15 @@ info (){ echo "" } +# - Remove leading/trailling whitespaces +# - +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + ## - Check if a given array (parameter 2) contains a given string (parameter 1) ## - containsElement () { @@ -171,7 +180,6 @@ while IFS='' read -r -d '' _conf_file ; do fi WEBSITE="" done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0) -#done < <(find "${conf_dir}" -maxdepth 1 -type f -name "create_missing_indices_*.conf" -print0) #if [[ ${#unsorted_website_arr} -eq 0 ]]; then # fatal "No configuration files found in '${script_dir}/conf' or no website configured!" @@ -275,57 +283,107 @@ if [[ ! -d ${WEB_BASE_DIR} ]] ; then fi DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)" -INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)" -CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)" [[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE -# Check PHP Version +if [[ "$DATABASE_TYPE" != "postgres" ]] && [[ "$DATABASE_TYPE" != "mysql" ]]; then + fatal "Wrong or missing database type (parameter 'DATABASE_TYPE')" +fi + +if [[ -z "$DATABASE_NAME" ]]; then + fatal "Missing database name (parameter 'DATABASE_NAME')" +fi + +if [[ "$DATABASE_TYPE" = "mysql" ]] && [[ -z "$MYSQL_CREDENTIALS" ]]; then + fatal "No Database Credentials for MySQL given (parameter 'MYSQL_CREDENTIALS')" +fi + +if [[ "$DATABASE_TYPE" = "postgres" ]]; then + if [[ -z "$PSQL_USER" ]] || [[ -z "$PSQL_PASS" ]]; then + fatal "No Database Credentials for PostgreSQL given (parameters: 'PSQL_USER' 'PSQL_PASS'" + fi +fi + +NGINX_IS_ENABLED=false +APACHE2_IS_ENABLED=false + +# Check if NGINX webserver is ctive # -if [[ "$PHP_ENGINE" = "FPM" ]] ; then - if [[ -z "$PHP_VERSION" ]] ; then - if [[ -z "$VHOST_CONFIG_FILE" ]] ; then - if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then - VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" - elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then - VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" - elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then - VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf" +if $(systemctl -q is-enabled nginx 2> /dev/null) ; then + + NGINX_IS_ENABLED=true + + # - Determin user of the webserver + # - + nginx_binary="$(which nginx)" + if [[ -z "$nginx_binary" ]] ; then + nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")" + if [[ -z "$nginx_binary" ]] ; then + if [[ -x "/usr/local/nginx/bin/nginx" ]]; then + nginx_binary="/usr/local/nginx/bin/nginx" + elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then + nginx_binary="/usr/local/nginx/sbin/nginx" fi fi - PHP_VERSION="$(grep -o -E "php-?.{1}\..{1}-fpm" $VHOST_CONFIG_FILE | grep -o -E ".{1}\..{1}")" - if [[ -z "$PHP_VERSION" ]] ; then - fatal "PHP Version must be givven if running PHP-FPM engine (parameter 'PHP_VERSION')" - fi fi -fi -# - Determin user/group of the webserver -# - -httpd_binary="`which httpd`" -if [ -z "$httpd_binary" ]; then - httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')" - if [ -z "$httpd_binary" ]; then - if [ -x "/usr/local/apache2/bin/httpd" ]; then - httpd_binary="/usr/local/apache2/bin/httpd" - fi + if [[ -x "$nginx_binary" ]] ; then + _HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')" fi -fi -if [ -x "$httpd_binary" ];then - - # - Determin websever user - # - - _HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" - _HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" # - Is webserver running ? # - - PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}') + PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}') if [[ "X${PID}X" = "XX" ]] ;then IS_HTTPD_RUNNING=false else IS_HTTPD_RUNNING=true fi + + +elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then + + APACHE2_IS_ENABLED=true + + # - Determin user of the webserver + # - + httpd_binary="`which httpd`" + if [ -z "$httpd_binary" ]; then + httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')" + if [ -z "$httpd_binary" ]; then + if [ -x "/usr/local/apache2/bin/httpd" ]; then + httpd_binary="/usr/local/apache2/bin/httpd" + fi + fi + fi + if [ -x "$httpd_binary" ];then + + # - Determin websever user + # - + _HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" + _HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" + + # - Is webserver running ? + # - + PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}') + if [[ "X${PID}X" = "XX" ]] ;then + IS_HTTPD_RUNNING=false + else + IS_HTTPD_RUNNING=true + fi + fi + +else + error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interrupted by user" fi if [[ -n "$_HTTP_USER" ]] ; then @@ -347,7 +405,72 @@ else [[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP fi -if [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then +# Check PHP Version +# +if [[ "$PHP_ENGINE" = "FPM" ]] ; then + if [[ -z "$PHP_VERSION" ]] ; then + if [[ -z "$VHOST_CONFIG_FILE" ]] ; then + if $NGINX_IS_ENABLED ; then + + if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then + VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")" + fi + + elif $APACHE2_IS_ENABLED ; then + + if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then + VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" + elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then + VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" + elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then + VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf" + fi + + fi + fi + if [[ -n "$VHOST_CONFIG_FILE" ]] ; then + PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \ + | grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")" + fi + if [[ -z "$PHP_VERSION" ]] ; then + + warn "The PHP version was not specified and cannot be determined!" + + main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$" + + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Enter the PHP main version, e.g. 7.4 or 8.0 .." + echo "" + echo "" + PHP_VERSION= + while [ "X$PHP_VERSION" = "X" ] + do + echononl " PHP main version: " + read PHP_VERSION + if [ "X$PHP_VERSION" = "X" ]; then + echo "" + echo -e "\033[33m\033[1mInput is required !!\033[m" + echo "" + fi + if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then + echo "" + echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m" + echo "" + PHP_VERSION= + fi + + done + + + fi + fi +fi + +if [[ -x "/usr/local/php-${PHP_VERSION}/bin/php" ]] ; then + PHP_BIN="/usr/local/php-${PHP_VERSION}/bin/php" +elif [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then PHP_BIN="/usr/local/php/bin/php" else PHP_BIN="$(which php)" @@ -357,6 +480,8 @@ if [[ ! -x "$PHP_BIN" ]]; then fatal "No PHP binary found!" fi +CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)" +CURRENT_VERSION="$(basename $CURRENT_INSTALL_DIR | cut -d"-" -f2)" echo "" echo -e "\033[1;32mStarting Script $script_name for \033[1;37m${WEBSITE}\033[m" @@ -366,7 +491,7 @@ echo "" echo -e " Nextcloud version....................: $CURRENT_VERSION" echo "" echo -e " Web base directory...................: $WEB_BASE_DIR" -echo -e " Install directory....................: $INSTALL_DIR" +echo -e " Install directory....................: $CURRENT_INSTALL_DIR" echo -e " Data directory.......................: $DATA_DIR" echo "" echo -e " Webserver user.......................: $HTTP_USER" @@ -383,7 +508,7 @@ read OK if [[ "$OK" = "YES" ]] ; then echo "" echo "" - echo -e "\033[1;32mGoing to update Nextcloud on \033[1;37m$WEBSITE \033[m" + echo -e "\033[1;32mGoing check encryption legacy-format Nextcloud on \033[1;37m$WEBSITE \033[m" echo "" else fatal "Abort by user request - Answer as not 'YES'" @@ -428,21 +553,97 @@ fi # - echo "" echononl " Stop Apache Webserver.." -if $SYSTEMD_EXISTS ; then - systemctl stop apache2 - if [[ $? -eq 0 ]]; then - echo_ok +if $APACHE2_IS_ENABLED ; then + if $IS_HTTPD_RUNNING ; then + if $SYSTEMD_EXISTS ; then + systemctl stop apache2 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interrupted by user." + + fi + else + /etc/init.d/apache2 stop + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interrupted by user." + + fi + fi else - echo_failed - fatal "$(cat $log_file)" + echo_skipped fi else - /etc/init.d/apache2 stop - if [[ $? -eq 0 ]]; then - echo_ok + echo_skipped +fi + +# - Stop Nginx Webservice +# - +echo "" +echononl " Stop Nginx Webserver.." +if $NGINX_IS_ENABLED ; then + if $IS_HTTPD_RUNNING ; then + if $SYSTEMD_EXISTS ; then + systemctl stop nginx + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interrupted by user." + + fi + else + /etc/init.d/nginx stop + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interrupted by user." + + fi + fi else - echo_failed - fatal "$(cat $log_file)" + echo_skipped fi fi @@ -485,7 +686,7 @@ echo -e "\033[37m\033[1mMain part of the script\033[m" echo "" -# - Create missing indices +# - Scan encryption legacy-format # - echononl " Running 'occ encryption:scan:legacy-format' .." echo 'y' | su -c "$PHP_BIN ${WEB_BASE_DIR}/htdocs/occ encryption:scan:legacy-format" -s /bin/bash $HTTP_USER @@ -499,6 +700,7 @@ fi + # ----- # - Doing some post-update tasks # ----- @@ -553,46 +755,101 @@ fi # - echo "" echononl " Start Apache Webserver.." -if $IS_HTTPD_RUNNING ; then - if $SYSTEMD_EXISTS ; then - systemctl start apache2 > $log_file 2>&1 - if [[ $? -eq 0 ]]; then - echo_ok - else - echo_failed - error "$(cat $log_file)" +if $APACHE2_IS_ENABLED ; then + if $IS_HTTPD_RUNNING ; then + if $SYSTEMD_EXISTS ; then + systemctl start apache2 > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" - echononl "continue anyway [yes/no]: " - read OK - OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" - while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/no]: " + echononl "continue anyway [yes/no]: " read OK - done - [[ $OK = "yes" ]] || fatal "Interrupted by user." + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interrupted by user." + fi + else + /etc/init.d/apache2 start > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interrupted by user." + fi fi else - /etc/init.d/apache2 start > $log_file 2>&1 - if [[ $? -eq 0 ]]; then - echo_ok - else - echo_failed - error "$(cat $log_file)" - - echononl "continue anyway [yes/no]: " - read OK - OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" - while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do - echononl "Wrong entry! - repeat [yes/no]: " - read OK - done - [[ $OK = "yes" ]] || fatal "Interrupted by user." - fi + echo_skipped + warn "The webserver was not running, so it will be keept down!" + fi +else + echo_skipped +fi + + +# - Start NGINX Webservise +# - +echo "" +echononl " Start Nginx Webserver.." +if $NGINX_IS_ENABLED ; then + if $IS_HTTPD_RUNNING ; then + if $SYSTEMD_EXISTS ; then + systemctl start nginx > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interrupted by user." + + fi + else + /etc/init.d/nginx start > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interrupted by user." + fi + fi + else + echo_skipped + warn "The NGINX is not configured as active - so nothing to do." fi else echo_skipped - warn "The webserver was not running, so it will be keept down!" fi _redis_cli_bin="$(which redis-cli)" diff --git a/check_for_old_files.sh b/check_for_old_files.sh index 6fd6065..6494485 100755 --- a/check_for_old_files.sh +++ b/check_for_old_files.sh @@ -19,6 +19,22 @@ backup_date=$(date +%Y-%m-%d-%H%M) clean_up() { + + if [[ -f "$_backup_crontab_file" ]]; then + + echononl " (Re)Install previously saved crontab .." + + crontab $_backup_crontab_file >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + fi + # Perform program exit housekeeping rm -f $log_file blank_line @@ -174,7 +190,6 @@ fi IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}")) - # ============= # --- Some # ============= @@ -195,10 +210,8 @@ else terminal=false fi -#clear +clear -echo "" -echo "" echo "" echo -e "\033[32m-----\033[m" echo -e "Add User to Group - \033[1mBoth, User and Group has to exist\033[m" @@ -245,6 +258,8 @@ fi echo "" + + # ============= # --- Some checks # ============= @@ -267,27 +282,9 @@ if [[ ! -d ${WEB_BASE_DIR} ]] ; then fatal "Web base directory not found (parameter 'WEB_BASE_DIR')" fi -[[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE +DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)" -# Check PHP Version -# -if [[ "$PHP_ENGINE" = "FPM" ]] ; then - if [[ -z "$PHP_VERSION" ]] ; then - if [[ -z "$VHOST_CONFIG_FILE" ]] ; then - if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then - VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" - elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then - VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" - elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then - VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf" - fi - fi - PHP_VERSION="$(grep -o -E "php-?.{1}\..{1}-fpm" $VHOST_CONFIG_FILE | grep -o -E ".{1}\..{1}")" - if [[ -z "$PHP_VERSION" ]] ; then - fatal "PHP Version must be givven if running PHP-FPM engine (parameter 'PHP_VERSION')" - fi - fi -fi +[[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE if [[ "$DATABASE_TYPE" != "postgres" ]] && [[ "$DATABASE_TYPE" != "mysql" ]]; then fatal "Wrong or missing database type (parameter 'DATABASE_TYPE')" @@ -307,32 +304,86 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then fi fi -# - Determin user/group of the webserver -# - -httpd_binary="`which httpd`" -if [ -z "$httpd_binary" ]; then - httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')" - if [ -z "$httpd_binary" ]; then - if [ -x "/usr/local/apache2/bin/httpd" ]; then - httpd_binary="/usr/local/apache2/bin/httpd" +NGINX_IS_ENABLED=false +APACHE2_IS_ENABLED=false + +# Check if NGINX webserver is ctive +# +if $(systemctl -q is-enabled nginx 2> /dev/null) ; then + + NGINX_IS_ENABLED=true + + # - Determin user of the webserver + # - + nginx_binary="$(which nginx)" + if [[ -z "$nginx_binary" ]] ; then + nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")" + if [[ -z "$nginx_binary" ]] ; then + if [[ -x "/usr/local/nginx/bin/nginx" ]]; then + nginx_binary="/usr/local/nginx/bin/nginx" + elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then + nginx_binary="/usr/local/nginx/sbin/nginx" + fi fi fi -fi -if [ -x "$httpd_binary" ];then - # - Determin websever user - # - - _HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" - _HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" + if [[ -x "$nginx_binary" ]] ; then + _HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')" + fi # - Is webserver running ? # - - PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}') + PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}') if [[ "X${PID}X" = "XX" ]] ;then IS_HTTPD_RUNNING=false else IS_HTTPD_RUNNING=true fi + + +elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then + + APACHE2_IS_ENABLED=true + + # - Determin user of the webserver + # - + httpd_binary="`which httpd`" + if [ -z "$httpd_binary" ]; then + httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')" + if [ -z "$httpd_binary" ]; then + if [ -x "/usr/local/apache2/bin/httpd" ]; then + httpd_binary="/usr/local/apache2/bin/httpd" + fi + fi + fi + if [ -x "$httpd_binary" ];then + + # - Determin websever user + # - + _HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" + _HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" + + # - Is webserver running ? + # - + PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}') + if [[ "X${PID}X" = "XX" ]] ;then + IS_HTTPD_RUNNING=false + else + IS_HTTPD_RUNNING=true + fi + fi + +else + error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interrupted by user" fi if [[ -n "$_HTTP_USER" ]] ; then @@ -354,14 +405,86 @@ else [[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP fi +# Check PHP Version +# +if [[ "$PHP_ENGINE" = "FPM" ]] ; then + if [[ -z "$PHP_VERSION" ]] ; then + if [[ -z "$VHOST_CONFIG_FILE" ]] ; then + if $NGINX_IS_ENABLED ; then + + if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then + VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")" + fi + + elif $APACHE2_IS_ENABLED ; then + + if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then + VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" + elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then + VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" + elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then + VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf" + fi + + fi + fi + if [[ -n "$VHOST_CONFIG_FILE" ]] ; then + PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \ + | grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")" + fi + if [[ -z "$PHP_VERSION" ]] ; then + + warn "The PHP version was not specified and cannot be determined!" + + main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$" + + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Enter the PHP main version, e.g. 7.4 or 8.0 .." + echo "" + echo "" + PHP_VERSION= + while [ "X$PHP_VERSION" = "X" ] + do + echononl " PHP main version: " + read PHP_VERSION + if [ "X$PHP_VERSION" = "X" ]; then + echo "" + echo -e "\033[33m\033[1mInput is required !!\033[m" + echo "" + fi + if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then + echo "" + echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m" + echo "" + PHP_VERSION= + fi + + done + + + fi + fi +fi + +if [[ -x "/usr/local/php-${PHP_VERSION}/bin/php" ]] ; then + PHP_BIN="/usr/local/php-${PHP_VERSION}/bin/php" +elif [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then + PHP_BIN="/usr/local/php/bin/php" +else + PHP_BIN="$(which php)" +fi + +if [[ ! -x "$PHP_BIN" ]]; then + fatal "No PHP binary found!" +fi + CURRENT_INSTALL_DIR=`realpath ${WEB_BASE_DIR}/nextcloud` -CURRENT_DATA_DIR=`realpath ${WEB_BASE_DIR}/data` CURRENT_VERSION=`basename $CURRENT_INSTALL_DIR | cut -d"-" -f2` - - echo "" -echo -e "\033[1;32mStarting Script for \033[1;37m${WEBSITE}\033[m" +echo -e "\033[1;32mStarting Script $script_name for \033[1;37m${WEBSITE}\033[m" echo "" echo -e " Cloud instance to be changed.........: $WEBSITE" echo ""