#!/bin/bash
set -e

ENV_FILE=".env"

if [ -f "$ENV_FILE" ]; then
  echo ".env already exists. Overwrite? (y/N)"
  read -r answer
  if [ "$answer" != "y" ] && [ "$answer" != "Y" ]; then
    echo "Aborted."
    exit 0
  fi
fi

echo "Generating .env with random secrets..."

cat > "$ENV_FILE" <<EOF
SESSION_SECRET=$(openssl rand -hex 32)
JWT_SECRET=$(openssl rand -hex 32)
EOF

echo "Created $ENV_FILE"
cat "$ENV_FILE"
