#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[@]}")"

exec &> /dev/stdout
echo "Starting $(date -Is)"

USER="$(cat ~/annex/secret/Nextcloud/user.txt)"
PASSWORD="$(cat ~/annex/secret/Nextcloud/password.txt)"
URL="$(cat ~/annex/secret/Nextcloud/url.txt)"

pgrep nextcloud && {
  echo 'Nextloud already running. Exitting.'
  exit 1
}

nextcloudcmd -h               \
             -u "${USER}"     \
             -p "${PASSWORD}" \
             ~/Nextcloud/     \
             "${URL}"

echo "Finishing: $(date -Is)"
