#! /bin/bash
# postinst script
#
# 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>
#        * <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/etc/oxfunctions.sh

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

  GLOBIGNORE='*'

  # SoftwareChange_Request-135
  # -----------------------------------------------------------------------
  local ofile=/opt/open-xchange/etc/groupware/server.properties
  local nfile=/opt/open-xchange/etc/groupware/management.properties
  if [ -e $ofile ]; then
     for prop in JMXPort JMXBindAddress JMXLogin JMXPassword; do
         if ox_exists_property $prop $ofile; then
             local oldval=$(ox_read_property $prop $ofile)
             ox_set_property $prop "$oldval" $nfile
             ox_remove_property $prop $ofile
         fi
     done
  fi
  local ofile=/opt/open-xchange/etc/admindaemon/plugin/hosting.properties
  local nfile=/opt/open-xchange/etc/admindaemon/management.properties
  if [ -e $ofile ]; then
     for prop in JMXPort JMXBindAddress JMXLogin JMXPassword; do
         if ox_exists_property $prop $ofile; then
             local oldval=$(ox_read_property $prop $ofile)
             ox_set_property $prop "$oldval" $nfile
             ox_remove_property $prop $ofile
         fi
     done
  fi
}

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

    ;;

    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


