#!/usr/bin/env bash # Install from caches filled by download-deps.sh. Unpacks the official Node # archive into .offline-cache/node/runtime and prepends it to PATH so the # offline machine does not need a system Node. Fails if any lockfile package # is missing from .offline-store (no registry access). # # Usage (repo root): bash scripts/offline/install-deps.sh [--build] set -euo pipefail ROOT="$(cd "$(dirname "$0")/../.." && pwd)" cd "$ROOT" BUILD=0 for arg in "$@"; do case "$arg" in --build) BUILD=1 ;; *) echo "Unknown argument: $arg (expected --build)" >&2 exit 1 ;; esac done NODE_CACHE="$ROOT/.offline-cache/node" META_PATH="$NODE_CACHE/runtime.json" if [[ ! -f "$META_PATH" ]]; then echo "Missing $META_PATH. Run scripts/offline/download-deps.sh on a networked machine first, then copy the checkout." >&2 exit 1 fi NODE_VERSION="$(sed -n 's/.*"version":"\([^"]*\)".*/\1/p' "$META_PATH" | head -n 1)" ARCHIVE_NAME="$(sed -n 's/.*"archive":"\([^"]*\)".*/\1/p' "$META_PATH" | head -n 1)" PLATFORM="$(sed -n 's/.*"platform":"\([^"]*\)".*/\1/p' "$META_PATH" | head -n 1)" ARCHIVE_PATH="$NODE_CACHE/$ARCHIVE_NAME" RUNTIME_DIR="$NODE_CACHE/runtime" NODE_PREFIX="$RUNTIME_DIR/node-v${NODE_VERSION}-${PLATFORM}" if [[ ! -x "$NODE_PREFIX/bin/node" ]]; then if [[ ! -f "$ARCHIVE_PATH" ]]; then echo "Missing Node archive $ARCHIVE_PATH. Re-run download-deps.sh." >&2 exit 1 fi rm -rf "$RUNTIME_DIR" mkdir -p "$RUNTIME_DIR" case "$ARCHIVE_PATH" in *.tar.xz) tar -xJf "$ARCHIVE_PATH" -C "$RUNTIME_DIR" ;; *.tar.gz) tar -xzf "$ARCHIVE_PATH" -C "$RUNTIME_DIR" ;; *.zip) unzip -q "$ARCHIVE_PATH" -d "$RUNTIME_DIR" ;; *) echo "Unknown Node archive: $ARCHIVE_PATH" >&2 exit 1 ;; esac fi if [[ ! -x "$NODE_PREFIX/bin/node" ]]; then echo "Unpacked Node is missing: $NODE_PREFIX/bin/node" >&2 exit 1 fi export PATH="$NODE_PREFIX/bin:$PATH" STORE_DIR="$ROOT/.offline-store" COREPACK_HOME="$ROOT/.offline-cache/corepack" if [[ ! -d "$STORE_DIR" ]]; then echo "Missing $STORE_DIR. Run scripts/offline/download-deps.sh on a networked machine first, then copy the checkout." >&2 exit 1 fi if [[ ! -d "$COREPACK_HOME" ]]; then echo "Missing $COREPACK_HOME. Re-run download-deps.sh so Corepack pnpm is cached in-repo." >&2 exit 1 fi export COREPACK_HOME export COREPACK_ENABLE_NETWORK=0 PACKAGE_MANAGER="$(sed -n 's/.*"packageManager": "\(pnpm@[0-9.]*\)".*/\1/p' package.json | head -n 1)" echo "Offline install $PACKAGE_MANAGER from $STORE_DIR (Node $(node --version))" corepack pnpm install --offline --frozen-lockfile --store-dir "$STORE_DIR" if [[ "$BUILD" -eq 1 ]]; then echo 'Building host/client libs, then the web frontend' npm run build:lib corepack pnpm --dir apps/web run build echo "Build complete. Start the UI with: $NODE_PREFIX/bin/corepack pnpm dsh web" else echo 'Install complete. For dsh web also run: bash scripts/offline/install-deps.sh --build' fi