mirror of
https://github.com/harivansh-afk/betterNAS.git
synced 2026-04-15 05:02:07 +00:00
Split node enrollment from export sync and issue Finder-compatible DAV credentials so the stack proves the real backend seam before any web UI consumes it.
69 lines
2.7 KiB
Bash
Executable file
69 lines
2.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
# shellcheck disable=SC1091
|
|
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../lib/runtime-env.sh"
|
|
|
|
"$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wait-stack"
|
|
|
|
control_health="$(curl -fsS "http://localhost:${BETTERNAS_CONTROL_PLANE_PORT}/health")"
|
|
echo "$control_health" | jq -e '.service == "control-plane" and .status == "ok"' >/dev/null
|
|
|
|
export_id=""
|
|
for _ in {1..30}; do
|
|
exports_response="$(curl -fsS -H "Authorization: Bearer ${BETTERNAS_CONTROL_PLANE_CLIENT_TOKEN}" "http://localhost:${BETTERNAS_CONTROL_PLANE_PORT}/api/v1/exports")"
|
|
export_id="$({
|
|
echo "$exports_response" | jq -er \
|
|
'map(select(.mountPath == "/dav/")) | .[0].id? // empty'
|
|
} 2>/dev/null || true)"
|
|
if [[ -n "$export_id" ]]; then
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
if [[ -z "$export_id" ]]; then
|
|
echo "Node agent export did not appear in the control plane." >&2
|
|
exit 1
|
|
fi
|
|
|
|
mount_profile="$({
|
|
curl -fsS \
|
|
-X POST \
|
|
-H 'Content-Type: application/json' \
|
|
-H "Authorization: Bearer ${BETTERNAS_CONTROL_PLANE_CLIENT_TOKEN}" \
|
|
-d "{\"exportId\":\"${export_id}\"}" \
|
|
"http://localhost:${BETTERNAS_CONTROL_PLANE_PORT}/api/v1/mount-profiles/issue"
|
|
})"
|
|
echo "$mount_profile" | jq -e --arg expected "$BETTERNAS_EXAMPLE_MOUNT_URL" '.protocol == "webdav" and .mountUrl == $expected and .credential.mode == "basic-auth"' >/dev/null
|
|
|
|
BETTERNAS_EXAMPLE_MOUNT_USERNAME="$(echo "$mount_profile" | jq -er '.credential.username')"
|
|
BETTERNAS_EXAMPLE_MOUNT_PASSWORD="$(echo "$mount_profile" | jq -er '.credential.password')"
|
|
export BETTERNAS_EXAMPLE_MOUNT_USERNAME
|
|
export BETTERNAS_EXAMPLE_MOUNT_PASSWORD
|
|
"$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/verify-webdav"
|
|
|
|
cloud_profile="$({
|
|
curl -fsS \
|
|
-X POST \
|
|
-H 'Content-Type: application/json' \
|
|
-H "Authorization: Bearer ${BETTERNAS_CONTROL_PLANE_CLIENT_TOKEN}" \
|
|
-d "{\"userId\":\"integration-user\",\"exportId\":\"${export_id}\",\"provider\":\"nextcloud\"}" \
|
|
"http://localhost:${BETTERNAS_CONTROL_PLANE_PORT}/api/v1/cloud-profiles/issue"
|
|
})"
|
|
echo "$cloud_profile" | jq -e --arg expected "$NEXTCLOUD_BASE_URL" '.provider == "nextcloud" and .baseUrl == $expected' >/dev/null
|
|
echo "$cloud_profile" | jq -e --arg expected "/apps/betternascontrolplane/exports/${export_id}" '.path == $expected' >/dev/null
|
|
|
|
nextcloud_status="$(curl -fsS "${NEXTCLOUD_BASE_URL}/status.php")"
|
|
echo "$nextcloud_status" | jq -e '.installed == true' >/dev/null
|
|
|
|
nextcloud_app_status="$({
|
|
curl -fsS \
|
|
-u "${NEXTCLOUD_ADMIN_USER}:${NEXTCLOUD_ADMIN_PASSWORD}" \
|
|
-H 'OCS-APIRequest: true' \
|
|
"${NEXTCLOUD_BASE_URL}/ocs/v2.php/apps/betternascontrolplane/api/status?format=json"
|
|
})"
|
|
echo "$nextcloud_app_status" | jq -e '.ocs.meta.statuscode == 200' >/dev/null
|
|
|
|
echo "Stack verified for ${BETTERNAS_CLONE_NAME}."
|