Repository Public
1#!/bin/sh2# Installs mcc-agent on a systemd Linux host. Idempotent. Run as root (sudo): it creates the dedicated3# unprivileged user `mcc-agent`; the agent itself never runs as root.4# sudo ./install.sh --binary ./mcc-agent-linux-amd64 --endpoints https://clustr.spboucher.ai \5# --token <one-time token> --ca-fingerprint sha256:<hex>6set -eu7BIN_SRC=""; ENDPOINTS=""; TOKEN=""; FPR=""8while [ $# -gt 0 ]; do9 case "$1" in10 --binary) BIN_SRC=$2; shift 2;;11 --endpoints) ENDPOINTS=$2; shift 2;;12 --token) TOKEN=$2; shift 2;;13 --ca-fingerprint) FPR=$2; shift 2;;14 *) echo "unknown option: $1" >&2; exit 2;;15 esac16done17[ "$(id -u)" -eq 0 ] || { echo "run with sudo" >&2; exit 1; }18HERE=$(cd "$(dirname "$0")" && pwd)19id mcc-agent >/dev/null 2>&1 || useradd --system --home-dir /var/lib/mcc-agent --shell /usr/sbin/nologin mcc-agent20install -d -o mcc-agent -g mcc-agent -m 700 /var/lib/mcc-agent21if [ -n "$BIN_SRC" ]; then22 install -o root -g root -m 755 "$BIN_SRC" /usr/local/bin/mcc-agent.new23 mv -f /usr/local/bin/mcc-agent.new /usr/local/bin/mcc-agent24fi25/usr/local/bin/mcc-agent version26if [ ! -f /var/lib/mcc-agent/identity.json ]; then27 [ -n "$ENDPOINTS" ] && [ -n "$TOKEN" ] && [ -n "$FPR" ] || { echo "--endpoints, --token and --ca-fingerprint are required" >&2; exit 1; }28 runuser -u mcc-agent -- env MCC_ENROLL_TOKEN="$TOKEN" /usr/local/bin/mcc-agent enroll \29 --endpoints "$ENDPOINTS" --ca-fingerprint "$FPR" --state-dir /var/lib/mcc-agent30else31 echo "already enrolled: keeping the existing identity"32fi33install -o root -g root -m 644 "$HERE/mcc-agent.service" /etc/systemd/system/mcc-agent.service34systemctl daemon-reload35systemctl enable --now mcc-agent.service36sleep 337runuser -u mcc-agent -- /usr/local/bin/mcc-agent status --state-dir /var/lib/mcc-agent || true38