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

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

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

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

    PFILE=/opt/open-xchange/etc/grizzly.properties

    # SoftwareChange_Request-2289
    ox_remove_property com.openexchange.http.grizzly.hasAJPEnabled $PFILE

    # SoftwareChange_Request-2492
    ox_add_property com.openexchange.http.grizzly.maxHttpHeaderSize 8192 $PFILE

    # SoftwareChange_Request-2864
    ox_add_property com.openexchange.http.grizzly.keepAlive true $PFILE
    ox_add_property com.openexchange.http.grizzly.tcpNoDelay true $PFILE
    ox_add_property com.openexchange.http.grizzly.readTimeoutMillis 60000 $PFILE
    ox_add_property com.openexchange.http.grizzly.writeTimeoutMillis 60000 $PFILE

    # SoftwareChange_Request-3248
    ox_add_property com.openexchange.http.grizzly.hasSSLEnabled false $PFILE
    ox_add_property com.openexchange.http.grizzly.enabledCipherSuites '' $PFILE
    ox_add_property com.openexchange.http.grizzly.keystorePath '' $PFILE
    ox_add_property com.openexchange.http.grizzly.keystorePassword '' $PFILE
}

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
