#!/bin/sh

set -e

#EXTRA#
#DEBHELPER#

reload_apache()
{
    if apache2ctl configtest 2>/dev/null; then
        invoke-rc.d apache2 $1 || true
    else
        echo "Your apache2 configuration is broken, so we're not restarting it for you."
    fi
}


plugin_config()
{
    if [ ! -e /usr/share/kolab-syncroton/lib/plugins/$1/config.inc.php ] && \
       [ ! -L /usr/share/kolab-syncroton/lib/plugins/$1/config.inc.php ]; then
        ln -s /etc/roundcubemail/$1.inc.php /usr/share/kolab-syncroton/lib/plugins/$1/config.inc.php
    fi
}

case "$1" in
    configure)
        a2ensite kolab-syncroton > /dev/null || true
        reload_apache stop
        reload_apache start


        if [ ! -e /usr/share/kolab-syncroton/config/main.inc.php ] && \
           [ ! -L /usr/share/kolab-syncroton/config/main.inc.php ]; then
            ln -s /etc/roundcubemail/main.inc.php /usr/share/kolab-syncroton/config/
        fi

        if [ ! -e /usr/share/kolab-syncroton/config/db.inc.php ] && \
           [ ! -L /usr/share/kolab-syncroton/config/db.inc.php ]; then
            ln -s /etc/roundcubemail/db.inc.php /usr/share/kolab-syncroton/config/
        fi

        plugin_config kolab_auth
        plugin_config kolab_folders
        plugin_config libkolab
    ;;
esac

exit 0

