install_postfixadmin.sh: some changes concerning mysql credentials.

This commit is contained in:
Christoph 2023-03-05 14:33:53 +01:00
parent 7e79d01ca3
commit abd96fe1bb

View File

@ -224,8 +224,14 @@ DEFAULT_POSTFIX_DB_HOST_PGSQL="/run/postgresql"
DEFAULT_POSTFIX_DB_HOST_MYSQL="unix:/tmp/mysql.sock"
DEFAULT_POSTFIX_DB_NAME="postfix"
DEFAULT_POSTFIX_DB_USER="postfix"
DEFAULT_DEBIAN_MYSQL_CREDENTIALS="--defaults-file=/etc/mysql/debian.cnf"
DEFAULT_MYSQL_CREDENTIALS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
if [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
DEFAULT_MYSQL_CREDENTIALS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
DEFAULT_MYSQL_CREDENTIALS="--defaults-file=/etc/mysql/debian.cnf"
else
DEFAULT_MYSQL_CREDENTIALS=""
fi
DEFAULT_DEBIAN_MYSQL_CREDENTIALS="/etc/mysql/debian.cnf"
DEFAULT_DOVEADM_PW="/usr/local/dovecot/bin/doveadm pw"
DEFAULT_DELETED_MAILBOX_DIR="/var/deleted-maildirs"
@ -538,14 +544,29 @@ else
echo_skipped
fi
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]] ; then
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
echononl "\tCheck if database '$POSTFIX_DB_NAME' already exists.."
_db_response="$(mysql $MYSQL_CREDENTIALS -N -s -e \
"SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$POSTFIX_DB_NAME'" 2>> $log_file)"
if [[ $? -ne 0 ]] ; then
echo_failed
echo ""
echo -e "\tMaybw your MySQL credentials are wrong. the credentials given were:"
echo ""
echo -e "\t MYSQL_CREDENTIALS: $MYSQL_CREDENTIALS"
echo ""
error "$(cat $log_file)"
fatal "Checking if database exists failed!"
else
echo_ok
fi
if [[ "${_db_response}" = "${POSTFIX_DB_NAME}" ]]; then
database_exists=true
else
database_exists=false
fi
elif [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then
count=$(su - postgres -c "psql -q -A -t -l" | grep -c -e "^$POSTFIX_DB_NAME")
@ -602,23 +623,41 @@ if ! $database_exists ; then
fi
else
echononl "\tBackup Postfix Database '$POSTFIX_DB_NAME'"
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
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
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
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
if [[ ! -d "${WEBSITE_BASEDIR}" ]] ; then
echo_skipped
else
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
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do
echononl "\033[33mWrong entry!\033[m [\033[1myes/no\033[m]: "
read OK
done
[[ "${OK,,}" = "yes" ]] || fatal "Canceled by user input."
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
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
echo ""
echononl "Continue with this parameters? [\033[1myes/no\033[m]: "
read OK
while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do
echononl "\033[33mWrong entry!\033[m [\033[1myes/no\033[m]: "
read OK
done
[[ "${OK,,}" = "yes" ]] || fatal "Canceled by user input."
fi
fi
fi
fi