This commit is contained in:
Alexey Berezhok
2024-03-19 22:05:27 +03:00
commit 346a50856b
1572 changed files with 182163 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
#!/bin/bash
# info: setup SMTP Account for server logging
# options: NONE
# labels:
#
# example: configure-server-smtp.sh
#
# This function provides an user-interactive configuration of a SMTP account
# for the server to use for logging, notification and warn emails etc.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/conf/hestia.conf
source $HESTIA/conf/hestia.conf
function setupFiles {
echo "Use SMTP account for server communication (Y/n): "
read use_smtp_prompt
use_smtp="${use_smtp_prompt:-y}"
use_smtp="${use_smtp,,}"
if [ "${use_smtp}" == "y" ]; then
use_smtp=true
echo "Enter SMTP Host:"
read -i $SERVER_SMTP_HOST -e smtp_server_host
echo "Enter SMTP Port:"
read -i $SERVER_SMTP_PORT -e smtp_server_port
echo "Enter SMTP Security:"
read -i $SERVER_SMTP_SECURITY -e smtp_server_security
echo "Enter SMTP Username:"
read -i $SERVER_SMTP_USER -e smtp_server_user_name
echo "Enter SMTP Password (stored as plaintext):"
read -i $SERVER_SMTP_PASSWD -e smtp_server_password
echo "Enter Email Address:"
read -i $SERVER_SMTP_ADDR -e smtp_server_addr
else
use_smtp=false
fi
echo "Summary:
Use SMTP: $use_smtp
SMTP Host: $smtp_server_host
SMTP Port: $smtp_server_port
SMTP Security: $smtp_server_security
SMTP Username: $smtp_server_user_name
SMTP Password: $smtp_server_password
Email Address: $smtp_server_addr
Are these values correct? (y/N)"
read correct_validation
correct="${correct_validation:-n}"
correct="${correct,,}"
if [ "${correct}" != "y" ]; then
echo "Not Proceeding. Restart or Quit (r/Q)?"
read restart_quit_prompt
restart_quit="${restart_quit_prompt:-q}"
restart_quit="${restart_quit,,}"
if [ "${restart_quit}" == "r" ]; then
clear
setupFiles
else
exit 3
fi
else
$BIN/v-change-sys-config-value "USE_SERVER_SMTP" "${use_smtp:-}"
$BIN/v-change-sys-config-value "SERVER_SMTP_HOST" "${smtp_server_host:-}"
$BIN/v-change-sys-config-value "SERVER_SMTP_PORT" "${smtp_server_port:-}"
$BIN/v-change-sys-config-value "SERVER_SMTP_SECURITY" "${smtp_server_security:-}"
$BIN/v-change-sys-config-value "SERVER_SMTP_USER" "${smtp_server_user_name:-}"
$BIN/v-change-sys-config-value "SERVER_SMTP_PASSWD" "${smtp_server_password:-}"
$BIN/v-change-sys-config-value "SERVER_SMTP_ADDR" "${smtp_server_addr:-}"
fi
}
setupFiles

View File

@@ -0,0 +1,50 @@
#!/bin/bash
# info: enable GeoIP Awstats
#
# This function enables GeoIP location lookup for
# IP addresses that are listed in awstats.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/conf/hestia.conf
source $HESTIA/conf/hestia.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
#check if string already exists
if grep "geoip" $HESTIA/data/templates/web/awstats/awstats.tpl; then
echo "Plugin allready enabled"
exit 0
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ -d /etc/awstats ]; then
perl -MCPAN -f -e "install Geo::IP::PurePerl"
perl -MCPAN -f -e "install Geo::IP"
sed -i '/LoadPlugin=\"geoip GEOIP_STANDARD \/usr\/share\/GeoIP\/GeoIP.dat\"/s/^#//g' /etc/awstats/awstats.conf
echo "LoadPlugin=\"geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat\"" >> $HESTIA/data/templates/web/awstats/awstats.tpl
for user in $($BIN/v-list-sys-users plain); do
$BIN/v-rebuild-web-domains $user no
done
fi
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
# Logging
log_history "Enabled GeoIP Awstats" '' 'admin'
log_event "$OK" "$ARGUMENTS"
exit 0

View File

@@ -0,0 +1,50 @@
#!/bin/bash
# info: enable GeoIP2 in Awstats
#
# This function enables GeoIP2 location lookup for
# IP addresses that are listed in awstats.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/conf/hestia.conf
source $HESTIA/conf/hestia.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
#check if string already exists
if grep "geoip2" $HESTIA/data/templates/web/awstats/awstats.tpl; then
echo "Plugin allready enabled"
exit 0
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ -d /etc/awstats ]; then
apt-get install make libssl-dev zlib1g-dev libdata-validate-ip-perl
perl -MCPAN -f -e "GeoIP2::Database::Reader"
sed -i '/LoadPlugin=\"geoip2_country \/pathto\/GeoLite2-Country.mmdb\"/s/^#//g;s/pathto/usr\/share\/GeoIP/g' /etc/awstats/awstats.conf
echo "LoadPlugin=\"geoip2_country /usr/share/GeoIP/GeoLite2-Country.mmdb\"" >> $HESTIA/data/templates/web/awstats/awstats.tpl
for user in $($BIN/v-list-sys-users plain); do
$BIN/v-rebuild-web-domains $user no
done
fi
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
# Logging
log_history "Enabled GeoIP2 Awstats" '' 'admin'
log_event "$OK" "$ARGUMENTS"
exit 0

View File

@@ -0,0 +1,127 @@
#!/bin/bash
# info: Install / remove sieve / manage-sieve for Dovecot
#
# Thos function installs manage-sieve functionality for dovecot.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"
source_conf "$HESTIA/install/upgrade/upgrade.conf"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
#check if string already exists
if grep "dovecot_virtual_delivery" /etc/exim4/exim4.conf.template; then
echo "Plugin allready enabled"
exit 0
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
HAS_DOVECOT_SIEVE_INSTALLED=$(dpkg --get-selections dovecot-sieve | grep dovecot-sieve | wc -l)
# Folder paths
RC_INSTALL_DIR="/var/lib/roundcube"
RC_CONFIG_DIR="/etc/roundcube"
# If we want to install sieve
if [ "$HAS_DOVECOT_SIEVE_INSTALLED" = "0" ]; then
# if sieve is not installed... install it.
apt-get -qq install dovecot-sieve dovecot-managesieved -y
# dovecot.conf install
sed -i "s/namespace/service stats \{\n unix_listener stats-writer \{\n group = mail\n mode = 0660\n user = dovecot\n \}\n\}\n\nnamespace/g" /etc/dovecot/dovecot.conf
# dovecot conf files
# 10-master.conf
sed -i -E -z "s/ }\n user = dovecot\n}/ \}\n unix_listener auth-master \{\n group = mail\n mode = 0660\n user = dovecot\n \}\n user = dovecot\n\}/g" /etc/dovecot/conf.d/10-master.conf
# 15-lda.conf
sed -i "s/\#mail_plugins = \\\$mail_plugins/mail_plugins = \$mail_plugins quota sieve\n auth_socket_path = \/var\/run\/dovecot\/auth-master/g" /etc/dovecot/conf.d/15-lda.conf
# 20-imap.conf
sed -i "s/mail_plugins = quota imap_quota/mail_plugins = quota imap_quota imap_sieve/g" /etc/dovecot/conf.d/20-imap.conf
# replace dovecot-sieve config files
cp -f $HESTIA_COMMON_DIR/dovecot/sieve/* /etc/dovecot/conf.d
# dovecot default file install
mkdir -p /etc/dovecot/sieve
echo -e "require [\"fileinto\"];\n# rule:[SPAM]\nif header :contains \"X-Spam-Flag\" \"YES\" {\n fileinto \"INBOX.Spam\";\n}\n" > /etc/dovecot/sieve/default
# exim4 install
sed -i "s/\stransport = local_delivery/ transport = dovecot_virtual_delivery/" /etc/exim4/exim4.conf.template
sed -i "s/address_pipe:/dovecot_virtual_delivery:\n driver = pipe\n command = \/usr\/lib\/dovecot\/dovecot-lda -e -d \${extract{1}{:}{\${lookup{\$local_part}lsearch{\/etc\/exim4\/domains\/\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\/accounts}}}}@\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\n delivery_date_add\n envelope_to_add\n return_path_add\n log_output = true\n log_defer_output = true\n user = \${extract{2}{:}{\${lookup{\$local_part}lsearch{\/etc\/exim4\/domains\/\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\/passwd}}}}\n group = mail\n return_output\n\naddress_pipe:/g" /etc/exim4/exim4.conf.template
# roundcube install
mkdir -p $RC_CONFIG_DIR/plugins/managesieve
cp -f $HESTIA_COMMON_DIR/roundcube/plugins/config_managesieve.inc.php $RC_CONFIG_DIR/plugins/managesieve/config.inc.php
ln -s $RC_CONFIG_DIR/plugins/managesieve/config.inc.php $RC_INSTALL_DIR/plugins/managesieve/config.inc.php
# permission changes
chown -R dovecot:mail /var/log/dovecot.log
chmod 660 /var/log/dovecot.log
chown -R root:www-data $RC_CONFIG_DIR/
chmod 751 -R $RC_CONFIG_DIR
chmod 644 $RC_CONFIG_DIR/plugins/managesieve/config.inc.php
sed -i "s/\"archive\"/\"archive\", \"managesieve\"/g" $RC_CONFIG_DIR/config.inc.php
#restart dovecot and exim4
systemctl restart dovecot > /dev/null 2>&1
systemctl restart exim4 > /dev/null 2>&1
else
# Uninstall sieve if it exist
if [ -f "/etc/dovecot/conf.d/90-sieve.conf" ]; then
# dovecot.conf multiline sed
sed -i -E -z "s/service stats \{\n unix_listener stats-writer \{\n group = mail\n mode = 0660\n user = dovecot\n \}\n\}\n\n//g" /etc/dovecot/dovecot.conf
# dovecot conf files
# 10-master.conf
sed -i -E -z "s/ \}\n unix_listener auth-master \{\n group = mail\n mode = 0660\n user = dovecot\n \}\n user = dovecot\n\}/ \}\n user = dovecot\n\}/g" /etc/dovecot/conf.d/10-master.conf
# 15-lda.conf
sed -i -E -z "s/mail_plugins = \\\$mail_plugins sieve\n auth_socket_path = \/run\/dovecot\/auth-master/\#mail_plugins = \$mail_plugins/g" /etc/dovecot/conf.d/15-lda.conf
# 20-imap.conf
sed -i "s/mail_plugins = quota imap_quota imap_sieve/mail_plugins = quota imap_quota/g" /etc/dovecot/conf.d/20-imap.conf
# Delete dovecot-sieve config files
rm -f /etc/dovecot/conf.d/20-managesieve.conf
rm -f /etc/dovecot/conf.d/90-sieve-extprograms.conf
rm -f /etc/dovecot/conf.d/90-sieve.conf
# Dovecot default file
rm -r -f /etc/dovecot/sieve
# If sieve is installed... remove it.
apt-get -qq remove --purge dovecot-sieve -y
# Exim4
sed -i "s/\stransport = dovecot_virtual_delivery/ transport = local_delivery/" /etc/exim4/exim4.conf.template
sed -i "s/dovecot_virtual_delivery:\n driver = pipe\n command = \/usr\/lib\/dovecot\/dovecot-lda -e -d \${extract{1}{:}{\${lookup{\$local_part}lsearch{\/etc\/exim4\/domains\/\${lookup{\$domain}dsearch{\/etc\/exim4\/domains/}}\/accounts}}}}@\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\n delivery_date_add\n envelope_to_add\n return_path_add\n log_output = true\n log_defer_output = true\n user = \${extract{2}{:}{\${lookup{\$local_part}lsearch{\/etc\/exim4\/domains\/\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\/passwd}}}}\n group = mail\n return_output\n//g" /etc/exim4/exim4.conf.template
# Roundcube
rm -f -r $RC_CONFIG_DIR/plugins/managesieve
rm -f $RC_INSTALL_DIR/plugins/managesieve/config.inc.php
sed -i "s/\"archive\", \"managesieve\"/\"archive\"/g" $RC_CONFIG_DIR/config.inc.php
#restart dovecot and exim4
systemctl restart dovecot > /dev/null 2>&1
systemctl restart exim4 > /dev/null 2>&1
fi
fi

View File

@@ -0,0 +1,99 @@
#!/bin/bash
# info: enable multiphp
#
# This function enables php-fpm backend for standalone apache2 configurations.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/conf/hestia.conf
source $HESTIA/conf/hestia.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
if [ ! -z "$WEB_BACKEND" ]; then
check_result $E_EXISTS "Web backend already enabled" > /dev/null
fi
if [ "$(multiphp_count)" -gt 1 ]; then
check_result $E_EXISTS "Multiphp already enabled" > /dev/null
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
php_v="$(multiphp_default_version)"
$BIN/v-add-web-php "$php_v"
cp -f "${HESTIA_INSTALL_DIR}/php-fpm/www.conf" "/etc/php/${php_v}/fpm/pool.d/www.conf"
systemctl start php${php_v}-fpm
check_result $? "php${php_v}-fpm start failed"
update-alternatives --set php /usr/bin/php${php_v}
if [ ! -z "$WEB_SYSTEM" ]; then
cp -rf "${HESTIA_INSTALL_DIR}/templates/web/$WEB_SYSTEM" "${WEBTPL}/"
fi
sed -i "/^WEB_BACKEND=/d" $HESTIA/conf/hestia.conf
echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
for user in $($BIN/v-list-sys-users plain); do
# Define user data and get suspended status
USER_DATA=$HESTIA/data/users/$user
SUSPENDED=$(get_user_value '$SUSPENDED')
# Check if user is suspended
if [ "$SUSPENDED" = "yes" ]; then
suspended="yes"
$BIN/v-unsuspend-user $user
fi
for domain in $($BIN/v-list-web-domains $user plain | cut -f1); do
SUSPENDED_WEB=$(get_object_value 'web' 'DOMAIN' "$domain" '$SUSPENDED')
# Check if web domain is suspended
if [ "$SUSPENDED_WEB" = "yes" ]; then
suspended_web="yes"
$BIN/v-unsuspend-web-domain $user $domain
fi
echo "Processing domain: $domain"
$BIN/v-change-web-domain-backend-tpl "$user" "$domain" "PHP-${php_v/\./_}" "no"
$BIN/v-change-web-domain-tpl "$user" "$domain" "default" "no"
# Suspend domain again, if it was suspended
if [ "$suspended_web" = "yes" ]; then
unset suspended_web
$BIN/v-suspend-web-domain $user $domain
fi
done
# Suspend user again, if he was suspended
if [ "$suspended" = "yes" ]; then
unset suspended
$BIN/v-suspend-user $user
fi
done
$BIN/v-update-web-templates "yes"
# Restarting backend
$BIN/v-restart-web-backend "yes"
check_result $? "Backend restart" > /dev/null 2>&1
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
# Logging
log_history "Enabled multiphp $version" '' 'admin'
log_event "$OK" "$ARGUMENTS"
exit

View File

@@ -0,0 +1,83 @@
#!/bin/bash
# This script migrates your apache2 installation form mod_prefork to mpm_event.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
source $HESTIA/conf/hestia.conf
# Check if apache2 is in use
if [ "$WEB_SYSTEM" != "apache2" ]; then
echo "Apache2 isn't installed on your system, canceling migration..." && exit 1
fi
# Check if PHP-FPM is instaled
if [ "$WEB_BACKEND" != "php-fpm" ]; then
echo "PHP-FPM not yet installed please run migrate_apache.sh first" && exit 1
fi
# Check if mod_event is already enabled
if [ $(a2query -M) = 'event' ]; then
echo "mod_event is already enabled, canceling migration..." && exit 1
fi
if ! apache2ctl configtest > /dev/null 2>&1; then
echo "Apache2 configtest failed" && exit 1
fi
a2modules="php5.6 php7.0 php7.1 php7.2 php7.3 php7.4 ruid2 mpm_itk mpm_prefork"
changed_a2modules=""
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
for module in $a2modules; do
a2query -q -m "$module" || continue
a2dismod -q "$module"
changed_a2modules="${changed_a2modules} ${module}"
done
a2enmod --quiet mpm_event
cp -f /usr/local/hestia/install/deb/apache2/hestia-event.conf /etc/apache2/conf.d/
# Check if all went well
if ! apache2ctl configtest > /dev/null 2>&1; then
echo "Something went wrong, rolling back. Please try to migrate manually to mpm_event."
a2dismod -q mpm_event
for module in $changed_a2modules; do
a2enmod "$module"
done
rm --force /etc/apache2/conf.d/hestia-event.conf
exit 1
fi
# Validate if www.conf is existent and port 9000 is active
if ! lsof -Pi :9000 -sTCP:LISTEN -t > /dev/null; then
if [ $(ls /etc/php/7.3/fpm/pool.d/www.conf) ]; then
# Replace listen port to 9000
sed -i "s/listen = 127.0.0.1:.*/listen = 127.0.0.1:9000/g" /etc/php/7.3/fpm/pool.d/www.conf
else
# Copy www.conf file
cp -f /usr/local/hestia/install/deb/php-fpm/www.conf /etc/php/7.3/fpm/pool.d/
fi
# Restart php7.3 fpm service.
systemctl restart php7.3-fpm
fi
# Check again if port 9000 is now in use.
if lsof -Pi :9000 -sTCP:LISTEN -t > /dev/null; then
echo "mpm_event module was successfully activated."
else
echo "There went something wrong with your php-fpm configuration - port 9000 isnt active. Please check if webmail and phpmyadmin (if installed) are working properly."
fi
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
systemctl restart apache2

View File

@@ -0,0 +1,162 @@
#!/bin/bash
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/conf/hestia.conf
source $HESTIA/conf/hestia.conf
#
# Migrate legacy multiphp to full php-fpm backend
#
# nginx+fpm (default)
# nothing to be done here,
# (Adding new php backends will make them available on edit/web)
#
# nginx+multiphp,
# nginx+apache+multiphp,
# apache+multiphp:
# Change Hestia WEB_BACKEND from null to php-fpm
# Create backend templates ex: PHP-7_3, PHP-5_6 (in $HESTIA/data/templates/web/php-fpm/)
# v-update-web-templates
# Loop through all web domains
# If official multiphp tpl is used ex: PHP-72, then change backend tpl and set app web template to default
# ( old default.tpl backend maps to PHP-7_3 )
# If not, parse php version from tpl file , fallback to latest version,
# Copy all non-official tpls to php-fpm folder (as app web template includin bash script if present)
#
# a2 (non-fpm) or nginx+a2(non-fpm)
# - Skipped
#
DEFAULT_BTPL="PHP-7_3"
num_php_versions=$(ls -d /etc/php/*/fpm/pool.d 2> /dev/null | wc -l)
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
echo "Found $num_php_versions php versions"
if [ "$num_php_versions" -gt 1 ] && [ -z "$WEB_BACKEND" ]; then
# Legacy multiphp
sed -i "/^WEB_BACKEND=/d" $HESTIA/conf/hestia.conf
echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
for php_ver in $(v-list-sys-php); do
[ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
cp -f "$HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl" ${WEBTPL}/php-fpm/PHP-${php_ver/\./_}.tpl
done
if [ ! -z "$WEB_SYSTEM" ]; then
cp -rf "${HESTIA_INSTALL_DIR}/templates/web/$WEB_SYSTEM" "${WEBTPL}/"
fi
# Migrate domains
for user in $($BIN/v-list-sys-users plain); do
# Define user data and get suspended status
USER_DATA=$HESTIA/data/users/$user
SUSPENDED=$(get_user_value '$SUSPENDED')
# Check if user is suspended
if [ "$SUSPENDED" = "yes" ]; then
suspended="yes"
$BIN/v-unsuspend-user $user
fi
echo "Migrating legacy multiphp domains for user: $user"
for domain in $($BIN/v-list-web-domains $user plain | cut -f1); do
SUSPENDED_WEB=$(get_object_value 'web' 'DOMAIN' "$domain" '$SUSPENDED')
# Check if web domain is suspended
if [ "$SUSPENDED_WEB" = "yes" ]; then
suspended_web="yes"
$BIN/v-unsuspend-web-domain $user $domain
fi
echo "Processing domain: $domain"
web_tpl="default"
backend_tpl="$DEFAULT_BTPL"
domain_tpl=$($BIN/v-list-web-domain $user $domain | grep "^TEMPLATE:" | awk '{print $2;}')
if [ "$domain_tpl" = "PHP-56" ]; then
backend_tpl="PHP-5_6"
elif [ "$domain_tpl" = "PHP-70" ]; then
backend_tpl="PHP-7_0"
elif [ "$domain_tpl" = "PHP-71" ]; then
backend_tpl="PHP-7_1"
elif [ "$domain_tpl" = "PHP-72" ]; then
backend_tpl="PHP-7_2"
elif [ "$domain_tpl" = "PHP-73" ] || [ "$domain_tpl" = "default" ] || [ -z "$domain_tpl" ]; then
backend_tpl="PHP-7_3"
elif [ "$domain_tpl" = "PHP-74" ]; then
backend_tpl="PHP-7_4"
else
# Custom domain template used
echo "Domain is using a custom multiphp template (or non-multiphp one)"
web_tpl="$domain_tpl"
if [ -f "${WEBTPL}/$WEB_SYSTEM/php-fpm/$web_tpl.tpl" ]; then
# php-fpm backend folder allready has a template with the same name
web_tpl="custom-$domain_tpl"
fi
# Copy custom template to php-fpm backend folder
mkdir -p "$WEBTPL/$WEB_SYSTEM/php-fpm"
if [ -f "$WEBTPL/$WEB_SYSTEM/$domain_tpl.sh" ]; then
cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.sh" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.sh"
fi
cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.tpl" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.tpl"
cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.stpl" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.stpl"
if [[ $(grep "unix:/" $WEBTPL/$WEB_SYSTEM/$domain_tpl.tpl | egrep -v "^\s*#" | tail -n1) =~ unix:\/run\/php\/php([0-9]+\.[0-9]+)-fpm.+\.sock ]]; then
# Found a custom template that is based on official multiphp one
backend_tpl="PHP-${BASH_REMATCH[1]/\./_}"
echo "Custom multiphp template ($domain_tpl) compatible with backend: $backend_tpl"
# Remove multiphp switching script
rm -f "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.sh"
# Replace hardcoded php-fpm socket path with tpl variable, ignoring commented lines
sed '/^[[:space:]]*#/!s/unix:.*;/%backend_lsnr%;/g' "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.tpl"
sed '/^[[:space:]]*#/!s/unix:.*;/%backend_lsnr%;/g' "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.stpl"
fi
fi
echo "Parsed config: oldTPL=$domain_tpl newTPL:$web_tpl newBackTPL:$backend_tpl"
$BIN/v-change-web-domain-tpl "$user" "$domain" "$web_tpl" "no"
$BIN/v-change-web-domain-backend-tpl "$user" "$domain" "$backend_tpl" "no"
echo -e "--done--\n"
# Suspend domain again, if it was suspended
if [ "$suspended_web" = "yes" ]; then
unset suspended_web
$BIN/v-suspend-web-domain $user $domain
fi
done
# Suspend user again, if he was suspended
if [ "$suspended" = "yes" ]; then
unset suspended
$BIN/v-suspend-user $user
fi
done
# cleanup legacy multiphp templates
for php_ver in $(v-list-sys-php); do
[ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
echo "Remove legacy multiphp templates for: $php_ver"
[ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//./}.sh" ] && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//./}.sh"
[ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//./}.tpl" ] && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//./}.tpl"
[ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//./}.stpl" ] && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//./}.stpl"
done
# Remove default symlinks
[ -f "$WEBTPL/$WEB_SYSTEM/default.sh" ] && rm "$WEBTPL/$WEB_SYSTEM/default.sh"
[ -f "$WEBTPL/$WEB_SYSTEM/default.tpl" ] && rm "$WEBTPL/$WEB_SYSTEM/default.tpl"
[ -f "$WEBTPL/$WEB_SYSTEM/default.stpl" ] && rm "$WEBTPL/$WEB_SYSTEM/default.stpl"
$BIN/v-update-web-templates 'no'
fi

View File

@@ -0,0 +1,67 @@
#!/bin/bash
# Function Description
# Manual upgrade script from Nginx + Apache2 + PHP-FPM to Nginx + PHP-FPM
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/conf/hestia.conf
source $HESTIA/conf/hestia.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
if [ "$WEB_BACKEND" != "php-fpm" ]; then
check_result $E_NOTEXISTS "PHP-FPM is not enabled" > /dev/null
exit 1
fi
if [ "$WEB_SYSTEM" != "apache2" ]; then
check_result $E_NOTEXISTS "Apache2 is not enabled" > /dev/null
exit 1
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Remove apache2 from config
sed -i "/^WEB_PORT/d" $HESTIA/conf/hestia.conf
sed -i "/^WEB_SSL/d" $HESTIA/conf/hestia.conf
sed -i "/^WEB_SSL_PORT/d" $HESTIA/conf/hestia.conf
sed -i "/^WEB_RGROUPS/d" $HESTIA/conf/hestia.conf
sed -i "/^WEB_SYSTEM/d" $HESTIA/conf/hestia.conf
# Remove nginx (proxy) from config
sed -i "/^PROXY_PORT/d" $HESTIA/conf/hestia.conf
sed -i "/^PROXY_SSL_PORT/d" $HESTIA/conf/hestia.conf
sed -i "/^PROXY_SYSTEM/d" $HESTIA/conf/hestia.conf
# Add Nginx settings to config
echo "WEB_PORT='80'" >> $HESTIA/conf/hestia.conf
echo "WEB_SSL='openssl'" >> $HESTIA/conf/hestia.conf
echo "WEB_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
echo "WEB_SYSTEM='nginx'" >> $HESTIA/conf/hestia.conf
rm $HESTIA/conf/defaults/hestia.conf
cp $HESTIA/conf/hestia.conf $HESTIA/conf/defaults/hestia.conf
# Rebuild web config
for user in $($BIN/v-list-users plain | cut -f1); do
echo $user
for domain in $($BIN/v-list-web-domains $user plain | cut -f1); do
$BIN/v-change-web-domain-tpl $user $domain 'default'
$BIN/v-rebuild-web-domain $user $domain no
done
done
systemctl restart nginx

View File

@@ -0,0 +1,198 @@
#!/bin/bash
# info: Disconnect phpMyadmin from APT and solving issues with PHPMyadmin accidental updates from ATP
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
source $HESTIA/func/main.sh
# get current phpmyadmin version
source $HESTIA/install/upgrade/upgrade.conf
source $HESTIA/conf/hestia.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
echo "To remove phpMyAdmin you will need use the root password. Password can be found in /usr/local/hestia/conf/mysql.conf"
read -p 'Would you like to continue? [y/n]'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Remove PMA SSO first
sso="no"
if [ "$PHPMYADMIN_KEY" != "" ]; then
sso="yes"
$BIN/v-delete-sys-pma-sso
fi
# Create an backup of current config
echo "[ * ] Backing up old configuration files..."
mkdir -p /root/hst_backup_man/phmyadmin
cp -r /etc/phpmyadmin/* /root/hst_backup_man/phmyadmin
mkdir -p /root/hst_backup_man/var_phmyadmin
cp -r /var/lib/phpmyadmin/* /root/hst_backup_man/var_phmyadmin
echo '[ * ] Marking phpmyadmin as held in apt...'
apt-mark hold phpmyadmin
echo '[ * ] Removing old folders...'
# make sure everything is deleted
rm -f -r /usr/share/phpmyadmin
rm -f -r /etc/phpmyadmin
rm -f -r /var/lib/phpmyadmin/
echo '[ * ] Creating new folders...'
# Create folders
mkdir -p /usr/share/phpmyadmin
mkdir -p /etc/phpmyadmin
mkdir -p /etc/phpmyadmin/conf.d/
mkdir /usr/share/phpmyadmin/tmp
chmod 770 /usr/share/phpmyadmin/tmp/
chown root:www-data /usr/share/phpmyadmin/tmp/
mkdir -p /etc/phpmyadmin/conf.d/
# Configuring Apache2 for PHPMYADMIN
if [ "$WEB_SYSTEM" == "apache2" ]; then
cp -f $HESTIA_INSTALL_DIR/pma/apache.conf /etc/phpmyadmin/
rm /etc/apache2/conf.d/phpmyadmin.conf
ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
fi
PASS=$(generate_password)
echo "[ * ] Installing phpMyAdmin version v$pma_v..."
# Download latest phpmyadmin release
wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
# Unpack files
tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
# Overwrite old files
cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
# Create copy of config file
cp -f $HESTIA_COMMON_DIR/phpmyadmin/config.inc.php /etc/phpmyadmin/
mkdir -p /var/lib/phpmyadmin/tmp
chmod 770 -R /var/lib/phpmyadmin/tmp
# Set config and log directory
sed -i "s|'configFile' => ROOT_PATH . 'config.inc.php',|'configFile' => '/etc/phpmyadmin/config.inc.php',|g" /usr/share/phpmyadmin/libraries/vendor_config.php
# Generate blowfish
blowfish=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
sed -i "s|%blowfish_secret%|$blowfish|" /etc/phpmyadmin/config.inc.php
# Clear Up
rm -fr phpMyAdmin-$pma_v-all-languages
rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
if [ -z "$DB_PMA_ALIAS" ]; then
echo "DB_PMA_ALIAS='phpmyadmin'" >> $HESTIA/conf/hestia.conf
fi
$BIN/v-change-sys-db-alias 'pma' "phpmyadmin"
# Special thanks to Pavel Galkin (https://skurudo.ru)
# https://github.com/skurudo/phpmyadmin-fixer
echo "[ * ] Creating localhost configuration..."
#ubuntu phpmyadmin path
pmapath="/etc/phpmyadmin/conf.d/01-localhost.php"
echo "<?php " >> $pmapath
echo "\$cfg['Servers'][\$i]['host'] = 'localhost';" >> $pmapath
echo "\$cfg['Servers'][\$i]['port'] = '3306';" >> $pmapath
echo "\$cfg['Servers'][\$i]['favorite'] = 'pma__favorite';" >> $pmapath
echo "\$cfg['Servers'][\$i]['usergroups'] = 'pma__usergroups';" >> $pmapath
echo "\$cfg['Servers'][\$i]['central_columns'] = 'pma__central_columns';" >> $pmapath
echo "\$cfg['Servers'][\$i]['designer_settings'] = 'pma__designer_settings';" >> $pmapath
echo "\$cfg['Servers'][\$i]['export_templates'] = 'pma__export_templates';" >> $pmapath
echo "\$cfg['Servers'][\$i]['savedsearches'] = 'pma__savedsearches';" >> $pmapath
echo "\$cfg['Servers'][\$i]['navigationhiding'] = 'pma__navigationhiding';" >> $pmapath
echo "\$cfg['Servers'][\$i]['users'] = 'pma__users';" >> $pmapath
echo "\$cfg['Servers'][\$i]['usergroups'] = 'pma__usergroups';" >> $pmapath
echo "\$cfg['Servers'][\$i]['pmadb'] = 'phpmyadmin';" >> $pmapath
echo "\$cfg['Servers'][\$i]['controluser'] = 'pma';" >> $pmapath
echo "\$cfg['Servers'][\$i]['controlpass'] = '$PASS';" >> $pmapath
echo "\$cfg['Servers'][\$i]['bookmarktable'] = 'pma__bookmark';" >> $pmapath
echo "\$cfg['Servers'][\$i]['relation'] = 'pma__relation';" >> $pmapath
echo "\$cfg['Servers'][\$i]['userconfig'] = 'pma__userconfig';" >> $pmapath
echo "\$cfg['Servers'][\$i]['table_info'] = 'pma__table_info';" >> $pmapath
echo "\$cfg['Servers'][\$i]['column_info'] = 'pma__column_info';" >> $pmapath
echo "\$cfg['Servers'][\$i]['history'] = 'pma__history';" >> $pmapath
echo "\$cfg['Servers'][\$i]['recent'] = 'pma__recent';" >> $pmapath
echo "\$cfg['Servers'][\$i]['table_uiprefs'] = 'pma__table_uiprefs';" >> $pmapath
echo "\$cfg['Servers'][\$i]['tracking'] = 'pma__tracking';" >> $pmapath
echo "\$cfg['Servers'][\$i]['table_coords'] = 'pma__table_coords';" >> $pmapath
echo "\$cfg['Servers'][\$i]['pdf_pages'] = 'pma__pdf_pages';" >> $pmapath
echo "\$cfg['Servers'][\$i]['designer_coords'] = 'pma__designer_coords';" >> $pmapath
#SOME WORK with DATABASE (table / user)
PMADB=phpmyadmin
PMAUSER=pma
echo '[ * ] Dropping database (could throw an error if successful)...'
# removed tabs due to here doc errors
#DROP USER and TABLE
mysql -uroot << MYSQL_PMA1
DROP USER '$PMAUSER'@'localhost';
DROP DATABASE $PMADB;
FLUSH PRIVILEGES;
MYSQL_PMA1
#CREATE PMA USER
if [ -f '/usr/bin/mariadb' ]; then
mysql="mariadb"
else
mysql="mysql"
fi
mysql_out=$(mktemp)
$mysql -e 'SELECT VERSION()' > $mysql_out
mysql_ver=$(cat $mysql_out | tail -n1 | cut -f 1 -d -)
mysql_ver_sub=$(echo $mysql_ver | cut -d '.' -f1)
mysql_ver_sub_sub=$(echo $mysql_ver | cut -d '.' -f2)
if [ "$mysql" = "mysql" ] && [ "$mysql_ver_sub" -ge 8 ]; then
query="CREATE USER '$PMAUSER'@'localhost' IDENTIFIED BY '$PASS';"
$mysql -uroot -e "$query" > /dev/null
query="CREATE DATABASE $PMADB;"
$mysql -uroot -e "$query" > /dev/null
query="GRANT USAGE ON $PMADB.* TO '$PMAUSER'@'localhost';"
$mysql -uroot -e "$query" > /dev/null
query="GRANT ALL PRIVILEGES ON $PMADB.* TO '$PMAUSER'@'localhost';"
$mysql -uroot -e "$query" > /dev/null
query="FLUSH PRIVILEGES;"
$mysql -uroot -e "$query" > /dev/null
else
query="CREATE USER '$PMAUSER'@'localhost' IDENTIFIED BY '$PASS';"
$mysql -uroot -e "$query" > /dev/null
query="CREATE DATABASE $PMADB;"
$mysql -uroot -e "$query" > /dev/null
query="GRANT USAGE ON $PMADB.* TO '$PMAUSER'@'localhost' IDENTIFIED BY '$PASS';"
$mysql -uroot -e "$query" > /dev/null
query="GRANT ALL PRIVILEGES ON $PMADB.* TO '$PMAUSER'@'localhost';"
$mysql -uroot -e "$query" > /dev/null
query="FLUSH PRIVILEGES;"
$mysql -uroot -e "$query" > /dev/null
fi
#MYSQL DB and TABLES ADDITION
mysql -uroot < $HESTIA_COMMON_DIR/phpmyadmin/create_tables.sql
if [ "$sso" == "yes" ]; then
$BIN/v-add-sys-pma-sso
fi
fi

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# info: Disconnect Roundcube from APT and solving issues with Roundcube accidental updates from ATP
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
source $HESTIA/func/main.sh
# get current Roundcube version
source $HESTIA/install/upgrade/upgrade.conf
source $HESTIA/conf/hestia.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
if [ ! -d "/usr/share/roundcube/" ]; then
echo "ERROR: Roundcube is not managed by apt."
exit 2
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
echo "To remove Roundcube you will need use the root password. Password can be found in /usr/local/hestia/conf/mysql.conf"
read -p 'Would you like to continue? [y/n]' -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
version=$(cat /usr/share/roundcube/index.php | grep -o -E '[0-9].[0-9].[0-9]+' | head -1)
# Backup database
echo "#version $version" >> ~/roundcube.sql
echo "SET FOREIGN_KEY_CHECKS = 0;" >> ~/roundcube.sql
mysqldump --add-drop-table roundcube >> ~/roundcube.sql
echo "SET FOREIGN_KEY_CHECKS = 1;" >> ~/roundcube.sql
echo '[ * ] Remove Roundcube via ATP'
apt-get autoremove roundcube-core roundcube-mysql roundcube-plugins
echo '[ * ] Delete possible trail'
# make sure everything is deleted
rm -f -r /usr/share/roundcube
rm -f -r /etc/roundcube
rm -f -r /var/lib/roundcube/
# Install Roundcube
$BIN/v-add-sys-roundcube
# restore backup
echo "SET FOREIGN_KEY_CHECKS = 0;" > ~/drop_all_tables.sql
(mysqldump --add-drop-table --no-data -u root roundcube | grep 'DROP TABLE') >> ./drop_all_tables.sql
echo "SET FOREIGN_KEY_CHECKS = 1;" >> ~/drop_all_tables.sql
mysql -u root roundcube < ./drop_all_tables.sql
mysql roundcube < ~/roundcube.sql
/var/lib/roundcube/bin/update.sh --version "$version"
fi

View File

@@ -0,0 +1,53 @@
#!/bin/bash
# Function Description
# Soft remove the mail stack
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/conf/hestia.conf
source $HESTIA/conf/hestia.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
echo "This will soft remove the mail stack from HestiaCP and disable related systemd service."
echo "You won't be able to access mail related configurations from HestiaCP."
echo "Your existing mail data and apt packages will be kept back."
read -p 'Would you like to continue? [y/n]'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ "$ANTISPAM_SYSTEM" == "spamassassin" ]; then
echo Removing Spamassassin
sed -i "/^ANTISPAM_SYSTEM/d" $HESTIA/conf/hestia.conf
systemctl disable --now spamassassin
fi
if [ "$ANTIVIRUS_SYSTEM" == "clamav-daemon" ]; then
echo Removing ClamAV
sed -i "/^ANTIVIRUS_SYSTEM/d" $HESTIA/conf/hestia.conf
systemctl disable --now clamav-daemon clamav-freshclam
fi
if [ "$IMAP_SYSTEM" == "dovecot" ]; then
echo Removing Dovecot
sed -i "/^IMAP_SYSTEM/d" $HESTIA/conf/hestia.conf
systemctl disable --now dovecot
fi
if [ "$MAIL_SYSTEM" == "exim4" ]; then
echo Removing Exim4
sed -i "/^MAIL_SYSTEM/d" $HESTIA/conf/hestia.conf
systemctl disable --now exim4
fi

View File

@@ -0,0 +1,69 @@
#!/bin/bash
# This script validates and upgrades the MariaDB version
#----------------------------------------------------------#
# Variable & Function #
#----------------------------------------------------------#
# Set MariaDB Target Version
mariadb_v='10.11'
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Detect installed MariaDB version
mysql_v="$(mysqld -V | awk '{print $3}' | cut -d: -f1)"
if [ "${mysql_v%.*}" = "$mariadb_v" ]; then
echo "[ ! ] MariaDB version ($mariadb_v) is already up to date."
exit 0
else
echo "[ * ] Upgrading MariaDB version to ($mariadb_v)..."
fi
# Get OS details
os="$(grep "^ID=" /etc/os-release | cut -d= -f2)"
codename="$(lsb_release -s -c)"
case $(arch) in
x86_64)
arch="amd64"
;;
aarch64)
arch="arm64"
;;
*)
echo "[ ! ] Error: $(arch) is currently not supported!"
exit 1
;;
esac
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Installing MariaDB repository
apt="/etc/apt/sources.list.d"
echo "[ * ] Installing MariaDB repository..."
echo "deb [arch=$arch signed-by=/usr/share/keyrings/mariadb-keyring.gpg] https://dlm.mariadb.com/repo/mariadb-server/$mariadb_v/repo/$os $codename main" > $apt/mariadb.list
curl -s https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor | tee /usr/share/keyrings/mariadb-keyring.gpg > /dev/null 2>&1
# Update repository
echo "[ * ] Update apt repository..."
apt update -qq > /dev/null 2>&1
# Stop and uninstall old version
echo "[ * ] Stop and remove old MariaDB Server (${mysql_v%.*})..."
systemctl -q stop mariadb mysql 2> /dev/null
apt remove -qq mariadb-server -y > /dev/null 2>&1
# Install new version and run upgrade
echo "[ * ] Installing new MariaDB Server, start and run upgrade..."
apt install -qq mariadb-server -y
update-rc.d mariadb defaults > /dev/null 2>&1
systemctl -q daemon-reload
systemctl -q enable mariadb
systemctl -q start mariadb
mariadb-upgrade

View File

@@ -0,0 +1,26 @@
#!/bin/bash
# Update www.conf to a different version so users can safely delete older php version.
# www.conf is used for Roundcube, Rainloop, SnappyMail and phpmyadmin
# Removal of the "www.conf" php version will cause issues with Rainloop not working. Current script updates it to the latest version of PHP installed. If that is not wanted use this script
version=$1
if [ ! -x "$(command -v php)" ]; then
echo "PHP is not installed. Aborting."
exit 1
fi
# Verify php version format
if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
echo "The PHP version format is invalid, it should look like [0-9].[0-9]."
echo "Example: 7.0, 7.4"
exit
fi
if [ ! -f /etc/php/$version/fpm/pool.d/dummy.conf ]; then
echo "PHP versions doesn't exists"
exit
fi
rm -f /etc/php/*/fpm/pool.d/www.conf
cp -f $HESTIA/install/deb/php-fpm/www.conf /etc/php/$version/fpm/pool.d/www.conf
$HESTIA/bin/v-restart-web-backend

View File

@@ -0,0 +1,66 @@
#!/bin/bash
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
phpnewversion=7.4
phpoldversion=7.3
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
if [ ! -x "$(command -v php)" ]; then
echo "PHP is not installed. Aborting."
exit 1
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
echo "PHP current version : $phpoldversion"
echo "PHP target version : $phpnewversion"
echo "Do you want to upgrade PHP now? [Y|N]"
read upgradeconfirmation
if [ "$upgradeconfirmation" = "Y" ] || [ "$upgradeconfirmation" = "y" ]; then
echo "Process: Upgrading PHP to $phpnewversion"
echo ""
cd /tmp
dpkg-query --showformat='${Package}\t\n' --show | grep php$phpoldversion > /tmp/phpoldpackages.txt
cp -a /tmp/phpoldpackages.txt /tmp/phpnewpackages.txt
sed -i "s|$phpoldversion|$phpnewversion|g" /tmp/phpnewpackages.txt
apt-get update > /dev/null 2>&1
apt-get install $(cat /tmp/phpnewpackages.txt)
update-rc.d php$phpnewversion-fpm defaults
mv /etc/php/$phpoldversion/cli/php.ini /etc/php/$phpnewversion/cli/php.ini
mv /etc/php/$phpoldversion/fpm/php.ini /etc/php/$phpnewversion/fpm/php.ini
sed -i "s|$phpoldversion|$phpnewversion|g" /etc/php/$phpoldversion/fpm/php-fpm.conf
mv /etc/php/$phpoldversion/fpm/php-fpm.conf /etc/php/$phpnewversion/fpm/php-fpm.conf
rm -rf /etc/php/$phpnewversion/fpm/pool.d
mkdir -p /etc/php/$phpnewversion/fpm/pool.d
mv /etc/php/$phpoldversion/fpm/pool.d/* /etc/php/$phpnewversion/fpm/pool.d
mv /etc/logrotate.d/php$phpoldversion-fpm /etc/logrotate.d/php$phpnewversion-fpm
sed -i "s|$phpoldversion|$phpnewversion|g" /etc/logrotate.d/php$phpnewversion-fpm
rm -rf /etc/logrotate.d/php$phpnewversion-fpm.dpkg-dist
systemctl stop php$phpoldversion-php
apt-get purge $(cat /tmp/phpoldpackages.txt)
apt-get -y purge php-imagick
apt-get -y install php$phpnewversion-imagick
systemctl restart php$phpnewversion-fpm
rm -rf /etc/php/$phpoldversion
rm -rf /var/lib/php/modules/$phpoldversion
rm -rf /tmp/phpoldpackages.txt
rm -rf /tmp/phpnewpackages.txt
if [ -d /var/cache/nginx/micro ]; then
rm -rf /var/cache/nginx/micro/*
fi
systemctl reload nginx
echo ""
echo "PHP has been upgraded succcesfully to version $phpnewversion"
else
echo "Process: Aborted"
exit 0
fi