2026-02-22 22:24:35 +00:00
|
|
|
#!/bin/bash
|
2026-03-13 23:01:51 +00:00
|
|
|
# Build (if needed) and install mcpctl locally.
|
|
|
|
|
# Auto-detects package format: RPM for Fedora/RHEL, DEB for Debian/Ubuntu.
|
|
|
|
|
#
|
|
|
|
|
# Usage:
|
|
|
|
|
# ./installlocal.sh # Build and install for native arch
|
|
|
|
|
# MCPCTL_TARGET_ARCH=amd64 ./installlocal.sh # Cross-compile for amd64
|
2026-02-22 22:24:35 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
|
cd "$SCRIPT_DIR"
|
|
|
|
|
|
2026-03-13 23:01:51 +00:00
|
|
|
# Resolve target architecture
|
|
|
|
|
source scripts/arch-helper.sh
|
|
|
|
|
resolve_arch "${MCPCTL_TARGET_ARCH:-}"
|
2026-02-22 22:24:35 +00:00
|
|
|
|
2026-03-13 23:01:51 +00:00
|
|
|
# Detect package format
|
|
|
|
|
if command -v rpm &>/dev/null && command -v dnf &>/dev/null; then
|
|
|
|
|
PKG_FORMAT="rpm"
|
|
|
|
|
elif command -v dpkg &>/dev/null && command -v apt &>/dev/null; then
|
|
|
|
|
PKG_FORMAT="deb"
|
|
|
|
|
elif command -v rpm &>/dev/null; then
|
|
|
|
|
PKG_FORMAT="rpm"
|
|
|
|
|
else
|
|
|
|
|
echo "Error: Neither rpm/dnf nor dpkg/apt found. Unsupported system."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "==> Detected package format: $PKG_FORMAT (arch: $NFPM_ARCH)"
|
|
|
|
|
|
|
|
|
|
# Find package matching the target architecture
|
2026-03-13 23:16:48 +00:00
|
|
|
# RPM uses x86_64/aarch64, DEB uses amd64/arm64
|
2026-03-13 23:01:51 +00:00
|
|
|
find_pkg() {
|
|
|
|
|
local pattern="$1"
|
2026-03-13 23:16:48 +00:00
|
|
|
ls $pattern 2>/dev/null | grep -E "[._](${NFPM_ARCH}|${RPM_ARCH})[._]" | head -1
|
2026-03-13 23:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [ "$PKG_FORMAT" = "rpm" ]; then
|
|
|
|
|
PKG_FILE=$(find_pkg "dist/mcpctl-*.rpm")
|
|
|
|
|
|
|
|
|
|
# Build if no package exists or if source is newer
|
|
|
|
|
if [[ -z "$PKG_FILE" ]] || [[ $(find src/ -name '*.ts' -newer "$PKG_FILE" 2>/dev/null | head -1) ]]; then
|
2026-02-22 22:24:35 +00:00
|
|
|
echo "==> Building RPM..."
|
|
|
|
|
bash scripts/build-rpm.sh
|
2026-03-13 23:01:51 +00:00
|
|
|
PKG_FILE=$(find_pkg "dist/mcpctl-*.rpm")
|
|
|
|
|
else
|
|
|
|
|
echo "==> RPM is up to date: $PKG_FILE"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "==> Installing $PKG_FILE..."
|
|
|
|
|
sudo rpm -Uvh --force "$PKG_FILE"
|
2026-02-22 22:24:35 +00:00
|
|
|
else
|
2026-03-13 23:01:51 +00:00
|
|
|
PKG_FILE=$(find_pkg "dist/mcpctl*.deb")
|
2026-02-22 22:24:35 +00:00
|
|
|
|
2026-03-13 23:01:51 +00:00
|
|
|
# Build if no package exists or if source is newer
|
|
|
|
|
if [[ -z "$PKG_FILE" ]] || [[ $(find src/ -name '*.ts' -newer "$PKG_FILE" 2>/dev/null | head -1) ]]; then
|
|
|
|
|
echo "==> Building DEB..."
|
|
|
|
|
bash scripts/build-deb.sh
|
|
|
|
|
PKG_FILE=$(find_pkg "dist/mcpctl*.deb")
|
|
|
|
|
else
|
|
|
|
|
echo "==> DEB is up to date: $PKG_FILE"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "==> Installing $PKG_FILE..."
|
|
|
|
|
sudo dpkg -i "$PKG_FILE" || sudo apt-get install -f -y
|
|
|
|
|
fi
|
2026-02-22 22:24:35 +00:00
|
|
|
|
|
|
|
|
echo "==> Reloading systemd user units..."
|
|
|
|
|
systemctl --user daemon-reload
|
|
|
|
|
|
|
|
|
|
echo "==> Done!"
|
|
|
|
|
echo " Enable mcplocal: systemctl --user enable --now mcplocal"
|