diff --git a/scripts/thunder/02-sample-resources.sh b/scripts/thunder/02-sample-resources.sh index e31cdb16..517b5c82 100755 --- a/scripts/thunder/02-sample-resources.sh +++ b/scripts/thunder/02-sample-resources.sh @@ -4,14 +4,54 @@ set -e SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]:-$0}")" source "${SCRIPT_DIR}/common.sh" -# Load .env values when available (useful for local execution). -ENV_FILE="${SCRIPT_DIR}/.env" +# Load values from the single services/.env file (useful for local execution). +ENV_FILE="${SCRIPT_DIR}/../../services/.env" if [[ -f "$ENV_FILE" ]]; then set -a source "$ENV_FILE" set +a fi +# Resolve primary domain. Prefer MAIL_DOMAIN env (set by docker-compose) so the +# script works the same on the host and inside the thunder-setup container. +# Falls back to scanning silver.yaml at a few well-known paths. +MAIL_DOMAIN="${MAIL_DOMAIN:-}" +if [[ -z "${MAIL_DOMAIN}" ]]; then + SILVER_CONF_FILE="" + for candidate in \ + "${SCRIPT_DIR}/silver.yaml" \ + "${SCRIPT_DIR}/../../conf/silver.yaml" \ + "/opt/thunder/bootstrap/silver.yaml"; do + if [[ -f "$candidate" ]]; then + SILVER_CONF_FILE="$candidate" + break + fi + done + if [[ -z "${SILVER_CONF_FILE}" ]]; then + echo "ERROR: Could not locate silver.yaml; set MAIL_DOMAIN or mount conf/silver.yaml" >&2 + exit 1 + fi + MAIL_DOMAIN=$(grep -m 1 '^\s*-\s*domain:' "${SILVER_CONF_FILE}" | sed 's/.*domain:\s*//' | xargs) +fi +if [[ -z "${MAIL_DOMAIN}" ]]; then + echo "ERROR: No domain configured (MAIL_DOMAIN env unset and silver.yaml domain empty)" >&2 + exit 1 +fi + +# Derive a human-readable OU name from the domain (e.g. example.com -> "Example Com"). +DOMAIN_OU_NAME=$(echo "${MAIL_DOMAIN}" | sed 's/\./ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)}1') +DOMAIN_OU_HANDLE="${MAIL_DOMAIN}" +DOMAIN_USER_SCHEMA_NAME="${THUNDER_DOMAIN_USER_SCHEMA_NAME:-Contact}" +CONTACT_USERNAME="${THUNDER_CONTACT_USERNAME:-contact}" +# Contact user password: take THUNDER_SMTP_PASSWORD from services/.env so the +# Thunder user and the SMTP credentials in deployment.yaml stay in sync. +# Falls back to a generated random value if the env var is empty. +CONTACT_PASSWORD="${THUNDER_SMTP_PASSWORD:-}" +if [[ -z "${CONTACT_PASSWORD}" ]]; then + CONTACT_PASSWORD=$(LC_ALL=C tr -dc 'A-Za-z0-9'