54 lines
1.3 KiB
Bash
Raw Normal View History

2025-05-14 15:57:34 +00:00
#!/usr/bin/env bash
set -euo pipefail
2025-05-14 16:11:40 +00:00
REPO_DIR="."
2025-05-14 15:57:34 +00:00
SECRETS_DIR="$REPO_DIR/data/secrets"
RUNTIME_ENV="$SECRETS_DIR/runtime.env"
2025-05-14 16:17:35 +00:00
# 1⃣ Ensure secrets folder
2025-05-14 15:57:34 +00:00
mkdir -p "$SECRETS_DIR"
2025-05-14 16:17:35 +00:00
# 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…"
2025-05-14 15:57:34 +00:00
2025-05-14 16:17:35 +00:00
# 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" <<EOF
2025-05-14 15:57:34 +00:00
DB_USER=${DB_USER}
DB_PASS=${DB_PASS}
DB_NAME=${DB_NAME}
DATABASE_URL=${DATABASE_URL}
FLASK_SECRET=${FLASK_SECRET}
EOF
2025-05-14 16:17:35 +00:00
echo "✅ Generated new secrets in $RUNTIME_ENV"
fi
2025-05-14 15:57:34 +00:00
2025-05-14 16:17:35 +00:00
# 3⃣ Build & run
cd "$REPO_DIR"
2025-05-14 15:57:34 +00:00
docker-compose up -d --build
2025-05-14 16:17:35 +00:00
# 4⃣ Show the values back to the user
echo
echo "🚀 Services are up!"
2025-05-14 15:57:34 +00:00
echo
2025-05-14 16:17:35 +00:00
echo "🔐 Database credentials (from $RUNTIME_ENV):"
echo " DB_USER: ${DB_USER:-<missing>}"
echo " DB_PASS: ${DB_PASS:-<missing>}"
echo " DB_NAME: ${DB_NAME:-<missing>}"
2025-05-14 15:57:34 +00:00
echo
2025-05-14 16:17:35 +00:00
echo "🔑 Flask session secret:"
echo " ${FLASK_SECRET:-<missing>}"
2025-05-14 15:57:34 +00:00
echo
2025-05-14 16:17:35 +00:00
echo "🌐 Open the web UI: http://localhost:3000"