#!/usr/bin/env bash set -euo pipefail REPO_DIR="." SECRETS_DIR="$REPO_DIR/data/secrets" RUNTIME_ENV="$SECRETS_DIR/runtime.env" # 1️⃣ Ensure secrets folder mkdir -p "$SECRETS_DIR" # 2️⃣ If runtime.env already exists, source it if [ -f "$RUNTIME_ENV" ]; then echo "♻️ Found existing secrets in $RUNTIME_ENV — reusing." # shellcheck disable=SC1091 source "$RUNTIME_ENV" else echo "🔐 No existing secrets found. Generating new ones…" # generate defaults DB_USER="postgres" DB_PASS="$(openssl rand -hex 16)" DB_NAME="lnbitsdb" FLASK_SECRET="$(openssl rand -hex 32)" DATABASE_URL="postgresql://${DB_USER}:${DB_PASS}@db:5432/${DB_NAME}" cat > "$RUNTIME_ENV" <}" echo " DB_PASS: ${DB_PASS:-}" echo " DB_NAME: ${DB_NAME:-}" echo echo "🔑 Flask session secret:" echo " ${FLASK_SECRET:-}" echo echo "🌐 Open the web UI: http://localhost:3000"