Files
web_django_template/scripts/validate-env.sh
T
westfarnandCursor 787f0e48fb Populate the client website template with catalog feature flags.
Extract always-on public/portal/UTM plus optional email_sms, directmail, blog, payments, social, and social_ai so new client sites can be bootstrapped from this seed.

Refs #1
Refs #2

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-26 07:55:26 -05:00

98 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${1:?Usage: $0 <env-file>}"
if [[ ! -f "$ENV_FILE" ]]; then
echo "Environment file not found: $ENV_FILE" >&2
exit 1
fi
set -a
# shellcheck disable=SC1090
source "$ENV_FILE"
set +a
DJANGO_ENV="${DJANGO_ENV:-prod}"
_true() { [[ "${1:-}" =~ ^(1|true|yes|on)$ ]]; }
required_vars=(
DJANGO_SECRET_KEY
DJANGO_ALLOWED_HOSTS
DATABASE_URL
WEB_PORT
)
if [[ "$DJANGO_ENV" == "prod" || "$DJANGO_ENV" == "beta" ]]; then
required_vars+=(
RECAPTCHA_PUBLIC_KEY
RECAPTCHA_PRIVATE_KEY
)
fi
if [[ "$DJANGO_ENV" == "prod" ]]; then
required_vars+=(
SITE_UNDER_CONSTRUCTION
TIANJI_WEBSITE_ID
)
fi
if _true "${FEATURE_EMAIL_SMS:-}"; then
required_vars+=(
EMAIL_HOST_USER
EMAIL_HOST_PASSWORD
SMTP2GO_SMS_API_KEY
SMTP2GO_WEBHOOK_SECRET
)
fi
if _true "${FEATURE_DIRECT_MAIL:-}"; then
required_vars+=(
PCM_API_KEY
PCM_API_SECRET
PCM_WEBHOOK_SECRETS
PCM_RETURN_ADDRESS
)
fi
if _true "${FEATURE_PAYMENTS:-}"; then
required_vars+=(
STRIPE_SECRET_KEY
STRIPE_PUBLISHABLE_KEY
STRIPE_WEBHOOK_SECRET
)
if ! _true "${FEATURE_EMAIL_SMS:-}"; then
echo "FEATURE_PAYMENTS requires FEATURE_EMAIL_SMS" >&2
exit 1
fi
fi
if _true "${FEATURE_SOCIAL:-}"; then
required_vars+=(SOCIAL_TOKEN_ENCRYPTION_KEY)
fi
if _true "${FEATURE_SOCIAL_AI:-}"; then
required_vars+=(OLLAMA_BASE_URL OLLAMA_MODEL)
if ! _true "${FEATURE_SOCIAL:-}"; then
echo "FEATURE_SOCIAL_AI requires FEATURE_SOCIAL" >&2
exit 1
fi
fi
missing=()
for var in "${required_vars[@]}"; do
if [[ -z "${!var:-}" ]]; then
missing+=("$var")
fi
done
if ((${#missing[@]} > 0)); then
echo "Missing required environment variables in $ENV_FILE:" >&2
printf ' - %s\n' "${missing[@]}" >&2
echo "Copy .env.prod.example to ~/Documents/secrets/<slug>_site/<slug>_site_${DJANGO_ENV}.env and set values." >&2
exit 1
fi
if [[ "$DJANGO_ENV" == "prod" && "$DJANGO_SECRET_KEY" == change-me* ]]; then
echo "DJANGO_SECRET_KEY must be changed from the example value for production." >&2
exit 1
fi
echo "Environment validation passed (DJANGO_ENV=$DJANGO_ENV)."