#!/usr/bin/env sh # riddler installer: curl -fsSL https://bottom1.com/riddler/install | sh # # Thin on purpose. npm does the hard part; this script only does the two things npm cannot: # check Node's version up front with a useful message, and teach the local coding agent. # # 🔴 Why npm and not a tarball of our own: node-datachannel is a compiled addon. npm resolves # the right prebuilt binary for this platform, arch and Node ABI. A tarball would have to carry # every combination (linux/darwin × x64/arm64 × each Node ABI) or shell out to npm anyway. # # Airgapped or behind a proxy that blocks the registry? Set RIDDLER_DIST to a tarball built by # deploy/pack-peer.sh and this script installs from that instead. set -eu RIDDLER_SERVER="${RIDDLER_SERVER:-https://bottom1.com/riddler}" PKG="${RIDDLER_PKG:-riddler-peer}" DIST="${RIDDLER_DIST:-}" PREFIX="${RIDDLER_PREFIX:-$HOME/.local/riddler}" say() { printf '%s\n' "$*"; } die() { printf 'riddler: %s\n' "$*" >&2; exit 1; } # ── prerequisites ─────────────────────────────────────────────────────────── case "$(uname -s)" in Linux|Darwin) ;; *) die "unsupported platform: $(uname -s). Linux and macOS for now." ;; esac command -v node >/dev/null 2>&1 || die "Node is required. Install Node 22+ from https://nodejs.org" MAJOR=$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0) [ "$MAJOR" -ge 22 ] || die "Node $(node --version) found; riddler needs 22 or newer." if [ -n "$DIST" ]; then # ── offline path: prebuilt tarball ──────────────────────────────────────── command -v curl >/dev/null 2>&1 || die "curl is required to fetch $DIST" TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT say "fetching $DIST ..." curl -fsSL "$DIST" -o "$TMP/r.tar.gz" || die "could not download $DIST" rm -rf "$PREFIX"; mkdir -p "$PREFIX" tar -xzf "$TMP/r.tar.gz" -C "$PREFIX" --strip-components=1 ( cd "$PREFIX" && npm ci --omit=dev --silent ) || die "dependency install failed in $PREFIX" mkdir -p "$HOME/.local/bin" cat > "$HOME/.local/bin/riddler" </dev/null 2>&1 || die "npm is required (it ships with Node)" say "installing $PKG ..." # Global installs fail with EACCES on system-owned prefixes. Say what to do instead of # leaking a wall of npm log paths. npm install -g "$PKG" || die "npm install failed. If that was a permissions error, either fix npm's global prefix: npm config set prefix \"\$HOME/.local\" or install without sudo via a Node manager (nvm, fnm, volta), then re-run this." command -v riddler >/dev/null 2>&1 || die "installed, but 'riddler' is not on PATH. Check: npm bin -g" BIN=riddler fi "$BIN" --help >/dev/null 2>&1 || die "installed, but the binary did not run." # ── teach the agent ───────────────────────────────────────────────────────── # The half npm cannot do. Not a postinstall hook: those are skipped by --ignore-scripts and # disabled outright in many corporate npm configs, and they fail silently when they do. say "" "$BIN" setup-agent || say "WARNING: agent guidance not installed, run 'riddler setup-agent'" say "" say "riddler installed." case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) [ "$BIN" = "riddler" ] || { say 'Add to your shell profile: export PATH="$HOME/.local/bin:$PATH"'; say ""; } ;; esac say "Then one of:" say " riddler join someone sent you an invite" say " riddler login you already have an account" say " riddler signup you don't"