#!/bin/sh
# Install the paddock CLI: curl -fsSL https://paddock.ailio.dev/install.sh | sh
# It installs the npm package from GitHub at a release tag, then checks what
# else paddock uses. PADDOCK_VERSION picks another release.
set -eu

version="${PADDOCK_VERSION:-0.1.0}"
say() { printf '%s\n' "$*"; }
warn() { printf 'paddock: %s\n' "$*" >&2; }

command -v node >/dev/null 2>&1 || { warn "Node.js 22 or newer is required (https://nodejs.org)."; exit 1; }
major=$(node -p 'process.versions.node.split(".")[0]')
[ "$major" -ge 22 ] || { warn "Node.js 22 or newer is required; this is $(node -v)."; exit 1; }
command -v npm >/dev/null 2>&1 || { warn "npm is required."; exit 1; }

say "==> Installing paddock $version"
npm install -g "github:ailio-technologies-inc/paddock#v$version"

command -v docker >/dev/null 2>&1 || say "    note: Docker is needed on machines that run spaces (paddock up)."
command -v ffmpeg >/dev/null 2>&1 || say "    note: ffmpeg is needed to watch spaces in a terminal (paddock watch)."
command -v tailscale >/dev/null 2>&1 || say "    note: Tailscale lets other machines reach your spaces (paddock up --tailnet)."

say "==> paddock $(paddock --version) installed. Next: paddock up <space> --tailnet"
