From c0ea4fa6d4856c76e01c7015a7a72e966050b7d1 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 2 Aug 2023 12:01:50 +0200 Subject: [PATCH] Determin PHP major version also for NGINX hosted nextclouds. Move Determination to separate file. --- add_missing_columns.sh | 61 +---------------------- add_missing_indices.sh | 62 +----------------------- add_missing_primary-keys.sh | 61 +---------------------- add_user_to_group.sh | 61 +---------------------- check_encryption_scan_legacy-format | 65 +++++++++++++++---------- check_for_old_files.sh | 67 ++++++++++++++++---------- convert_filecache_bigint.sh | 66 +++++++++++++++---------- remove_user_from_group.sh | 61 +---------------------- replace_favicon.sh | 61 +---------------------- replace_logo.sh | 60 +---------------------- snippet-get-php-major-version | 75 +++++++++++++++++++++++++++++ update_nextcloud.sh | 62 +----------------------- 12 files changed, 206 insertions(+), 556 deletions(-) create mode 100755 snippet-get-php-major-version diff --git a/add_missing_columns.sh b/add_missing_columns.sh index c83848e..267287f 100755 --- a/add_missing_columns.sh +++ b/add_missing_columns.sh @@ -409,66 +409,7 @@ 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 +source ${script_dir}/snippet-get-php-major-version CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)" diff --git a/add_missing_indices.sh b/add_missing_indices.sh index 27bcbe6..a066260 100755 --- a/add_missing_indices.sh +++ b/add_missing_indices.sh @@ -409,67 +409,7 @@ 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 - +source ${script_dir}/snippet-get-php-major-version CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)" CURRENT_VERSION="$(basename $CURRENT_INSTALL_DIR | cut -d"-" -f2)" diff --git a/add_missing_primary-keys.sh b/add_missing_primary-keys.sh index c8c02b8..a930988 100755 --- a/add_missing_primary-keys.sh +++ b/add_missing_primary-keys.sh @@ -409,66 +409,7 @@ 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 +source ${script_dir}/snippet-get-php-major-version CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)" diff --git a/add_user_to_group.sh b/add_user_to_group.sh index 6081bdf..523a924 100755 --- a/add_user_to_group.sh +++ b/add_user_to_group.sh @@ -447,66 +447,7 @@ 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 +source ${script_dir}/snippet-get-php-major-version CURRENT_INSTALL_DIR=`realpath ${WEB_BASE_DIR}/nextcloud` CURRENT_DATA_DIR=`realpath ${WEB_BASE_DIR}/data` diff --git a/check_encryption_scan_legacy-format b/check_encryption_scan_legacy-format index 7bdfa3e..7428509 100755 --- a/check_encryption_scan_legacy-format +++ b/check_encryption_scan_legacy-format @@ -446,35 +446,50 @@ if [[ "$PHP_ENGINE" = "FPM" ]] ; then fi if [[ -z "$PHP_VERSION" ]] ; then - warn "The PHP version was not specified and cannot be determined!" + if $NGINX_IS_ENABLED ; then + upstream_handler="$(grep -o -E "^[^#]*fastcgi_pass\s+[^;]+" ${VHOST_CONFIG_FILE} | awk '{print$2}' )" + for _file in $(ls /etc/nginx/conf.d/) ; do + _rp_file="$(realpath "/etc/nginx/conf.d/${_file}")" + if $(grep -q -E "\s+${upstream_handler}\s*" ${_rp_file} 2> /dev/null) ; then + PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" ${_rp_file} \ + | grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")" + break + fi + done + fi - main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$" + if [[ -z "$PHP_VERSION" ]] ; then - 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 + warn "Cannot determin the PHP version\! Enter it manually" - done + 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.2 .." + 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 diff --git a/check_for_old_files.sh b/check_for_old_files.sh index eb81590..99a83ab 100755 --- a/check_for_old_files.sh +++ b/check_for_old_files.sh @@ -446,35 +446,50 @@ if [[ "$PHP_ENGINE" = "FPM" ]] ; then fi if [[ -z "$PHP_VERSION" ]] ; then - warn "The PHP version was not specified and cannot be determined!" + if $NGINX_IS_ENABLED ; then + upstream_handler="$(grep -o -E "^[^#]*fastcgi_pass\s+[^;]+" ${VHOST_CONFIG_FILE} | awk '{print$2}' )" + for _file in $(ls /etc/nginx/conf.d/) ; do + _rp_file="$(realpath "/etc/nginx/conf.d/${_file}")" + if $(grep -q -E "\s+${upstream_handler}\s*" ${_rp_file} 2> /dev/null) ; then + PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" ${_rp_file} \ + | grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")" + break + fi + done + fi - main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$" + if [[ -z "$PHP_VERSION" ]] ; then - 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 + warn "Cannot determin the PHP version\! Enter it manually" - done + 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.2 .." + 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 @@ -509,6 +524,8 @@ echo "" echo -e " Webserver user.......................: $HTTP_USER" echo -e " Webserver group......................: $HTTP_GROUP" echo "" +echo -e " PHP Command..........................: $PHP_BIN" +echo "" echo -e " PHP version..........................: $PHP_VERSION" echo -e " PHP Engine...........................: $PHP_ENGINE" echo "" diff --git a/convert_filecache_bigint.sh b/convert_filecache_bigint.sh index 8be666c..4329f6d 100755 --- a/convert_filecache_bigint.sh +++ b/convert_filecache_bigint.sh @@ -446,39 +446,55 @@ if [[ "$PHP_ENGINE" = "FPM" ]] ; then fi if [[ -z "$PHP_VERSION" ]] ; then - warn "The PHP version was not specified and cannot be determined!" + if $NGINX_IS_ENABLED ; then + upstream_handler="$(grep -o -E "^[^#]*fastcgi_pass\s+[^;]+" ${VHOST_CONFIG_FILE} | awk '{print$2}' )" + for _file in $(ls /etc/nginx/conf.d/) ; do + _rp_file="$(realpath "/etc/nginx/conf.d/${_file}")" + if $(grep -q -E "\s+${upstream_handler}\s*" ${_rp_file} 2> /dev/null) ; then + PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" ${_rp_file} \ + | grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")" + break + fi + done + fi - main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$" + if [[ -z "$PHP_VERSION" ]] ; then - 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 + warn "Cannot determin the PHP version\! Enter it manually" - done + 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.2 .." + 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 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 diff --git a/remove_user_from_group.sh b/remove_user_from_group.sh index a4ebafa..40a9337 100755 --- a/remove_user_from_group.sh +++ b/remove_user_from_group.sh @@ -447,66 +447,7 @@ 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 +source ${script_dir}/snippet-get-php-major-version CURRENT_INSTALL_DIR=`realpath ${WEB_BASE_DIR}/nextcloud` CURRENT_DATA_DIR=`realpath ${WEB_BASE_DIR}/data` diff --git a/replace_favicon.sh b/replace_favicon.sh index 309d922..a5a9fbb 100755 --- a/replace_favicon.sh +++ b/replace_favicon.sh @@ -412,66 +412,7 @@ 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 +source ${script_dir}/snippet-get-php-major-version echo "" echo -e " \033[32m--\033[m" diff --git a/replace_logo.sh b/replace_logo.sh index 87c03d5..0257bfd 100755 --- a/replace_logo.sh +++ b/replace_logo.sh @@ -412,66 +412,8 @@ 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 +source ${script_dir}/snippet-get-php-major-version - 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 echo "" echo -e " \033[32m--\033[m" diff --git a/snippet-get-php-major-version b/snippet-get-php-major-version new file mode 100755 index 0000000..5739992 --- /dev/null +++ b/snippet-get-php-major-version @@ -0,0 +1,75 @@ +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 + + if $NGINX_IS_ENABLED ; then + upstream_handler="$(grep -o -E "^[^#]*fastcgi_pass\s+[^;]+" ${VHOST_CONFIG_FILE} | awk '{print$2}' )" + for _file in $(ls /etc/nginx/conf.d/) ; do + _rp_file="$(realpath "/etc/nginx/conf.d/${_file}")" + if $(grep -q -E "\s+${upstream_handler}\s*" ${_rp_file} 2> /dev/null) ; then + PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" ${_rp_file} \ + | grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")" + break + fi + done + fi + + if [[ -z "$PHP_VERSION" ]] ; then + + warn "Cannot determin the PHP version\! Enter it manually" + + 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.2 .." + 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 +fi diff --git a/update_nextcloud.sh b/update_nextcloud.sh index a28c371..03df476 100755 --- a/update_nextcloud.sh +++ b/update_nextcloud.sh @@ -500,67 +500,7 @@ 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 - +source ${script_dir}/snippet-get-php-major-version # - Determin PHP binary