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


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

    abort-upgrade)
    ;;

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

CRAWLERCONFFILES="crawlers/gmx.com.yml crawlers/gmx.de.yml crawlers/GoogleCalendar.yml crawlers/GoogleMail.yml 'crawlers/Sun Calendar.yml' 'crawlers/Sun Contacts.yml' 'crawlers/Sun Tasks.yml' crawlers/t-online.de.yml crawlers/web.de.yml crawlers/XING.yml crawlers/yahoo.com.yml crawler.properties"

for FILE in ${CRAWLERCONFFILES}; do
    dpkg-maintscript-helper mv_conffile "/opt/open-xchange/etc/groupware/${FILE}" "/opt/open-xchange/etc/${FILE}" 6.20.99 \
        open-xchange-subscribe-crawler -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-subscribe-crawler)
done

dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/facebooksubscribe.properties \
    /opt/open-xchange/etc/facebooksubscribe.properties 6.20.99 open-xchange-subscribe-facebook -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-subscribe-facebook)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/linkedinsubscribe.properties \
    /opt/open-xchange/etc/linkedinsubscribe.properties 6.20.99 open-xchange-subscribe-linkedin -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-subscribe-linkedin)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/microformatSubscription.properties \
    /opt/open-xchange/etc/microformatSubscription.properties 6.20.99 open-xchange-subscribe-microformats -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-subscribe-microformats)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/yahoosubscribe.properties \
    /opt/open-xchange/etc/yahoosubscribe.properties 6.20.99 open-xchange-subscribe-yahoo -- $1 \
    $(dpkg-query -W -f='${Config-Version}' open-xchange-subscribe-yahoo)

#SoftwareChange_Request-1847
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/crawlers/XING.yml /opt/open-xchange/etc/crawlers/xing.yml 7.4.2~ -- "$@"

#SoftwareChange_Request-2145
dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/crawlers/GoogleCalendar.yml 7.6.1~ -- "$@"
dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/crawlers/GoogleMail.yml 7.6.1~ -- "$@"

# SoftwareChange_Request-2147
dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/crawlers/xing.yml 7.6.1~ -- "$@"

# SoftwareChange_Request-2154
dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/msnsubscribe.properties 7.6.1~ -- "$@"

# SoftwareChange_Request-2444
dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/facebooksubscribe.properties 7.6.2~ -- "$@"

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

#DEBHELPER#

exit 0
