diff options
author | Jonas Smedegaard <dr@jones.dk> | 2014-07-06 15:05:18 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2014-07-06 15:05:18 +0200 |
commit | ab651d3cbd9909e10dd2ef97d364314b81dbcd14 (patch) | |
tree | cb7c638a5a9818f181b91c97ac87aadc14d30b71 /postfix | |
parent | 2527b269308e3dedc033550ef4de8d377c3ef721 (diff) |
Fix add-or-replace (not only add if missing) master.cf lines.
Diffstat (limited to 'postfix')
-rw-r--r-- | postfix/TODO | 1 | ||||
-rwxr-xr-x | postfix/postfix.sh | 35 |
2 files changed, 21 insertions, 15 deletions
diff --git a/postfix/TODO b/postfix/TODO deleted file mode 100644 index 08b6e2d..0000000 --- a/postfix/TODO +++ /dev/null @@ -1 +0,0 @@ - * Always replace master.cf lines (currently they are only added if not alreeady exist - later improvements are ignored) diff --git a/postfix/postfix.sh b/postfix/postfix.sh index 9cceaf3..edf5d08 100755 --- a/postfix/postfix.sh +++ b/postfix/postfix.sh @@ -215,6 +215,18 @@ getlinesfromfile() { catfirstfile "$param" | sed 's/#.*//' | tr '\n' ',' | sed -e 's/^[, ]*//;s/[, ]\+/,/g' -e 's/\^/ /g' -e "s/,\$//$replacements" } +addoroverwritewithindents() { + set -e + file="$1" + export token="$2" + # provide replacement as STDIN + perl -0777 -pi \ + -E 'BEGIN{ $s=<STDIN>; chomp $s }'\ + -E 's/$ENV{"token"}.*(?:\n\h.*)+\n/$s/m and $seen=1;'\ + -E 'END{ unless ($seen) { print $s } }'\ + "$file" +} + postmapfiles= tempdir="$(mktemp -td postfix.XXXXXX)" @@ -291,8 +303,9 @@ if [ -n "$sasl_cyrus" ]; then -e "s/^#\?\(\(smtps\|587\)$sp\+inet\($sp\+[n-]\)\{2\}$sp\+\)[n-]/\1n/" \ -e "s/^#\(tlsmgr$sp\)/\1/" \ "$tempdir/master.cf" - cat $tempdir/master.cf | egrep -q "^tlsmgr$sp" || \ - echo 'tlsmgr unix - - - 300 1 tlsmgr' >> $tempdir/master.cf + addoroverwritewithindents $tempdir/master.cf '^tlsmgr\h' << EOF +tlsmgr unix - - - 300 1 tlsmgr +EOF fi case "$sasl_main_type" in '') ;; @@ -352,8 +365,7 @@ fi if [ -n "$amavis" ]; then $postconf -c "$tempdir" -e 'max_use = 10' # Avoid too much reuse amavis_maxproc=$(getperlvarfromfile max_servers "$default_amavis_maxproc" amavisd.conf.addon amavis) - cat $tempdir/master.cf | egrep -q "^smtp-amavis$sp" || \ - cat >> $tempdir/master.cf << EOF + addoroverwritewithindents $tempdir/master.cf '^smtp-amavis\h' << EOF smtp-amavis unix - - n - $amavis_maxproc smtp -o smtp_data_done_timeout=1200s -o smtp_never_send_ehlo=yes @@ -361,8 +373,7 @@ smtp-amavis unix - - n - $amavis_maxproc smtp -o disable_dns_lookups=yes -o max_use=20 EOF - cat $tempdir/master.cf | egrep -q "^127.0.0.1:10025$sp" || \ - cat >> $tempdir/master.cf << EOF + addoroverwritewithindents $tempdir/master.cf '^127.0.0.1:10025\h' << EOF 127.0.0.1:10025 inet n - n - - smtpd -o content_filter= -o local_recipient_maps= @@ -382,8 +393,7 @@ EOF if [ -n "$dkimproxy" ]; then $postconf -c "$tempdir" -e 'content_filter = smtp-amavis:[127.0.0.1]:10028' # FIXME: needs multiline replacementroutine (using perl?) -# cat $tempdir/master.cf | egrep -q "^submission$sp" || \ -# cat >> $tempdir/master.cf << EOF +# addoroverwritewithindents $tempdir/master.cf '^submission\h' << EOF #submission inet n - n - - smtpd # -o smtpd_etrn_restrictions=reject # -o smtpd_enforce_tls=yes @@ -392,19 +402,16 @@ EOF # -o receive_override_options=no_address_mappings # -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject #EOF -# cat $tempdir/master.cf | egrep -q "^pickup$sp" || \ -# cat >> $tempdir/master.cf << EOF +# addoroverwritewithindents $tempdir/master.cf '^pickup\h' << EOF #pickup fifo n - - 60 1 pickup # -o content_filter=dkimsign:127.0.0.1:10028 #EOF - cat $tempdir/master.cf | egrep -q "^dkimsign$sp" || \ - cat >> $tempdir/master.cf << EOF + addoroverwritewithindents $tempdir/master.cf '^dkimsign\h' << EOF dkimsign unix - - n - $dkimproxy_maxproc_out smtp -o smtp_send_xforward_command=yes -o smtp_discard_ehlo_keywords=8bitmime,starttls EOF - cat $tempdir/master.cf | egrep -q "^127\.0\.0\.1:10029$sp" || \ - cat >> $tempdir/master.cf << EOF + addoroverwritewithindents $tempdir/master.cf '^127\.0\.0\.1:10029\h' << EOF 127.0.0.1:10029 inet n - n - - smtpd -o content_filter= -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks |