Files
mcpctl/scripts/build-deb.sh

71 lines
2.4 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
cd "$PROJECT_ROOT"
# Load .env if present
if [ -f .env ]; then
set -a; source .env; set +a
fi
# Ensure tools are on PATH
export PATH="$HOME/.npm-global/bin:$HOME/.bun/bin:$HOME/.local/bin:$PATH"
# Architecture detection / cross-compilation support
# MCPCTL_TARGET_ARCH overrides native detection (e.g. "amd64" or "arm64")
source "$SCRIPT_DIR/arch-helper.sh"
resolve_arch "${MCPCTL_TARGET_ARCH:-}"
# Sets: NFPM_ARCH, BUN_TARGET, ARCH_SUFFIX
# 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..."
echo ""
echo "==> Running unit tests..."
pnpm test:run
echo ""
echo "==> Building TypeScript..."
pnpm build
echo "==> Generating shell completions..."
pnpm completions:generate
echo "==> Bundling standalone binaries (target: ${NFPM_ARCH})..."
mkdir -p dist
# Ink optionally imports react-devtools-core which isn't installed.
# Provide a no-op stub so bun can bundle it (it's only invoked when DEV=true).
if [ ! -e node_modules/react-devtools-core ]; then
ln -s ../src/cli/stubs/react-devtools-core node_modules/react-devtools-core
fi
bun build src/cli/src/index.ts --compile ${BUN_TARGET:+--target "$BUN_TARGET"} --outfile "dist/mcpctl${ARCH_SUFFIX}"
bun build src/mcplocal/src/main.ts --compile ${BUN_TARGET:+--target "$BUN_TARGET"} --outfile "dist/mcpctl-local${ARCH_SUFFIX}"
else
echo "==> Using existing binaries in dist/"
fi
# If cross-compiling, copy arch-suffixed binaries to the names nfpm expects
if [ -n "$ARCH_SUFFIX" ]; then
cp "dist/mcpctl${ARCH_SUFFIX}" dist/mcpctl
cp "dist/mcpctl-local${ARCH_SUFFIX}" dist/mcpctl-local
fi
echo "==> Packaging DEB (arch: ${NFPM_ARCH})..."
# Only remove DEBs for the target arch (preserve cross-compiled packages)
ls dist/mcpctl*_${NFPM_ARCH}.deb 2>/dev/null | xargs -r rm -f
export NFPM_ARCH
nfpm pkg --packager deb --target dist/
DEB_FILE=$(ls dist/mcpctl*.deb 2>/dev/null | grep -E "[._]${NFPM_ARCH}[._]" | head -1)
echo "==> Built: $DEB_FILE"
echo " Size: $(du -h "$DEB_FILE" | cut -f1)"
# dpkg-deb may not be available on RPM-based systems (Fedora)
if command -v dpkg-deb &>/dev/null; then
dpkg-deb --info "$DEB_FILE" 2>/dev/null || true
fi