#!/bin/sh

set -e

if [ "$1" = "upgrade" ] ; then
  #
  #  Do nothing for upgrades.
  #
  exit 0
fi

#
# Remove the clamav defaults file, if it matches the md5sum of the one we created.
#
if echo "ae779d6822f91492b26697d6b9931835  /etc/default/clamav-daemon" | md5sum -c --status 2>/dev/null ; then
  rm -f /etc/default/clamav-daemon
fi

# 
# Remove the old diversion 
#
package="sympl-mail"
conf="/etc/dovecot/dovecot.conf"

# 
# Dovecot ships with its own config.
#
package="sympl-mail"
conf="/etc/dovecot/dovecot.conf"
theirfile="$conf.dpkg-sympl-orig"

#
# Add the diversion if the file has not been generated by Sympl, and if the
# diversion doesn't exist.
#
if dpkg-divert --list "$package" | grep -xFq "diversion of $conf to $theirfile by $package"; then

  if [ -e "$theirfile" ] ; then
    mv -f $conf ${conf}.dpkg-sympl
    dpkg-divert --remove --rename --package "$package" "$conf" || true
  else
    # Otherwise just remove the diversion
    dpkg-divert --remove --package "$package" "$conf" || true
  fi

fi


#DEBHELPER#
exit 0
