#!/bin/bash # Déploie maclustr-agentd sur le nœud hôte (AGENT_HOST) : # - clé SSH dédiée id_ed25519_agentd (générée si absente) autorisée sur tous les nœuds # - marqueurs ~/.maclustr-node partout # - agent + config + lanmap + launchd set -euo pipefail DIR="$(cd "$(dirname "$0")" && pwd)" AGENT_HOST="${AGENT_HOST:-M4M64a}" ALL_NODES="M3U96a M3U96b M2U64 M4M64a M4M64b M4BP48 M4BP36 M4M36 M2M32 M2M32b M2M32c m4mc M1M32 m4ma m4mb m2m16 M3BA24 M3BA16 m2m8a m2m8b" echo ">> clé dédiée sur $AGENT_HOST" ssh "$AGENT_HOST" '[ -f ~/.ssh/id_ed25519_agentd ] || ssh-keygen -t ed25519 -N "" -C "maclustr-agentd" -f ~/.ssh/id_ed25519_agentd -q' PUB=$(ssh "$AGENT_HOST" 'cat ~/.ssh/id_ed25519_agentd.pub') echo ">> autorisation de la clé + marqueur sur chaque nœud" for n in $ALL_NODES; do (ssh -o ConnectTimeout=6 "$n" "mkdir -p ~/.ssh && chmod 700 ~/.ssh grep -qF '$PUB' ~/.ssh/authorized_keys 2>/dev/null || echo '$PUB' >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys echo $n > ~/.maclustr-node" 2>/dev/null \ && echo " $n ok" || echo " $n INJOIGNABLE") & done wait echo ">> agent -> $AGENT_HOST:~/maclustr-agentd/" ssh "$AGENT_HOST" "mkdir -p ~/maclustr-agentd" scp -q "$DIR/agentd.py" "$DIR/config.json" M4M64a:~/maclustr-agentd/ 2>/dev/null || scp -q "$DIR/agentd.py" "$DIR/config.json" "$AGENT_HOST":~/maclustr-agentd/ [ -f "$DIR/lanmap.json" ] && scp -q "$DIR/lanmap.json" "$AGENT_HOST":~/maclustr-agentd/ scp -q "$DIR/io.maclustr.agentd.plist" "$AGENT_HOST":/tmp/io.maclustr.agentd.plist ssh "$AGENT_HOST" 'chmod 600 ~/maclustr-agentd/config.json PY=$(command -v /opt/homebrew/bin/python3 || command -v /usr/bin/python3) /usr/bin/sed -i "" "s|/opt/homebrew/bin/python3|$PY|" /tmp/io.maclustr.agentd.plist mkdir -p ~/Library/LaunchAgents cp /tmp/io.maclustr.agentd.plist ~/Library/LaunchAgents/ launchctl bootout gui/$(id -u)/io.maclustr.agentd 2>/dev/null || true launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/io.maclustr.agentd.plist sleep 2 launchctl print gui/$(id -u)/io.maclustr.agentd | grep -E "state|pid" | head -3' echo ">> déployé sur $AGENT_HOST."