#!/bin/bash
# postinst script for open-xchange-realtime-core
#
# 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

postFix() {
    local version=${1%-*}
    version=${version//[-.]/}

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

    # prevent bash from expanding, see bug 13316
    GLOBIGNORE='*'

    # SoftwareChange_Request-1539
    # updated by SoftwareChange_Request-1721
    # updated by SoftwareChange_Request-1730
    pfile=/opt/open-xchange/etc/hazelcast/rtResourceDirectory.properties
    VALUE=$(ox_read_property com.openexchange.hazelcast.configuration.map.name $pfile)
    if [ "$VALUE" == "rtResourceDirectory-0" ] || [ "$VALUE" == "rtResourceDirectory-1" ]; then
        ox_set_property com.openexchange.hazelcast.configuration.map.name rtResourceDirectory-2 $pfile
    fi
    VALUE=$(ox_read_property com.openexchange.hazelcast.configuration.map.maxIdleSeconds $pfile)
    if [ "$VALUE" == "0" ] || [ "$VALUE" == "3600" ]; then
        ox_set_property com.openexchange.hazelcast.configuration.map.maxIdleSeconds 86400 $pfile
    fi

    # SoftwareChange_Request-1721
    pfile=/opt/open-xchange/etc/hazelcast/rtIDMapping.properties
    if ox_exists_property com.openexchange.hazelcast.configuration.map.maxIdleSeconds $pfile; then
       ox_remove_property com.openexchange.hazelcast.configuration.map.maxIdleSeconds $pfile
    fi
}

case "$1" in
    configure)
        test -n "$2" && {
            # we are in update mode, run postFix to apply fixes
            postFix "$2"
        }
    ;;

    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
