b1516e825d59389be06cc36df84db15d85452412
[amavisd-cn.git] / debian / postinst
1 #!/bin/sh
2 # last update: zoran.dzelajlija@carnet.hr  Fri, 19 Oct 2007 00:34:32 +0200
3
4 set -e
5
6 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
7
8 case "$1" in
9   configure)
10     # continue below
11   ;;
12
13   abort-upgrade|abort-remove|abort-deconfigure)
14     exit 0
15   ;;
16
17   *)
18     echo "postinst called with unknown argument \`$1'" >&2
19     exit 0
20   ;;
21 esac
22
23 PATH=/bin:/usr/bin:/sbin:/usr/sbin
24 export PATH
25
26 . /usr/share/amavisd-cn/version.sh
27 . /usr/share/carnet-tools/functions.sh
28 . /usr/share/amavisd-cn/variables.sh
29 . /usr/share/amavisd-cn/functions.sh
30
31 # Place configuration tweaks done on upgrades into this function
32 update_conf() {
33   [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
34   # placeholder.
35   # remember to set changed_config=1 and restart_daemon=1 if necessary
36   #:
37   if dpkg --compare-versions "$1" lt 3:2.4.2-3; then
38     conf_from_template
39   fi
40 }
41
42 mta=postfix
43 . /usr/share/amavisd-cn/postfix.sh
44
45 # $domain will be equal to $host if nothing better can be found
46 cp_get_mx_domain
47 domain=$RET
48
49 update_postfix
50
51 # amavisd.conf
52 if [ -f "$ACONFOLD" ]; then
53   cp_echo "CN: Amavisd configuration is now in $ACONF."
54   noisy_backup "$ACONFOLD"
55   rm -f "$ACONFOLD"
56   cp_echo ""
57   cp_echo "CN: Please read /usr/share/doc/amavisd-cn/README.CARNet."
58 elif [ -f "$ACONFOLD.disabled" ]; then
59   noisy_backup "$ACONFOLD.disabled" "$(basename $ACONFOLD)"
60   rm -f "$ACONFOLD.disabled"
61   cp_echo "CN: Please read /usr/share/doc/amavisd-cn/README.CARNet."
62 fi
63
64 if [ -f $ACONF ]; then
65   # add other fixups to function update_conf(), way above
66   update_conf $*
67 fi
68 # nonexistent or empty config
69 if [ ! -f $ACONF -o ! -s $ACONF ]; then
70   # Create fresh config from template
71   conf_from_template
72 fi
73
74 # check for SAVI:
75 # if not there, comment it out, if there, uncomment and restart
76 if ! dpkg -l libsavi-perl 2> /dev/null | egrep -q '^.i' || ! [ -f /usr/lib/libsavi.so ]; then
77   if cp_check_and_sed "^\['Sophos SAVI'" \
78      "s/^\(\['Sophos SAVI', ..sophos_savi \]\)/#\1/" $ACONF; then
79     cp_echo "CN: Disabled SAVI::Perl usage in ${ACONF}."
80     cp_echo "    To enable it, run sophos-sweep-update, uncomment and restart amavis."
81   fi
82 else
83   if cp_check_and_sed "^#\['Sophos SAVI'" \
84      "s/^#\(\['Sophos SAVI', ..sophos_savi \]\)/\1/" $ACONF; then
85     cp_echo "CN: Enabled SAVI::Perl usage in ${ACONF}."
86     restart_daemon=1
87   fi
88 fi
89
90 check_and_add_alias virusalert root
91 check_and_add_alias spamalert root
92
93 if [ ! -f $AHOME/.spamassassin/user_prefs ] ; then
94   [ -d $AHOME/.spamassassin ] || mkdir -p $AHOME/.spamassassin
95   cat > $AHOME/.spamassassin/user_prefs <<-EEND
96         bayes_path              $AHOME/.spamassassin/bayes
97         bayes_auto_expire       0
98         auto_whitelist_path     $AHOME/.spamassassin/auto-whitelist
99         EEND
100   chown_ahome=1
101 fi
102
103 if [ ! -f $AHOME/.spamassassin/auto-whitelist ] ; then
104   touch $AHOME/.spamassassin/auto-whitelist
105   chown_ahome=1
106 fi
107
108 # No sysvinit order fixes
109 :
110
111 # Cleanup and finalization
112 if dpkg --compare-versions "$2" lt 2:20030616p10-4; then
113   update-rc.d -f amavisd remove > /dev/null
114   restart_daemon=1
115   chown_ahome=1
116   # a complicated way to say chmod 750
117   dpkg-statoverride --remove $AHOME > /dev/null || true
118   dpkg-statoverride --update --add amavis amavis 750 $AHOME
119 fi
120
121 if [ -n "$chown_ahome" ]; then
122   # might be slow
123   echo -n "CN: Fixing ownership in /var/*/amavis... "
124   chown -R amavis:amavis $AHOME /var/run/amavis || true
125   echo "done."
126   cp_echo -mailonly "CN: Fixed ownerships in /var/*/amavis."
127 fi
128
129 # kill naughty pyzor descendants -- XXX needed for 2.4 or not?
130 if dpkg --compare-versions "$2" lt 2:20030616p10-7 && \
131     pgrep -u amavis -f '/usr/bin/pyzor check' > /dev/null; then
132   /etc/init.d/amavisd-cn stop
133   pkill -9 -u amavis -f '/usr/bin/pyzor check' > /dev/null || true
134   /etc/init.d/amavisd-cn start
135   restart_daemon=
136   restart_mta=
137 fi
138
139 # START AMAVISD
140 # about a half of amavisd-cn script is here
141 if [ "$restart_daemon" -a -x /etc/init.d/amavis.amavisd-new ]; then
142   /etc/init.d/amavis.amavisd-new restart
143 fi
144 # always check that the daemons are running
145 if ! wait_for_fds amavis; then
146   /etc/init.d/amavis.amavisd-new start
147   wait_for_fds amavis
148 fi
149 if [ "$restart_mta" ]; then
150   /etc/init.d/$mta restart
151 fi
152
153 # this needs to be updated when $CRONTAB file changes
154 if dpkg --compare-versions "$2" lt "2:20030616p10-4"; then
155   cp_echo ""
156   cp_echo "CN: Deleting temp files older than 1 day every day at 01:35 AM"
157   cp_echo "CN: Deleting spam-mail  older than 7 days every day at 03:15 AM"
158   cp_echo "CN: Deleting virus-mail older than 7 days every day at 04:25 AM"
159   cp_echo "    (can be changed in $CRONTAB)"
160 fi
161 # This script is, hopefully, not needed any more.  Hide it.
162 ## display this message just once... maybe use debconf instead
163 #if dpkg --compare-versions "$2" lt "2:20030616p10-4"; then
164 #  cp_echo ""
165 #  cp_echo "CN: To stop, start or restart all of the clamav+amavis+mta components,"
166 #  cp_echo "CN: use the /etc/init.d/amavisd-cn script."
167 #fi
168 if [ "$failed" ]; then
169   cp_echo ""
170   cp_echo "CN: Services $failed failed to restart!"
171   cp_echo "CN: Please check and start manually if needed."
172 fi
173
174 # Upgrade, but no automatically changed config;
175 # warn if new template available
176 if [ -n "$2" -a -z "$changed_config" ] && \
177    dpkg --compare-versions "$2" lt "$TMPLVERSION"; then
178   cp_echo ""
179   cp_echo "CN: It seems you have upgraded this package from version $2."
180   cp_echo "CN: Configuration template for $mta was modified in version ${TMPLVERSION}."
181   cp_echo "    You might want to review the changes, or simply copy the new template and"
182   cp_echo "    and replace the _CN_DOMAIN_ string with an adequate value:"
183   cp_echo "    cp $ACONFTMPL $ACONF"
184   cp_echo "    perl -pi -e 's/_CN_DOMAIN_/$domain/g' $ACONF"
185 fi
186
187 cp_mail $PKG $VERSION