#!/bin/bash

set -e

DOMAIN=$(relation-get domain) || exit 1

## These are mainly to setup the correct web-hook
if [ "$MASTER_BASE_SERVICE_NAME" == "$DOMAIN" ]; then
    ## This is because the IP will be the docker container version
    PROTO="http"
else
    URL="$(relation-get url)" || exit 1
    PROTO="${URL%%://*}"
fi

read-0 ts _ _ < <(get_service_relation "$SERVICE_NAME" "nextcloud-app") || {
    err "Could not find ${DARKCYAN}nextcloud-app${WHITE} service name."
    exit 1
}


compose --no-relations --no-init occ "$ts" \
        config:system:set onlyoffice DocumentServerUrl --value="$PROTO://$DOMAIN/" \;