#!/usr/bin/env bash
# Keep CLI installer — the G0 rail:
#   curl -sL https://keep.45-82-56-69.sslip.io/install.sh | sh
# Drops a single-file, stdlib-only `keep` client (no pip, no venv).
set -eu

BASE="${KEEP_URL:-https://keep.45-82-56-69.sslip.io}"
if [ -n "${KEEP_CLI_DEST:-}" ]; then
  DEST="${KEEP_CLI_DEST}"
elif [ -w /usr/local/bin ]; then
  DEST="/usr/local/bin/keep"
else
  DEST="${HOME}/.local/bin/keep"
fi

mkdir -p "$(dirname "$DEST")"
if command -v curl >/dev/null 2>&1; then
  curl -fsSL "${BASE%/}/cli.py" -o "$DEST"
elif command -v wget >/dev/null 2>&1; then
  wget -qO "$DEST" "${BASE%/}/cli.py"
else
  echo "✖ need curl or wget to fetch the keep CLI" >&2
  exit 1
fi
chmod +x "$DEST"

echo "✔ keep installed → $DEST"
"$DEST" version
case ":$PATH:" in
  *":$(dirname "$DEST"):"*) ;;
  *) echo "  note: $(dirname "$DEST") is not on your PATH — add it to use keep" ;;
esac
echo "  next: keep signup <your-lab-name>"
