r1: [svn-inject] Installing original source of amavisd-cn
[amavisd-cn.git] / src / postfix.sh
1 update_postfix() {
2   # set up master.cf
3   if [ -f /etc/postfix/master.cf ] && \
4      ! grep -q smtp-amavis /etc/postfix/master.cf; then
5     cp-update $PKG /etc/postfix/master.cf <<-EOF
6         smtp-amavis unix -  - n - 2  smtp
7             -o smtp_data_done_timeout=1200
8             -o disable_dns_lookups=yes
9             -o smtp_line_length_limit=0
10             -o notify_classes=protocol,resource,software
11             -o max_use=10
12         
13         127.0.0.1:10025 inet n  - n - -  smtpd
14             -o content_filter=
15             -o local_recipient_maps=
16             -o smtpd_helo_restrictions=
17             -o smtpd_client_restrictions=
18             -o smtpd_sender_restrictions=
19             -o smtpd_recipient_restrictions=permit_mynetworks,reject
20             -o mynetworks=127.0.0.0/8
21             -o strict_rfc821_envelopes=yes
22         EOF
23   fi
24
25   # main.cf
26   postconf -e content_filter="smtp-amavis:[127.0.0.1]:10024"
27 }
28
29 conf_postfixize() {
30   local tmp
31   tmp=`basename $ACONF.dpkg-tmp.$$`
32   noisy_backup $ACONF
33   # detect non-postfix config
34   # XXX add $inet_socket_port & $inet_socket_bind
35   if egrep -q '^[[:blank:]]*\$notify_method = .*argv=/usr/sbin/sendmail -Ac.*-odd' $ACONF || \
36      ! ( egrep -q '^\$forward_method = '\''smtp:127.0.0.1:10025'\'';[[:blank:]]*(#|$)' $ACONF && \
37          egrep -q '^\$notify_method = \$forward_method;[[:blank:]]*(#|$)' $ACONF && \
38          egrep -q '^\$inet_socket_port.*10024' $ACONF && \
39          egrep -q '^\$inet_socket_bind' $ACONF ); then
40     if catpatch $ACONF | patch -sfp0 --dry-run >&- 2>&-; then
41       oldpwd=`pwd`
42       cd `dirname $ACONF`
43       cp -p $ACONF $tmp
44       catpatch $tmp | patch -fp0
45       cp_mv $tmp $ACONF
46       cd $oldpwd
47       cp_echo -mailonly "CN: $ACONF patched for postfix."
48     # then try to update exact options without disturbing anything else
49     elif commented_in_paragraph '^[[:blank:]]*#.*POSTFIX' \
50       '^$forward_method = '\''smtp:127.0.0.1:10025'\'';[[:blank:]]*(#|$)' \
51       '^\$notify_method = \$forward_method;[[:blank:]]*(#|$)' \
52       -f $ACONF &&
53        uncommented_in_paragraph '^[[:blank:]]*#.*MILTER' \
54       '$forward_method = undef;[[:blank:]]*(#|$)' \
55       '$notify_method = .*argv=/usr/sbin/sendmail -Ac.*-odd' \
56       -f $ACONF; then
57       cp $ACONF $tmp
58       uncomment_in_paragraph '^[[:blank:]]*#.*POSTFIX' \
59         '^$forward_method = '\''smtp:127.0.0.1:10025'\'';[[:blank:]]*(#|$)' \
60         '^\$notify_method = \$forward_method;[[:blank:]]*(#|$)' \
61         -f $tmp
62       comment_in_paragraph '^[[:blank:]]*#.*MILTER' \
63         '$forward_method = undef;[[:blank:]]*(#|$)' \
64         '$notify_method = .*argv=/usr/sbin/sendmail -Ac.*-odd' \
65         -f $tmp
66       cp_mv $tmp $ACONF
67       cp_echo "CN: $ACONF updated for ${mta}."
68     # or just use the template
69     else
70       conf_from_template
71       cp_echo "CN: Config generated from ${ACONFTMPL}."
72     fi
73     restart_daemon=1
74     changed_config=1
75   fi
76   restart_mta=1
77 }