106 lines
2.6 KiB
Bash
Executable File
106 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
#
|
|
|
|
#
|
|
# Plesk script
|
|
#
|
|
|
|
|
|
|
|
#default values
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:syntax=sh
|
|
|
|
generate_encryption_key()
|
|
{
|
|
local key_file="/etc/psa/private/secret_key"
|
|
local key_dir="`dirname $key_file`"
|
|
local rc=0
|
|
|
|
[ -d "$key_dir" ] || mkdir -p "$key_dir"
|
|
|
|
if [ ! -e "$key_file" ]; then
|
|
dd if=/dev/urandom of="$key_file" bs=16 count=1 2>/dev/null
|
|
else
|
|
rc=1
|
|
fi
|
|
fix_key_permissions
|
|
return $rc
|
|
}
|
|
|
|
fix_key_permissions()
|
|
{
|
|
local key_file="/etc/psa/private/secret_key"
|
|
local key_dir="`dirname $key_file`"
|
|
|
|
if [ -e "$key_file" ]; then
|
|
chown psaadm:0 "$key_file"
|
|
chmod 0600 "$key_file"
|
|
fi
|
|
|
|
if [ -d "$key_dir" ]; then
|
|
chown psaadm:0 "$key_dir"
|
|
chmod 0700 "$key_dir"
|
|
fi
|
|
}
|
|
### 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"
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh:
|
|
|
|
reexec_with_clean_env "$@"
|
|
|
|
key_file="/etc/psa/private/secret_key"
|
|
if [ -e "$key_file" ]; then
|
|
echo "Unable to generate new key - key file exists"
|
|
fix_key_permissions
|
|
exit 1
|
|
else
|
|
generate_encryption_key
|
|
fi
|