e5e179e541
Operator can run make bootstrap/install through S2 using nemohermes/openshell wrappers; docs and implement queue updated. No S3+ and no push.
75 lines
2.4 KiB
Bash
75 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
|
# scripts/lib/env.sh — .env validation helpers
|
|
# Sourced by install stages that need environment checks.
|
|
|
|
set -euo pipefail
|
|
|
|
# Required keys for S1. Each entry: "KEY description"
|
|
S1_REQUIRED_KEYS=(
|
|
"LUMINA_SANDBOX Sandbox name (default: hermes)"
|
|
"LUMINA_INFERENCE_BASE_URL OpenAI-compatible inference endpoint base URL"
|
|
"LUMINA_INFERENCE_MODEL Model identifier on the inference endpoint"
|
|
"LUMINA_VISION_MODEL Vision-capable model identifier (may equal LUMINA_INFERENCE_MODEL)"
|
|
)
|
|
|
|
# Optional keys with defaults
|
|
declare -A S1_OPTIONAL_KEYS=(
|
|
["LUMINA_INFERENCE_API_KEY"]="API key for the inference endpoint (empty if endpoint is unauthenticated)"
|
|
["LUMINA_GATEWAY_URL"]="NemoClaw gateway URL (default: https://127.0.0.1:8080)"
|
|
["LUMINA_DASHBOARD_PORT"]="Dashboard port (default: 18789)"
|
|
)
|
|
|
|
# ── Validate .env has all required keys ────────────────────────────────────
|
|
validate_env() {
|
|
local env_file="${1:-${REPO_ROOT}/.env}"
|
|
local missing=0
|
|
|
|
if [[ ! -f "$env_file" ]]; then
|
|
log_error ".env file not found at $env_file"
|
|
log_error "Copy .env.example to .env and fill in values first."
|
|
return 1
|
|
fi
|
|
|
|
for entry in "${S1_REQUIRED_KEYS[@]}"; do
|
|
# Split on first space
|
|
local key="${entry%% *}"
|
|
local desc="${entry#* }"
|
|
if ! grep -q "^${key}=" "$env_file" 2>/dev/null; then
|
|
log_error "Missing required key: $key ($desc)"
|
|
missing=1
|
|
elif grep -qE "^${key}=[[:space:]]*$" "$env_file" 2>/dev/null; then
|
|
log_error "Empty or whitespace-only required key: $key ($desc)"
|
|
missing=1
|
|
fi
|
|
done
|
|
|
|
if [[ $missing -ne 0 ]]; then
|
|
log_error "Fix missing keys in $env_file and re-run."
|
|
return 1
|
|
fi
|
|
|
|
log_info ".env validation passed ($env_file)"
|
|
return 0
|
|
}
|
|
|
|
# ── Create .env from .env.example if it doesn't exist ──────────────────────
|
|
create_env_from_example() {
|
|
local env_file="${1:-${REPO_ROOT}/.env}"
|
|
local example_file="${2:-${REPO_ROOT}/.env.example}"
|
|
|
|
if [[ -f "$env_file" ]]; then
|
|
log_info ".env already exists at $env_file — skipping creation"
|
|
return 0
|
|
fi
|
|
|
|
if [[ ! -f "$example_file" ]]; then
|
|
log_error ".env.example not found at $example_file"
|
|
return 1
|
|
fi
|
|
|
|
cp "$example_file" "$env_file"
|
|
log_info "Created $env_file from .env.example"
|
|
log_warn "Edit $env_file with your actual values before continuing."
|
|
return 0
|
|
}
|