#!/bin/bash

# VERSION has to be set for external programs to parse
# join scripts will in general onyl be run once per VERSION
# so you need to increment this value when you are changing the script
VERSION="2"

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

joinscript_init

# apache config
apache_cfg="/etc/apache2/ucs-sites.conf.d/$APP.conf"
container_port="$(ucr get appcenter/apps/$APP/ports/80)"
cat > "$apache_cfg" << EOF
ProxyPass /roiwebui/ http://127.0.0.1:$container_port/roiwebui/ retry=0
ProxyPassReverse /roiwebui/ http://127.0.0.1:$container_port/roiwebui/
ProxyPass /api/ http://127.0.0.1:$container_port/api/ retry=0
ProxyPassReverse /api/ http://127.0.0.1:$container_port/api/
ProxyPass /api-docs/ http://127.0.0.1:$container_port/api-docs/ retry=0
ProxyPassReverse /api-docs/ http://127.0.0.1:$container_port/api-docs/
EOF
service apache2 reload

ucs_addServiceToLocalhost "${SERVICE}" "$@"

ucr set mysql/config/mysqld/lower_case_table_names=1 \
  mysql/config/mysqld/transaction-isolation=READ-COMMITTED
invoke-rc.d mysql reload

joinscript_save_current_version
exit 0