Repository Public
1#!/bin/bash2# install-node.sh — fait d'un nœud MacLustr (M5M36 : Claude Remote + Codex Remote) un OPÉRATEUR DISTANT équivalent au laptop :3# accès SSH à tout le cluster (clé du nœud, IP LAN vivantes, agent persistant + forwarding), outillage cluster-skill4# (mld / mlt / mlmobile dans le PATH, dépôt ~/cluster-skill — jamais sous ~/Desktop, protégé par TCC), auto-approbation Claude Code et Codex comme sur le laptop.5# Les connaissances (CLAUDE.md, mémoire, commandes, MCP) sont poussées par sync-knowledge.sh depuis le laptop.6# Prérequis : la clé publique ~/.ssh/claude_remote_ed25519.pub autorisée partout (autoriser-operateur.sh). Idempotent.7set -uo pipefail8HERE="$(cd "$(dirname "$0")" && pwd)"; STAMP=$(date +%Y%m%d-%H%M%S); U=$(id -u)9LA="$HOME/Library/LaunchAgents"; BIN="$HOME/.maclustr-operator"; mkdir -p "$LA" "$BIN" "$HOME/.ssh"10KEY="$HOME/.ssh/claude_remote_ed25519"; [ -f "$KEY" ] || { echo "clé $KEY absente"; exit 1; }1112echo "== 1. SSH (config, carte LAN, agent persistant)"13cp "$HERE/ssh-refresh.sh" "$HERE/operator-agent.sh" "$BIN/" && chmod +x "$BIN"/*.sh14if ! grep -q "operateur/remote/install-node.sh" "$HOME/.ssh/config" 2>/dev/null; then15 [ -f "$HOME/.ssh/config" ] && cp "$HOME/.ssh/config" "$HOME/.ssh/config.bak-$STAMP-operateur"16fi17cp "$HERE/ssh-config.tmpl" "$HOME/.ssh/config" && chmod 600 "$HOME/.ssh/config"18plist(){ # label, intervalle (0 = KeepAlive), programme19 cat > "$LA/$1.plist" <<P20<?xml version="1.0" encoding="UTF-8"?>21<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">22<plist version="1.0"><dict>23 <key>Label</key><string>$1</string>24 <key>ProgramArguments</key><array><string>/bin/bash</string><string>$3</string></array>25 <key>RunAtLoad</key><true/>26 $( [ "$2" = 0 ] && echo "<key>KeepAlive</key><true/>" || echo "<key>StartInterval</key><integer>$2</integer>" )27 <key>StandardOutPath</key><string>$BIN/$1.log</string>28 <key>StandardErrorPath</key><string>$BIN/$1.log</string>29</dict></plist>30P31 launchctl bootout "gui/$U/$1" 2>/dev/null; launchctl bootstrap "gui/$U" "$LA/$1.plist" 2>/dev/null || launchctl load -w "$LA/$1.plist"32}33plist io.maclustr.operator-ssh-agent 0 "$BIN/operator-agent.sh"34"$BIN/ssh-refresh.sh" || echo " ⚠️ ssh-refresh a échoué"35plist io.maclustr.operator-ssh-refresh 1800 "$BIN/ssh-refresh.sh"36cp "$HERE/offsite-backup.sh" "$HERE/e2e-session.sh" "$BIN/" && chmod +x "$BIN"/*.sh37plist io.maclustr.operator-offsite-backup 86400 "$BIN/offsite-backup.sh"38cp "$HERE/agentd-forward.sh" "$BIN/" && chmod +x "$BIN/agentd-forward.sh"39plist io.maclustr.operator-agentd-forward 0 "$BIN/agentd-forward.sh" # agentd sur 127.0.0.1:9210 (voir agentd-forward.sh)40sleep 2; SSH_AUTH_SOCK="$HOME/.ssh/operator-agent.sock" ssh-add -l 2>&1 | sed 's/^/ agent : /'4142echo "== 2. Environnement shell (~/.zshenv)"43touch "$HOME/.zshenv"44if ! grep -q "maclustr-operator" "$HOME/.zshenv"; then cat >> "$HOME/.zshenv" <<'Z'4546# maclustr-operator (install-node.sh) : agent SSH persistant du nœud quand aucun agent n'est transmis, wrappers cluster47[ -S "${SSH_AUTH_SOCK:-/nonexistent}" ] || export SSH_AUTH_SOCK="$HOME/.ssh/operator-agent.sock"48Z49fi5051echo "== 3. cluster-skill + maclustr-mobile — HORS de ~/Desktop (TCC : un processus lancé par PM2/launchd qui touche ~/Desktop se fige sur une demande d'accès à l'écran)"52for r in cluster-skill maclustr-mobile; do53 D="$HOME/$r"54 if [ -d "$D/.git" ]; then git -C "$D" pull -q --ff-only && echo " $r à jour"; else git clone -q "gitsrv:srv/git/$r.git" "$D" && echo " $r cloné"; fi55done56for w in mld mlt; do printf '#!/bin/bash\n# posé par cluster-skill/operateur/remote/install-node.sh — même outil que sur le laptop\nexec "$HOME/cluster-skill/%s" "$@"\n' $w > /opt/homebrew/bin/$w; chmod +x /opt/homebrew/bin/$w; done57cat > /opt/homebrew/bin/mlmobile <<'MLM'58#!/bin/bash59# posé par cluster-skill/operateur/remote/install-node.sh — coordinateur des iPhones par l'IP LAN de M4M64a60export MLMOBILE_URL="${MLMOBILE_URL:-http://$(/usr/bin/awk '/^Host M4M64a/{f=1} f&&/HostName/{print $2; exit}' "$HOME/.ssh/config-lan"):9320}"61exec /usr/bin/env python3 "$HOME/maclustr-mobile/bin/mlmobile" "$@"62MLM63chmod +x /opt/homebrew/bin/mlmobile64mkdir -p "$HOME/.local/bin"; [ -e "$HOME/.local/bin/uv" ] || ln -s /opt/homebrew/bin/uv "$HOME/.local/bin/uv"6566echo "== 4. Claude Code : auto-approbation comme sur le laptop (hook PreToolUse)"67[ -f "$HOME/.claude/settings.json" ] && cp "$HOME/.claude/settings.json" "$HOME/.claude/settings.json.bak-$STAMP-operateur"68python3 - <<'PY'69import json, os70p = os.path.expanduser("~/.claude/settings.json"); d = json.load(open(p)) if os.path.exists(p) else {}71cmd = "echo '{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"allow\"}}'"72pre = d.setdefault("hooks", {}).setdefault("PreToolUse", [])73if not any(h.get("command") == cmd for g in pre for h in g.get("hooks", [])):74 pre.append({"hooks": [{"type": "command", "command": cmd, "statusMessage": "Auto-approving..."}]})75d["enableAllProjectMcpServers"] = True76json.dump(d, open(p, "w"), indent=2); os.chmod(p, 0o600); print(" settings.json : hook PreToolUse allow en place")77PY7879echo "== 5. Codex : mêmes pouvoirs (aucune demande d'approbation, pas de bac à sable)"80C="$HOME/.codex/config.toml"81if [ -f "$C" ]; then82 cp "$C" "$C.bak-$STAMP-operateur"83 python3 - "$C" <<'PY'84import sys, re85p = sys.argv[1]; s = open(p).read()86head, sep, rest = s.partition("\n[") # clés racine = avant la première table87# check_for_update_on_startup=false : l'invite « Update now » de Codex lance npm install -g ; le 2026-11-17 la 0.169.1 n'avait pas encore son88# binaire darwin-arm64 sur le registre → Codex cassé pour toute nouvelle session. Mettre à jour à la main : npm i -g @openai/codex@<version> && codex --version89for k, v in (("approval_policy", '"never"'), ("sandbox_mode", '"danger-full-access"'), ("check_for_update_on_startup", "false")):90 if re.search(r"(?m)^%s\s*=" % k, head): head = re.sub(r"(?m)^%s\s*=.*$" % k, "%s = %s" % (k, v), head)91 else: head = "%s = %s\n" % (k, v) + head92open(p, "w").write(head + sep + rest); print(" config.toml : approval_policy=never, sandbox_mode=danger-full-access")93PY94fi9596echo "== 6. Vérification"97ok=0; ko=""98for n in $(awk '/^Host /{print $2}' "$HOME/.ssh/config-lan") BHS64; do99 if ssh -o BatchMode=yes -o ConnectTimeout=6 "$n" true 2>/dev/null; then ok=$((ok+1)); else ko="$ko $n"; fi100done101echo " SSH : $ok machines joignables${ko:+ ; injoignables :$ko}"102/opt/homebrew/bin/mld status 2>/dev/null | head -3 | sed 's/^/ mld : /'103echo "terminé"104