- Fix error on mysql credentials.

- Take passwordhash (CONFIG['setup_password']) from existing installation.
This commit is contained in:
Christoph 2017-10-08 19:24:16 +02:00
parent a5aa813af9
commit ae00962403

View File

@ -415,6 +415,13 @@ fi
_log_dir=${_src_base_dir}/log-postfixadmin-$_version
# - Determine major/minor version
# -
MAJOR_VERSION="$(echo $PF_ADMIN_VERSION | cut -d '.' -f1)"
MINOR_VERSION="$(echo $PF_ADMIN_VERSION | cut -d '.' -f2)"
echo -e "\n\n\t\033[37m\033[1mPre-installion tasks ..\033[m\n"
@ -426,8 +433,49 @@ echo -e "\n\n\t\033[37m\033[1mPre-installion tasks ..\033[m\n"
_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
if ! mysql $mysql_credential_args -N -s -e \
if ! mysql $MYSQL_CREDENTIALS -N -s -e \
"SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$POSTFIX_DB_NAME'" 2>> $log_file \
| grep $POSTFIX_DB_NAME >> $log_file 2>&1 ; then
database_exists=false
@ -449,17 +497,17 @@ if ! $database_exists ; then
echononl "\tCreate Postfix Database '$POSTFIX_DB_NAME'"
if [ "$POSTFIX_DB_TYPE" = "mysql" ]; then
echo -n " (MySQL).."
mysql $mysql_credential_args -N -s -e \
mysql $MYSQL_CREDENTIALS -N -s -e \
"CREATE DATABASE IF NOT EXISTS $POSTFIX_DB_NAME CHARACTER SET utf8 COLLATE utf8_general_ci" >> $log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
fi
mysql $mysql_credential_args -N -s -e \
mysql $MYSQL_CREDENTIALS -N -s -e \
"GRANT ALL ON $POSTFIX_DB_NAME.* TO '$POSTFIX_DB_USER'@'localhost' IDENTIFIED BY '$POSTFIX_DB_PASS'" >> $log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
fi
mysql $mysql_credential_args -N -s -e "FLUSH PRIVILEGES" >> $log_file 2>&1
mysql $MYSQL_CREDENTIALS -N -s -e "FLUSH PRIVILEGES" >> $log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
fi
@ -491,7 +539,7 @@ else
echononl "\tBackup Postfix Database '$POSTFIX_DB_NAME'"
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then
echo -n " (MySQL).."
mysqldump $mysql_credential_args --opt $POSTFIX_DB_NAME >> ${WEBSITE_BASEDIR}/${POSTFIX_DB_NAME}.${backup_date}.sql 2> $log_file
mysqldump $MYSQL_CREDENTIALS --opt $POSTFIX_DB_NAME >> ${WEBSITE_BASEDIR}/${POSTFIX_DB_NAME}.${backup_date}.sql 2> $log_file
if [[ $? -eq 0 ]]; then
echo_ok
else
@ -652,6 +700,7 @@ else
fi
echononl "\tCopy Postfix Admin Directory to web-directory"
cp -a ${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION} ${WEBSITE_BASEDIR}/
if [[ $? -eq 0 ]]; then
@ -1651,7 +1700,15 @@ fi
echo -e "\n\n\t\033[37m\033[1mConfigure Postfix Admin\033[m\n"
pfa_conf_file=${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/config.inc.php
if [[ $MAJOR_VERSION -eq 3 &&$MINOR_VERSION -gt 0 ]]; then
pfa_conf_file="${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/config.local.php"
cp -a "${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/config.inc.php" "$pfa_conf_file"
else
pfa_conf_file="${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/config.inc.php"
cp -a "$pfa_conf_file" "${pfa_conf_file}.ORIG"
fi
# - Use 'Re: $SUBJECT' as the default subject template for vacation
# - in postfixadmin
@ -1701,7 +1758,7 @@ echo ""
echononl "\tAdjust Postfix Admin's Configuration - Part 1"
_failed=false
> $log_file
perl -i.ORIG -n -p -e "s#^(\s*\\\$CONF\['default_language'\]\s*=.*)#//!\1\n\\\$CONF['default_language'] = 'de';#" \
perl -i -n -p -e "s#^(\s*\\\$CONF\['default_language'\]\s*=.*)#//!\1\n\\\$CONF['default_language'] = 'de';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_type'\]\s*=.*)#//!\1\n\\\$CONF['database_type'] = '$POSTFIX_DB_TYPE';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
@ -1985,6 +2042,25 @@ else
echo_failed
fi
# - Take passwordhash from previosly installation
# -
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
fi
else
echo_skipped
fi
echo ""
# - AFTER DELETION MAILBOX
# -
# - activate script for moving a mailbox from the mailboxdirectory