#!/bin/bash
# postinst script for open-xchange
#
# 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>
#        * <postinst> `abort-remove'
#        * <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

dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/caldav.properties \
    /opt/open-xchange/etc/caldav.properties 6.20.99 open-xchange-caldav -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-caldav)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/contextSets/caldav.yml \
    /opt/open-xchange/etc/contextSets/caldav.yml 6.20.99 open-xchange-caldav -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-caldav)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/meta/caldav.yml \
    /opt/open-xchange/etc/meta/caldav.yml 6.20.99 open-xchange-caldav -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-caldav)

dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/carddav.properties \
    /opt/open-xchange/etc/carddav.properties 6.20.99 open-xchange-carddav -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-carddav)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/contextSets/carddav.yml \
    /opt/open-xchange/etc/contextSets/carddav.yml 6.20.99 open-xchange-carddav -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-carddav)

. /opt/open-xchange/lib/oxfunctions.sh

postFix622() {
    # prevent bash from expanding, see bug 13316
    GLOBIGNORE='*'

    # SoftwareChange_Request-1028
    pfile=/opt/open-xchange/etc/carddav.properties
    if ! ox_exists_property com.openexchange.carddav.tree $pfile; then
        ox_set_property com.openexchange.carddav.tree "0" $pfile
    fi
    if ! ox_exists_property com.openexchange.carddav.exposedCollections $pfile; then
        ox_set_property com.openexchange.carddav.exposedCollections "0" $pfile
    fi
    # SoftwareChange_Request-1129
    if ! ox_exists_property com.openexchange.carddav.reducedAggregatedCollection $pfile; then
        ox_set_property com.openexchange.carddav.reducedAggregatedCollection "false" $pfile
    fi
}

case "$1" in
    configure)
        postFix622
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

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

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

#DEBHELPER#

exit 0
