#!/bin/bash

VERSION="1"

. /usr/share/univention-appcenter/joinscripthelper.sh

eval "$(ucr shell)"

joinscript_init

ucs_addServiceToLocalhost "${SERVICE}" "$@"

# apache config
apache_cfg="/etc/apache2/ucs-sites.conf.d/relution.conf"
container_port="$(ucr get appcenter/apps/relution/ports/8080)"
locations="relution
gofer
system
mcap
push
rest
exchange
Microsoft-Server-ActiveSync"

if [ ! -e "$apache_cfg" ]; then
        for i in $locations; do
                echo >>"$apache_cfg"
                echo ProxyPass /$i http://127.0.0.1:$container_port/$i timeout=4000 connectiontimeout=600 acquire=3000 retry=6 >>"$apache_cfg"
                echo ProxyPassReverse  /$i http://127.0.0.1:$container_port/$i >>"$apache_cfg"
        done
        invoke-rc.d apache2 reload
fi

joinscript_save_current_version

exit 0