#!/usr/bin/env bash
# ===========================================================================
#  Paper Atlas 1.5 - optional preparation step (Ubuntu / Linux / macOS)
#
#  start.sh already installs everything on demand, so running this file is
#  optional. Use it when you want the (slow) first-time download to finish
#  before you start working, e.g. on a machine with a flaky network.
# ===========================================================================
set -euo pipefail
cd "$(dirname "$0")"

PY=""
for candidate in python3.13 python3.12 python3.11 python3.10 python3.9 python3 python; do
  if command -v "$candidate" >/dev/null 2>&1; then PY="$candidate"; break; fi
done
[ -n "$PY" ] || { echo "Python 3 is required. Try: sudo apt install -y python3 python3-venv"; exit 1; }

echo "==> Preparing the environment (this may take a few minutes the first time)"
"$PY" launcher.py --check || true
"$PY" launcher.py --prepare-only
echo
echo "==> Done. Start the dashboard with:  ./start.sh"