layered-soul/skills/iso-visuals/scripts/clawdie-join-hive.sh

71 lines
2.2 KiB
Bash
Raw Normal View History

#!/bin/sh
# One-click "Join Hive" — registers this machine as a Colibri agent.
# Runs in a visible terminal so the operator sees the result.
# Idempotent: safe to re-run on an already-registered agent.
set -e
SOCKET="${COLIBRI_SOCKET:-/var/run/colibri/colibri.sock}"
PROVIDER_ENV="/usr/local/etc/colibri/provider.env"
echo "========================================"
echo " Clawdie — Join Hive"
echo "========================================"
echo ""
# 1. Check daemon
if [ ! -S "$SOCKET" ]; then
echo "[1/4] Starting colibri daemon..."
mdo -u root service colibri_daemon start
sleep 2
else
echo "[1/4] Daemon already running."
fi
# 2. Vault creds
echo "[2/4] Checking vault credentials..."
if [ -f "$PROVIDER_ENV" ] && grep -q 'BW_CLIENTID=.' "$PROVIDER_ENV" 2>/dev/null; then
echo " provider.env present with credentials."
else
echo " WARNING: provider.env missing or empty."
echo " Vault provisioning will be skipped."
echo " Edit ${PROVIDER_ENV} and re-run."
fi
# 3. Detect capabilities
HOST=$(hostname)
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
CAPS="$OS,shell"
# Add optional capabilities
which colibri >/dev/null 2>&1 && CAPS="$CAPS,colibri"
which hermes >/dev/null 2>&1 && CAPS="$CAPS,hermes"
which pi >/dev/null 2>&1 && CAPS="$CAPS,pi"
tailscale status >/dev/null 2>&1 && CAPS="$CAPS,tailscale"
[ "$OS" = "freebsd" ] && CAPS="$CAPS,rc.d,jail,zfs"
AGENT_NAME="${HOST}"
echo "[3/4] Registering agent: ${AGENT_NAME}"
echo " capabilities: ${CAPS}"
RESP=$(printf '{"cmd":"register-agent","name":"%s","capabilities":%s}\n' \
"$AGENT_NAME" "$(echo "$CAPS" | python3 -c "import sys; print(__import__('json').dumps(sys.stdin.read().strip().split(',')))")" \
| nc -U "$SOCKET" -w 3 2>/dev/null)
if echo "$RESP" | grep -q '"ok":true'; then
echo " registered."
elif echo "$RESP" | grep -q 'already exists'; then
echo " already registered (idempotent)."
else
echo " registration note: ${RESP}"
fi
# 4. Start poll loop
echo "[4/4] Agent ${AGENT_NAME} is live on the Colibri board."
echo ""
echo " Check: colibri status"
echo " Tasks: colibri list-tasks --status started"
echo " Board: colibri list-agents"
echo ""
echo "Hive joined. Press Enter to close."
read -r _