install_postfixadmin.sh: support transfer 'setup_password' from old installation.
This commit is contained in:
parent
db1c2fd72b
commit
a0f75035ad
@ -424,13 +424,85 @@ else
|
||||
fatal "No PHP binary found in PATH environment.."
|
||||
fi
|
||||
|
||||
_actual_config_file=""
|
||||
_actual_password_hash=""
|
||||
_actual_pfa_dir=""
|
||||
_actual_pfa_documentroot=""
|
||||
if [[ -d "${WEBSITE_BASEDIR}/htdocs" ]] ; then
|
||||
PFA_UPDATE=true
|
||||
_actual_pfa_documentroot="$(realpath "${WEBSITE_BASEDIR}/htdocs")"
|
||||
if [[ "$(basename "$(dirname "${_actual_pfa_documentroot}")")" =~ ^postfixadmin ]]; then
|
||||
_actual_pfa_dir="$(dirname "${_actual_pfa_documentroot}")"
|
||||
else
|
||||
_actual_pfa_dir="${_actual_pfa_documentroot}"
|
||||
fi
|
||||
else
|
||||
PFA_UPDATE=false
|
||||
fi
|
||||
|
||||
echononl "\tKeep passwordhasch from actual installation in mind.."
|
||||
if [[ -n "$_actual_pfa_dir" && -d "$_actual_pfa_dir" ]] ; then
|
||||
if [[ -f "${_actual_pfa_dir}/config.local.php" ]]; then
|
||||
_actual_config_file="${_actual_pfa_dir}/config.local.php"
|
||||
else
|
||||
_actual_config_file="${_actual_pfa_dir}/config.inc.php"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [[ -f "$_actual_config_file" ]]; then
|
||||
_actual_password_hash="$(grep -E "^\s*\\\$CONF\['setup_password'\]" $_actual_config_file 2> /dev/null \
|
||||
| grep -v changeme \
|
||||
| awk -F '=' '{print$2}'\
|
||||
| awk -F ';' '{print$1}')"
|
||||
|
||||
_actual_password_hash="${_actual_password_hash#"${_actual_password_hash%%[![:space:]]*}"}"
|
||||
# - Remove trailing whitespace characters
|
||||
_actual_password_hash="${_actual_password_hash%"${_actual_password_hash##*[![:space:]]}"}"
|
||||
# - Remove leading single quote
|
||||
_actual_password_hash="${_actual_password_hash#"${_actual_password_hash%%[!\']*}"}"
|
||||
# - Remove trailing single quote
|
||||
_actual_password_hash="${_actual_password_hash%"${_actual_password_hash##*[!\']}"}"
|
||||
# - Remove leading double quote
|
||||
_actual_password_hash="${_actual_password_hash#"${_actual_password_hash%%[!\"]*}"}"
|
||||
# - Remove trailing double quote
|
||||
_actual_password_hash="${_actual_password_hash%"${_actual_password_hash##*[!\"]}"}"
|
||||
|
||||
echo_ok
|
||||
else
|
||||
echo_skipped
|
||||
fi
|
||||
|
||||
_installed_version=""
|
||||
if $PFA_UPDATE ; then
|
||||
echononl "\tDetermine installed version of PFA .."
|
||||
_installed_version="$(echo "$(basename "${_actual_pfa_dir}")" | cut -d'-' -f2)"
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
echo -e "\033[1;32mSettings for installation of \033[1;37mPostfix Admin / Vacation\033[m"
|
||||
echo ""
|
||||
echo -e "\tPostfix Admin Version................: $PF_ADMIN_VERSION"
|
||||
if $PFA_UPDATE ; then
|
||||
echo -e "\tUpdate Postfixadmin..................: YES"
|
||||
if [[ -n "${_installed_version}" ]] ; then
|
||||
echo -e "\tinstalled PFA verion.................: $_installed_version"
|
||||
else
|
||||
echo -e "\tinstalled PFA verion.................: "** \033[33mnot detected\033[m **
|
||||
fi
|
||||
if [[ -n "$_actual_password_hash" ]]; then
|
||||
echo -e "\tactual Passwordhash..................: $_actual_password_hash"
|
||||
else
|
||||
echo -e "\tactual Passwordhash..................: ** \033[33mnot found\033[m **"
|
||||
fi
|
||||
else
|
||||
echo -e "\tInstall Postfixadmin first time......: YES"
|
||||
fi
|
||||
echo ""
|
||||
echo -e "\tPostfix Admin new Version............: $PF_ADMIN_VERSION"
|
||||
echo ""
|
||||
echo -e "\tName of the Website..................: $WEBSITE_NAME"
|
||||
echo ""
|
||||
@ -538,45 +610,6 @@ _failed=false
|
||||
> $log_file
|
||||
|
||||
|
||||
_actual_config_file=""
|
||||
_actual_password_hash=""
|
||||
_actual_pfa_dir=""
|
||||
if [[ -d "${WEBSITE_BASEDIR}/htdocs" ]] ; then
|
||||
_actual_pfa_dir="$(realpath "${WEBSITE_BASEDIR}/htdocs")"
|
||||
fi
|
||||
echononl "\tKeep passwordhasch from actual installation in mind.."
|
||||
if [[ -n "$_actual_pfa_dir" && -d "$_actual_pfa_dir" ]] ; then
|
||||
if [[ -f "${_actual_pfa_dir}/config.local.php" ]]; then
|
||||
_actual_config_file="${_actual_pfa_dir}/config.local.php"
|
||||
else
|
||||
_actual_config_file="${_actual_pfa_dir}/config.inc.php"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [[ -f "$_actual_config_file" ]]; then
|
||||
_actual_password_hash="$(grep -E "^\s*\\\$CONF\['setup_password'\]" $_actual_config_file 2> /dev/null \
|
||||
| grep -v changeme \
|
||||
| awk -F '=' '{print$2}'\
|
||||
| awk -F ';' '{print$1}')"
|
||||
|
||||
_actual_password_hash="${_actual_password_hash#"${_actual_password_hash%%[![:space:]]*}"}"
|
||||
# - Remove trailing whitespace characters
|
||||
_actual_password_hash="${_actual_password_hash%"${_actual_password_hash##*[![:space:]]}"}"
|
||||
# - Remove leading single quote
|
||||
_actual_password_hash="${_actual_password_hash#"${_actual_password_hash%%[!\']*}"}"
|
||||
# - Remove trailing single quote
|
||||
_actual_password_hash="${_actual_password_hash%"${_actual_password_hash##*[!\']}"}"
|
||||
# - Remove leading double quote
|
||||
_actual_password_hash="${_actual_password_hash#"${_actual_password_hash%%[!\"]*}"}"
|
||||
# - Remove trailing double quote
|
||||
_actual_password_hash="${_actual_password_hash%"${_actual_password_hash##*[!\"]}"}"
|
||||
|
||||
echo_ok
|
||||
else
|
||||
echo_skipped
|
||||
fi
|
||||
|
||||
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]] ; then
|
||||
echononl "\tCheck if database '$POSTFIX_DB_NAME' already exists.."
|
||||
_db_response="$(mysql $MYSQL_CREDENTIALS -N -s -e \
|
||||
@ -659,9 +692,14 @@ else
|
||||
if [[ ! -d "${WEBSITE_BASEDIR}" ]] ; then
|
||||
echo_skipped
|
||||
else
|
||||
if [[ -n "$_installed_version" ]] ; then
|
||||
_db_backup_file_name="${POSTFIX_DB_NAME}-pfa-${_installed_version}.${backup_date}.sql"
|
||||
else
|
||||
_db_backup_file_name="${POSTFIX_DB_NAME}-pfa.${backup_date}.sql"
|
||||
fi
|
||||
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then
|
||||
echo -n " (MySQL).."
|
||||
mysqldump $MYSQL_CREDENTIALS --opt $POSTFIX_DB_NAME > ${WEBSITE_BASEDIR}/${POSTFIX_DB_NAME}.${backup_date}.sql 2> $log_file
|
||||
mysqldump $MYSQL_CREDENTIALS --opt $POSTFIX_DB_NAME > ${WEBSITE_BASEDIR}/${_db_backup_file_name} 2> $log_file
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo_ok
|
||||
else
|
||||
@ -675,7 +713,7 @@ else
|
||||
fi
|
||||
elif [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then
|
||||
echo -n " (PostgreSQL).."
|
||||
su - postgres -c "pg_dump -c $POSTFIX_DB_NAME" >> ${WEBSITE_BASEDIR}/${POSTFIX_DB_NAME}.${backup_date}.sql 2> $log_file
|
||||
su - postgres -c "pg_dump -c $POSTFIX_DB_NAME" >> ${WEBSITE_BASEDIR}/${_db_backup_file_name} 2> $log_file
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo_ok
|
||||
else
|
||||
@ -1406,22 +1444,22 @@ EOF
|
||||
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
|
||||
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
|
||||
|
||||
<FilesMatch \.php$>
|
||||
EOF
|
||||
if $PHP_DEBIAN_INSTALLATION ; then
|
||||
php_socket_file="/run/php/php${php_major_version}-fpm.sock"
|
||||
if [[ -S "/run/php$(echo $php_major_version | cut -d'.' -f1)-fpm.sock" ]]; then
|
||||
php_socket_file="/run/php$(echo $php_major_version | cut -d'.' -f1)-fpm.sock"
|
||||
fi
|
||||
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
|
||||
SetHandler "proxy:unix:${php_socket_file}|fcgi://127.0.0.1"
|
||||
EOF
|
||||
else
|
||||
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
|
||||
SetHandler "proxy:unix:/tmp/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1"
|
||||
EOF
|
||||
php_socket_file="/run/php/php-${php_latest_ver}-fpm.www.sock"
|
||||
if [[ -S "/tmp/php-${php_latest_ver}-fpm.www.sock" ]]; then
|
||||
php_socket_file="/run/php/php-${php_latest_ver}-fpm.www.sock"
|
||||
fi
|
||||
fi
|
||||
|
||||
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
|
||||
<FilesMatch \.php$>
|
||||
SetHandler "proxy:unix:${php_socket_file}|fcgi://127.0.0.1"
|
||||
</FilesMatch>
|
||||
|
||||
<IfModule dir_module>
|
||||
@ -2425,13 +2463,47 @@ fi
|
||||
# -
|
||||
echononl "\tTake passwordhash from previosly installation.."
|
||||
if [[ -n "$_actual_password_hash" ]] ; then
|
||||
perl -i -n -p -e "s#^(\s*\\\$CONF\['setup_password'\]\s*=.*)#//!\1\n\\\$CONF['setup_password'] = '$_actual_password_hash';#" \
|
||||
$pfa_conf_file >> $log_file 2>&1
|
||||
if [[ $? -eq 0 ]] ; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
|
||||
_failed=false
|
||||
_backup_file="/tmp/$(basename "${pfa_conf_file}")"
|
||||
mv "$pfa_conf_file" "$_backup_file" > $log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
_failed=true
|
||||
fi
|
||||
|
||||
> $pfa_conf_file
|
||||
_found=false
|
||||
while IFS='' read -r _line || [[ -n $_line ]] ; do
|
||||
if echo "$_line" | grep -i -E "^\s*\\\$CONF\['setup_password'\]\s*=.*;" > /dev/null 2>&1 ; then
|
||||
echo -n '//!' >> $pfa_conf_file
|
||||
echo "$_line" >> $pfa_conf_file
|
||||
if ! $_found ; then
|
||||
echo "\$CONF['setup_password'] = '$_actual_password_hash';" >> $pfa_conf_file
|
||||
_found=true
|
||||
fi
|
||||
else
|
||||
echo "$_line" >> $pfa_conf_file
|
||||
fi
|
||||
done < $_backup_file
|
||||
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
_failed=true
|
||||
fi
|
||||
|
||||
if $_failed ; then
|
||||
echo_failed
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
#perl -i -n -p -e "s#^(\s*\\\$CONF\['setup_password'\]\s*=.*)#//!\1\n\\\$CONF['setup_password'] = '$_actual_password_hash';#" \
|
||||
# $pfa_conf_file > $log_file 2>&1
|
||||
#if [[ $? -eq 0 ]] ; then
|
||||
# echo_ok
|
||||
#else
|
||||
# echo_failed
|
||||
#fi
|
||||
|
||||
else
|
||||
echo_skipped
|
||||
fi
|
||||
@ -3360,6 +3432,11 @@ fi
|
||||
echo ""
|
||||
info "Browse to \033[1mhttp://${WEBSITE_NAME}/setup.php\033[m to create a 'setup password'\n$(cat <<EOF
|
||||
|
||||
\t \033[33mIn caes of updating postfix.admin brows this URL and \033[1mlogin with your
|
||||
\t setup_password\033[m\033[33m, because only after that the database '${POSTFIX_DB_NAME}'
|
||||
\t will be updated. If you don't know this password, create a new one. This is also
|
||||
\t done within this interface.
|
||||
|
||||
\t If this is a fresh new installation, you have also to ceate one (ore more)
|
||||
\t superadmin account(s).
|
||||
|
||||
@ -3383,6 +3460,14 @@ info "Browse to \033[1mhttp://${WEBSITE_NAME}/setup.php\033[m to create a 'setup
|
||||
EOF
|
||||
)"
|
||||
|
||||
if [[ -n "$_actual_password_hash" ]] ; then
|
||||
info "The Parameter \$CONF['setup_password'] was set as follows:\n$(cat <<EOF
|
||||
|
||||
\t \$CONF['setup_password'] = '${_actual_password_hash}';
|
||||
EOF
|
||||
)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
clean_up 0
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user