#!/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" # ── Argument parsing ─────────────────────────────────────────────── BUILD_ALL=false TARGET_ARCH="" SKIP_TESTS=false usage() { cat < Bundling standalone binary for ${arch}..." bun build src/cli/src/index.ts --compile --target="${bun_target}" --outfile "${binary_name}" echo "==> Packaging RPM (${arch})..." # Create a temporary nfpm config with the correct arch and binary path local tmpconfig tmpconfig="$(mktemp /tmp/nfpm-XXXXXX.yaml)" sed -e "s|^arch:.*|arch: ${nfpm_arch}|" \ -e "s|src: ./dist/labctl$|src: ./${binary_name}|" \ nfpm.yaml > "$tmpconfig" nfpm pkg --config "$tmpconfig" --packager rpm --target dist/ rm -f "$tmpconfig" local rpm_arch rpm_arch="$(rpm_arch_for "$arch")" RPM_FILE=$(ls dist/labctl-*.${rpm_arch}.rpm 2>/dev/null | head -1) echo "==> Built: $RPM_FILE" echo " Size: $(du -h "$RPM_FILE" | cut -f1)" echo "" echo "==> Packaging DEB (${arch})..." local deb_arch deb_arch="$(deb_arch_for "$arch")" tmpconfig="$(mktemp /tmp/nfpm-XXXXXX.yaml)" sed -e "s|^arch:.*|arch: ${nfpm_arch}|" \ -e "s|src: ./dist/labctl$|src: ./${binary_name}|" \ nfpm.yaml > "$tmpconfig" nfpm pkg --config "$tmpconfig" --packager deb --target dist/ rm -f "$tmpconfig" DEB_FILE=$(ls dist/labctl_*_${deb_arch}.deb 2>/dev/null | head -1) echo "==> Built: $DEB_FILE" echo " Size: $(du -h "$DEB_FILE" | cut -f1)" } # ── Main ────────────────────────────────────────────────────────── if [ "$SKIP_TESTS" = false ]; then echo "==> Running unit tests..." pnpm test:run echo "" fi echo "==> Building TypeScript..." pnpm build echo "==> Generating shell completions..." pnpm completions:generate mkdir -p dist rm -f dist/labctl dist/labctl-x86_64 dist/labctl-arm64 dist/labctl-*.rpm dist/labctl*.deb if [ "$BUILD_ALL" = true ]; then build_arch "x86_64" build_arch "arm64" elif [ -n "$TARGET_ARCH" ]; then build_arch "$TARGET_ARCH" else # Default to host architecture HOST_ARCH="$(detect_host_arch)" build_arch "$HOST_ARCH" fi echo "" echo "==> Build complete. Artifacts in dist/:" ls -lh dist/labctl* 2>/dev/null || echo " (none)"