#!/usr/bin/env bash # # Generates a .env file with freshly generated secrets. # # ./docs/generate-env.sh # writes ./.env # ./docs/generate-env.sh --print # prints to stdout instead # # Every generated value is hex or base64, neither of which contains "$". # A literal "$" in a value would be read by Docker Compose as a variable # reference and silently dropped, so avoid one if you edit these by hand. set -euo pipefail OUT=".env" PRINT_ONLY=0 for arg in "$@"; do case "$arg" in --print) PRINT_ONLY=1 ;; -h|--help) sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; *) echo "unknown option: $arg" >&2; exit 1 ;; esac done if ! command -v openssl >/dev/null 2>&1; then echo "openssl is required but was not found on PATH." >&2 exit 1 fi if [ "$PRINT_ONLY" -eq 0 ] && { [ -e "$OUT" ] || [ -L "$OUT" ]; }; then echo "$OUT already exists. Move or delete it first, or use --print." >&2 exit 1 fi # ENCRYPTION_KEY must be exactly 64 hex characters; the others are free-form. JWT_SECRET="$(openssl rand -base64 48)" DB_PASSWORD="$(openssl rand -base64 24)" ENCRYPTION_KEY="$(openssl rand -hex 32)" SESSION_SECRET="$(openssl rand -base64 48)" MINIO_SECRET_KEY="$(openssl rand -base64 24)" render() { cat < "$OUT") chmod 600 "$OUT" echo "Wrote $OUT with generated secrets." echo "Edit the BACKEND_URL / PUBLIC_URL lines to match your domain before starting." fi