#!/bin/bash

appOwnCloudSetupConfig()
{
    isNotice "ownCloud is currently being set up, please wait..."
    isNotice "This may take a few minutes..."
    echo ""
    # Run the health check loop with timings
    dockerCheckContainerHealthLoop "owncloud" 180 15

    # If container is healthy
    if dockerCheckContainerHealth "owncloud"; then
        isSuccessful "OwnCloud container is healthy, continuing with the install."

        # config.php is owned by the in-container uid (165568), so the whole
        # normalise (wait for ownCloud to write it, strip the default
        # trusted_domains/overwrite.cli.url, append the LibrePortal ones, fix
        # ownership) runs in the root-owned appcfg helper with validated args.
        if runAppCfg owncloud-config "$public" "$host_setup" "$ip_setup" "$public_ip_v4"; then
            isSuccessful "ownCloud config.php normalised (trusted_domains + overwrite.cli.url)."
        else
            isError "Failed to normalise ownCloud config.php."
        fi
    else
        isError "Container is not healthy. Setup seems to have failed."
    fi

}
