#!/bin/bash
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

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

CONFFILES="AdminDaemon.properties Group.properties ModuleAccessDefinitions.properties mpasswd Resource.properties Sql.properties"

for FILE in $CONFFILES; do
    dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/admindaemon/$FILE \
        /opt/open-xchange/etc/$FILE 6.20.99 -- "$@"
done
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/admindaemon/User.properties \
        /opt/open-xchange/etc/AdminUser.properties 6.20.99 -- "$@"

ofile=/opt/open-xchange/etc/admindaemon/RMI.properties
pfile=/opt/open-xchange/etc/rmi.properties
if [ -e $ofile ]; then
    oval=$(ox_read_property RMI_PORT $ofile)
    if [ -n "$oval" ]; then
       ox_set_property com.openexchange.rmi.port $oval $pfile
    fi
fi
dpkg-maintscript-helper rm_conffile \
	/opt/open-xchange/etc/admindaemon/RMI.properties -- "$@"

ofile=/opt/open-xchange/etc/admindaemon/ox-admin-scriptconf.sh
pfile=/opt/open-xchange/etc/ox-scriptconf.sh
grep JAVA_OXCMD_OPTS $pfile >/dev/null || {
     oval=$(ox_read_property JAVA_OXCMD_OPTS $ofile)
     if [ -n "$oval" ]; then
        ox_set_property JAVA_OXCMD_OPTS "$oval" $pfile
     else
        ox_set_property JAVA_OXCMD_OPTS "-Djava.net.preferIPv4Stack=true" $pfile
     fi
}
dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/admindaemon/ox-admin-scriptconf.sh -- "$@"


dpkg-maintscript-helper mv_conffile \
    /opt/open-xchange/etc/admindaemon/plugin/hosting.properties \
    /opt/open-xchange/etc/plugin/hosting.properties 6.20.99 \
    open-xchange-admin-plugin-hosting -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-admin-plugin-hosting)

for FILE in cache.ccf configdb.properties file-logging.properties management.properties \
        logging.properties system.properties; do
    dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/admindaemon/$FILE -- "$@"
done

dpkg-maintscript-helper rm_conffile /etc/default/open-xchange-admin -- "$@"
dpkg-maintscript-helper rm_conffile /etc/init.d/open-xchange-admin -- "$@"

case "$1" in
    install|upgrade)
    ;;

    abort-upgrade)
    ;;

    *)
        echo "preinst 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
