#!/usr/bin/env bash # # Lighting MVP one-time setup script. # # Generates a .env file with the minimum required environment variables. # Read HANDOVER.md before running this; it explains what the values mean # and which optional settings you may want to add. # # Usage: # scripts/setup.sh # writes .env if missing # scripts/setup.sh --force # overwrite existing .env (regenerates password) # scripts/setup.sh --print # print to stdout, don't write # set -euo pipefail force=false print_only=false for arg in "$@"; do case "$arg" in --force) force=true ;; --print) print_only=true ;; -h|--help) sed -n '3,15p' "$0" exit 0 ;; *) echo "Unknown argument: $arg" >&2 echo "Use --help for usage." >&2 exit 2 ;; esac done REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" ENV_FILE="$REPO_ROOT/.env" if [[ -f "$ENV_FILE" && "$force" == false && "$print_only" == false ]]; then echo "$ENV_FILE already exists. Pass --force to overwrite, or --print to dump a fresh template to stdout." >&2 exit 1 fi # Generate a strong random password. Falls back to /dev/urandom if openssl is # missing so the script works on minimal containers. if command -v openssl >/dev/null 2>&1; then ACCESS_PASSWORD="$(openssl rand -base64 24 | tr -d '/+=' | cut -c1-24)" else ACCESS_PASSWORD="$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 24)" fi env_contents=$(cat < "$ENV_FILE" chmod 600 "$ENV_FILE" echo "Wrote $ENV_FILE (mode 0600)." echo echo "Next steps:" echo " 1. docker build -t lighting-mvp ." echo " 2. docker run --rm -p 7860:7860 --env-file .env lighting-mvp" echo " 3. Open http://localhost:7860 and log in with the password in .env" echo " 4. Click the gear icon (⚙) to complete the Claude or Codex login flow." echo echo "Full walkthrough: HANDOVER.md"