mirror of
https://github.com/harivansh-afk/betterNAS.git
synced 2026-04-15 14:03:48 +00:00
89 lines
3.2 KiB
Bash
Executable file
89 lines
3.2 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
|
|
|
|
auth_payload="$(jq -nc --arg username "$BETTERNAS_USERNAME" --arg password "$BETTERNAS_PASSWORD" '{username: $username, password: $password}')"
|
|
session_token="$({
|
|
curl -fsS \
|
|
-X POST \
|
|
-H 'Content-Type: application/json' \
|
|
-d "$auth_payload" \
|
|
"http://localhost:${BETTERNAS_CONTROL_PLANE_PORT}/api/v1/auth/login" \
|
|
| jq -er '.token'
|
|
} 2>/dev/null || true)"
|
|
if [[ -z "$session_token" ]]; then
|
|
session_token="$({
|
|
curl -fsS \
|
|
-X POST \
|
|
-H 'Content-Type: application/json' \
|
|
-d "$auth_payload" \
|
|
"http://localhost:${BETTERNAS_CONTROL_PLANE_PORT}/api/v1/auth/register" \
|
|
| jq -er '.token'
|
|
})"
|
|
fi
|
|
|
|
export_id=""
|
|
for _ in {1..30}; do
|
|
exports_response="$(curl -fsS -H "Authorization: Bearer ${session_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 ${session_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="${BETTERNAS_USERNAME}"
|
|
BETTERNAS_EXAMPLE_MOUNT_PASSWORD="${BETTERNAS_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 ${session_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}."
|