betterNAS/scripts/lib/runtime-env.sh
Harivansh Rathi ed40da7326 Secure first-loop control-plane auth and mount routing.
Protect the control-plane API with explicit bearer auth, add node-scoped
registration/heartbeat credentials, and make export mount paths an explicit
contract field so mount profiles stay correct across runtimes.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-04-01 14:13:14 +00:00

73 lines
2.4 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
compose_file="$repo_root/infra/docker/compose.dev.yml"
default_env_file="$repo_root/.env.agent"
env_file="${BETTERNAS_ENV_FILE:-$default_env_file}"
# shellcheck disable=SC1091
source "$repo_root/scripts/lib/agent-env.sh"
if [[ -f "$env_file" ]]; then
set -a
# shellcheck disable=SC1090
source "$env_file"
set +a
fi
if [[ -z "${BETTERNAS_CLONE_NAME:-}" ]]; then
BETTERNAS_CLONE_NAME="$(betternas_default_clone_name "$repo_root")"
fi
COMPOSE_PROJECT_NAME="$(
betternas_resolve_compose_project_name "$repo_root" "${COMPOSE_PROJECT_NAME:-}" "$BETTERNAS_CLONE_NAME"
)"
read -r default_nextcloud_port default_node_agent_port default_control_plane_port <<<"$(betternas_default_ports "$repo_root" "$BETTERNAS_CLONE_NAME")"
: "${BETTERNAS_CONTROL_PLANE_PORT:=$default_control_plane_port}"
: "${BETTERNAS_NODE_AGENT_PORT:=$default_node_agent_port}"
: "${BETTERNAS_NEXTCLOUD_PORT:=$default_nextcloud_port}"
: "${BETTERNAS_VERSION:=local-dev}"
: "${BETTERNAS_CONTROL_PLANE_CLIENT_TOKEN:=${BETTERNAS_CLONE_NAME}-local-client-token}"
: "${BETTERNAS_CONTROL_PLANE_NODE_BOOTSTRAP_TOKEN:=${BETTERNAS_CLONE_NAME}-local-node-bootstrap-token}"
: "${NEXTCLOUD_ADMIN_USER:=admin}"
: "${NEXTCLOUD_ADMIN_PASSWORD:=admin}"
if [[ -z "${BETTERNAS_EXPORT_PATH:-}" ]]; then
BETTERNAS_EXPORT_PATH="$repo_root/.state/$BETTERNAS_CLONE_NAME/export"
fi
if [[ "$BETTERNAS_EXPORT_PATH" != /* ]]; then
BETTERNAS_EXPORT_PATH="$repo_root/$BETTERNAS_EXPORT_PATH"
fi
: "${BETTERNAS_NODE_DIRECT_ADDRESS:=http://localhost:${BETTERNAS_NODE_AGENT_PORT}}"
: "${BETTERNAS_EXAMPLE_MOUNT_URL:=http://localhost:${BETTERNAS_NODE_AGENT_PORT}/dav/}"
: "${NEXTCLOUD_BASE_URL:=http://localhost:${BETTERNAS_NEXTCLOUD_PORT}}"
export repo_root
export compose_file
export env_file
export BETTERNAS_CLONE_NAME
export COMPOSE_PROJECT_NAME
export BETTERNAS_CONTROL_PLANE_PORT
export BETTERNAS_NODE_AGENT_PORT
export BETTERNAS_NEXTCLOUD_PORT
export BETTERNAS_EXPORT_PATH
export BETTERNAS_VERSION
export BETTERNAS_CONTROL_PLANE_CLIENT_TOKEN
export BETTERNAS_CONTROL_PLANE_NODE_BOOTSTRAP_TOKEN
export NEXTCLOUD_ADMIN_USER
export NEXTCLOUD_ADMIN_PASSWORD
export BETTERNAS_NODE_DIRECT_ADDRESS
export BETTERNAS_EXAMPLE_MOUNT_URL
export NEXTCLOUD_BASE_URL
mkdir -p "$BETTERNAS_EXPORT_PATH"
compose() {
docker compose -f "$compose_file" "$@"
}