#!/bin/sh
set -eu

if [ -z "${CHAT_URL+x}" ]; then
    /usr/local/bin/php occ config:app:delete indie_external chat_url
else
    /usr/local/bin/php occ config:app:set indie_external chat_url --value "${CHAT_URL}"
fi

if [ -z "${VISIO_URL+x}" ]; then
    /usr/local/bin/php occ config:app:delete indie_external visio_url
else
    /usr/local/bin/php occ config:app:set indie_external visio_url --value "${VISIO_URL}"
fi

if [ -z "${SAML_IDP_URL+x}" ]; then
    /usr/local/bin/php occ config:app:delete indie_external sso_account_url
    /usr/local/bin/php occ config:app:delete indie_external sso_admin_url
else
    /usr/local/bin/php occ config:app:set indie_external sso_account_url --value "${SAML_IDP_URL}/auth/realms/${SAML_REALM}/account"
    /usr/local/bin/php occ config:app:set indie_external sso_admin_url --value "${SAML_IDP_URL}/auth/admin/${SAML_REALM}/console"
fi

php occ config:app:set mail app.mail.smtp.timeout --value=10
