c3e9da1944596b2c820963331abdabb70ff65724
[amavisd-cn.git] / debian / prerm
1 #!/bin/sh
2
3 set -e
4 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -x
5
6 . /usr/share/carnet-tools/functions.sh
7
8 PKG=amavisd-cn
9 MAILDIR=/etc/mail
10 ALIASES=/etc/aliases
11 sendmail_cf=$MAILDIR/sendmail.cf
12 sendmail_mc=$MAILDIR/sendmail.mc
13 submit_mc=$MAILDIR/submit.mc
14 ct_file=$MAILDIR/trusted-users
15 main_cf=/etc/postfix/main.cf
16 master_cf=/etc/postfix/master.cf
17
18 del_postconf() {
19   egrep -v "^$1[[:blank:]]*=[[:blank:]]*" $main_cf > $main_cf.dpkg-tmp.$$
20   cp_mv $main_cf.dpkg-tmp.$$ $main_cf
21 }
22
23 if [ "$1" = remove ]; then
24   # sendmail?
25   if grep -q $PKG $sendmail_mc $submit_mc 2>&- || \
26      grep -q '^amavis$' $ct_file 2>&- ; then
27     echo "Removing sendmail configuration for ${PKG}... "
28     cp-update -r -c dnl $PKG $sendmail_mc >&-
29     cp-update -r -c dnl $PKG $submit_mc >&-
30     grep -v '^amavis$' $ct_file > ${ct_file}.dpkg-tmp.$$ || true
31     cp_mv ${ct_file}.dpkg-tmp.$$ $ct_file
32     make -C /etc/mail 2>&1 | grep -v 'issue .*/etc/init.d/sendmail reload' 1>&2 || true
33     echo "Removed sendmail configuration for ${PKG}."
34     if pgrep -u root -f 'sendmail: MTA: accepting connections' >&- ; then
35       /etc/init.d/sendmail reload
36       if ! pgrep -u root -f 'sendmail: MTA: accepting connections' >&- ; then
37         echo 'CN: Something bad happened to sendmail on reload!' 1>&2
38         exit 1
39       fi
40       # Everything went well, apparently.  Remove old backup files.
41       rm -f $sendmail_cf.$PKG
42       rm -f $sendmail_mc.$PKG
43       rm -f $submit_mc.$PKG
44     fi
45   fi
46   # postfix?
47   if grep -q $PKG $master_cf; then
48     cp-update -r $PKG $master_cf >&-
49     del_postconf content_filter
50     echo "Removed postfix configuration for ${PKG}."
51     if pgrep -u root -f /usr/lib/postfix/master >&- && \
52        [ -x /etc/init.d/postfix ] >&- ; then
53       /etc/init.d/postfix restart
54     fi
55   fi
56   cp-update -r $PKG $ALIASES >&-
57   newaliases
58 fi