#!/bin/bash
# postinst script for open-xchange-pns-impl
#
# 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() {
    SCR=SCR-1289
    if ox_scr_todo ${SCR}
    then
      pfile=/opt/open-xchange/etc/pns.properties
      if [ -f "$pfile" ]
      then
        sed -i -e 's/^com\.openexchange\.pns\.transport\.gcm/com\.openexchange\.pns\.transport\.fcm/' "$pfile"
      fi
      ox_scr_done ${SCR}
    fi
}

setConfigFilePermissions() {
    ox_update_permissions "/opt/open-xchange/etc/pns-apns_http2-options.yml" root:open-xchange 640
    ox_update_permissions "/opt/open-xchange/etc/pns-apns-options.yml" root:open-xchange 640
    ox_update_permissions "/opt/open-xchange/etc/pns-fcm-options.yml" root:open-xchange 640
    ox_update_permissions "/opt/open-xchange/etc/pns-wns-options.yml" root:open-xchange 640
}

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

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

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


# SCR-1314
dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/pns-gcm-options.yml 7.10.6~ -- "$@"

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

#DEBHELPER#

exit 0
