From 8eee0f3f3e1ae2b1fc85bf00c742a6e5f5869d71 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 30 Oct 2017 17:30:56 +0100 Subject: [PATCH] Some changes on script output. --- convert_dovecot_pfa_password.sh | 100 ++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 30 deletions(-) diff --git a/convert_dovecot_pfa_password.sh b/convert_dovecot_pfa_password.sh index b815c66..4c0cb62 100755 --- a/convert_dovecot_pfa_password.sh +++ b/convert_dovecot_pfa_password.sh @@ -261,8 +261,10 @@ if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]] ; then su - postgres -c "pg_dump -c $POSTFIX_DB_NAME" > ${LOG_DIR}/dump-${POSTFIX_DB_NAME}.${date}.sql 2> $log_file_backup_database_error if [[ $? -eq 0 ]]; then echo_ok + echo "[ ok ]: Backup Postfix Database to ${LOG_DIR}/dump-${POSTFIX_DB_NAME}.${date}.sql." >> $log_file else echo_failed + echo "[failed ]: Backup Postfix Database failed ;" >> $log_file fatal "$(cat "$log_file_backup_database_error")" fi @@ -271,8 +273,10 @@ elif [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then mysqldump $MYSQL_CREDENTIALS --opt "$POSTFIX_DB_NAME" > ${LOG_DIR}/dump-${POSTFIX_DB_NAME}.${date}.sql 2> $log_file_backup_database_error if [[ $? -eq 0 ]]; then echo_ok + echo "[ ok ]: Backup Postfix Database to ${LOG_DIR}/dump-${POSTFIX_DB_NAME}.${date}.sql." >> $log_file else echo_failed + echo "[failed ]: Backup Postfix Database failed ;" >> $log_file fatal "$(cat "$log_file_backup_database_error")" fi else @@ -336,19 +340,33 @@ fi echo -e "\n \033[1mAdjust configuration of Roundcube's password plugin\033[m\n" -echo "" >> $log_file -echo "" >> $log_file -echo "# ---" >> $log_file -echo "# - Adjust configuration of roundcube password plugin" >> $log_file -echo "# -" >> $log_file -echo "# - \$config['password_algorithm'] = 'dovecot';" >> $log_file -echo "# - \$config['password_algorithm_prefix'] = '{${DOVECOT_ENC_METHOD_NEW}}';" >> $log_file -echo "# - \$config['password_dovecotpw_method'] = '${DOVECOT_ENC_METHOD_NEW}';" >> $log_file -echo "# - \$config['password_dovecotpw'] = '/usr/local/dovecot/bin/doveadm pw';" >> $log_file -echo "# - \$config['password_dovecotpw_with_method'] = true;" >> $log_file -echo "# -" >> $log_file -echo "# ---" >> $log_file -echo "" >> $log_file +_failed=false +_config_file="${DOCROOT_ROUNDCUBE}/plugins/password/config.inc.php" + +echononl " Backup configuration file '$(basename "$_config_file")' from Roundcube's password plugin" +if [[ -f "$_config_file" ]]; then + + echo "" >> $log_file + echo "" >> $log_file + echo "# ---" >> $log_file + echo "# - Backup configuration file '$(basename "$_config_file")' Roundcube's password plugin" >> $log_file + echo "# ---" >> $log_file + echo "" >> $log_file + + cp -a "$_config_file" "${_config_file}.BAK.${date}" > $err_msg 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + echo "[ ok ]: File '${_config_file}.BAK.${date}' saved." >> $log_file + else + echo_failed + echo "[ failed ]: Backup configuration file '$(basename "$_config_file")'!" >> $log_file + error "$(cat "$err_msg")" + fi +else + echo_failed + fatal "Configuration file for Postfixadmin not found!" +fi + # - Adjust configuration of roundcube password plugin # - @@ -358,26 +376,23 @@ echo "" >> $log_file # - $config['password_dovecotpw_method'] = $DOVECOT_ENC_METHOD_NEW; # - $config['password_dovecotpw_with_method'] = true; # - -_failed=false -_config_file="${DOCROOT_ROUNDCUBE}/plugins/password/config.inc.php" - -echononl " Backup configuration file '$(basename "$_config_file")' from Roundcube's password plugin" -if [[ -f "$_config_file" ]]; then - cp -a "$_config_file" "${_config_file}.BAK.${date}" > $err_msg 2>&1 - if [[ $? -eq 0 ]] ; then - echo_ok - else - echo_failed - error "$(cat "$err_msg")" - fi -else - echo_failed - fatal "Configuration file for Postfixadmin not found!" -fi - echononl " Adjust configuration of roundcube password plugin.." if [[ -f "${_config_file}" ]]; then + echo "" >> $log_file + echo "" >> $log_file + echo "# ---" >> $log_file + echo "# - Adjust configuration of roundcube password plugin" >> $log_file + echo "# -" >> $log_file + echo "# - \$config['password_algorithm'] = 'dovecot';" >> $log_file + echo "# - \$config['password_algorithm_prefix'] = '{${DOVECOT_ENC_METHOD_NEW}}';" >> $log_file + echo "# - \$config['password_dovecotpw_method'] = '${DOVECOT_ENC_METHOD_NEW}';" >> $log_file + echo "# - \$config['password_dovecotpw'] = '/usr/local/dovecot/bin/doveadm pw';" >> $log_file + echo "# - \$config['password_dovecotpw_with_method'] = true;" >> $log_file + echo "# -" >> $log_file + echo "# ---" >> $log_file + echo "" >> $log_file + _key="password_algorithm" _val="'dovecot'" if ! grep -q -E "^\s*\\\$config\['$_key'\]\s*=\s*$_val" "${_config_file}" 2> /dev/null ; then @@ -385,6 +400,9 @@ if [[ -f "${_config_file}" ]]; then ${_config_file} >> $log_file 2>&1 if [[ $? -ne 0 ]] ; then _failed=true + echo "[failed ]: Setting \$config['$_key'] = $_val ;" >> $log_file + else + echo "[ ok ]: Setting \$config['$_key'] = $_val ;" >> $log_file fi fi @@ -395,6 +413,9 @@ if [[ -f "${_config_file}" ]]; then ${_config_file} >> $log_file 2>&1 if [[ $? -ne 0 ]] ; then _failed=true + echo "[failed ]: Setting \$config['$_key'] = $_val ;" >> $log_file + else + echo "[ ok ]: Setting \$config['$_key'] = $_val ;" >> $log_file fi fi @@ -405,6 +426,9 @@ if [[ -f "${_config_file}" ]]; then ${_config_file} >> $log_file 2>&1 if [[ $? -ne 0 ]] ; then _failed=true + echo "[failed ]: Setting \$config['$_key'] = $_val ;" >> $log_file + else + echo "[ ok ]: Setting \$config['$_key'] = $_val ;" >> $log_file fi fi @@ -415,6 +439,9 @@ if [[ -f "${_config_file}" ]]; then ${_config_file} >> $log_file 2>&1 if [[ $? -ne 0 ]] ; then _failed=true + echo "[failed ]: Setting \$config['$_key'] = $_val ;" >> $log_file + else + echo "[ ok ]: Setting \$config['$_key'] = $_val ;" >> $log_file fi fi @@ -425,6 +452,9 @@ if [[ -f "${_config_file}" ]]; then ${_config_file} >> $log_file 2>&1 if [[ $? -ne 0 ]] ; then _failed=true + echo "[failed ]: Setting \$config['$_key'] = $_val ;" >> $log_file + else + echo "[ ok ]: Setting \$config['$_key'] = $_val ;" >> $log_file fi fi @@ -443,6 +473,7 @@ if [[ -f "${_config_file}.BAK.${date}" ]]; then if diff "${_config_file}" "${_config_file}.BAK.${date}" > /dev/null 2>&1 ; then info "${_config_file} has not changed.\n Removing previos created backup.." rm "${_config_file}.BAK.${date}" + echo "[ ok ]: ${_config_file} has not changed. Removing previos created backup.." >> $log_file fi fi @@ -534,8 +565,10 @@ if [[ -f "$_config_file" ]]; then cp -a "$_config_file" "${_config_file}.BAK.${date}" > $err_msg 2>&1 if [[ $? -eq 0 ]] ; then echo_ok + echo "[ ok ]: File '${_config_file}.BAK.${date}' saved." >> $log_file else echo_failed + echo "[ failed ]: Backup configuration file '$(basename "$_config_file")'!" >> $log_file error "$(cat "$err_msg")" fi else @@ -553,6 +586,9 @@ if [[ -f "$_config_file" ]]; then ${_config_file} >> $log_file 2>&1 if [[ $? -ne 0 ]] ; then _failed=true + echo "[failed ]: Setting \$CONF['$_key'] = $_val ;" >> $log_file + else + echo "[ ok ]: Setting \$CONF['$_key'] = $_val ;" >> $log_file fi fi @@ -564,6 +600,9 @@ if [[ -f "$_config_file" ]]; then "$_config_file" >> $log_file 2>&1 if [[ $? -ne 0 ]] ; then _failed=true + echo "[failed ]: Setting \$CONF['$_key'] = $_val ;" >> $log_file + else + echo "[ ok ]: Setting \$CONF['$_key'] = $_val ;" >> $log_file fi fi else @@ -596,6 +635,7 @@ if [[ -f "${_config_file}.BAK.${date}" ]]; then if diff "${_config_file}" "${_config_file}.BAK.${date}" > /dev/null 2>&1 ; then info "${_config_file} has not changed.\n Removing previos created backup.." rm "${_config_file}.BAK.${date}" + echo "[ ok ]: ${_config_file} has not changed. Removing previos created backup.." >> $log_file fi fi