Template
## Summary - Closes #5 - Optional `shop`, `pos_sync`, `events`, and `shipping` apps gated by `FEATURE_*` flags - Deps match the catalog: shop/events need email + Stripe; POS/shipping need shop - Portal inventory, POS webhooks, capacity tickets, EasyPost/Pirate Ship shipping ## Test plan - [ ] `manage.py test` (152 passed locally) - [ ] Shop cart + paid order decrements stocked inventory - [ ] POS inbound webhook decrements SKU; paid order queues outbound reserve - [ ] Event capacity blocks overbook; paid order emails ticket codes - [ ] Shipping stub label + Pirate Ship CSV of unshipped paid orders - [ ] `validate-env.sh` rejects shop without email/payments, POS/shipping without shop Reviewed-on: #6
141 lines
3.3 KiB
Bash
Executable File
141 lines
3.3 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_EMAIL_SMS:-}" || _true "${FEATURE_DIRECT_MAIL:-}"; then
|
|
if [[ "$DJANGO_ENV" == "prod" || "$DJANGO_ENV" == "beta" ]]; then
|
|
required_vars+=(
|
|
SHORTENER_BASE_URL
|
|
SHORTENER_API_TOKEN
|
|
)
|
|
fi
|
|
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
|
|
if _true "${FEATURE_SHOP:-}"; then
|
|
if ! _true "${FEATURE_EMAIL_SMS:-}"; then
|
|
echo "FEATURE_SHOP requires FEATURE_EMAIL_SMS" >&2
|
|
exit 1
|
|
fi
|
|
if ! _true "${FEATURE_PAYMENTS:-}"; then
|
|
echo "FEATURE_SHOP requires FEATURE_PAYMENTS" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
if _true "${FEATURE_POS_SYNC:-}"; then
|
|
if ! _true "${FEATURE_SHOP:-}"; then
|
|
echo "FEATURE_POS_SYNC requires FEATURE_SHOP" >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$DJANGO_ENV" == "prod" || "$DJANGO_ENV" == "beta" ]]; then
|
|
required_vars+=(POS_WEBHOOK_SECRET)
|
|
fi
|
|
fi
|
|
if _true "${FEATURE_EVENTS:-}"; then
|
|
if ! _true "${FEATURE_EMAIL_SMS:-}"; then
|
|
echo "FEATURE_EVENTS requires FEATURE_EMAIL_SMS" >&2
|
|
exit 1
|
|
fi
|
|
if ! _true "${FEATURE_PAYMENTS:-}"; then
|
|
echo "FEATURE_EVENTS requires FEATURE_PAYMENTS" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
if _true "${FEATURE_SHIPPING:-}"; then
|
|
if ! _true "${FEATURE_SHOP:-}"; then
|
|
echo "FEATURE_SHIPPING requires FEATURE_SHOP" >&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)."
|