3099 lines
81 KiB
Bash
Executable File
3099 lines
81 KiB
Bash
Executable File
#!/bin/bash
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
#
|
|
|
|
#
|
|
# Plesk script
|
|
#
|
|
|
|
|
|
|
|
#default values
|
|
|
|
product_default_conf()
|
|
{
|
|
|
|
PRODUCT_ROOT_D=/opt/psa
|
|
PRODUCT_RC_D=/etc/init.d
|
|
PRODUCT_ETC_D=/opt/psa/etc
|
|
PLESK_LIBEXEC_DIR=/usr/lib/plesk-9.0
|
|
HTTPD_VHOSTS_D=/var/www/vhosts
|
|
HTTPD_CONF_D=/etc/apache2
|
|
HTTPD_INCLUDE_D=/etc/apache2/conf-enabled
|
|
HTTPD_BIN=/usr/sbin/apache2
|
|
HTTPD_LOG_D=/var/log/apache2
|
|
HTTPD_SERVICE=apache2
|
|
QMAIL_ROOT_D=/var/qmail
|
|
PLESK_MAILNAMES_D=/var/qmail/mailnames
|
|
RBLSMTPD=/usr/sbin/rblsmtpd
|
|
NAMED_RUN_ROOT_D=/var/named/run-root
|
|
WEB_STAT=/usr/bin/webalizer
|
|
MYSQL_VAR_D=/var/lib/mysql
|
|
MYSQL_BIN_D=/usr/bin
|
|
MYSQL_SOCKET=/var/run/mysqld/mysqld.sock
|
|
PGSQL_DATA_D=/var/lib/postgresql/16/main
|
|
PGSQL_CONF_D=/etc/postgresql/16/main
|
|
PGSQL_BIN_D=/usr/lib/postgresql/16/bin
|
|
DUMP_D=/var/lib/psa/dumps
|
|
DUMP_TMP_D=/tmp
|
|
MAILMAN_ROOT_D=/usr/lib/mailman
|
|
MAILMAN_VAR_D=/var/lib/mailman
|
|
PYTHON_BIN=/usr/bin/python2
|
|
GPG_BIN=/usr/bin/gpg
|
|
TAR_BIN=/usr/lib/plesk-9.0/sw-tar
|
|
AWSTATS_ETC_D=/etc/awstats
|
|
AWSTATS_BIN_D=/usr/lib/cgi-bin
|
|
AWSTATS_TOOLS_D=/usr/share/awstats/tools
|
|
AWSTATS_DOC_D=/usr/share/awstats
|
|
OPENSSL_BIN=/usr/bin/openssl
|
|
LIB_SSL_PATH=/lib/libssl.so
|
|
LIB_CRYPTO_PATH=/lib/libcrypto.so
|
|
CLIENT_PHP_BIN=/opt/psa/bin/php-cli
|
|
SNI_SUPPORT=true
|
|
APS_DB_DRIVER_LIBRARY=/usr/lib/x86_64-linux-gnu/sw/libmysqlserver.so.2.0
|
|
SA_MAX_MAIL_SIZE=256000
|
|
|
|
}
|
|
|
|
# db_select <query>
|
|
# runs <query> via mysql_raw
|
|
# writes output to db_select_output
|
|
# if query fails, output errors and return 1
|
|
db_select()
|
|
{
|
|
local desc="execute SQL query"
|
|
local query="$1"
|
|
|
|
local output
|
|
output="`mysql_raw -e \"$query\" 2>>\"$product_log\"`"
|
|
local status="$?"
|
|
if [ "$status" -ne "0" ]; then
|
|
p_echo "$output"
|
|
die "run the following SQL query: $query"
|
|
fi
|
|
|
|
db_select_output="$output"
|
|
return 0
|
|
}
|
|
|
|
deferred_install_postfix_smtpd_sasl_config()
|
|
{
|
|
touch "/var/lock/plesk_deferred_install_postfix_smtpd_sasl_config"
|
|
}
|
|
|
|
deferred_postfix_restart()
|
|
{
|
|
touch "/var/lock/plesk_deferred_postfix_restart"
|
|
}
|
|
|
|
deferred_mail_pc_driver_transport_restore()
|
|
{
|
|
# restarts postfix
|
|
touch "/var/lock/plesk_deferred_mail_pc_driver_transport_restore"
|
|
}
|
|
|
|
is_remote_db_feature_enabled()
|
|
{
|
|
[ -s "/etc/psa/private/dsn.ini" ]
|
|
}
|
|
|
|
get_dsn()
|
|
{
|
|
local section="$1"
|
|
local param="$2"
|
|
! is_remote_db_feature_enabled || get_ini_conf_var "/etc/psa/private/dsn.ini" "$section" "$param"
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh
|
|
# Usage: pleskrc <service> <action>
|
|
pleskrc()
|
|
{
|
|
[ 2 -le $# ] || die "Not enough arguments"
|
|
|
|
local service_name=${1//[-.@]/_}
|
|
local action=$2
|
|
local ret=0
|
|
local inten
|
|
shift
|
|
shift
|
|
|
|
# Now check redefined functions
|
|
if test "$machine" = "linux" && is_function "${service_name}_${action}_${machine}_${linux_distr}"; then
|
|
"${service_name}_${action}_${machine}_${linux_distr}" "$@"
|
|
return $?
|
|
elif is_function "${service_name}_${action}_${machine}"; then
|
|
"${service_name}_${action}_${machine}" "$@"
|
|
return $?
|
|
elif is_function "${service_name}_${action}"; then
|
|
"${service_name}_${action}" "$@"
|
|
return $?
|
|
fi
|
|
|
|
# Not redefined - call default action
|
|
eval "service=\$${service_name}_service"
|
|
[ -n "$service" ] || die "$action $service_name service (Empty service name for '$service_name')"
|
|
|
|
if [ "$action" = "name" ]; then
|
|
echo "${service}.service"
|
|
return 0
|
|
fi
|
|
|
|
inten="$action service $service"
|
|
pleskrc_is_failure_for_action_ok "$action" || echo_try "$inten"
|
|
|
|
if [ -x "/bin/systemctl" -a "$do_upgrade" = "1" -a ! -f "/var/lock/parallels-panel-bootstrapper-running.lock" -a -z "$SYSTEMD_DAEMON_RELOADED" ]; then
|
|
# reload systemd units if requested from an upgrade package script - in case a unit was changed
|
|
/bin/systemctl daemon-reload
|
|
SYSTEMD_DAEMON_RELOADED="yes"
|
|
fi
|
|
|
|
service_ctl "$action" "$service" "$service_name"
|
|
ret="$?"
|
|
|
|
pleskrc_is_failure_for_action_ok "$action" || {
|
|
if [ "$ret" -eq 0 ]; then
|
|
suc
|
|
else
|
|
if [ -x "/bin/systemctl" ]; then
|
|
p_echo "`/bin/systemctl -l status \"${service}.service\" | awk 'BEGIN {s=0} s==1 {s=2} /^$/ {s=1} s==2 {print}'`"
|
|
fi
|
|
warn "$inten failed"
|
|
fi
|
|
}
|
|
|
|
return $ret
|
|
}
|
|
|
|
pleskrc_is_failure_for_action_ok()
|
|
{
|
|
local action="$1"
|
|
case "$action" in
|
|
status|exists|is-active|is-enabled|is-failed) return 0 ;;
|
|
esac
|
|
return 1
|
|
}
|
|
|
|
# NOTE:
|
|
# Function service_ctl is just helper for pleskrc().
|
|
# Do not call it directly, use pleskrc()!!!
|
|
service_ctl()
|
|
{
|
|
local action=$1
|
|
local service=$2
|
|
local service_name=$3
|
|
|
|
if [ "$action" != "exists" ]; then
|
|
_service_exec $service exists
|
|
if [ "$?" != "0" ]; then
|
|
p_echo "attempt to ${inten} - service doesn't exist (missing unit file or not executable control script)"
|
|
return 1
|
|
fi
|
|
fi
|
|
|
|
case "$action" in
|
|
start)
|
|
pleskrc "$service_name" status || _service_exec "$service" "$action"
|
|
;;
|
|
stop)
|
|
! pleskrc "$service_name" status || _service_exec "$service" "$action"
|
|
;;
|
|
restart)
|
|
if pleskrc "$service_name" status; then
|
|
_service_exec "$service" "$action"
|
|
else
|
|
_service_exec "$service" start
|
|
fi
|
|
;;
|
|
reload)
|
|
! pleskrc "$service_name" status || _service_exec "$service" "$action"
|
|
;;
|
|
status)
|
|
_service_exec "$service" status
|
|
;;
|
|
try-restart)
|
|
if [ -x "/bin/systemctl" ]; then
|
|
_service_exec "$service" "$action"
|
|
else
|
|
! pleskrc "$service_name" status || _service_exec "$service" "restart"
|
|
fi
|
|
;;
|
|
try-reload)
|
|
! pleskrc "$service_name" status || _service_exec "$service" "reload"
|
|
;;
|
|
reload-or-restart)
|
|
if [ -x "/bin/systemctl" ]; then
|
|
_service_exec "$service" "$action"
|
|
elif pleskrc "$service_name" status; then
|
|
_service_exec "$service" "reload"
|
|
else
|
|
_service_exec "$service" "start"
|
|
fi
|
|
;;
|
|
*)
|
|
_service_exec "$service" "$action"
|
|
;;
|
|
esac >> "$product_log"
|
|
}
|
|
|
|
_service_exec()
|
|
{
|
|
# Keep in sync with pylibplesk/plesk_service.py
|
|
local service=$1
|
|
local action=$2
|
|
|
|
local action_cmd
|
|
local sysvinit_service="/etc/init.d/$service"
|
|
|
|
if [ -x "/bin/systemctl" ]; then
|
|
case "${action}" in
|
|
exists)
|
|
if /bin/systemctl cat "$service.service" >/dev/null 2>&1; then
|
|
return 0 # systemd unit
|
|
elif [ -f "/lib/systemd/system/$service.service" ]; then
|
|
/bin/systemctl daemon-reload
|
|
return 0 # systemd unit which exists but was changed and has not been reloaded before
|
|
elif [ -x "$sysvinit_service" ]; then
|
|
return 0 # sysvinit compat
|
|
fi
|
|
return 1 # not found
|
|
;;
|
|
status)
|
|
action="is-active"
|
|
;;
|
|
reload|graceful)
|
|
action='reload-or-try-restart'
|
|
;;
|
|
esac
|
|
/bin/systemctl "$action" "${service}.service"
|
|
else
|
|
warn "Cannot $action $service on this system: no executable /bin/systemctl"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
is_function()
|
|
{
|
|
local type_output=$(type -t "$1")
|
|
test "X${type_output}" = "Xfunction"
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
# echo message to product log and console (always visible)
|
|
pp_echo()
|
|
{
|
|
if [ -n "$product_log" ] ; then
|
|
echo "$@" >> "$product_log" 2>&1
|
|
fi
|
|
echo "$@" >&2
|
|
}
|
|
|
|
# echo message to product log, also to console in debug mode
|
|
p_echo()
|
|
{
|
|
if [ -n "$product_log" ] ; then
|
|
echo "$@" >> "$product_log" 2>&1
|
|
fi
|
|
if [ -n "$PLESK_INSTALLER_DEBUG" -o -n "$PLESK_INSTALLER_VERBOSE" -o -z "$product_log" ] ; then
|
|
echo "$@" >&2
|
|
fi
|
|
}
|
|
|
|
# same as p_echo, but without new line
|
|
pnnl_echo()
|
|
{
|
|
p_echo -n "$@"
|
|
}
|
|
|
|
int_err()
|
|
{
|
|
report_problem "internal" "Internal error: $@"
|
|
exit 1
|
|
}
|
|
|
|
p_see_product_log()
|
|
{
|
|
log_is_in_dev "${product_log}" || printf " (see log file: ${product_log})" >&2
|
|
}
|
|
|
|
die()
|
|
{
|
|
report_problem "fatal" "ERROR while trying to $@"
|
|
printf "Check the error reason" >&2
|
|
p_see_product_log
|
|
echo ", fix and try again" >&2
|
|
|
|
selinux_close
|
|
|
|
exit 1
|
|
}
|
|
|
|
simply_die()
|
|
{
|
|
report_problem "fatal" "$@"
|
|
exit 1
|
|
}
|
|
|
|
warn()
|
|
{
|
|
local inten="$1"
|
|
|
|
if [ -n "$PLESK_INSTALLER_DEBUG" -o -n "$PLESK_INSTALLER_VERBOSE" ]; then
|
|
p_echo
|
|
p_echo "WARNING!"
|
|
pnnl_echo "Some problems are found during $inten"
|
|
p_see_product_log
|
|
p_echo
|
|
p_echo "Continue..."
|
|
p_echo
|
|
fi
|
|
|
|
report_problem "warning" "Warning: $inten"
|
|
}
|
|
|
|
comm_err()
|
|
{
|
|
p_echo " Unfortunately, this situation has not yet been"
|
|
p_echo " resolved."
|
|
p_echo " Please, visit $support_contact for assistance."
|
|
p_echo
|
|
p_echo "Exiting..."
|
|
p_echo
|
|
|
|
exit 1
|
|
}
|
|
|
|
gid_err()
|
|
{
|
|
gid="$1"
|
|
|
|
p_echo
|
|
p_echo "ERROR: It seems there is a group with GID=$gid"
|
|
p_echo " in this system, but $PRODUCT_NAME needs the same GID"
|
|
p_echo " for its operation."
|
|
|
|
report_problem "error" "Error: group with GID=$gid already exists."
|
|
comm_err
|
|
}
|
|
|
|
group_err()
|
|
{
|
|
group="$1"
|
|
gid="$2"
|
|
|
|
p_echo
|
|
p_echo "ERROR: It seems that there is group $group"
|
|
p_echo " in your system. $PRODUCT_NAME uses the same group"
|
|
p_echo " name but with another group ID ($gid)."
|
|
|
|
report_problem "error" "Error: group $group exists, but it doesn't have GID=$gid."
|
|
comm_err
|
|
}
|
|
|
|
uid_err()
|
|
{
|
|
uid="$1"
|
|
|
|
p_echo
|
|
p_echo "ERROR: It seems there is a user with UID=$uid"
|
|
p_echo " in this system, but $PRODUCT_NAME needs the same UID"
|
|
p_echo " for its operation."
|
|
|
|
report_problem "error" "Error: user with UID=$uid already exists."
|
|
comm_err
|
|
}
|
|
|
|
logname_err()
|
|
{
|
|
user="$1"
|
|
uid="$2"
|
|
|
|
p_echo
|
|
p_echo "ERROR: It seems that there is a $user in your system"
|
|
p_echo " with a UID other than that used by $PRODUCT_NAME ($uid)"
|
|
p_echo " or the $user is in the primary group, but this"
|
|
p_echo " group is not the one that $PRODUCT_NAME uses."
|
|
|
|
report_problem "error" "Error: user $user exists, but it doesn't have UID=$uid or it belongs to wrong primary group."
|
|
comm_err
|
|
}
|
|
|
|
echo_try()
|
|
{
|
|
msg="$*"
|
|
pnnl_echo " Trying to $msg... "
|
|
}
|
|
|
|
suc()
|
|
{
|
|
p_echo "done"
|
|
}
|
|
|
|
write_structured_report()
|
|
{
|
|
# Write json error report into file $PLESK_INSTALLER_ERROR_REPORT if specified.
|
|
# @params are tags in format "key=value"
|
|
# Report body (human readable information) is read from stdin.
|
|
local report_file="$PLESK_INSTALLER_ERROR_REPORT"
|
|
|
|
[ -n "$report_file" ] || return 0
|
|
|
|
local python_bin=
|
|
for bin in "/opt/psa/bin/python" "/usr/local/psa/bin/python" "/usr/bin/python2" "/usr/libexec/platform-python" "/usr/bin/python3"; do
|
|
if [ -x "$bin" ]; then
|
|
python_bin="$bin"
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ ! -x "$python_bin" ]; then
|
|
p_echo "Cannot write structured error report: python interpreter not found."
|
|
return 1
|
|
fi
|
|
|
|
"$python_bin" -c 'import sys, json
|
|
report_file = sys.argv[1]
|
|
error = sys.stdin.read()
|
|
|
|
data = {
|
|
"error": error,
|
|
}
|
|
|
|
for tag in sys.argv[2:]:
|
|
k, v = tag.split("=", 1)
|
|
data[k] = v
|
|
|
|
with open(report_file, "a") as f:
|
|
json.dump(data, f)
|
|
f.write("\n")
|
|
' "$report_file" "date=$(date --utc --iso-8601=ns)" "$@"
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
reexec_with_clean_env()
|
|
{
|
|
# Usage: call this function as 'reexec_with_clean_env "$@"' at the start of a script.
|
|
# Don't use with scripts that require sensitive environment variables.
|
|
# Don't put the call under any input/output redirection.
|
|
# Purpose: make sure the script is executed with a sane environment.
|
|
|
|
local lc="`get_default_locale`"
|
|
export LANG="$lc" LC_MESSAGES="$lc" LC_ALL="$lc"
|
|
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
|
umask 022
|
|
|
|
PLESK_SCRIPT_COMMAND_LINE="$0 $*"
|
|
[ -z "$PLESK_INSTALLER_ENV_CLEANED" ] || { unset PLESK_INSTALLER_ENV_CLEANED; return 0; }
|
|
[ -n "$BASH" ] || exec /bin/bash "$0" "$@"
|
|
|
|
# N.B.: the following code requires Bash. On Dash it would cause syntax error upon parse w/o eval.
|
|
eval '
|
|
local extra_vars=() # list of variables to preserve
|
|
for var in "${!PLESK_@}"; do # enumerate all PLESK_* variables
|
|
extra_vars+=("$var=${!var}")
|
|
done
|
|
extra_vars+=("PLESK_INSTALLER_ENV_CLEANED=1")
|
|
|
|
# Exec self with clean env except for extra_vars, shell opts, and arguments.
|
|
exec /usr/bin/env -i "${extra_vars[@]}" /bin/bash ${-:+-$-} "$0" "$@" || {
|
|
echo "Failed to reexec self ($0) with clean environment" >&2
|
|
exit 91 # Just some relatively unique error code
|
|
}
|
|
'
|
|
}
|
|
|
|
get_default_locale()
|
|
{
|
|
# Note that CentOS 7 typically doesn't have C.UTF-8
|
|
for lc in "C.UTF-8" "en_US.UTF-8" "C"; do
|
|
if [ -z "`LC_ALL=$lc locale 2>&1 >/dev/null`" ]; then
|
|
echo "$lc"
|
|
return 0
|
|
fi
|
|
done
|
|
echo "C"
|
|
}
|
|
|
|
# accumulates chown and chmod
|
|
set_ac()
|
|
{
|
|
local u_owner g_owner perms node
|
|
u_owner="$1"
|
|
g_owner="$2"
|
|
perms="$3"
|
|
node="$4"
|
|
|
|
# A very small optimization - replacing of two execs by one,
|
|
# it works only if the following conditions are observed:
|
|
# - u_owner is username (not UID);
|
|
# - g_owner is group (not GID);
|
|
# - perms is in octal mode.
|
|
# If some conditions aren't observed,
|
|
# optimization doesn't work,
|
|
# but it doesn't break function
|
|
[ "$(stat -c '%U:%G 0%a' $node)" != "$u_owner:$g_owner $perms" ] || return 0
|
|
chown $u_owner:$g_owner $node || die "chown $u_owner:$g_owner $node"
|
|
chmod $perms $node || die "chmod $perms $node"
|
|
}
|
|
|
|
detect_vz()
|
|
{
|
|
[ -z "$PLESK_VZ_RESULT" ] || return $PLESK_VZ_RESULT
|
|
|
|
PLESK_VZ_RESULT=1
|
|
PLESK_VZ=0
|
|
PLESK_VE_HW_NODE=0
|
|
PLESK_VZ_TYPE=
|
|
|
|
local issue_file="/etc/issue"
|
|
local vzcheck_file="/proc/self/status"
|
|
[ -f "$vzcheck_file" ] || return 1
|
|
|
|
local env_id=`sed -ne 's|^envID\:[[:space:]]*\([[:digit:]]\+\)$|\1|p' "$vzcheck_file"`
|
|
[ -n "$env_id" ] || return 1
|
|
if [ "$env_id" = "0" ]; then
|
|
# Either VZ/OpenVZ HW node or unjailed CloudLinux
|
|
PLESK_VE_HW_NODE=1
|
|
return 1
|
|
fi
|
|
|
|
if grep -q "CloudLinux" "$issue_file" >/dev/null 2>&1 ; then
|
|
return 1
|
|
fi
|
|
|
|
if [ -f "/proc/vz/veredir" ]; then
|
|
PLESK_VZ_TYPE="vz"
|
|
elif [ -d "/proc/vz" ]; then
|
|
PLESK_VZ_TYPE="openvz"
|
|
fi
|
|
|
|
PLESK_VZ=1
|
|
PLESK_VZ_RESULT=0
|
|
return 0
|
|
}
|
|
|
|
# detects lxc and docker containers
|
|
detect_lxc()
|
|
{
|
|
[ -z "$PLESK_LXC_RESULT" ] || return $PLESK_LXC_RESULT
|
|
PLESK_LXC_RESULT=1
|
|
PLESK_LXC=0
|
|
if { [ -f /proc/1/cgroup ] && grep -q 'docker\|lxc' /proc/1/cgroup; } || \
|
|
{ [ -f /proc/1/environ ] && cat /proc/1/environ | tr \\0 \\n | grep -q "container=lxc"; };
|
|
then
|
|
PLESK_LXC_RESULT=0
|
|
PLESK_LXC=1
|
|
fi
|
|
return "$PLESK_LXC_RESULT"
|
|
}
|
|
|
|
call_optional_function()
|
|
{
|
|
local type_output="`LC_ALL=C type \"$1\" 2>/dev/null | head -n 1`"
|
|
case "$type_output" in
|
|
*function)
|
|
"$@"
|
|
;;
|
|
*)
|
|
return 0
|
|
;;
|
|
esac
|
|
}
|
|
|
|
### the function similar to awk -F'$fs' 'print $N'
|
|
get_narg_fs()
|
|
{
|
|
local IFS="$2"
|
|
get_narg $3 $1
|
|
}
|
|
|
|
get_narg()
|
|
{
|
|
shift $1 2>/dev/null || return 0
|
|
echo $1
|
|
}
|
|
|
|
get_random_string()
|
|
{
|
|
local str_length="$1"
|
|
local str_symbols="$2"
|
|
if [ -x "$PRODUCT_ROOT_D/admin/sbin/random_str" -a -z "$str_symbols" ]; then
|
|
"$PRODUCT_ROOT_D/admin/sbin/random_str" "$str_length"
|
|
else
|
|
# random_str utility may be unavailable in pre phase
|
|
if [ -z "$str_length" ]; then
|
|
str_length="14"
|
|
fi
|
|
if [ -z "$str_symbols" ]; then
|
|
str_symbols="A-Za-z0-9_"
|
|
fi
|
|
|
|
< /dev/urandom tr -dc "$str_symbols" 2>/dev/null | head -c "$str_length" 2>/dev/null
|
|
fi
|
|
}
|
|
|
|
sequence()
|
|
{
|
|
if type seq >/dev/null 2>&1; then
|
|
seq $*
|
|
elif type jot >/dev/null 2>&1; then
|
|
jot $*
|
|
else
|
|
die "Unable to find seq or jot command"
|
|
fi
|
|
}
|
|
|
|
get_ini_conf_var()
|
|
{
|
|
local conf="$1"
|
|
local section="$2"
|
|
local param="$3"
|
|
|
|
[ -n "$conf" -a -n "$param" ] || die "get_ini_conf_var(): required parameters missing"
|
|
|
|
local section_empty=0
|
|
[ -n "$section" ] || section_empty=1
|
|
|
|
perl -n -e 'BEGIN { $insect='$section_empty' }
|
|
next if (/^\s*;/);
|
|
$insect=0 if (/^\s*\[.*\]/);
|
|
$insect=1 if (/^\s*\['$section'\]/);
|
|
$val = $2, $val =~ s/\s+$//, print $val . "\n"
|
|
if ($insect && /^\s*('$param')\s*=\s*([^;\n]*)(;.*)?$/);' $conf | head -n 1
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
#-*- vim:syntax=sh
|
|
|
|
product_log_name_ex()
|
|
{
|
|
local aux_descr="$1"
|
|
local action="${CUSTOM_LOG_ACTION_NAME-installation}"
|
|
|
|
if [ -n "$aux_descr" ]; then
|
|
aux_descr="_${aux_descr}"
|
|
fi
|
|
|
|
if [ -n "$CUSTOM_LOG_NAME" ]; then
|
|
echo "${CUSTOM_LOG_NAME}${action:+_$action}${aux_descr}.log"
|
|
else
|
|
get_product_versions
|
|
echo "plesk_${product_this_version}${action:+_$action}${aux_descr}.log"
|
|
fi
|
|
}
|
|
|
|
product_log_name()
|
|
{
|
|
product_log_name_ex
|
|
}
|
|
|
|
product_problems_log_name()
|
|
{
|
|
product_log_name_ex "problems"
|
|
}
|
|
|
|
problems_log_tail()
|
|
{
|
|
[ -f "$product_problems_log" ] || return 0
|
|
{
|
|
tac "$product_problems_log" | awk '/^START/ { exit } { print }' | tac
|
|
} 2>/dev/null
|
|
}
|
|
|
|
product_log_tail()
|
|
{
|
|
[ -f "$product_log" ] || return 0
|
|
{
|
|
tac "$product_log" | awk '/^START/ { exit } { print }' | tac
|
|
} 2>/dev/null
|
|
}
|
|
|
|
product_and_problems_log_tail()
|
|
{
|
|
product_log_tail
|
|
[ "$product_log" = "$product_problems_log" ] || problems_log_tail
|
|
}
|
|
|
|
cleanup_problems_log()
|
|
{
|
|
[ -f "$product_problems_log" ] || return 0
|
|
touch "$product_problems_log.tmp"
|
|
chmod 0600 "$product_problems_log.tmp"
|
|
awk 'BEGIN { st = "" }
|
|
/^START/ && (st ~ /^START/) { print st; }
|
|
/^START/ { st=$0; next }
|
|
/^STOP/ && (st ~ /^START/) { st=""; next }
|
|
(st != "") { print st; st="" }
|
|
{ print }
|
|
' "$product_problems_log" > "$product_problems_log.tmp" && \
|
|
mv -f "$product_problems_log.tmp" "$product_problems_log" || \
|
|
rm -f "$product_problems_log.tmp"
|
|
|
|
if [ ! -s "$product_problems_log" ]; then
|
|
rm -f "$product_problems_log"
|
|
fi
|
|
}
|
|
|
|
mktemp_log()
|
|
{
|
|
local logname="$1"
|
|
local dir="$2"
|
|
|
|
if [ "${logname:0:1}" != "/" ]; then
|
|
logname="$dir/$logname"
|
|
fi
|
|
dir="`dirname $logname`"
|
|
if [ ! -d "$dir" ]; then
|
|
mkdir -p "$dir" || { echo "Unable to create log directory : $dir"; exit 1; }
|
|
if [ "$EUID" -eq "0" ]; then
|
|
set_ac root root 0700 "$dir"
|
|
fi
|
|
fi
|
|
|
|
if [ "${logname%XXX}" != "$logname" ]; then
|
|
mktemp "$logname"
|
|
else
|
|
echo "$logname"
|
|
fi
|
|
}
|
|
|
|
log_is_in_dev()
|
|
{
|
|
test "${1:0:5}" = "/dev/"
|
|
}
|
|
|
|
start_writing_logfile()
|
|
{
|
|
local logfile="$1"
|
|
local title="$2"
|
|
! log_is_in_dev "$logfile" || return 0
|
|
echo "START $title" >> "$logfile" || { echo "Cannot write installation log $logfile" >&2; exit 1; }
|
|
[ "$EUID" -ne "0" ] || set_ac root root 0600 "$logfile"
|
|
}
|
|
|
|
log_start()
|
|
{
|
|
true product_log_name product_problems_log_name mktemp_log
|
|
|
|
local title="$1"
|
|
local custom_log="$2"
|
|
local custom_problems_log="$3"
|
|
|
|
local product_log_dir="/var/log/plesk/install"
|
|
|
|
product_log="$product_log_dir/`product_log_name`"
|
|
product_problems_log="$product_log_dir/`product_problems_log_name`"
|
|
problems_occured=0
|
|
|
|
# init product log
|
|
[ ! -n "$custom_log" ] || product_log="$custom_log"
|
|
product_log=`mktemp_log "$product_log" "$product_log_dir"`
|
|
|
|
# init problems log
|
|
if [ -n "$custom_problems_log" ]; then
|
|
product_problems_log=`mktemp_log "$custom_problems_log" "$product_log_dir"`
|
|
elif [ -n "$custom_log" ]; then
|
|
product_problems_log="$product_log"
|
|
else
|
|
product_problems_log=`mktemp_log "$product_problems_log" "$product_log_dir"`
|
|
fi
|
|
|
|
# write starting message into logs
|
|
start_writing_logfile "$product_log" "$title"
|
|
if [ "$product_log" != "$product_problems_log" ]; then
|
|
start_writing_logfile "$product_problems_log" "$title"
|
|
fi
|
|
|
|
is_function profiler_setup && profiler_setup "$title" || :
|
|
}
|
|
|
|
log_stop()
|
|
{
|
|
local title="$1"
|
|
local subject="$2"
|
|
|
|
if [ "$product_log" = "$product_problems_log" ] || \
|
|
log_is_in_dev "$product_problems_log"; then
|
|
[ -e "$product_log" ] && echo "STOP $title" >>"$product_log"
|
|
is_function profiler_stop && profiler_stop || :
|
|
return
|
|
fi
|
|
|
|
if [ -z "$subject" ]; then
|
|
subject="[${title}]"
|
|
fi
|
|
|
|
# check if problems are non-empty, check for problems_occured
|
|
local status
|
|
local problem_lines="`problems_log_tail | wc -l`"
|
|
if [ "$problem_lines" -eq 0 ]; then
|
|
status="completed successfully"
|
|
else
|
|
if [ $problems_occured -ne 0 ]; then
|
|
status="failed"
|
|
else
|
|
status="completed with warnings"
|
|
fi
|
|
fi
|
|
|
|
if [ -e "$product_log" ]; then
|
|
p_echo
|
|
p_echo "**** $subject $status."
|
|
p_echo
|
|
fi
|
|
|
|
if [ "$problem_lines" -ne 0 ]; then
|
|
[ ! -e "$product_log" ] || problems_log_tail >>"$product_log" 2>&1
|
|
problems_log_tail
|
|
fi
|
|
|
|
[ ! -e "$product_log" ] || echo "STOP $title" >>"$product_log"
|
|
if [ $problems_occured -ne 0 ]; then
|
|
echo "STOP $title: PROBLEMS FOUND" >>"$product_problems_log"
|
|
else
|
|
[ ! -s "$product_problems_log" ] || echo "STOP $title: OK" >>"$product_problems_log"
|
|
fi
|
|
|
|
if [ "X${PLESK_INSTALLER_KEEP_PROBLEMS_LOG}" = "X" ]; then
|
|
cleanup_problems_log
|
|
fi
|
|
|
|
is_function profiler_stop && profiler_stop || :
|
|
}
|
|
|
|
package_script_begin()
|
|
{
|
|
if [ -z "$process" ]; then
|
|
if [ "$do_reconfigure" = "1" ]; then
|
|
process="reconfiguration"
|
|
elif [ "$do_upgrade" = "1" ]; then
|
|
process="upgrade"
|
|
elif [ -n "$PACKAGE_TRIGGERING_NAMES" ]; then
|
|
process="trigger"
|
|
else
|
|
process="installation"
|
|
fi
|
|
fi
|
|
|
|
log_start "`package_script_log_title`"
|
|
set_error_report_context "`package_script_log_title`. `report_context_action`"
|
|
|
|
product_default_conf
|
|
initial_conf
|
|
set_common_params
|
|
read_conf
|
|
}
|
|
|
|
package_script_end()
|
|
{
|
|
packagemng_set_dirty_flag
|
|
|
|
log_stop "`package_script_log_title`" "Package $PACKAGE_NAME scriptlet"
|
|
}
|
|
|
|
package_script_log_title()
|
|
{
|
|
local stage
|
|
case "$do_upgrade" in
|
|
0) stage="installing";;
|
|
1) stage="upgrading";;
|
|
*) stage="installing";;
|
|
esac
|
|
[ -z "$PACKAGE_TRIGGERING_NAMES" ] || stage="triggered (by $PACKAGE_TRIGGERING_NAMES)"
|
|
echo "$PACKAGE_NAME-$PACKAGE_VERSION $stage AT `date`"
|
|
}
|
|
|
|
report_context_action()
|
|
{
|
|
local action
|
|
get_product_versions
|
|
if [ "X$do_upgrade" = "X1" -o "$product_prev_version" != "$product_this_version" ]; then
|
|
action="Doing $product_name upgrade from $product_prev_version to $product_this_version"
|
|
else
|
|
action="Doing $product_name $product_this_version installation"
|
|
fi
|
|
echo "$action"
|
|
}
|
|
|
|
# <fun> NAME VERSION <function name 1> [function name 2] ... [function name N]
|
|
package_script_safe_run()
|
|
{
|
|
PACKAGE_NAME="$1"
|
|
PACKAGE_VERSION="$2"
|
|
|
|
shift 2
|
|
|
|
local func_list="$@"
|
|
|
|
# Run functions in subshell because package scriptlet must exit with status code indicating success.
|
|
# Postpone package problem report till post-install package scriptlet (package_script_safe_run_with_report)
|
|
package_script_begin
|
|
(
|
|
transaction_begin
|
|
transaction_add_rollback_action "package_script_end"
|
|
transaction_add_rollback_action "set_upgrade_failure_flag"
|
|
|
|
# Execute all mentioned functions
|
|
for func in $func_list; do
|
|
call_optional_function "$func"
|
|
done
|
|
|
|
transaction_add_commit_action "package_script_end"
|
|
transaction_commit
|
|
)
|
|
}
|
|
|
|
set_upgrade_failure_flag()
|
|
{
|
|
touch /var/lock/parallels-panel-upgrade-failure.flag
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
get_pid()
|
|
{
|
|
local i
|
|
|
|
local ex_f="$1"
|
|
local opt="$2"
|
|
local owner="$3"
|
|
|
|
local min_num="1"
|
|
local ps_long="ps axuw"
|
|
|
|
# Use pidof by default, bug 121868, except for FreeBSD - 140182
|
|
if type pidof >/dev/null 2>&1 && [ "$os" != "BSD" ]; then
|
|
for pid in `pidof -o $$ -o $PPID -o %PPID -x $ex_f`; do
|
|
# Check for owner
|
|
[ "$opt" = "true" -a "$owner" != "`ps -p $pid -o ruser=`" ] && continue
|
|
min_num=$pid
|
|
break
|
|
done
|
|
common_var=$min_num
|
|
return $min_num
|
|
fi
|
|
|
|
case "$opt" in
|
|
false)
|
|
for i in `$ps_long | grep $ex_f | grep -v grep | grep -v httpsdctl | grep -v apachectl | awk '{print $2}' -`; do
|
|
min_num=$i
|
|
break
|
|
done
|
|
;;
|
|
true)
|
|
for i in `$ps_long | grep $ex_f | grep -v grep | grep -v httpsdctl | grep -v apachectl | grep "$owner" | awk '{print $2}' -`; do
|
|
min_num=$i
|
|
break
|
|
done
|
|
;;
|
|
*)
|
|
p_echo "get_pid: wrong parameter"
|
|
die "get_pid $ex_f $opt $owner"
|
|
;;
|
|
esac
|
|
|
|
common_var=$min_num
|
|
return $min_num
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
construct_report_template()
|
|
{
|
|
local severity="${1:-error}"
|
|
local summary="$2"
|
|
|
|
local update_ticket="`get_update_ticket`"
|
|
|
|
set_error_report_source
|
|
set_error_report_component
|
|
set_error_report_params
|
|
set_error_report_environment
|
|
|
|
true construct_report_code construct_report_debug construct_report_message
|
|
|
|
cat <<-EOL
|
|
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<error>
|
|
<source>$report_source</source>
|
|
<severity>$severity</severity>
|
|
<datetime>`date --iso-8601=seconds`</datetime>
|
|
|
|
<component>$report_component</component>
|
|
<summary><![CDATA[`echo "$summary" | sed -e 's/\]\]>/] ]>/g'`]]></summary>
|
|
<message encoding="base64">`construct_report_message | base64`</message>
|
|
|
|
<additional_info>
|
|
<component_params encoding="base64">$report_params</component_params>
|
|
<code encoding="base64">`construct_report_code | base64`</code>
|
|
<debug encoding="base64">`construct_report_debug | base64`</debug>
|
|
<environment encoding="base64">$report_environment</environment>
|
|
<update_ticket>$update_ticket</update_ticket>
|
|
</additional_info>
|
|
</error>
|
|
EOL
|
|
}
|
|
|
|
construct_report_code()
|
|
{
|
|
local call_level=${1:-5}
|
|
local func_level=$[call_level - 1]
|
|
local lineno_func=${BASH_LINENO[ $func_level ]}
|
|
local script_name=${BASH_SOURCE[ $[func_level + 1] ]}
|
|
|
|
echo "# Call of ${FUNCNAME[$func_level]}() from ${FUNCNAME[$[func_level + 1]]}() at `readlink -m $script_name`:${BASH_LINENO[$func_level]}"
|
|
head -n $[lineno_func + 4] "$script_name" 2>/dev/null | tail -n 8
|
|
}
|
|
|
|
construct_report_debug()
|
|
{
|
|
local call_level=${1:-5}
|
|
call_level=$[call_level-1]
|
|
|
|
# Generate calls stack trace.
|
|
for i in `seq $call_level ${#FUNCNAME[@]}`; do
|
|
[ "${FUNCNAME[$i]}" != "main" ] || break
|
|
|
|
local func_call="`sed -n -e "${BASH_LINENO[$i]}p" "${BASH_SOURCE[$[i+1]]}" 2>/dev/null |
|
|
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`"
|
|
[ -n "$func_call" -a -z "${func_call##*${FUNCNAME[$i]}*}" ] || func_call="${FUNCNAME[$i]}"
|
|
echo "#$[i - $call_level] `readlink -m ${BASH_SOURCE[$[i+1]]}`(${BASH_LINENO[$i]}): $func_call"
|
|
done
|
|
}
|
|
|
|
construct_report_message()
|
|
{
|
|
product_and_problems_log_tail
|
|
|
|
echo ""
|
|
if [ -n "$report_context" ]; then
|
|
echo "Context: $report_context"
|
|
echo ""
|
|
fi
|
|
if [ -n "$RP_LOADED_PATCHES" ]; then
|
|
echo "Loaded runtime patches: $RP_LOADED_PATCHES"
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
# Construct report to send it to our errors tracker
|
|
construct_report()
|
|
{
|
|
local severity="${1:-error}"
|
|
local summary="$2"
|
|
|
|
[ -n "$summary" ] || int_err "Unable to send error report. Some parameters are not defined."
|
|
|
|
set_error_report_source
|
|
get_product_versions
|
|
|
|
construct_report_template "$severity" "$summary" \
|
|
| $PRODUCT_ROOT_D/admin/bin/send-error-report --version "$product_this_version" $report_source >/dev/null 2>&1
|
|
}
|
|
|
|
# Use this function to report failed actions.
|
|
# Typical report should contain
|
|
# - reason or problem description (example: file copying failed)
|
|
# - how to resolve or investigate problem (example: check file permissions, free disk space)
|
|
# - how to re-run action (example: perform specific command, restart bootstrapper script, run installation again)
|
|
report_problem()
|
|
{
|
|
local severity="${1:-error}"
|
|
|
|
# Get first string of error as a summary of report
|
|
shift
|
|
|
|
local summary="$1"
|
|
|
|
[ -n "$product_problems_log" ] || product_problems_log="/dev/stderr"
|
|
|
|
p_echo
|
|
if [ "0$problems_occured" -eq 0 ]; then
|
|
echo "***** $process problem report *****" >> "$product_problems_log" 2>&1
|
|
fi
|
|
for problem_message in "$@"; do
|
|
p_echo "$problem_message"
|
|
if [ "$product_log" != "$product_problems_log" ]; then
|
|
echo "$problem_message" >> "$product_problems_log" 2>&1
|
|
fi
|
|
done
|
|
p_echo
|
|
|
|
construct_report "$severity" "$summary"
|
|
|
|
[ -n "$PLESK_INSTALLER_DEBUG" -o -n "$PLESK_INSTALLER_VERBOSE" ] || \
|
|
product_log_tail
|
|
|
|
problems_occured=1
|
|
}
|
|
|
|
set_error_report_context()
|
|
{
|
|
report_context="$*"
|
|
}
|
|
|
|
set_error_report_source()
|
|
{
|
|
[ -z "$1" ] || report_source="$1"
|
|
[ -n "$report_source" ] || {
|
|
if [ -n "$PACKAGE_ID" -o -n "$PACKAGE_ACTION" -o -n "$PACKAGE_NAME" -o -n "$PACKAGE_VERSION" ]; then
|
|
report_source="install"
|
|
else
|
|
report_source="backend"
|
|
fi
|
|
}
|
|
}
|
|
|
|
set_error_report_component()
|
|
{
|
|
local component="$1"
|
|
|
|
if [ "$report_source" = "install" ]; then
|
|
[ -n "$report_component" ] || report_component="$PACKAGE_ID"
|
|
return 0
|
|
fi
|
|
|
|
[ -z "$component" ] || report_component="$1"
|
|
[ -n "$report_component" ] || report_component="`basename $0`"
|
|
}
|
|
|
|
set_error_report_params()
|
|
{
|
|
if [ "$report_source" = "install" ]; then
|
|
[ -n "$report_params" ] || report_params="`echo "$PACKAGE_ACTION of $PACKAGE_NAME $PACKAGE_VERSION" | base64`"
|
|
return 0
|
|
fi
|
|
|
|
[ -z "$*" ] || report_params="`echo "$*" | base64`"
|
|
[ -n "$report_params" ] || report_params="`echo "$PLESK_SCRIPT_COMMAND_LINE" | base64`"
|
|
}
|
|
|
|
detect_virtualization()
|
|
{
|
|
detect_vz
|
|
detect_lxc
|
|
local is_docker="`[ -f "/.dockerenv" ] && echo yes || :`"
|
|
local systemd_detect_virt_ct="`/usr/bin/systemd-detect-virt -c 2>/dev/null | grep -v '^none$' || :`"
|
|
local systemd_detect_virt_vm="`/usr/bin/systemd-detect-virt -v 2>/dev/null | grep -v '^none$' || :`"
|
|
local virt_what="`/usr/sbin/virt-what 2>/dev/null | xargs || :`"
|
|
|
|
if [ -n "$is_docker" ]; then
|
|
echo "docker $virt_what"
|
|
elif [ "$PLESK_VZ" = "1" ]; then
|
|
echo "${PLESK_VZ_TYPE:-virtuozzo}"
|
|
elif [ "$PLESK_LXC" = "1" ]; then
|
|
echo "lxc $virt_what"
|
|
elif [ -n "$systemd_detect_virt_ct" ]; then
|
|
echo "$systemd_detect_virt_ct $systemd_detect_virt_vm"
|
|
elif [ -n "$virt_what" ]; then
|
|
echo "$virt_what"
|
|
elif [ -n "$systemd_detect_virt_vm" ]; then
|
|
echo "$systemd_detect_virt_vm"
|
|
fi
|
|
}
|
|
|
|
default_error_report_environment()
|
|
{
|
|
local virtualization="`detect_virtualization`"
|
|
|
|
if [ -n "$virtualization" ]; then
|
|
echo "virtualization: $virtualization"
|
|
fi
|
|
}
|
|
|
|
set_error_report_environment()
|
|
{
|
|
[ -z "$*" ] || report_environment="`echo "$*" | base64`"
|
|
[ -n "$report_environment" ] || report_environment="`default_error_report_environment | base64`"
|
|
}
|
|
|
|
get_update_ticket()
|
|
{
|
|
[ -r $PRODUCT_ROOT_D/var/update_ticket ] && cat $PRODUCT_ROOT_D/var/update_ticket | awk '{$1=$1};1'
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
#
|
|
# Support for runtime patching of shell scripts (including utilities and package scripts).
|
|
#
|
|
|
|
# --- Service functions ---
|
|
|
|
# Load and apply a patch in a relatively safe way
|
|
rp_safe_load_patch()
|
|
{
|
|
local patch_file="$1"
|
|
echo_try "load shell patch '$patch_file'"
|
|
/bin/sh -n "$RP_BASEDIR/$patch_file" &&
|
|
{
|
|
. "$RP_BASEDIR/$patch_file"
|
|
RP_LOADED_PATCHES="$RP_LOADED_PATCHES $patch_file"
|
|
} &&
|
|
suc
|
|
}
|
|
|
|
# Apply patches specific to the current context (e.g., depending on utility basename or package name)
|
|
# This is currently not implemented. This may be overriden by "spark".
|
|
rp_patch_runtime_context_specific()
|
|
{
|
|
:
|
|
}
|
|
|
|
# --- Main entry points ---
|
|
|
|
rp_patch_runtime()
|
|
{
|
|
# List of loaded patch files
|
|
RP_LOADED_PATCHES=
|
|
|
|
local RP_BASEDIR="$PRODUCT_BOOTSTRAPPER_DIR/rp"
|
|
[ -d "$RP_BASEDIR" ] || return 0
|
|
|
|
if [ -r "$RP_BASEDIR/spark" ]; then
|
|
rp_safe_load_patch "spark"
|
|
fi
|
|
|
|
call_optional_function rp_patch_runtime_context_specific "$@"
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
transaction_begin()
|
|
{
|
|
[ -n "$TRANSACTION_STARTED" ] && die "Another transaction in progress!"
|
|
TRANSACTION_STARTED="true"
|
|
TRANSACTION_ROLLBACK_FUNCS=
|
|
TRANSACTION_COMMIT_FUNCS=
|
|
local transaction_autocommit="$1"
|
|
if [ -n "$transaction_autocommit" ]; then
|
|
trap "transaction_commit_auto" EXIT
|
|
trap "transaction_rollback" HUP PIPE INT QUIT TERM
|
|
else
|
|
trap "transaction_rollback" HUP PIPE INT QUIT TERM EXIT
|
|
fi
|
|
}
|
|
|
|
transaction_rollback()
|
|
{
|
|
TRANSACTION_RETURN_CODE="${TRANSACTION_RETURN_CODE:-$?}"
|
|
[ -z "$TRANSACTION_STARTED" ] && die "Transaction is not started!"
|
|
# perform rollback actions
|
|
local f
|
|
for f in ${TRANSACTION_ROLLBACK_FUNCS}; do
|
|
"$f"
|
|
done
|
|
TRANSACTION_STARTED=
|
|
TRANSACTION_ROLLBACK_FUNCS=
|
|
TRANSACTION_COMMIT_FUNCS=
|
|
trap - HUP PIPE INT QUIT TERM EXIT
|
|
exit 1
|
|
}
|
|
|
|
transaction_commit()
|
|
{
|
|
TRANSACTION_RETURN_CODE="${TRANSACTION_RETURN_CODE:-$?}"
|
|
[ -z "$TRANSACTION_STARTED" ] && die "Transaction is not started!"
|
|
# perform commit actions
|
|
local f
|
|
for f in ${TRANSACTION_COMMIT_FUNCS}; do
|
|
"$f"
|
|
done
|
|
TRANSACTION_STARTED=
|
|
TRANSACTION_ROLLBACK_FUNCS=
|
|
TRANSACTION_COMMIT_FUNCS=
|
|
trap - HUP PIPE INT QUIT TERM EXIT
|
|
}
|
|
|
|
transaction_commit_auto()
|
|
{
|
|
TRANSACTION_RETURN_CODE="$?"
|
|
if [ "$TRANSACTION_RETURN_CODE" -eq 0 ]; then
|
|
transaction_commit "$@"
|
|
else
|
|
transaction_rollback "$@"
|
|
fi
|
|
}
|
|
|
|
transaction_add_rollback_action()
|
|
{
|
|
[ -z "$TRANSACTION_STARTED" ] && die "Transaction is not started!"
|
|
# LIFO rollback order
|
|
[ -z "$TRANSACTION_ROLLBACK_FUNCS" ] \
|
|
&& TRANSACTION_ROLLBACK_FUNCS="$1" \
|
|
|| TRANSACTION_ROLLBACK_FUNCS="$1 $TRANSACTION_ROLLBACK_FUNCS"
|
|
}
|
|
|
|
transaction_remove_rollback_action()
|
|
{
|
|
[ -z "$TRANSACTION_STARTED" ] && die "Transaction is not started!"
|
|
# Preserves order of remaining records
|
|
TRANSACTION_ROLLBACK_FUNCS=`remove_from_array "$1" "$TRANSACTION_ROLLBACK_FUNCS"`
|
|
}
|
|
|
|
transaction_add_commit_action()
|
|
{
|
|
[ -z "$TRANSACTION_STARTED" ] && die "Transaction is not started!"
|
|
# FIFO commit order
|
|
[ -z "$TRANSACTION_COMMIT_FUNCS" ] \
|
|
&& TRANSACTION_COMMIT_FUNCS="$1" \
|
|
|| TRANSACTION_COMMIT_FUNCS="$TRANSACTION_COMMIT_FUNCS $1"
|
|
}
|
|
|
|
txtdb_set_params()
|
|
{
|
|
db_file=""
|
|
db_owner=""
|
|
db_group=""
|
|
db_perms="0644"
|
|
db_delim=':'
|
|
db_key_field="1"
|
|
"$@"
|
|
[ -n "$db_file" -a -n "$db_delim" ] || die "set txtdb parameters. Check arguments for 'txtdb_*' calls."
|
|
}
|
|
|
|
txtdb_fix_perms()
|
|
{
|
|
[ -n "$db_owner" -a -n "$db_group" ] && chown "$db_owner":"$db_group" "$db_file"
|
|
[ -n "$db_perms" ] && chmod "$db_perms" "$db_file"
|
|
:
|
|
}
|
|
|
|
# Create new empty DB or replace an existing one
|
|
txtdb_truncate()
|
|
{
|
|
local set_params_func="$1"
|
|
local db_file db_owner db_group db_perms db_delim db_key_field
|
|
txtdb_set_params "$set_params_func"
|
|
|
|
rm -f "$db_file" && touch "$db_file" && txtdb_fix_perms
|
|
}
|
|
|
|
# Check whether DB file already exists and is writable
|
|
txtdb_exists()
|
|
{
|
|
local set_params_func="$1"
|
|
local db_file db_owner db_group db_perms db_delim db_key_field
|
|
txtdb_set_params "$set_params_func"
|
|
|
|
[ -w "$db_file" ]
|
|
}
|
|
|
|
txtdb_do_update()
|
|
{
|
|
local set_params_func="$1"
|
|
local awk_script="$2"
|
|
local key_value="$3"
|
|
local data_value="$4"
|
|
local db_file db_owner db_group db_perms db_delim db_key_field
|
|
txtdb_set_params "$set_params_func"
|
|
|
|
awk -F "$db_delim" -v KEY="$key_value" -v DATA="$data_value" -v KEY_FIELD="$db_key_field" \
|
|
"$awk_script" "$db_file" > "$db_file.new" 2>> $product_log && \
|
|
mv -f "$db_file.new" "$db_file" && txtdb_fix_perms
|
|
}
|
|
|
|
txtdb_do_select()
|
|
{
|
|
local set_params_func="$1"
|
|
local awk_script="$2"
|
|
local key_value="$3"
|
|
local data_value="$4"
|
|
local db_file db_owner db_group db_perms db_delim db_key_field
|
|
txtdb_set_params "$set_params_func"
|
|
|
|
awk -F "$db_delim" -v KEY="$key_value" -v DATA="$data_value" -v KEY_FIELD="$db_key_field" \
|
|
"$awk_script" "$db_file" 2>> $product_log
|
|
}
|
|
|
|
# Insert or replace existing record identified by key field
|
|
txtdb_replace()
|
|
{
|
|
local db_file db_owner db_group db_perms db_delim db_key_field
|
|
txtdb_set_params "$1"
|
|
|
|
# Note that records order is not preserved
|
|
local replace_with="$2"
|
|
local key_to_replace=`get_narg_fs "$replace_with" "$db_delim" "$db_key_field"`
|
|
txtdb_do_update "$1" 'END { print DATA } ( $KEY_FIELD != KEY )' "$key_to_replace" "$replace_with"
|
|
}
|
|
|
|
# Select entire record by key field
|
|
txtdb_select()
|
|
{
|
|
local key_to_select="$2"
|
|
txtdb_do_select "$1" '( $KEY_FIELD == KEY )' "$key_to_select"
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
#
|
|
# Unified per-component cumulative upgrade support.
|
|
#
|
|
|
|
# --- Upgrader utility functions ---
|
|
|
|
cu_get_continue_stage()
|
|
{
|
|
local continue_from="$1"
|
|
get_narg_fs "$continue_from" '-' 1
|
|
}
|
|
|
|
cu_get_continue_id()
|
|
{
|
|
local continue_from="$1"
|
|
echo "` get_narg_fs "$continue_from" '-' 2 `-` get_narg_fs "$continue_from" '-' 3 `"
|
|
}
|
|
|
|
cu_get_current_continue_from()
|
|
{
|
|
echo "$CU_LAST_STAGE-$CU_LAST_ACTION_ID"
|
|
}
|
|
|
|
# Remove extraneous delimiters (usually spaces) between array elements
|
|
normalize_array()
|
|
{
|
|
echo $@
|
|
}
|
|
|
|
# Check that first argument is in array (other arguments)
|
|
is_in_array()
|
|
{
|
|
local needle="$1"
|
|
shift # everything else is haystack
|
|
for elem in $@; do
|
|
[ "$elem" = "$needle" ] && return 0
|
|
done
|
|
return 1
|
|
}
|
|
|
|
# Remove all instances of first argument from array (other arguments). Echoes normalized array with space delimiters.
|
|
remove_from_array()
|
|
{
|
|
local what="$1"
|
|
shift # everything else is array
|
|
local new_array=
|
|
for elem in $@; do
|
|
[ "$elem" = "$what" ] || new_array="$new_array $elem"
|
|
done
|
|
echo $new_array
|
|
}
|
|
|
|
# --- Chained upgrade actions checks ---
|
|
|
|
# cu_do <upgrade action> [<arguments>]: Execute an action or echo information about it
|
|
cu_do()
|
|
{
|
|
if [ -n "$CU_DO_GET_ACTION_NAME" ]; then
|
|
echo "$1"
|
|
return
|
|
fi
|
|
|
|
if [ -n "$CU_CONTINUE_FROM_ID" ]; then
|
|
# Run only actions starting from CU_CONTINUE_FROM_ID
|
|
# WARNING: this will not work properly if there is a subshell execution somewhere along the chain!
|
|
[ "$CU_LAST_ACTION_ID" = "$CU_CONTINUE_FROM_ID" ] && CU_CONTINUE_FROM_ID= || return 0
|
|
fi
|
|
|
|
if "$@"; then
|
|
cu_remove_failed_action "$CU_LAST_ACTION_ID"
|
|
return 0
|
|
else
|
|
cu_add_failed_action "$CU_LAST_ACTION_ID"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Echo resulting action name (function name) or empty if skipped
|
|
cu_get_action_name()
|
|
{
|
|
local CU_DO_GET_ACTION_NAME="yes"
|
|
"$@"
|
|
}
|
|
|
|
# Execute action only if it wasn't applied before (by timestamp, e.g. use `date '+%Y%m%d%H%M%0S'` or even `date '+%Y/%m/%d %H:%M:%0S'`)
|
|
cu_check_timestamp()
|
|
{
|
|
local timestamp="`echo \"$1\" | tr -dc '[:digit:]'`"
|
|
shift
|
|
|
|
true cu_get_action_name
|
|
CU_LAST_ACTION_ID="$timestamp-`cu_get_action_name "$@"`"
|
|
|
|
# Skip timestamp check if this action should be done again (during repair)
|
|
if [ -z "$CU_FAILED_ACTIONS" ] || ! is_in_array "$CU_LAST_ACTION_ID" "$CU_FAILED_ACTIONS"; then
|
|
[ "$timestamp" -gt "$CU_START_TIMESTAMP" ] || return 0
|
|
fi
|
|
|
|
if [ "$timestamp" -gt "$CU_LATEST_TIMESTAMP" ]; then
|
|
CU_LATEST_TIMESTAMP="$timestamp"
|
|
fi
|
|
|
|
"$@"
|
|
}
|
|
|
|
# Execute action only if it belongs to a current stage
|
|
cu_check_stage()
|
|
{
|
|
local stage="$1"
|
|
shift
|
|
|
|
[ "$stage" = "$CU_STAGE" ] || return 0
|
|
|
|
"$@"
|
|
}
|
|
|
|
# Check that all previous cu_check_timestamp actions contain timestamps less than a given one
|
|
cu_verify_latest_timestamp_lt()
|
|
{
|
|
local timestamp="`echo \"$1\" | tr -dc '[:digit:]'`"
|
|
[ "$CU_LATEST_TIMESTAMP" -lt "$timestamp" ] || simply_die "Upgrader actions for '$CU_STAGE' stage of '$CU_LAST_DB_UPGRADER_NAME' upgrader are not valid. Timestamp values MUST be less than $timestamp. Please fix upgrader definition!"
|
|
}
|
|
|
|
# --- Upgrader bookkeeping functions ---
|
|
|
|
# Start a block of upgrade actions that should be executed when upgrading from a given version
|
|
cu_start_upgrade_from_version()
|
|
{
|
|
CU_UPGRADE_VERSION_FROM="$1"
|
|
}
|
|
|
|
# Remember failed upgrade action (to be able to rerun it afterwards)
|
|
cu_add_failed_action()
|
|
{
|
|
local action_id="$1"
|
|
[ -n "$action_id" ] && CU_FAILED_ACTIONS="$CU_FAILED_ACTIONS $action_id" && CU_HAS_NEW_FAILED_ACTIONS="yes"
|
|
}
|
|
|
|
cu_remove_failed_action()
|
|
{
|
|
local action_id="$1"
|
|
[ -n "$CU_FAILED_ACTIONS" -a -n "$action_id" ] && CU_FAILED_ACTIONS="` remove_from_array "$action_id" "$CU_FAILED_ACTIONS" `"
|
|
}
|
|
|
|
# Store configuration data using supplied callback. Duplicate to default location if necessary.
|
|
cu_do_store_config_data()
|
|
{
|
|
local upgrader_name="$1"
|
|
local store_config_data_func="$2"
|
|
|
|
$store_config_data_func "$upgrader_name"
|
|
# Duplicate into default storage, if custom one was used. This is mostly for humans.
|
|
[ "$store_config_data_func" = "cu_txtdb_store_config_data" ] || cu_txtdb_store_config_data "$upgrader_name"
|
|
}
|
|
|
|
# Handler for cases when critical action fails and there is no rollback procedure defined
|
|
cu_critical_failure_handler()
|
|
{
|
|
[ -n "$CU_LAST_DB_UPGRADER_NAME" -a -z "$CU_LAST_DB_CONTINUE_FROM" ] || {
|
|
p_echo "Can't handle upgrader critical failure - upgrader state is broken. Probably a programming error."
|
|
return
|
|
}
|
|
|
|
p_echo "Updating '$CU_LAST_DB_UPGRADER_NAME' configuration status after a critical failure during upgrade stage '$CU_LAST_STAGE' on '$CU_LAST_ACTION_ID' action"
|
|
|
|
local cu_db_current_timestamp cu_db_continue_from cu_db_failed_actions_list cu_db_latest_timestamp
|
|
# Update only continue_from and failed_actions_list fields.
|
|
cu_db_current_timestamp="$CU_LAST_DB_CURRENT_TIMESTAMP"
|
|
cu_db_continue_from="`cu_get_current_continue_from`"
|
|
cu_db_failed_actions_list="$CU_FAILED_ACTIONS"
|
|
cu_db_latest_timestamp="$CU_LAST_DB_LATEST_TIMESTAMP"
|
|
|
|
cu_do_store_config_data "$CU_LAST_DB_UPGRADER_NAME" "$CU_LAST_STORE_CONFIG_DATA_FUNC"
|
|
|
|
CU_LAST_DB_UPGRADER_NAME=
|
|
}
|
|
|
|
# Check that following upgrader run will actually have any actions executed
|
|
cu_check_upgrade_required()
|
|
{
|
|
local upgrader_func="$1"
|
|
local CU_DO_GET_ACTION_NAME="yes"
|
|
local upgrade_actions="`$upgrader_func`"
|
|
[ -n "$upgrade_actions" ]
|
|
}
|
|
|
|
# --- Upgrader set up functions ---
|
|
|
|
# Set up installed (product/package) version and installed configuration timestamp
|
|
cu_set_initial_versions()
|
|
{
|
|
CU_START_VERSION_FROM="${1:-starting_component_version_not_specified}"
|
|
CU_START_TIMESTAMP="${2:-0}"
|
|
}
|
|
|
|
# Reset upgrader global variables
|
|
cu_set_globals()
|
|
{
|
|
local upgrader_name="$1"
|
|
local stage="$2"
|
|
local store_config_data_func="$3"
|
|
|
|
CU_DO_GET_ACTION_NAME=
|
|
CU_LATEST_TIMESTAMP=0
|
|
CU_LAST_ACTION_ID=
|
|
|
|
# Initial DB record values. Used by cu_critical_failure_handler()
|
|
CU_LAST_DB_UPGRADER_NAME="$upgrader_name"
|
|
CU_LAST_DB_CURRENT_TIMESTAMP="$cu_db_current_timestamp"
|
|
CU_LAST_DB_CONTINUE_FROM="$cu_db_continue_from"
|
|
CU_LAST_DB_FAILED_ACTIONS_LIST="$cu_db_failed_actions_list"
|
|
CU_LAST_DB_LATEST_TIMESTAMP="$cu_db_latest_timestamp"
|
|
CU_LAST_STAGE="$stage"
|
|
CU_LAST_STORE_CONFIG_DATA_FUNC="$store_config_data_func"
|
|
}
|
|
|
|
# --- Default implementations to load/store configuration data ---
|
|
|
|
cu_txtdb_config_data_params()
|
|
{
|
|
db_file="$PLESK_DB_DIR/components-configuration-state.db"
|
|
db_delim='#'
|
|
}
|
|
|
|
# Path to default upgrader configuration db changed in Plesk 11.5.26. This function moves existing db.
|
|
cu_txtdb_try_upgrade_location()
|
|
{
|
|
local old_db_file="$PRODUCT_ROOT_D/var/components-configuration-state.db"
|
|
local db_file db_owner db_group db_perms db_delim db_key_field
|
|
txtdb_set_params cu_txtdb_config_data_params
|
|
|
|
if [ -s "$old_db_file" -a ! -e "$db_file" ]; then
|
|
mv -f "$old_db_file" "$db_file"
|
|
fi
|
|
}
|
|
|
|
cu_txtdb_ensure_config_data_exists()
|
|
{
|
|
cu_txtdb_try_upgrade_location
|
|
txtdb_exists cu_txtdb_config_data_params >/dev/null 2>&1 || txtdb_truncate cu_txtdb_config_data_params
|
|
}
|
|
|
|
cu_txtdb_load_config_data()
|
|
{
|
|
local upgrader_name="$1"
|
|
|
|
cu_txtdb_ensure_config_data_exists
|
|
local record="`txtdb_select cu_txtdb_config_data_params "$upgrader_name"`"
|
|
|
|
cu_db_current_timestamp="` get_narg_fs "$record" '#' 2`"
|
|
cu_db_continue_from="` get_narg_fs "$record" '#' 3`"
|
|
cu_db_failed_actions_list="`get_narg_fs "$record" '#' 4`"
|
|
cu_db_latest_timestamp="` get_narg_fs "$record" '#' 5`"
|
|
}
|
|
|
|
cu_txtdb_store_config_data()
|
|
{
|
|
local upgrader_name="$1"
|
|
local record="$upgrader_name#$cu_db_current_timestamp#$cu_db_continue_from#$cu_db_failed_actions_list#$cu_db_latest_timestamp"
|
|
cu_txtdb_ensure_config_data_exists
|
|
txtdb_replace cu_txtdb_config_data_params "$record"
|
|
}
|
|
|
|
# --- Main code for generic cumulative upgrader ---
|
|
|
|
cu_run_upgrader()
|
|
{
|
|
local opt_upgrader_name="$1"
|
|
local opt_upgrader_func="$2"
|
|
shift 2
|
|
|
|
local opt_prepare_func= opt_rollback_func= opt_commit_func= opt_start_version= opt_stage= opt_do_repair= opt_do_update_version_in_db= opt_do_init=
|
|
local opt_load_config_data_func=cu_txtdb_load_config_data opt_store_config_data_func=cu_txtdb_store_config_data
|
|
|
|
local inten="perform upgrade for $opt_upgrader_name"
|
|
|
|
while [ "$#" -gt 0 ]; do
|
|
case "$1" in
|
|
--prepare)
|
|
opt_prepare_func="$2"
|
|
[ "$#" -ge 2 ] && shift 2 || break
|
|
;;
|
|
--rollback)
|
|
opt_rollback_func="$2"
|
|
[ "$#" -ge 2 ] && shift 2 || break
|
|
;;
|
|
--commit)
|
|
opt_commit_func="$2"
|
|
[ "$#" -ge 2 ] && shift 2 || break
|
|
;;
|
|
--load-config-data)
|
|
opt_load_config_data_func="$2"
|
|
[ "$#" -ge 2 ] && shift 2 || break
|
|
;;
|
|
--store-config-data)
|
|
opt_store_config_data_func="$2"
|
|
[ "$#" -ge 2 ] && shift 2 || break
|
|
;;
|
|
--from-version)
|
|
opt_start_version="$2"
|
|
[ "$#" -ge 2 ] && shift 2 || break
|
|
;;
|
|
--stage)
|
|
opt_stage="$2"
|
|
[ "$#" -ge 2 ] && shift 2 || break
|
|
;;
|
|
--repair)
|
|
opt_do_repair="yes"
|
|
shift
|
|
;;
|
|
--update-version)
|
|
opt_do_update_version_in_db="yes"
|
|
shift
|
|
;;
|
|
--init)
|
|
opt_do_init="yes"
|
|
shift
|
|
;;
|
|
*)
|
|
die "$inten: unknown key '$1'"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Sanity checks
|
|
[ -n "$opt_upgrader_name" ] || die "$inten: empty component upgrader name argument"
|
|
[ -n "$opt_upgrader_func" ] && is_function "$opt_upgrader_func" || die "$inten: invalid component upgrader function argument"
|
|
[ -n "$opt_load_config_data_func" ] && is_function "$opt_load_config_data_func" || die "$inten: invalid value for --load-config-data argument"
|
|
[ -n "$opt_store_config_data_func" ] && is_function "$opt_store_config_data_func" || die "$inten: invalid value for --store-config-data argument"
|
|
[ -z "$opt_prepare_func" ] || is_function "$opt_prepare_func" || die "$inten: invalid value for --prepare argument"
|
|
[ -z "$opt_rollback_func" ] || is_function "$opt_rollback_func" || die "$inten: invalid value for --rollback argument"
|
|
[ -z "$opt_commit_func" ] || is_function "$opt_commit_func" || die "$inten: invalid value for --commit argument"
|
|
[ -n "$opt_do_init" -a \( -n "$opt_do_repair" -o -n "$opt_prepare_func" -o -n "$opt_rollback_func" -o -n "$opt_commit_func" \) ] && die "$inten: excessive options prohibited for use with --init"
|
|
|
|
# Upgrader setup
|
|
local CU_STAGE="$opt_stage"
|
|
local cu_db_current_timestamp cu_db_continue_from cu_db_failed_actions_list cu_db_latest_timestamp
|
|
$opt_load_config_data_func "$opt_upgrader_name"
|
|
cu_set_initial_versions "$opt_start_version" "$cu_db_current_timestamp"
|
|
cu_set_globals "$opt_upgrader_name" "$opt_stage" "$opt_store_config_data_func"
|
|
|
|
local CU_CONTINUE_FROM_ID= CU_FAILED_ACTIONS= CU_HAS_NEW_FAILED_ACTIONS=
|
|
if [ -z "$opt_do_init" ]; then
|
|
if [ -n "$cu_db_continue_from" ]; then
|
|
if [ -z "$opt_do_repair" ]; then
|
|
pp_echo "Unable to upgrade '$opt_upgrader_name' to the latest version, since its configuration is in broken state. Run bootstrapper repair to fix."
|
|
return 2
|
|
fi
|
|
|
|
local cu_continue_from_stage="` cu_get_continue_stage "$cu_db_continue_from" `"
|
|
CU_CONTINUE_FROM_ID="` cu_get_continue_id "$cu_db_continue_from" `"
|
|
if [ "$cu_continue_from_stage" != "$CU_STAGE" ]; then
|
|
p_echo "Skipping stage '$CU_STAGE' of upgrade for '$opt_upgrader_name' as previous upgrade attempt was not finished on another stage."
|
|
return 3
|
|
fi
|
|
elif [ -n "$cu_db_failed_actions_list" ]; then
|
|
if [ -z "$opt_do_repair" ]; then
|
|
p_echo "Before start of upgrade for '$opt_upgrader_name' (stage '$CU_STAGE') following actions are registered as failed: $cu_db_failed_actions_list."
|
|
else
|
|
CU_FAILED_ACTIONS="` normalize_array "$cu_db_failed_actions_list" `"
|
|
fi
|
|
fi
|
|
|
|
if ! cu_check_upgrade_required "$opt_upgrader_func" ; then
|
|
p_echo "Upgrade or repair for '$opt_upgrader_name' (stage '$CU_STAGE') is not required"
|
|
[ -n "$opt_prepare_func" ] && $opt_prepare_func "$opt_upgrader_name" "$CU_STAGE" noop-stage
|
|
[ -n "$opt_commit_func" ] && $opt_commit_func "$opt_upgrader_name" "$CU_STAGE" noop-stage
|
|
return 0
|
|
fi
|
|
|
|
# Preparation step
|
|
[ -n "$opt_prepare_func" ] && $opt_prepare_func "$opt_upgrader_name" "$CU_STAGE"
|
|
|
|
# Register rollback actions.
|
|
# Note that rollback scope currently spans to the end of upgrade procedure (this function).
|
|
if [ -n "$opt_rollback_func" ]; then
|
|
transaction_add_rollback_action "$opt_rollback_func"
|
|
# Rollback function contract: everything changed in this upgrader pass will be
|
|
# rolled back. Component version should not change. Therefore there is no need
|
|
# to update anything in DB.
|
|
else
|
|
transaction_add_rollback_action "cu_critical_failure_handler"
|
|
fi
|
|
|
|
# Run upgrade actions
|
|
$opt_upgrader_func
|
|
|
|
# Commit (post) step - if we are here upgrade has completed (but there may be failed actions)
|
|
[ -n "$opt_commit_func" ] && $opt_commit_func "$opt_upgrader_name" "$CU_STAGE"
|
|
else
|
|
# This is just an initialization run to set proper upgrader configuration on component installation
|
|
p_echo "Initializing '$opt_upgrader_name' upgrader configuration (stage '$CU_STAGE')"
|
|
local CU_DO_GET_ACTION_NAME="yes"
|
|
$opt_upgrader_func >/dev/null 2>&1
|
|
fi
|
|
|
|
# Update DB record if there are changes. Update current_timestamp only if explicitly allowed (e.g. this is the last stage).
|
|
cu_db_continue_from=
|
|
|
|
if [ -n "$opt_do_repair" -o -z "$CU_LAST_DB_FAILED_ACTIONS_LIST" ]; then
|
|
cu_db_failed_actions_list="$CU_FAILED_ACTIONS"
|
|
else
|
|
# Append failed actions from this stage. Don't care for duplicates - they will be removed when a given action succeeds.
|
|
cu_db_failed_actions_list="` normalize_array "$CU_LAST_DB_FAILED_ACTIONS_LIST" "$CU_FAILED_ACTIONS" `"
|
|
fi
|
|
|
|
if [ -z "$cu_db_latest_timestamp" -a "$CU_LATEST_TIMESTAMP" -gt 0 ] || [ "0$cu_db_latest_timestamp" -lt "$CU_LATEST_TIMESTAMP" ]; then
|
|
cu_db_latest_timestamp="$CU_LATEST_TIMESTAMP"
|
|
fi
|
|
|
|
[ -n "$opt_do_update_version_in_db" -a "0$cu_db_latest_timestamp" -gt 0 ] && cu_db_current_timestamp="$cu_db_latest_timestamp"
|
|
|
|
if [ "$cu_db_current_timestamp" != "$CU_LAST_DB_CURRENT_TIMESTAMP" \
|
|
-o "$cu_db_latest_timestamp" != "$CU_LAST_DB_LATEST_TIMESTAMP" \
|
|
-o "$cu_db_failed_actions_list" != "$CU_LAST_DB_FAILED_ACTIONS_LIST" \
|
|
-o "$cu_db_continue_from" != "$CU_LAST_DB_CONTINUE_FROM" ]; then
|
|
cu_do_store_config_data "$opt_upgrader_name" "$opt_store_config_data_func"
|
|
fi
|
|
|
|
# If this is just an initialization, we don't need to disarm rollback, etc.
|
|
[ -z "$opt_do_init" ] || return 0
|
|
|
|
# Upgrade is complete - disarm rollback actions
|
|
if [ -n "$opt_rollback_func" ]; then
|
|
transaction_remove_rollback_action "$opt_rollback_func"
|
|
else
|
|
transaction_remove_rollback_action "cu_critical_failure_handler"
|
|
fi
|
|
|
|
if [ -n "$cu_db_failed_actions_list" ]; then
|
|
p_echo "After end of upgrade for '$opt_upgrader_name' (stage '$CU_STAGE') following actions are registered as failed: $cu_db_failed_actions_list."
|
|
fi
|
|
|
|
[ ! -n "$CU_HAS_NEW_FAILED_ACTIONS" ]
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
get_user_id()
|
|
{
|
|
local name="$1"
|
|
|
|
[ -n "$name" ] || int_err "Wrong value of argument 'name': $name"
|
|
|
|
getent passwd "$name" 2>/dev/null | awk -F':' '{print $3}'
|
|
}
|
|
|
|
get_group_id()
|
|
{
|
|
local name="$1"
|
|
|
|
[ -n "$name" ] || int_err "Wrong value of argument 'name': $name"
|
|
|
|
getent group "$name" 2>/dev/null | awk -F':' '{print $3}'
|
|
}
|
|
|
|
group_op()
|
|
{
|
|
local group="$1"
|
|
local gid="$2"
|
|
local id_force="$3"
|
|
local gid_min="${4:-30}"
|
|
local gid_max="${5:-400}"
|
|
|
|
if [ "X$gid" = "Xsearch" ]; then
|
|
gid=`get_user_group_id "$group" "gid" $gid_min $gid_max`
|
|
fi
|
|
|
|
local inten="add group '$group'"
|
|
local group_id="`get_group_id $group`"
|
|
|
|
case "$id_force" in
|
|
true)
|
|
if [ -n "$group_id" ]; then
|
|
[ "$group_id" = "$gid" ] && p_echo " Group '$group' already exists" || group_err "$group" "$gid"
|
|
else
|
|
# We do not expect any created group with ID == $gid
|
|
getent group 2>/dev/null | grep -E -q "^[^:]*:[*x]*:$gid:" && gid_err "$gid" || :
|
|
|
|
echo_try "$inten"
|
|
groupadd -g "$gid" "$group" >> $product_log 2>&1 && suc || die $inten
|
|
fi
|
|
;;
|
|
false)
|
|
if [ -n "$group_id" ]; then
|
|
p_echo " Group '$group' already exists"
|
|
else
|
|
echo_try "$inten"
|
|
groupadd "$group" >> $product_log 2>&1 && suc || die $inten
|
|
fi
|
|
;;
|
|
*)
|
|
int_err "group_op: wrong last parameter -- must be 'true' or 'false'"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
user_op()
|
|
{
|
|
user="$1"
|
|
uid="$2"
|
|
group="$3"
|
|
u_desc="$4"
|
|
u_home="$5"
|
|
u_shell="$6"
|
|
id_force="$7"
|
|
gid_force="$8"
|
|
|
|
local inten="add user $user"
|
|
|
|
if [ "X$uid" = "Xsearch" ]; then
|
|
uid=`get_user_group_id "$user" "uid" 30 400`
|
|
fi
|
|
|
|
p_echo " Checking for the user '$user'..."
|
|
user_id="`get_user_id $user`"
|
|
|
|
case "$id_force" in
|
|
true)
|
|
if [ -n "$user_id" ]; then
|
|
chk_res=`id "$user" 2>&1 | grep -E '(^uid=.*gid=.*)|(^id.*user)'`
|
|
if [ "X${gid_force}" = "Xfalse" ]; then
|
|
chk_uid=`echo "$chk_res" | grep -E "uid=""$uid""\(""$user""\)"`
|
|
else
|
|
chk_uid=`echo "$chk_res" | grep -E "uid=""$uid""\(""$user""\)" | grep -E "gid=[0-9]*\(""$group""\)"`
|
|
fi
|
|
case "$chk_uid" in
|
|
uid=*gid=*)
|
|
p_echo " User '$user' already exists"
|
|
;;
|
|
*) logname_err "$user" "$uid"
|
|
;;
|
|
esac
|
|
usermod -s "$u_shell" "$user" >> $product_log 2>&1
|
|
else
|
|
getent passwd 2>/dev/null | grep -E -q "^[^:]*:[^:]*:""$uid"":" && uid_err "$uid" || :
|
|
|
|
pnnl_echo " Trying to add user '$user'... "
|
|
useradd -r -u "$uid" -g "$group" -d "$u_home" -s "$u_shell" -c "$u_desc" "$user" >> $product_log 2>&1 &&
|
|
suc || die "$inten"
|
|
fi
|
|
;;
|
|
false)
|
|
if [ -n "$user_id" ]; then
|
|
p_echo " User '$user' already exists"
|
|
else
|
|
pnnl_echo " Trying to add user '$user'... "
|
|
useradd -r -g "$group" -d "$u_home" -s "$u_shell" -c "$u_desc" "$user" >> $product_log 2>&1 &&
|
|
suc || die "$inten"
|
|
fi
|
|
;;
|
|
*)
|
|
int_err "user_op: wrong last parameter -- must be 'true' or 'false'"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
get_user_group_id()
|
|
{
|
|
local src
|
|
|
|
local name="$1"
|
|
local src_name="$2"
|
|
local min_num="$3"
|
|
local max_num="$4"
|
|
|
|
case "$src_name" in
|
|
uid)
|
|
src="passwd"
|
|
uid="`get_user_id $name`"
|
|
[ -n "$uid" ] && echo "$uid" && return 0 || :
|
|
;;
|
|
gid)
|
|
src="group"
|
|
gid="`get_group_id $name`"
|
|
[ -n "$gid" ] && echo "$gid" && return 0 || :
|
|
;;
|
|
*)
|
|
p_echo "$src_name for $name was not set"
|
|
die "detect uid/gid. Source file was not detect."
|
|
;;
|
|
esac
|
|
|
|
if [ $min_num -le 0 -o $min_num -ge $max_num ]; then
|
|
int_err "group_op(): wrong group ID's range to look for the empty ID: $gid_min ... $gid_max"
|
|
fi
|
|
|
|
# list of busy ids
|
|
nums="`getent $src 2>/dev/null | awk -F: '{print $3}' | sort -g | xargs echo -n`"
|
|
|
|
# Find an empty id
|
|
for num in `seq $min_num $max_num`; do
|
|
echo " $nums " | grep -q " $num " && continue
|
|
echo "$num"
|
|
return 0
|
|
done
|
|
|
|
p_echo "$src_name for $name was not set"
|
|
die "get free $src_name. Free $src_name not found."
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh
|
|
|
|
initial_conf()
|
|
{
|
|
PRODNAME="psa"
|
|
PRODUCT_NAME="psa"
|
|
product=${PRODNAME}
|
|
PRODUCT_FULL_NAME="Plesk"
|
|
|
|
product_etc="/etc/${PRODNAME}"
|
|
prod_conf_t="/etc/psa/psa.conf"
|
|
|
|
support_contact="https://support.plesk.com/"
|
|
|
|
conceived_os_vendor=Ubuntu
|
|
conceived_os_version="24.04"
|
|
|
|
clients_group="psacln"
|
|
clients_GID="10001"
|
|
|
|
services_group="psaserv"
|
|
services_GID="10003"
|
|
|
|
product_suff="saved_by_${product}".`date "+%m.%d;%H:%M"`
|
|
product_suffo="saved_by_${product}"
|
|
|
|
# plesk default password
|
|
PRODUCT_DEFAULT_PASSWORD="setup"
|
|
}
|
|
|
|
read_conf()
|
|
{
|
|
[ -n "$prod_conf_t" ] || prod_conf_t=/etc/psa/psa.conf
|
|
|
|
if [ -s $prod_conf_t ]; then
|
|
tmp_var=`perl -e 'undef $/; $_=<>; s/#.*$//gm;
|
|
s/^\s*(\S+)\s*/$1=/mg;
|
|
print' $prod_conf_t`
|
|
eval $tmp_var
|
|
else
|
|
if ! is_product_installation; then
|
|
p_echo "Unable to find product configuration file: $prod_conf_t. Default values will be used."
|
|
return 1
|
|
fi
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
get_my_cnf_param()
|
|
{
|
|
local r=
|
|
|
|
local my_cnf
|
|
find_my_cnf "non-fatal" && \
|
|
r=`perl -e '$p="'"$1"'";
|
|
undef $/; $_=<>; s/#.*$//gm;
|
|
/\[mysqld\](.*?)\[/sg;
|
|
$_=substr($1, rindex $1,"$p") and
|
|
/$p\s*=(.*)/m and print $1
|
|
' ${my_cnf}`
|
|
echo $r
|
|
}
|
|
|
|
get_mysql_socket()
|
|
{
|
|
# Marked as local as it's not used anywhere else now.
|
|
local mysql_socket="/var/run/mysqld/mysqld.sock"
|
|
|
|
local mysqlsock=`get_my_cnf_param socket`
|
|
local MYSQL_SOCKETS="/var/lib/mysql/mysql.sock /tmp/mysql.sock /var/run/mysqld/mysqld.sock"
|
|
|
|
for i in $mysql_socket $mysqlsock $MYSQL_SOCKETS; do
|
|
if [ -S "$i" ]; then
|
|
# This is used internally by mysqld_safe. Maybe this whole function isn't required nowadays.
|
|
# See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-mysql-sock.html
|
|
MYSQL_UNIX_PORT=$i
|
|
export MYSQL_UNIX_PORT
|
|
mysql_socket="$i"
|
|
break
|
|
fi
|
|
done
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
#-*- vim:ft=sh
|
|
|
|
enable_respawn_service()
|
|
{
|
|
|
|
grep_q_recursive() {
|
|
local val="$1"
|
|
local file="$2"
|
|
if [ -f "$file" ]; then
|
|
! grep -q "$val" "$file" || return 0
|
|
for f in `sed -n -e "s/^\.include\s//p" $file`; do
|
|
! grep_q_recursive "$val" "$f" || return 0
|
|
done
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
[ -n "$1" ] || die "enable_respawn_service: service name not specified"
|
|
local inten="enable automatic respawn for service $1"
|
|
echo_try "$inten"
|
|
|
|
local service=$1
|
|
local main_unit=`systemctl show $service | sed -n -e "s/FragmentPath=//p"`
|
|
local respawn_unit="/lib/systemd/system/$service.d/respawn.conf"
|
|
local dropin_units=`systemctl show $service | sed -n -e "s/DropInPaths=//p" | sed "s|$respawn_unit||"`
|
|
local ini="/opt/psa/admin/conf/panel.ini"
|
|
local ini_section="systemd"
|
|
|
|
local respawn
|
|
[ ! -f "$ini" ] || respawn=`get_ini_conf_var "$ini" "$ini_section" respawn`
|
|
|
|
if [ -z "${respawn/on/}" ]; then
|
|
for unit in $main_unit $dropin_units; do
|
|
! grep_q_recursive "^Restart=" "$unit" || respawn="off"
|
|
! grep_q_recursive "^Type=oneshot" "$unit" || respawn="off"
|
|
done
|
|
fi
|
|
|
|
rm -f "$respawn_unit"
|
|
|
|
if [ -z "${respawn/on/}" ]; then
|
|
mkdir -p "$(dirname $respawn_unit)"
|
|
if [ -f "$ini" ]; then
|
|
local restart=` get_ini_conf_var "$ini" "$ini_section" Service.Restart`
|
|
local restartsec=` get_ini_conf_var "$ini" "$ini_section" Service.RestartSec`
|
|
fi
|
|
cat <<EOT > "$respawn_unit"
|
|
[Service]
|
|
Restart=${restart:-"on-failure"}
|
|
RestartSec=${restartsec:-"5"}
|
|
EOT
|
|
fi
|
|
|
|
suc
|
|
}
|
|
|
|
selinux_close()
|
|
{
|
|
if [ -z "$SELINUX_ENFORCE" -o "$SELINUX_ENFORCE" = "Disabled" ]; then
|
|
return
|
|
fi
|
|
|
|
setenforce "$SELINUX_ENFORCE"
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh:
|
|
|
|
#set_params
|
|
|
|
set_common_params()
|
|
{
|
|
common_var=0
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
|
LANG="`get_default_locale`"
|
|
export PATH LANG
|
|
unset GREP_OPTIONS
|
|
umask 022
|
|
ulimit -n 65535 2>/dev/null
|
|
|
|
get_product_versions
|
|
|
|
certificate_file="$PRODUCT_ETC_D/httpsd.pem"
|
|
services="/etc/services"
|
|
|
|
crontab="/usr/bin/crontab"
|
|
|
|
SYSTEM_RC_D="/etc/init.d"
|
|
PLESK_LIBEXEC_DIR="/usr/lib/plesk-9.0"
|
|
PLESK_DB_DIR="/var/lib/plesk"
|
|
PRODUCT_BOOTSTRAPPER_DIR="`printf "/opt/psa/bootstrapper/pp%s-bootstrapper" "$product_this_version"`"
|
|
AUTOGENERATED_CONFIGS="#ATTENTION!\n#\n#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,\n#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.\n"
|
|
AUTOGENERATED_CONFIGS_UPGRADE="#ATTENTION!\n#\n#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,\n#SO ALL YOUR CHANGES WILL BE LOST AFTER YOU UPGRADE PLESK.\n"
|
|
PRODUCT_LOGS_D="/var/log/plesk"
|
|
|
|
sendmail="/usr/sbin/sendmail"
|
|
ps="ps axw"
|
|
ifconfig="/sbin/ifconfig -a"
|
|
|
|
machine="linux"
|
|
if [ -f /etc/debian_version ]; then
|
|
linux_distr="debian"
|
|
else
|
|
linux_distr="redhat"
|
|
fi
|
|
|
|
dummy_home="/"
|
|
if [ -x /usr/sbin/nologin ]; then
|
|
dummy_shell="/usr/sbin/nologin"
|
|
else
|
|
dummy_shell="/bin/false"
|
|
fi
|
|
|
|
rp_patch_runtime
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# -*- vim:syntax=sh
|
|
|
|
set_syslog_params()
|
|
{
|
|
syslog_conf_ng="/etc/syslog-ng/syslog-ng.conf"
|
|
|
|
syslog_conf=""
|
|
for config in rsyslog.conf rsyslog.d/50-default.conf rsyslog.early.conf syslog.conf; do
|
|
[ -f "/etc/$config" ] && syslog_conf="$syslog_conf /etc/$config"
|
|
done
|
|
|
|
syslog_service=""
|
|
syslog_binary=""
|
|
|
|
# Make sure the sequence of services is correlate with binaries
|
|
local syslog_services="syslog sysklogd rsyslog syslog-ng"
|
|
local syslog_binaries="syslogd syslogd rsyslogd syslog-ng"
|
|
|
|
for service in $syslog_services; do
|
|
[ -f "/lib/systemd/system/${service}.service" ] && \
|
|
syslog_service="$service" && break
|
|
done
|
|
|
|
for binary in $syslog_binaries; do
|
|
for bin_path in /sbin /usr/sbin; do
|
|
[ -x "$bin_path/${binary}" ] && \
|
|
syslog_binary="$bin_path/${binary}" && break
|
|
done
|
|
[ -n "$syslog_binary" ] && break
|
|
done
|
|
|
|
[ -n "$syslog_conf" ] || p_echo "\$syslog_conf: not found"
|
|
[ -n "$syslog_service" ] || p_echo "\$syslog_service: not found"
|
|
[ -n "$syslog_binary" ] || p_echo "\$syslog_binary: not found"
|
|
|
|
[ -n "$syslog_conf" -a -n "$syslog_service" -a -n "$syslog_binary" ]
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# -*- vim:syntax=sh
|
|
|
|
packagemng_set_dirty_flag()
|
|
{
|
|
if [ -f ${PRODUCT_ROOT_D}/admin/bin/packagemng ]; then
|
|
${PRODUCT_ROOT_D}/admin/bin/packagemng --set-dirty-flag 1>>$product_log 2>&1
|
|
fi
|
|
}
|
|
|
|
get_product_versions()
|
|
{
|
|
# Don't use global variables set elsewhere in this code. Use substitutions if needed.
|
|
local prod_root_d="/opt/psa"
|
|
|
|
product_name="psa"
|
|
|
|
if [ -z "$product_this_version" ]; then
|
|
# 1. Try to fetch version from file created by bootstrapper (should be 3-component).
|
|
product_this_version="`cat "/var/lock/plesk-target-version" 2>/dev/null`"
|
|
# 2. Fallback to $PRODUCT_ROOT_D/version (should be 3-component).
|
|
if [ -z "$product_this_version" -a -r "$prod_root_d/version" ]; then
|
|
product_this_version="`awk '{ print $1 }' "$prod_root_d/version"`"
|
|
fi
|
|
# 3. Fallback to hardcoded version (2-component). This may cause some other code to fail.
|
|
if [ -z "$product_this_version" ]; then
|
|
product_this_version="18.0"
|
|
echo "Unable to determine \$product_this_version, will use less precise value '$product_this_version'" >&2
|
|
fi
|
|
fi
|
|
|
|
product_version="$product_this_version"
|
|
|
|
if [ -z "$product_prev_version" ]; then
|
|
if [ -r "$prod_root_d/version.upg" ]; then
|
|
product_prev_version=`awk '{ print $1 }' "$prod_root_d/version.upg"`
|
|
elif [ -r "$prod_root_d/version" ]; then
|
|
product_prev_version=`awk '{ print $1 }' "$prod_root_d/version"`
|
|
else
|
|
product_prev_version="$product_this_version"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Clean installation of the product is being performed
|
|
is_product_installation()
|
|
{
|
|
[ "X$do_upgrade" != "X1" -a ! -s "/opt/psa/version.upg" ]
|
|
}
|
|
|
|
true exim_status_linux_debian
|
|
exim_status_linux_debian()
|
|
{
|
|
get_pid /usr/lib/exim/exim3 false
|
|
local pid=$common_var
|
|
|
|
if test "$pid" -ne 1; then
|
|
#running
|
|
return 0;
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
configure_mail_users()
|
|
{
|
|
p_echo "Create Mail accounts"
|
|
group_op "$MAIL_USERGROUP" "search" true
|
|
user_op "$MAIL_USERGROUP" "search" "$MAIL_USERGROUP" "POP3 service user" "$MAIL_USERGROUP_HOMEDIR" "$dummy_shell" true false
|
|
user_op "$HANDLERS_USER" "search" "$MAIL_USERGROUP" "mail handlers user" "$dummy_home" "$dummy_shell" true false
|
|
}
|
|
|
|
init_userdb()
|
|
{
|
|
/usr/lib/plesk-9.0/mail_userdb_init >>"$product_log" 2>&1
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
#-*- vim:syntax=sh
|
|
|
|
select_maillog()
|
|
{
|
|
local mail_log="/var/log/maillog"
|
|
local inten="set maillog file to $mail_log"
|
|
|
|
echo_try "$inten"
|
|
set_syslog_params
|
|
|
|
if [ "$syslog_service" = "rsyslog" ]; then
|
|
for config in $syslog_conf; do
|
|
if [ -f "$config" ]; then
|
|
# comment out default 'mail.*' records:
|
|
perl -i -ple 's/^(mail\.\*.*)/#\1/' "$config"
|
|
fi
|
|
done
|
|
elif [ -f "$syslog_conf_ng" ]; then
|
|
# override mail log destination
|
|
perl -i -ple 's#^destination d_mail \{ .* \};\s*$#destination d_mail { file("'"${mail_log}"'"); };#' "$syslog_conf_ng"
|
|
else
|
|
warn "Unknown syslog: rsyslog or syslog-ng were not found"
|
|
return
|
|
fi
|
|
|
|
# Move old logfile into new place.
|
|
local old_mail_log='/var/log/mail.log'
|
|
if [ -f "$old_mail_log" -a ! -e "$mail_log" ]; then
|
|
mv "$old_mail_log" "$mail_log"
|
|
fi
|
|
|
|
! [ -f "$mail_log" ] || chmod 640 "$mail_log"
|
|
|
|
pleskrc syslog reload-or-restart || return 1
|
|
suc
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
set_mail_params()
|
|
{
|
|
HANDLERS_USER="mhandlers-user"
|
|
MAIL_USERGROUP="popuser"
|
|
MAIL_USERGROUP_HOMEDIR="/var/qmail/$MAIL_USERGROUP"
|
|
}
|
|
|
|
set_mysql_auth()
|
|
{
|
|
# This function requires set_mysql_server_params and set_mysql_client_params (or set_mysqld_params)
|
|
# to be called before
|
|
local inten="set up mysql authentication"
|
|
local dsn_plesk_host="`get_dsn plesk host`"
|
|
local dsn_plesk_port="`get_dsn plesk port`"
|
|
local dsn_plesk_username="`get_dsn plesk username`"
|
|
local dsn_plesk_password="`get_dsn plesk password`"
|
|
|
|
get_admin_passwd
|
|
|
|
[ -n "$dsn_plesk_host" ] || pleskrc mysql start
|
|
|
|
mysql_host="${dsn_plesk_host:+--host=$dsn_plesk_host}"
|
|
mysql_port="${dsn_plesk_port:+--port=$dsn_plesk_port}"
|
|
mysql_user="--user=${dsn_plesk_username:-admin}"
|
|
mysql_passwd="${dsn_plesk_password:-$admin_passwd}"
|
|
|
|
if find_my_cnf 'non-fatal'; then
|
|
mysql_defaults="--defaults-file=$my_cnf"
|
|
else
|
|
mysql_defaults="--no-defaults"
|
|
fi
|
|
|
|
if [ -z "$PLESK_MYSQL_AUTH_SKIP_CONNECTION_CHECK" ]; then
|
|
mysql_test_connection 10 || die "$inten"
|
|
fi
|
|
suc
|
|
}
|
|
|
|
get_admin_passwd()
|
|
{
|
|
[ -z "$admin_passwd" ] || return 0
|
|
|
|
if [ -f "$mysql_passwd_file" ]; then
|
|
admin_passwd=`cat "$mysql_passwd_file"`
|
|
return 0
|
|
fi
|
|
|
|
admin_passwd=`get_random_string 1 'A-Z'`
|
|
admin_passwd+=`get_random_string 1 'a-z'`
|
|
admin_passwd+=`get_random_string 1 '0-9'`
|
|
admin_passwd+=`get_random_string 1 '_%=+\-@<>:.,:'`
|
|
admin_passwd+=`get_random_string 10 'A-Za-z0-9_%=+\-@<>:.,:'`
|
|
admin_passwd=`printf "%s" "$admin_passwd" | fold -w 1 | shuf - | tr -d '\n'`
|
|
|
|
[ -n "$admin_passwd" ] || admin_passwd="$PRODUCT_DEFAULT_PASSWORD"
|
|
touch "$admin_password_needs_encryption_flag"
|
|
}
|
|
|
|
mysql_test_connection()
|
|
{
|
|
inten="establish test connection"
|
|
echo_try $inten
|
|
attempts=${1:-1}
|
|
for i in `sequence $attempts`; do
|
|
echo "" | mysql_direct mysql >> "$product_log" 2>&1
|
|
if [ "$?" -eq "0" ]; then
|
|
p_echo "connected"
|
|
return 0
|
|
fi
|
|
[ "$attempts" -eq "1" ] || sleep 1
|
|
done
|
|
|
|
p_echo "failed"
|
|
return 1
|
|
}
|
|
|
|
find_my_cnf()
|
|
{
|
|
local non_fatal="$1"
|
|
local cnf_files="/etc/my.cnf /etc/mysql/my.cnf /var/db/mysql/my.cnf"
|
|
|
|
for my_cnf in $cnf_files; do
|
|
if [ -f ${my_cnf} ]; then
|
|
break
|
|
fi
|
|
done
|
|
|
|
[ -f "$my_cnf" -o -n "$non_fatal" ] || {
|
|
local msg="find the MySQL server configuration file. \
|
|
If you use a third-party MySQL server build, make sure you do not use implicit default configuration \
|
|
and you have the MySQL configuration file in one of the following locations: $cnf_files"
|
|
echo "Failed to $msg" | write_structured_report 'stage=mysqlsetup' 'level=fatal' 'errtype=mysqlnomycnf' "mycnffiles=$cnf_files" || :
|
|
die "$msg"
|
|
}
|
|
|
|
[ -f "$my_cnf" ] || return 1
|
|
|
|
my_cnf_d=`awk '/^\s*!includedir\>/ {print $2}' "$my_cnf" | head -1`
|
|
|
|
return 0
|
|
}
|
|
|
|
set_mysql_server_params()
|
|
{
|
|
get_mysql_socket
|
|
|
|
if [ -n "/lib/systemd/system" -a -f "/lib/systemd/system/mariadb.service" ]; then
|
|
mysql_service="mariadb"
|
|
elif [ -n "/lib/systemd/system" -a -f "/lib/systemd/system/mysqld.service" ]; then
|
|
# Percona server
|
|
mysql_service="mysqld"
|
|
elif [ -n "/lib/systemd/system" -a -f "/lib/systemd/system/mysql.service" ]; then
|
|
# MySQL 8 installations on debian / ubuntu
|
|
mysql_service="mysql"
|
|
elif [ -x "${PRODUCT_RC_D}/mysql" ]; then
|
|
mysql_service="mysql"
|
|
elif [ -x "${PRODUCT_RC_D}/mysql.sh" ]; then
|
|
mysql_service="mysql.sh"
|
|
elif [ -x "${PRODUCT_RC_D}/mysqld" ]; then
|
|
mysql_service="mysqld"
|
|
elif [ -x "${PRODUCT_RC_D}/mysql" ]; then
|
|
mysql_service="mysql"
|
|
else
|
|
die "detect MySQL service name"
|
|
fi
|
|
}
|
|
|
|
set_mysql_client_params()
|
|
{
|
|
mysql_client="$MYSQL_BIN_D/mysql"
|
|
[ -f "$MYSQL_BIN_D/mariadb" ] && mysql_client="$MYSQL_BIN_D/mariadb"
|
|
|
|
# Override this variable as needed
|
|
mysql_db_name="$PRODNAME"
|
|
mysql_passwd_file="$product_etc/.${PRODNAME}.shadow"
|
|
|
|
mysql_args="-N"
|
|
mysql_args_raw="-Br"
|
|
|
|
local dsn_plesk_dbname="`get_dsn plesk dbname`"
|
|
[ -z "$dsn_plesk_dbname" ] || mysql_db_name="$dsn_plesk_dbname"
|
|
}
|
|
|
|
#Invoke mysql
|
|
dbclient_invoke()
|
|
{
|
|
mysql_anydb -D$mysql_db_name "$@"
|
|
}
|
|
|
|
mysql_anydb()
|
|
{
|
|
(
|
|
export MYSQL_PWD="$mysql_passwd"
|
|
$mysql_client $mysql_defaults $mysql_host $mysql_port $mysql_user $mysql_args "$@" 2>>"$product_log"
|
|
local status=$?
|
|
|
|
if [ $status -gt 0 ]; then
|
|
$mysql_client $mysql_defaults $mysql_host $mysql_port $mysql_user $mysql_args -D$mysql_db_name $mysql_args_raw -e "SHOW ENGINE innodb status" >>"$product_log" 2>&1
|
|
fi
|
|
unset MYSQL_PWD
|
|
return $status
|
|
)
|
|
}
|
|
|
|
# Invoke mysql without any wrapper or something else
|
|
mysql_direct()
|
|
{
|
|
# a bit dirty but it works properly for passwords with spaces, quotes and double quotes:
|
|
if [ -n "$mysql_passwd" ]; then
|
|
(
|
|
export MYSQL_PWD="$mysql_passwd"
|
|
$mysql_client $mysql_defaults $mysql_host $mysql_port $mysql_user $mysql_args "$@" 2>>"$product_log"
|
|
rc=$?
|
|
unset MYSQL_PWD
|
|
return $rc
|
|
)
|
|
else
|
|
$mysql_client $mysql_defaults $mysql_host $mysql_port $mysql_user $mysql_args "$@" 2>>"$product_log"
|
|
fi
|
|
}
|
|
|
|
# Invoke mysql in raw mode
|
|
mysql_raw()
|
|
{
|
|
dbclient_invoke $mysql_args_raw "$@"
|
|
}
|
|
|
|
uses_mysql_client()
|
|
{
|
|
# Initialize local MySQL authentication parameters and test connection.
|
|
# After that db_*() and mysql*() functions may be used.
|
|
# Any MySQL-specific overrides (e.g., local mysql_db_name="whatever") should appear
|
|
# *after* calling this function.
|
|
# This function is for use in component installers that require access to MySQL DB.
|
|
|
|
set_mysql_server_params
|
|
set_mysql_client_params
|
|
set_mysql_auth
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# -*- vim:ft=sh
|
|
|
|
# MySQL service action handlers
|
|
|
|
### FIXME: probably need var service_restart warn
|
|
true mysql_stop
|
|
mysql_stop()
|
|
{
|
|
local op_result i
|
|
|
|
inten="stop MySQL server"
|
|
echo_try $inten
|
|
|
|
service_ctl stop $mysql_service mysql
|
|
op_result=$?
|
|
|
|
if [ "X$linux_distr" = "Xdebian" ]; then
|
|
# Debian has well designed mysql stopping code
|
|
[ "$op_result" -eq 0 ] || die $inten
|
|
suc
|
|
return 0
|
|
fi
|
|
|
|
for i in 2 4 6 8 16; do
|
|
if ! mysql_status ; then
|
|
suc
|
|
return 0
|
|
fi
|
|
|
|
# I just want to be sure that mysql really stopped
|
|
killall -TERM mysqld mysql safe_mysqld mysqld_safe >> $product_log 2>&1
|
|
|
|
sleep $i
|
|
done
|
|
|
|
die "$inten"
|
|
}
|
|
|
|
true mysql_status
|
|
mysql_status()
|
|
{
|
|
# Previously this handler also checked for mysqld pid on Debian systems. Should not be needed nowadays.
|
|
service_ctl status $mysql_service mysql
|
|
}
|
|
|
|
write_postconf_value()
|
|
{
|
|
local param="$1"
|
|
local value="$2"
|
|
local conf_value="`echo "$value" | awk 'BEGIN { ORS=""; PORS="" } { print PORS; print; PORS=", " }'`"
|
|
/usr/sbin/postconf -e "$param=$conf_value" >>"$product_log" 2>&1
|
|
}
|
|
|
|
postconf_param_exists()
|
|
{
|
|
local param="$1"
|
|
local value=`/usr/sbin/postconf -d "$param" 2>/dev/null`
|
|
test -n "$value"
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
set_postfix_params()
|
|
{
|
|
postfix_service="postfix"
|
|
pc_remote_service="pc-remote"
|
|
}
|
|
|
|
true postfix_status
|
|
postfix_status()
|
|
{
|
|
# here be dragons.
|
|
# the practical experience shows that simple checking of status of
|
|
# Postfix "master" process is not enough. So we read Postfix master
|
|
# process pid file if any, then try to look for a process with
|
|
# name ``qmgr'' and parent pid being equal to
|
|
# the pid read from the pidfile. If pgrep finds such a process
|
|
# it returns 0, if not its exit status is non-zero.
|
|
# pgrep is portable enough to prefer it to "hand-made" alternatives
|
|
# such as famous ``ps | grep $name | grep -v grep...'' pipes
|
|
# bug 147822. do not interrupt installation for FreeBSD
|
|
|
|
[ -f "/var/spool/postfix/pid/master.pid" ] || return 1
|
|
|
|
local ppid
|
|
|
|
read ppid </var/spool/postfix/pid/master.pid 2>/dev/null
|
|
if [ $? -ne 0 -o -z "$ppid" ]; then
|
|
# not found or other error
|
|
return 1;
|
|
fi
|
|
pgrep -P $ppid qmgr >/dev/null 2>/dev/null
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh
|
|
|
|
# Follow variables are supported in <package>_upgrader_conf:
|
|
# upgrader_name - Upgrader id
|
|
# upgrader_description - Short description which will be used in terminal and logs output.
|
|
# upgrader_func_prefix - Prefix to generate function names used in upgrader.
|
|
# upgrader_stages - Stages which upgrader supports for this component.
|
|
# IMPORTANT: This stages list should be sorted in execution order because
|
|
# last stage in list will store data into upgrader's cache and
|
|
# upgrader_run_post do not care about one either.
|
|
#
|
|
# Optional flags to execute / do not execute some upgrader's parts. Default 'true':
|
|
# upgrader_call_init - upgrader_init() control
|
|
# upgrader_call_reset - upgrader_reset() control
|
|
#
|
|
# Example:
|
|
# upgrader_name="dns-bind-driver"
|
|
# upgrader_description="DNS service support"
|
|
# upgrader_func_prefix="dnsbinddriver"
|
|
# upgrader_stages="prep post bootstrapper-post"
|
|
#
|
|
# upgrader_call_init="false"
|
|
# upgrader_call_reset="false"
|
|
|
|
upgrader_conf_init()
|
|
{
|
|
[ -n "$PACKAGE_ID" ] || die "initialize upgrader: PACKAGE_ID is not set"
|
|
# Check package uses the default upgrader
|
|
is_function "${PACKAGE_ID}_upgrader_conf" || return 1
|
|
|
|
upgrader_call_init="true"
|
|
upgrader_call_reset="true"
|
|
|
|
"${PACKAGE_ID}_upgrader_conf"
|
|
|
|
# Sanity checks
|
|
[ -z "$upgrader_name" -o -z "$upgrader_description" -o -z "$upgrader_func_prefix" -o -z "$upgrader_stages" ] \
|
|
&& die "initialize upgrader for $PACKAGE_ID: some upgrader variables are not defined"
|
|
|
|
return 0
|
|
}
|
|
|
|
upgrader_run()
|
|
{
|
|
# Usage: upgrader_run [--repair] [stage ...]
|
|
upgrader_conf_init || return 0
|
|
|
|
local options=
|
|
local optional_repair_arg=
|
|
|
|
if [ "$1" = "--repair" ]; then
|
|
optional_repair_arg="$1"
|
|
shift
|
|
fi
|
|
|
|
! is_function "${upgrader_func_prefix}_cu_load_config_data" || \
|
|
options="--load-config-data ${upgrader_func_prefix}_cu_load_config_data"
|
|
|
|
! is_function "${upgrader_func_prefix}_cu_store_config_data" || \
|
|
options="$options --store-config-data ${upgrader_func_prefix}_cu_store_config_data"
|
|
|
|
local stages_to_run=
|
|
[ -n "$*" ] && stages_to_run="$*" || stages_to_run="$upgrader_stages"
|
|
|
|
local last_stage="${upgrader_stages##* }"
|
|
|
|
for stage in $stages_to_run; do
|
|
local opt_update_version=
|
|
if [ "$stage" = "$last_stage" ]; then
|
|
opt_update_version="--update-version"
|
|
fi
|
|
|
|
local inten="upgrade${optional_repair_arg:+ and repair} $upgrader_description ($stage stage)"
|
|
echo_try "$inten"
|
|
|
|
cu_run_upgrader "$upgrader_name" "${upgrader_func_prefix}_upgrader" \
|
|
--stage "$stage" $optional_repair_arg $options $opt_update_version
|
|
if [ "$?" = "0" ]; then
|
|
suc
|
|
else
|
|
warn "$inten"
|
|
# return non-zero exit code on error in repair mode:
|
|
[ -z "$optional_repair_arg" ] || return 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
upgrader_run_pre()
|
|
{
|
|
upgrader_conf_init || return 0
|
|
|
|
# do not execute unified upgrader if there's a custom function
|
|
# upgrade_new_pre() in preinst.in component script
|
|
! is_function "${PACKAGE_ID}_upgrade_new_pre" || return 0
|
|
|
|
# Execute default stages for pre- stage
|
|
for stage in ${upgrader_stages}; do
|
|
if [ "$stage" = "prep" ]; then
|
|
upgrader_run "$stage"
|
|
return $?
|
|
fi
|
|
done
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh
|
|
|
|
postfix_disable_smtputf8()
|
|
{
|
|
# We decided to disable smtputf8 for a while.
|
|
# These changes must be rolled back after the root of a problem has been fixed.
|
|
# Original value of smtputf8_enable is '${{$compatibility_level} < {1} ? {no} : {yes}}'
|
|
local smtputf8_value=`/usr/sbin/postconf -h smtputf8_enable 2>/dev/null`
|
|
if [ "$smtputf8_value" != "no" ]; then
|
|
/usr/sbin/postconf -e smtputf8_enable=no
|
|
deferred_postfix_restart
|
|
fi
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh:
|
|
|
|
true mailpcdriver_upgrader_conf
|
|
|
|
mailpcdriver_upgrader_conf()
|
|
{
|
|
upgrader_name="mail-pc-driver"
|
|
upgrader_description="Postfix Plesk mail driver"
|
|
upgrader_func_prefix="mailpcdriver"
|
|
upgrader_stages="post"
|
|
|
|
# Do not wipe it out after the sh_optimizer processing
|
|
true mailpcdriver_upgrader
|
|
}
|
|
|
|
mailpcdriver_upgrader()
|
|
{
|
|
local post="cu_check_stage post"
|
|
local ts="cu_check_timestamp"
|
|
local do="cu_do"
|
|
|
|
cu_start_upgrade_from_version 017009004
|
|
$post $ts '2018/08/22 16:30:00' $do postfix_restrict_authorized_queue_users
|
|
|
|
cu_start_upgrade_from_version 018000014
|
|
$post $ts '2019/05/21 16:30:00' $do postfix_fix_debian_chroot
|
|
$post $ts '2019/05/23 15:00:00' $do postfix_force_systemd_respawn
|
|
$post $ts '2019/05/24 12:30:00' $do deferred_install_postfix_smtpd_sasl_config
|
|
$post $ts '2019/05/31 13:44:00' $do postfix_sni_support
|
|
|
|
cu_start_upgrade_from_version 018000020
|
|
$post $ts '2019/10/23 10:17:14' $do postfix_clear_smtp_privileged
|
|
|
|
cu_start_upgrade_from_version 018000031
|
|
$post $ts '2020/10/27 10:30:00' $do postfix_revert_smtpd_timeouts_to_default
|
|
|
|
cu_start_upgrade_from_version 018000033
|
|
$post $ts '2021/01/26 08:10:00' $do postfix_increase_compatibility_level
|
|
$post $ts '2021/03/01 08:10:00' $do postfix_reenable_chroot
|
|
|
|
cu_start_upgrade_from_version 018000034
|
|
$post $ts '2021/04/05 09:10:00' $do postfix_disable_smtputf8
|
|
|
|
cu_start_upgrade_from_version 018000037
|
|
$post $ts '2021/07/19 14:30:00' $do postfix_enable_postfix_local_tracing
|
|
|
|
cu_start_upgrade_from_version 018000046
|
|
$post $ts '2022/08/26 12:00:00' $do postfix_pc_remote_purge_sysvinit
|
|
|
|
cu_start_upgrade_from_version 018000057
|
|
$post $ts '2024/01/06 15:00:00' $do prevent_smtp_smuggling_attack
|
|
|
|
cu_start_upgrade_from_version 018000061
|
|
$post $ts '2024/06/11 14:00:00' $do select_maillog
|
|
|
|
cu_start_upgrade_from_version 018000066
|
|
$post $ts '2024/10/28 10:00:00' $do move_postfix_sasl2_conf
|
|
|
|
cu_start_upgrade_from_version 018000069
|
|
$post $ts '2025/05/13 10:00:00' $do refresh_maps_protection
|
|
|
|
cu_start_upgrade_from_version 018000071
|
|
$post $ts '2025/07/18 10:13:00' $do init_userdb
|
|
|
|
cu_start_upgrade_from_version 018000072
|
|
$post $ts '2025/09/05 19:00:00' $do disable_postfix_srs_process_limit
|
|
$post $ts '2025/09/16 14:28:00' $do deferred_install_postfix_smtpd_sasl_config
|
|
$post $ts '2025/09/16 14:38:00' $do deferred_install_postfix_smtpd_sasl_config
|
|
$post $ts '2025/09/16 14:48:00' $do deferred_install_postfix_smtpd_sasl_config
|
|
|
|
# DO NOT MODIFY ANYTHING BELOW THIS LINE! (without approval of review from the entire Linux team)
|
|
call_optional_function dev_mailpcdriver_upgrader
|
|
cu_verify_latest_timestamp_lt '2025/09/28 11:00:00'
|
|
}
|
|
|
|
postfix_restrict_authorized_queue_users()
|
|
{
|
|
/usr/sbin/postconf -e authorized_mailq_users= authorized_flush_users=
|
|
}
|
|
|
|
postfix_fix_debian_chroot()
|
|
{
|
|
|
|
|
|
# chroot environment may not be configured in Debian
|
|
# because call of configure-instance was omitted in debian startup script
|
|
pleskrc postfix try-restart
|
|
|
|
}
|
|
|
|
postfix_force_systemd_respawn()
|
|
{
|
|
# systemd respawn config may not be created because systemd unit was omitted
|
|
enable_respawn_service postfix.service
|
|
/bin/systemctl daemon-reload
|
|
}
|
|
|
|
postfix_sni_support()
|
|
{
|
|
# set tls_server_sni_maps in main.cf
|
|
write_postconf_value "tls_server_sni_maps" "hash:/var/spool/postfix/plesk/certs"
|
|
|
|
# create empty certs.db database even if SNI is not supported on this OS
|
|
[ ! -f "/var/spool/postfix/plesk/certs.db" ] || return 0
|
|
echo "" | /usr/sbin/postmap -i "hash:/var/spool/postfix/plesk/certs"
|
|
}
|
|
|
|
postfix_clear_smtp_privileged()
|
|
{
|
|
# Clear unpriv=n for smtp transport with explicit IP or hostname
|
|
# since process run as root requires CAP_DAC_OVERRIIDE capability
|
|
# and related SELinux permission to access /var/spool/postfix directories.
|
|
deferred_mail_pc_driver_transport_restore
|
|
}
|
|
|
|
postfix_revert_smtpd_timeouts_to_default()
|
|
{
|
|
local is_need_restart=
|
|
|
|
local old_value=`/usr/sbin/postconf -h smtpd_timeout`
|
|
if [ "$old_value" = "3600s" ]; then
|
|
/usr/sbin/postconf -# smtpd_timeout
|
|
is_need_restart=true
|
|
fi
|
|
|
|
old_value=`/usr/sbin/postconf -h smtpd_proxy_timeout`
|
|
if [ "$old_value" = "3600s" ]; then
|
|
/usr/sbin/postconf -# smtpd_proxy_timeout
|
|
is_need_restart=true
|
|
fi
|
|
|
|
[ -z "$is_need_restart" ] || deferred_postfix_restart
|
|
}
|
|
|
|
postfix_increase_compatibility_level()
|
|
{
|
|
local is_need_restart=
|
|
|
|
local old_value=`/usr/sbin/postconf -h compatibility_level`
|
|
if [ "$old_value" = "0" ] || [ "$old_value" = "1" ]; then
|
|
/usr/sbin/postconf compatibility_level=2
|
|
is_need_restart=true
|
|
fi
|
|
|
|
[ -z "$is_need_restart" ] || deferred_postfix_restart
|
|
}
|
|
|
|
postfix_reenable_chroot()
|
|
{
|
|
local is_need_restart=
|
|
local chroot_value=`/usr/sbin/postconf -Fh smtps/inet/chroot 2>/dev/null`
|
|
if [ "$chroot_value" = "-" ]; then
|
|
/usr/sbin/postconf -F smtps/inet/chroot=y
|
|
is_need_restart=true
|
|
fi
|
|
|
|
chroot_value=`/usr/sbin/postconf -Fh smtp/inet/chroot 2>/dev/null`
|
|
if [ "$chroot_value" = "-" ]; then
|
|
/usr/sbin/postconf -F smtp/inet/chroot=y
|
|
is_need_restart=true
|
|
fi
|
|
|
|
[ -z "$is_need_restart" ] || deferred_postfix_restart
|
|
}
|
|
|
|
postfix_enable_postfix_local_tracing()
|
|
{
|
|
local inten="enable tracing in postfix-local"
|
|
echo_try "$inten"
|
|
|
|
local param="plesk_virtual/unix/command"
|
|
local val=$("/usr/sbin/postconf" -F "$param") 2>>"$product_log"
|
|
if [ -z "$val" ]; then
|
|
warn "postconf failed to read \"$param\""
|
|
return 1
|
|
elif ! [ "${val/ -q /}" = "$val" ]; then
|
|
p_echo "queue_id is already specified among args passed to postfix-local"
|
|
return 0
|
|
fi
|
|
|
|
"/usr/sbin/postconf" -Fe "$val -q \${queue_id}" >>"$product_log" 2>&1
|
|
if [ $? -ne 0 ]; then
|
|
warn "postconf failed to set \"param\""
|
|
return 1
|
|
fi
|
|
|
|
deferred_postfix_restart
|
|
|
|
suc
|
|
}
|
|
|
|
postfix_pc_remote_purge_sysvinit()
|
|
{
|
|
# sysvinit scripts weren't shipped for systemd OSes
|
|
# except for debian ones due to value of `HAS_SYSVINIT`
|
|
# which is set to True up to debian 11
|
|
:
|
|
}
|
|
|
|
prevent_smtp_smuggling_attack()
|
|
{
|
|
# Prevent SMTP smuggling attacks https://www.postfix.org/smtp-smuggling.html
|
|
# same logic as in mailsrv_conf_init.cc
|
|
echo_try "configure postfix to prevent SMTP smuggling attack"
|
|
if postconf_param_exists "smtpd_forbid_bare_newline"; then
|
|
p_echo "enable smtpd_forbid_bare_newline"
|
|
write_postconf_value "smtpd_forbid_bare_newline" "yes"
|
|
write_postconf_value "smtpd_forbid_bare_newline_exclusions" '$mynetworks'
|
|
elif postconf_param_exists "smtpd_forbid_unauth_pipelining"; then
|
|
p_echo "enable smtpd_forbid_unauth_pipelining"
|
|
write_postconf_value "smtpd_forbid_unauth_pipelining" "yes"
|
|
write_postconf_value "smtpd_discard_ehlo_keywords" "chunking, silent-discard"
|
|
else
|
|
p_echo "reject unauth pipelining"
|
|
write_postconf_value "smtpd_data_restrictions" "reject_unauth_pipelining"
|
|
write_postconf_value "smtpd_discard_ehlo_keywords" "chunking, silent-discard"
|
|
fi
|
|
suc
|
|
deferred_postfix_restart
|
|
}
|
|
|
|
move_postfix_sasl2_conf()
|
|
{
|
|
:
|
|
}
|
|
|
|
refresh_maps_protection()
|
|
{
|
|
uses_mysql_client
|
|
|
|
db_select "SELECT value FROM ServiceNodeConfiguration WHERE name='rbl' AND serviceNodeId=1 AND section='mailServer'"
|
|
|
|
if [ "$db_select_output" != "true" ]; then
|
|
return 0
|
|
fi
|
|
|
|
db_select "SELECT value FROM ServiceNodeConfiguration WHERE name='rbl_server' AND serviceNodeId=1 AND section='mailServer'"
|
|
|
|
if [ -n "$db_select_output" ]; then
|
|
"$PRODUCT_ROOT_D/admin/sbin/mailmng-server" --set-maps-protection "--maps-zones=$(echo "$db_select_output" | tr ';' ',')" --without-restart
|
|
deferred_postfix_restart
|
|
fi
|
|
}
|
|
|
|
disable_postfix_srs_process_limit()
|
|
{
|
|
/usr/sbin/postconf -eF "127.0.0.1:12346/inet/process_limit=0"
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
#-*- vim:ft=sh
|
|
|
|
create_plesksendmail_group()
|
|
{
|
|
groupadd --system --force "plesksendmail"
|
|
}
|
|
|
|
mailpcdriver_upgrade_new_pre()
|
|
{
|
|
set_postfix_params
|
|
pleskrc pc_remote stop
|
|
create_plesksendmail_group
|
|
}
|
|
|
|
mailpcdriver_install_pre()
|
|
{
|
|
set_mail_params
|
|
configure_mail_users
|
|
create_plesksendmail_group
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
if [ "X${PLESK_INSTALLER_DEBUG}" != "X" ]; then
|
|
set -x
|
|
fi
|
|
|
|
if [ "X${PLESK_INSTALLER_STRICT_MODE}" != "X" ]; then
|
|
set -e
|
|
fi
|
|
|
|
reexec_with_clean_env "$@"
|
|
|
|
export PLESK_INTERNAL_PHP_EXEC=1
|
|
|
|
do_upgrade=0
|
|
|
|
# Need for extended error reporting to the external errors tracker.
|
|
PACKAGE_ID="mailpcdriver"
|
|
PACKAGE_ACTION="prein"
|
|
|
|
case "$1" in
|
|
install)
|
|
package_script_safe_run plesk-mail-pc-driver 18.0 \
|
|
mailpcdriver_install_pre
|
|
;;
|
|
upgrade)
|
|
# We are the new upgrading package
|
|
do_upgrade=1
|
|
prev_version="${2%%-*}"
|
|
PACKAGE_ACTION="preup-new"
|
|
|
|
package_script_safe_run plesk-mail-pc-driver 18.0 \
|
|
mailpcdriver_upgrade_new_pre \
|
|
upgrader_run_pre
|
|
;;
|
|
abort-upgrade)
|
|
;;
|
|
*)
|
|
echo "Unknown operation: preinst $*"
|
|
exit 1
|
|
;;
|
|
esac
|