#!/bin/bash
# preinst script for open-xchange
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

CONFFILES="outlook2003.de_DE.properties outlook2003.en_EN.properties outlook2003.fr_FR.properties outlook2003.nl_NL.properties"

case "$1" in
    upgrade)
        if dpkg --compare-versions "$2" lt "6.21.0-0"; then
            for FILE in ${CONFFILES}; do
                dpkg-divert --package open-xchange --add --rename --divert /opt/open-xchange/importCSV/${FILE}.old \
                    /opt/open-xchange/importCSV/${FILE}
            done
        fi
    ;;
    install)
    ;;

    abort-upgrade)
    ;;

    *)
        echo "preinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

COMMONCONFFILES="excludedupdatetasks.properties foldercache.properties transport.properties"

for FILE in ${COMMONCONFFILES}; do
    dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/common/${FILE} \
	/opt/open-xchange/etc/${FILE} 6.20.99 -- "$@"
done

GWCONFFILES="ajp.properties attachment.properties cache.ccf calendar.properties configdb.properties contact.properties event.properties file-logging.properties HTMLEntities.properties imap.properties importerExporter.xml import.properties infostore.properties javamail.properties ldap.properties login.properties mailcache.ccf mail.properties mime.types noipcheck.cnf notification.properties ox-scriptconf.sh participant.properties passwordchange.properties server.properties sessioncache.ccf sessiond.properties smtp.properties system.properties TidyConfiguration.properties TidyMessages.properties user.properties whitelist.properties folder-reserved-names"

for FILE in ${GWCONFFILES}; do
    dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/${FILE} \
	/opt/open-xchange/etc/${FILE} 6.20.99 -- "$@"
done

dpkg-maintscript-helper mv_conffile /etc/default/open-xchange-groupware \
    /etc/default/open-xchange 6.20.99 -- "$@"

# SoftwareChange_Request-1094
# -----------------------------------------------------------------------
dpkg-maintscript-helper rm_conffile \
    /opt/open-xchange/etc/groupware/mailjsoncache.properties -- "$@"

# SoftwareChange_Request-1091
dpkg-maintscript-helper rm_conffile \
    /opt/open-xchange/etc/groupware/TidyConfiguration.properties -- "$@"
dpkg-maintscript-helper rm_conffile \
    /opt/open-xchange/etc/groupware/TidyMessages.properties -- "$@"

dpkg-maintscript-helper rm_conffile /etc/init.d/open-xchange-groupware -- "$@"

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
