Priprema za bullseye, ne briĊĦemo se iz prerm
[amavisd-cn.git] / src / sendmail.sh
1 update_sendmail_mc() {
2   cp-update -c dnl $PKG $sendmail_mc <<-END
3         define(\`MILTER', 1)dnl
4         INPUT_MAIL_FILTER(\`amavis-milter', \`S=local:$AHOME/amavisd-new-milter.sock, F=T, T=S:10m;R:10m;E:10m')dnl
5         dnl Reducing number of messages in syslog for milter
6         define(\`confMILTER_LOG_LEVEL', \`4')dnl
7         END
8         #' XXX stupid joe syntax highlighing
9 }
10
11 # sendmail chunk moved out from postinst in 20030616p10-10
12 update_sendmail() {
13   if [ -f $sendmail_mc ]; then
14     # creating backup files, just in case
15     cp -p $sendmail_mc $sendmail_mc.$PKG
16     mcbak=1
17     cp -p $sendmail_cf $sendmail_cf.$PKG
18     cfbak=1
19
20     if ! egrep -q '^INPUT_MAIL_FILTER.*amavis-milter' $sendmail_mc; then
21       update_sendmail_mc
22       makecf=1
23     elif grep -q 'Begin update by CARNet package amavisd-cn' $sendmail_mc; then
24       update_sendmail_mc
25       makecf=1
26     elif grep -q 'local:/var/run/amavis/amavis-milter.sock' $sendmail_mc; then
27       echo "CN: You seem to have a custom configuration for milter in"
28       echo "    ${sendmail_mc}. I'll try to fix it but I don't promise anything."
29       echo "    Things might break or behave unexpectedly."
30       cp_echo -mailonly "CN: Tried to fix custom milter config in ${sendmail_mc}."
31       cp_check_and_sed "/var/run/amavis/amavis-milter.sock" \
32         "s,/var/run/amavis/amavis-milter.sock,$AHOME/amavisd-new-milter.sock," \
33         $sendmail_mc
34       makecf=1
35     fi
36   fi # sendmail.mc
37
38   # submit.mc: use /etc/mail/trusted-users, and add user amavis
39   # to get rid of Authentication-Warnings
40   if [ -f "$submit_mc" ]; then
41     cp -p $submit_mc $submit_mc.$PKG
42     subak=1
43     if ! grep -q use_ct_file $submit_mc; then
44       cp-update -R --insert-before '^FEATURE\(`?msp' -c dnl $PKG $submit_mc <<-END
45         FEATURE(\`use_ct_file')dnl
46         END
47       grep -q '^amavis$' $ct_file || echo amavis >> $ct_file
48       echo "CN: Added FEATURE(use_ct_file) to $submit_mc."
49     fi
50   fi # submit.mc
51
52   if [ "$makecf" ]; then
53     make -C /etc/mail >/dev/null 2>&1
54     restart_mta=1
55   else
56     [ "$mcbak" ] && rm -f $sendmail_mc.$PKG
57     [ "$cfbak" ] && rm -f $sendmail_cf.$PKG
58     [ "$subak" ] && rm -f $submit_mc.$PKG
59   fi
60 }
61
62 conf_sendmailize() {
63   local tmp oldpwd
64   tmp=`basename $ACONF.dpkg-tmp.$$`
65   noisy_backup $ACONF
66   # are we configured for milter?
67   if ! egrep -q '^[[:blank:]]*\$notify_method = .*argv=/usr/sbin/sendmail -Ac.*-odd' $ACONF; then
68     # first try to apply patch
69     if catpatch $ACONF | patch -Rsfp0 --dry-run 2>&- ; then
70       oldpwd=`pwd`
71       cd `dirname $ACONF`
72       cp -p $ACONF $tmp
73       catpatch $tmp | patch -Rfp0
74       cp_mv $tmp $ACONF
75       cd $oldpwd
76       cp_echo -mailonly "CN: $ACONF postfix patch removed."
77     # then try to update exact options without disturbing anything else
78     elif uncommented_in_paragraph '^[[:blank:]]*#.*POSTFIX' \
79       '^$forward_method = '\''smtp:127.0.0.1:10025'\'';[[:blank:]]*(#|$)' \
80       '^\$notify_method = \$forward_method;[[:blank:]]*(#|$)' \
81       -f $ACONF &&
82        commented_in_paragraph '^[[:blank:]]*#.*MILTER' \
83       '$forward_method = undef;[[:blank:]]*(#|$)' \
84       '$notify_method = .*argv=/usr/sbin/sendmail -Ac.*-odd' \
85       -f $ACONF; then
86       cp $ACONF $tmp
87       comment_in_paragraph '^[[:blank:]]*#.*POSTFIX' \
88         '^$forward_method = '\''smtp:127.0.0.1:10025'\'';[[:blank:]]*(#|$)' \
89         '^\$notify_method = \$forward_method;[[:blank:]]*(#|$)' \
90         -f $tmp
91       uncomment_in_paragraph '^[[:blank:]]*#.*MILTER' \
92         '$forward_method = undef;[[:blank:]]*(#|$)' \
93         '$notify_method = .*argv=/usr/sbin/sendmail -Ac.*-odd' \
94         -f $tmp
95       cp_mv $tmp $ACONF
96       cp_echo "CN: $ACONF updated for ${mta}."
97     # or just overwrite
98     else
99       conf_from_template
100       cp_echo "CN: Config generated from ${ACONFTMPL}."
101     fi
102     restart_daemon=1
103     changed_config=1
104   fi
105 }