From c7c9f0923f993b0ddd9b765834882dc5e347ee0d Mon Sep 17 00:00:00 2001 From: Michal Rydlikowski Date: Fri, 13 Mar 2026 23:11:35 +0000 Subject: [PATCH] feat: auto-install missing build dependencies (pnpm, bun, nfpm) Build scripts now check for required tools before building and install them automatically if missing. Handles both amd64 and arm64 host systems. - pnpm: installed via corepack or npm - bun: installed via official install script - nfpm: downloaded from GitHub for the correct host architecture - node_modules: runs pnpm install if missing Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/build-deb.sh | 4 ++ scripts/build-rpm.sh | 4 ++ scripts/ensure-deps.sh | 120 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 scripts/ensure-deps.sh diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index 812171b..bc83c22 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -19,6 +19,10 @@ source "$SCRIPT_DIR/arch-helper.sh" resolve_arch "${MCPCTL_TARGET_ARCH:-}" # Sets: NFPM_ARCH, BUN_TARGET, ARCH_SUFFIX +# Check and install missing build dependencies +source "$SCRIPT_DIR/ensure-deps.sh" +ensure_build_deps + # Check if binaries already exist (build-rpm.sh may have been run first) if [ ! -f "dist/mcpctl${ARCH_SUFFIX}" ] || [ ! -f "dist/mcpctl-local${ARCH_SUFFIX}" ]; then echo "==> Binaries not found, building from scratch..." diff --git a/scripts/build-rpm.sh b/scripts/build-rpm.sh index b5d9a45..1f72996 100755 --- a/scripts/build-rpm.sh +++ b/scripts/build-rpm.sh @@ -19,6 +19,10 @@ source "$SCRIPT_DIR/arch-helper.sh" resolve_arch "${MCPCTL_TARGET_ARCH:-}" # Sets: NFPM_ARCH, BUN_TARGET, ARCH_SUFFIX +# Check and install missing build dependencies +source "$SCRIPT_DIR/ensure-deps.sh" +ensure_build_deps + echo "==> Running unit tests..." pnpm test:run echo "" diff --git a/scripts/ensure-deps.sh b/scripts/ensure-deps.sh new file mode 100644 index 0000000..2f9bf43 --- /dev/null +++ b/scripts/ensure-deps.sh @@ -0,0 +1,120 @@ +#!/bin/bash +# Ensure build dependencies are installed. +# Source this file from build scripts: source "$SCRIPT_DIR/ensure-deps.sh" +# +# Checks for: node, pnpm, bun, nfpm +# Auto-installs missing tools. Uses npm for pnpm/bun, downloads nfpm binary. + +NFPM_VERSION="${NFPM_VERSION:-2.45.0}" + +_ensure_node() { + if command -v node &>/dev/null; then + return + fi + + echo "ERROR: Node.js is required but not installed." + if command -v dnf &>/dev/null; then + echo " Install with: sudo dnf install nodejs" + elif command -v apt &>/dev/null; then + echo " Install with: sudo apt install nodejs npm" + else + echo " Install from: https://nodejs.org/" + fi + exit 1 +} + +_ensure_pnpm() { + if command -v pnpm &>/dev/null; then + return + fi + + echo "==> pnpm not found, installing..." + if command -v corepack &>/dev/null; then + corepack enable + corepack prepare pnpm@9.15.0 --activate + else + npm install -g pnpm + fi + + # Verify + if ! command -v pnpm &>/dev/null; then + echo "ERROR: pnpm installation failed." + echo " Try manually: npm install -g pnpm" + exit 1 + fi + echo " Installed pnpm $(pnpm --version)" +} + +_ensure_bun() { + if command -v bun &>/dev/null; then + return + fi + + echo "==> bun not found, installing..." + # bun's official install script handles both amd64 and arm64 + curl -fsSL https://bun.sh/install | bash + + # Add to PATH for this session + export PATH="$HOME/.bun/bin:$PATH" + + if ! command -v bun &>/dev/null; then + echo "ERROR: bun installation failed." + echo " Try manually: curl -fsSL https://bun.sh/install | bash" + exit 1 + fi + echo " Installed bun $(bun --version)" +} + +_ensure_nfpm() { + if command -v nfpm &>/dev/null; then + return + fi + + echo "==> nfpm not found, installing v${NFPM_VERSION}..." + + # Detect host arch for the nfpm binary itself (not the target arch) + local dl_arch + case "$(uname -m)" in + x86_64) dl_arch="x86_64" ;; + aarch64) dl_arch="arm64" ;; + arm64) dl_arch="arm64" ;; + *) dl_arch="x86_64" ;; + esac + + local url="https://github.com/goreleaser/nfpm/releases/download/v${NFPM_VERSION}/nfpm_${NFPM_VERSION}_Linux_${dl_arch}.tar.gz" + local install_dir="$HOME/.local/bin" + mkdir -p "$install_dir" + + curl -sL -o /tmp/nfpm.tar.gz "$url" + tar xzf /tmp/nfpm.tar.gz -C "$install_dir" nfpm + rm -f /tmp/nfpm.tar.gz + + export PATH="$install_dir:$PATH" + + if ! command -v nfpm &>/dev/null; then + echo "ERROR: nfpm installation failed." + echo " Download manually from: https://github.com/goreleaser/nfpm/releases" + exit 1 + fi + echo " Installed nfpm $(nfpm --version) to $install_dir" +} + +_ensure_npm_deps() { + if [ -d node_modules ]; then + return + fi + + echo "==> node_modules not found, running pnpm install..." + pnpm install --frozen-lockfile +} + +ensure_build_deps() { + echo "==> Checking build dependencies..." + _ensure_node + _ensure_pnpm + _ensure_bun + _ensure_nfpm + _ensure_npm_deps + echo " All build dependencies OK" + echo "" +}