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

PROTECT="facebookoauth.properties linkedinoauth.properties msnoauth.properties yahoooauth.properties xingoauth.properties settings/flickroauth.properties settings/tumblroauth.properties"

setConfigFilePermissions() {
    for FILE in $PROTECT
    do
        ox_update_permissions /opt/open-xchange/etc/$FILE root:open-xchange 640
    done
}

case "$1" in
    configure)
        setConfigFilePermissions
    ;;

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

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

dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/deferrer.properties /opt/open-xchange/etc/deferrer.properties 6.20.99 \
    open-xchange-http-deferrer -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-http-deferrer)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/oauth.properties /opt/open-xchange/etc/oauth.properties 6.20.99 -- "$@"
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/facebookoauth.properties \
    /opt/open-xchange/etc/facebookoauth.properties 6.20.99 open-xchange-oauth-facebook -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-oauth-facebook)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/linkedinoauth.properties \
    /opt/open-xchange/etc/linkedinoauth.properties 6.20.99 open-xchange-oauth-linkedin -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-oauth-linkedin)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/msnoauth.properties /opt/open-xchange/etc/msnoauth.properties 6.20.99 \
    open-xchange-oauth-msn -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-oauth-msn)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/twitteroauth.properties /opt/open-xchange/etc/twitteroauth.properties \
    6.20.99 open-xchange-oauth-twitter -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-oauth-twitter)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/yahoooauth.properties /opt/open-xchange/etc/yahoooauth.properties \
    6.20.99 open-xchange-oauth-yahoo -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-oauth-yahoo)

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

#DEBHELPER#

exit 0
