SPB Git

Repository Public

rollout-agents.sh 3.2 KB 40 lines shellscript

1#!/bin/bash2# Installs / enrolls mcc-agent on cluster Macs, one node at a time, and verifies each before the next.3#   rollout-agents.sh <alias>[@<lan-ip>] ...4# "<alias>" is reached directly by SSH from this machine; "<alias>@<lan-ip>" is reached through the gateway5# (M1M32) on the LAN. Before installing through the gateway, the node's own marker (~/.maclustr-node) must6# equal the alias: an address is never trusted as an identity (DHCP renumbering has happened).7# Options (env): HOST=M4M64c (control-plane host), DAEMON="M2U64" (aliases installed as LaunchDaemon).8set -uo pipefail9ROOT="$(cd "$(dirname "$0")/../.." && pwd)"; HOST="${HOST:-M4M64c}"; GW="${GW:-M1M32}"; DAEMON=" ${DAEMON:-M2U64} "10BIN="$ROOT/dist/mcc-agent-darwin-arm64"; [ -x "$BIN" ] || { echo "build agents first (agents/build.sh)"; exit 1; }11SSHO="-o BatchMode=yes -o ConnectTimeout=10"12ok=(); failed=()13for spec in "$@"; do14  alias="${spec%%@*}"; ip=""; [ "$spec" != "$alias" ] && ip="${spec##*@}"15  echo "── $alias ${ip:+(via $GW → $ip)}"16  mode=""; case "$DAEMON" in *" $alias "*) mode="--daemon";; esac17  if [ -z "$ip" ]; then18    run() { ssh $SSHO "$alias" "$@"; }19    push() { ssh $SSHO "$alias" 'rm -rf /tmp/mcc-install && mkdir -p /tmp/mcc-install' && scp -q $SSHO "$BIN" "$ROOT"/agents/macos/install.sh "$ROOT"/agents/macos/*.tmpl "$alias":/tmp/mcc-install/; }20  else21    KH="-o UserKnownHostsFile=/tmp/mcc-rollout-kh -o StrictHostKeyChecking=accept-new -o LogLevel=ERROR"22    run() { ssh $SSHO "$GW" "ssh $SSHO $KH $ip $(printf '%q' "$*")"; }23    push() { ssh $SSHO "$GW" 'rm -rf /tmp/mcc-install-src && mkdir -p /tmp/mcc-install-src' && scp -q $SSHO "$BIN" "$ROOT"/agents/macos/install.sh "$ROOT"/agents/macos/*.tmpl "$GW":/tmp/mcc-install-src/ \24      && ssh $SSHO "$GW" "ssh $SSHO $KH $ip 'rm -rf /tmp/mcc-install' && scp -q $SSHO $KH -r /tmp/mcc-install-src $ip:/tmp/mcc-install"; }25    marker="$(run 'cat ~/.maclustr-node 2>/dev/null' | tr -d '[:space:]')"26    if [ "$marker" != "$alias" ]; then echo "   SKIP: the machine at $ip identifies as '${marker:-?}', not '$alias'"; failed+=("$alias"); continue; fi27  fi28  if run 'test -f ~/.mcc-agent/agent.crt || test -f ~/.mcc-agent/identity.json' 2>/dev/null; then echo "   already enrolled — reinstalling binary only"; TOK=""; FP=""; else29    read -r TOK FP < <(ssh $SSHO "$HOST" "cd ~/apps/maclustr-command-center && scripts/mccctl enroll-token --alias '$alias' --quiet") || true30    [ -n "${TOK:-}" ] || { echo "   FAIL: no enrollment token"; failed+=("$alias"); continue; }31  fi32  push || { echo "   FAIL: copy"; failed+=("$alias"); continue; }33  if [ -n "$TOK" ]; then args="--endpoints https://clustr.spboucher.ai --token $TOK --ca-fingerprint $FP"; else args=""; fi34  out="$(run "cd /tmp/mcc-install && sh install.sh --binary ./mcc-agent-darwin-arm64 $args $mode 2>&1 | tail -6; rm -rf /tmp/mcc-install")"35  if echo "$out" | grep -q "connection   online"; then echo "   OK  $(echo "$out" | grep -E '^last report' | head -1)"; ok+=("$alias"); else echo "$out" | sed 's/^/   | /'; failed+=("$alias"); fi36done37[ -n "${GW:-}" ] && ssh $SSHO "$GW" 'rm -rf /tmp/mcc-install-src /tmp/mcc-rollout-kh' 2>/dev/null38echo; echo "enrolled/updated: ${ok[*]:-none}"; echo "failed: ${failed[*]:-none}"39[ ${#failed[@]} -eq 0 ]40
Files main
Menu

Theme