#! /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-865
  # -----------------------------------------------------------------------
  local pfile=/opt/open-xchange/etc/groupware/settings/ui.properties
  if ! ox_exists_property "ui/global/notifier/report/sendEnabled" $pfile; then
      ox_set_property "ui/global/notifier/report/sendEnabled" true $pfile
  fi
  if ! ox_exists_property "ui/global/notifier/report/mailAddress" $pfile; then
      ox_set_property "ui/global/notifier/report/mailAddress" '' $pfile
  fi
  
  # SoftwareChange_Request-831
  # -----------------------------------------------------------------------
  local pfile=/opt/open-xchange/etc/groupware/settings/ui.properties
  if ! ox_exists_property "ui/mail/replyTo/configurable" $pfile; then
      ox_set_property "ui/mail/replyTo/configurable" false $pfile
  fi

  # SoftwareChange_Request-826
  # -----------------------------------------------------------------------
  local pfile=/opt/open-xchange/etc/groupware/settings/ui.properties
  if ! ox_exists_property "ui/global/expert/mode/configurable" $pfile; then
      ox_set_property "ui/global/expert/mode/configurable" true $pfile
  fi
  if ! ox_exists_property "ui/global/expert/mode/value" $pfile; then
      ox_set_property "ui/global/expert/mode/value" false $pfile
  fi

  # SoftwareChange_Request-747
  # -----------------------------------------------------------------------
  local pfile=/opt/open-xchange/etc/groupware/settings/ui.properties
  if ! ox_exists_property "ui/portal/customUWA" $pfile; then
      ox_set_property "ui/portal/customUWA" true $pfile
  fi

  # SoftwareChange_Request-741
  # -----------------------------------------------------------------------
  local pfile=/opt/open-xchange/etc/groupware/settings/ui.properties
  if ! ox_exists_property "ui/portal/autoRefresh" $pfile; then
      ox_set_property "ui/portal/autoRefresh" false $pfile
  fi

  # SoftwareChange_Request-717
  # -----------------------------------------------------------------------
  local pfile=/opt/open-xchange/etc/groupware/settings/ui.properties
  for key in ui/mail/showContactImage/value ui/mail/showContactImage/configurable; do
	if ! ox_exists_property $key $pfile; then
	    ox_set_property $key true $pfile
	fi
  done
}

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


