clawdie-iso/scripts/fetch-npm-globals.sh
Sam & Claude b03e740fb7 Pin ISO npm global CLI versions
Use packages/npm-globals.txt as the source of truth for offline npm CLI tarballs, update Pi to 0.75.5, and keep Claude Code out of the XFCE USB path.

---

Build: not run — ISO build not requested

Tests: pass — sh -n fetch-npm-globals and shell-npm-globals; pinned npm pack smoke passed
2026-06-04 20:04:23 +02:00

64 lines
2.2 KiB
Bash
Executable file

#!/bin/sh
# Fetch npm-global CLIs as .tgz tarballs for offline install on the ISO target.
#
# These packages are installed by firstboot with `npm install -g` from local
# tarballs (no network needed on the target). Exact versions are pinned in
# packages/npm-globals.txt to prevent build-to-build drift.
#
# Notes:
# - Codex is shipped via the FreeBSD `codex` pkg (see pkg-list-host.txt),
# not via npm — kept out of this bundle on purpose.
# - Claude Code is intentionally not bundled in the XFCE USB image path.
# - opencode + cursor have no working FreeBSD distribution (upstream gap).
# - Output is dual-purpose: bundled into the ISO and used by firstboot.
#
# Usage:
# ./scripts/fetch-npm-globals.sh # fetch into tmp/npm-globals/
# OUT_DIR=/some/path ./scripts/fetch-npm-globals.sh
# NPM_GLOBALS_LIST=/path/to/list ./scripts/fetch-npm-globals.sh
set -eu
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
OUT_DIR="${OUT_DIR:-${ROOT_DIR}/tmp/npm-globals}"
NPM_GLOBALS_LIST="${NPM_GLOBALS_LIST:-${ROOT_DIR}/packages/npm-globals.txt}"
if ! command -v npm >/dev/null 2>&1; then
echo "ERROR: npm not found in PATH (install www/npm-node24)" >&2
exit 1
fi
if [ ! -f "$NPM_GLOBALS_LIST" ]; then
echo "ERROR: npm globals list not found: $NPM_GLOBALS_LIST" >&2
exit 1
fi
mkdir -p "$OUT_DIR"
cd "$OUT_DIR"
# Keep the bundle deterministic. The output directory is cached across builds,
# so remove old versions and legacy package names before fetching current
# tarballs; otherwise firstboot may install stale CLIs after newer ones.
rm -f ./*.tgz
echo "==> Fetching npm-global tarballs into ${OUT_DIR}"
echo "==> Package list: ${NPM_GLOBALS_LIST}"
while IFS= read -r pkg || [ -n "$pkg" ]; do
case "$pkg" in
''|'#'*) continue ;;
esac
echo " npm pack ${pkg}"
# `npm pack <name>@<version>` downloads the pinned published tarball without
# installing it. Output is `<name>-<version>.tgz` (scoped names get
# their slash flattened to a dash).
npm pack "$pkg" >/dev/null
done < "$NPM_GLOBALS_LIST"
echo ""
echo "==> Bundle contents:"
ls -lh "$OUT_DIR"/*.tgz
TOTAL=$(du -sh "$OUT_DIR" | cut -f1)
echo ""
echo "==> Total size: ${TOTAL}"