#!/bin/sh -e

# Source debconf library.
. /usr/share/debconf/confmodule

action="$1"
oldversion="$2"

if [ "$action" != configure ]
  then
  exit 0
fi

# starting of daemon (now started by debhelper)
#update-rc.d sagator defaults

# fix permissions
chgrp vscan /etc/sagator.conf /usr/share/sagator/etc
chown -Rh vscan:vscan /var/log/sagator 2>/dev/null || true
chown -Rh vscan:vscan /var/www/html/sagator 2>/dev/null || true

# reinit chroot from init script
touch /var/lib/sagator-mkchroot

# update configuration
/usr/share/sagator/updatecfg.py >&2 || true

if db_get sagator/confpostfix; then
        if [ "$RET" = "true" ]; then
	        if [ -f /etc/postfix/master.cf -a -f /etc/postfix/main.cf ]; then
                        db_subst sagator/confpostfix boolean false
                        db_go
                        echo -n "Reconfiguring postfix ... "
                        sh /usr/share/doc/sagator-base/unconfigure_postfix.sh
                        sh /usr/share/doc/sagator-base/configure_postfix.sh
                        echo "done"
                fi >&2
        fi
fi

#DEBHELPER#
