#!/usr/bin/env bash
# Source the correct dotenv for smom-dbis-138 (single source for deploy, relay, token-aggregation).
# Uses repo-root .env unless ENV_FILE is already set. Export ENV_FILE so scripts using
# scripts/lib/deployment/dotenv.sh (load_deployment_env) use the same file.
# Usage: source scripts/load-env.sh   (from smom-dbis-138)
#        source smom-dbis-138/scripts/load-env.sh   (from repo root)
#        ENV_FILE=/path/to/.env source scripts/load-env.sh   (override)
# Do not execute; source it so variables are in the current shell.

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
[[ -z "${ENV_FILE:-}" ]] && ENV_FILE="${SCRIPT_DIR}/../.env"
export ENV_FILE
if [[ -f "$ENV_FILE" ]]; then
  set -a
  source "$ENV_FILE"
  set +a
  echo "Loaded: $ENV_FILE"
else
  echo "WARN: $ENV_FILE not found" >&2
fi
