From fabd9fc11f3ad8d41307a7e7a1978c0c140fcb93 Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 29 Apr 2021 18:31:23 +0200 Subject: [PATCH] install_opendmarc.sh: some minor fixes. --- install_opendmarc.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/install_opendmarc.sh b/install_opendmarc.sh index 0446918..4280957 100755 --- a/install_opendmarc.sh +++ b/install_opendmarc.sh @@ -47,6 +47,7 @@ done postfix_needs_restart=false opendmarc_needs_restart=false +backup_date="$(date +%Y-%m-%d-%H%M)" log_file="$(mktemp)" # ------------- @@ -362,7 +363,6 @@ fi # - Edit /etc/postfix/main.cf and add a section to activate # - processing of e-mail through the opendmarc daemon: # - -backup_date="$(date +%Y-%m-%d-%H%M)" echononl " Backup existing postfix configuration (main.cf).." cp -a /etc/postfix/main.cf /etc/postfix/main.cf.$backup_date 2> $log_file if [[ $? -eq 0 ]] ; then @@ -374,7 +374,7 @@ fi echononl " Set Variable non_smtpd_milters at '/etc/postfix/main.cf'.." if $(grep -q -E "^\s*non_smtpd_milters\s*=\s*.*opendkim.sock" /etc/postfix/main.cf 2> /dev/null) ; then - if $(grep -q -E "^\s*non_smtpd_milters\s*=\s*.*${opendmarc_socket_file}" /etc/postfix/main.cf); then + if $(grep -q -E "^\s*non_smtpd_milters\s*=\s*.*$(basename "${opendmarc_socket_file}")" /etc/postfix/main.cf); then echo_skipped else perl -i -n -p -e "s&^\s*(non_smtpd_milters\s*=.*opendkim.sock)&\1,local:/$(basename "${opendmarc_socket_dir}")/$(basename "${opendmarc_socket_file}")&" \ @@ -409,7 +409,7 @@ fi # - -o smtpd_milters=local:/opendmarc/opendmarc.sock # - echononl " Backup file '/etc/postfix/master.cf'.." -cp -a /etc/postfix/master.cf /etc/postfix/master.cf.$backup_date 2> $log_file +cp -a /etc/postfix/master.cf /etc/postfix/master.cf.${backup_date} 2> $log_file if [[ $? -eq 0 ]] ; then echo_ok else @@ -503,6 +503,21 @@ else echo_skipped fi +echo "" +if [[ -f "/etc/postfix/master.cf.${backup_date}" ]] ; then + if $(diff "/etc/postfix/master.cf" "/etc/postfix/master.cf.${backup_date}"> /dev/null 2>&1) ; then + info "File \033[1m/etc/postfix/master.cf\033[m has not changed.\n\t Removing previos created backup.." + rm "/etc/postfix/master.cf.${backup_date}" + fi +fi +if [[ -f "/etc/postfix/main.cf.${backup_date}" ]] ; then + if $(diff "/etc/postfix/main.cf" "/etc/postfix/main.cf.${backup_date}"> /dev/null 2>&1) ; then + info "File \033[1m/etc/postfix/main.cf\033[m has not changed.\n\t Removing previos created backup.." + rm "/etc/postfix/main.cf.${backup_date}" + fi +fi + + echo "" rm -f "$log_file" exit 0