restart amavisd-cn
[amavisd-cn.git] / debian / postinst
index 0d341f6..0bd6a78 100755 (executable)
@@ -1,7 +1,22 @@
 #!/bin/sh
+# postinst script for amavisd-cn
+#
+# see: dh_installdeb(1)
 
 set -e
 
+# summary of how this script can be called:
+#        * <postinst> `configure' <most-recently-configured-version>
+#        * <old-postinst> `abort-upgrade' <new version>
+#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#          <new-version>
+#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#          <failed-install-package> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+#
+
 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
 
 case "$1" in
@@ -57,12 +72,14 @@ fi
 if [ ! -f $ACONF -o ! -s $ACONF ]; then
   # Create fresh config from template
   conf_from_template
+  restart_daemon=1
 fi
 
 # disable SAVI as proven problematic
-if cp_check_and_sed "^\['Sophos SAVI'" \
- "s/^\(\['Sophos SAVI', ..sophos_savi \]\)/#\1/" $ACONF; then
+if cp_check_and_sed "^[[:blank:]]*\['Sophos SAVI'" \
+ "s/^[[:blank:]]*\(\['Sophos SAVI', ..sophos_savi \]\)/#\1/" $ACONF; then
   cp_echo "CN: Disabled SAVI::Perl usage in ${ACONF}."
+  restart_daemon=1
 fi
 
 check_and_add_alias virusalert root
@@ -108,26 +125,69 @@ fi
 
 # kill naughty pyzor descendants -- XXX needed for 2.4 or not?
 if dpkg --compare-versions "$2" lt 2:20030616p10-7 && \
-    pgrep -u amavis -f '/usr/bin/pyzor check' > /dev/null; then
-  /etc/init.d/amavisd-cn stop
+  pgrep -u amavis -f '/usr/bin/pyzor check' > /dev/null; then
+  if [ -x "/etc/init.d/amavisd-cn" ]; then
+    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
+      invoke-rc.d amavisd-cn stop
+    else
+      /etc/init.d/amavisd-cn stop
+    fi
+  fi
   pkill -9 -u amavis -f '/usr/bin/pyzor check' > /dev/null || true
-  /etc/init.d/amavisd-cn start
+  if [ -x "/etc/init.d/amavisd-cn" ]; then
+    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
+      invoke-rc.d amavisd-cn start
+    else
+      /etc/init.d/amavisd-cn start
+    fi
+  fi
   restart_daemon=
   restart_mta=
 fi
 
+# register for automatic start
+update-rc.d -f amavis remove >/dev/null || true
+update-rc.d amavisd-cn defaults 19 21 >/dev/null
+
 # START AMAVISD
 # about a half of amavisd-cn script is here
-if [ "$restart_daemon" -a -x /etc/init.d/amavis.amavisd-new ]; then
-  /etc/init.d/amavis.amavisd-new restart
-fi
-# always check that the daemons are running
-if ! wait_for_fds amavis; then
-  /etc/init.d/amavis.amavisd-new start
-  wait_for_fds amavis
-fi
-if [ "$restart_mta" ]; then
-  /etc/init.d/$mta restart
+#if [ "$restart_daemon" -a -x /etc/init.d/amavis.amavisd-new ]; then
+#  if [ -x "/etc/init.d/amavis.amavisd-new" ]; then
+#    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
+#      invoke-rc.d amavis.amavisd-new restart
+#    else
+#      /etc/init.d/amavis.amavisd-new restart
+#    fi
+#  fi
+#fi
+## always check that the daemons are running
+#if ! wait_for_fds amavis; then
+#  if [ -x "/etc/init.d/amavis.amavisd-new" ]; then
+#    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
+#      invoke-rc.d amavis.amavisd-new start
+#    else
+#      /etc/init.d/amavis.amavisd-new start
+#    fi
+#  fi
+#  wait_for_fds amavis
+#fi
+#if [ "$restart_mta" ]; then
+#  if [ -x "/etc/init.d/$mta" ]; then
+#    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
+#      invoke-rc.d $mta restart
+#    else
+#      /etc/init.d/$mta restart
+#    fi
+#  fi
+#fi
+if [ "$restart_daemon" -a -x /etc/init.d/amavisd-cn ]; then
+  if [ -x "/etc/init.d/amavisd-cn" ]; then
+    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
+      invoke-rc.d amavisd-cn restart
+    else
+      /etc/init.d/amavisd-cn restart
+    fi
+  fi
 fi
 
 # this needs to be updated when $CRONTAB file changes
@@ -164,4 +224,17 @@ if [ -n "$2" -a -z "$changed_config" ] && \
   cp_echo "    perl -pi -e 's/_CN_DOMAIN_/$domain/g' $ACONF"
 fi
 
+# Delete old conffiles...
+for conffile in /etc/logcheck/violations.ignore.d/amavisd-new \
+         /etc/logcheck/ignore.d.server/amavisd-new \
+         /etc/logcheck/ignore.d.workstation/amavisd-new \
+         /etc/cron.daily/amavisd-new; do
+  if [ -f ${conffile} ]; then
+    cp_echo "CN: Deleting old conffile ${conffile}..."
+    rm -f ${conffile}
+  fi
+done
+
 cp_mail $PKG $VERSION
+
+exit 0