#!/usr/bin/env bash # Install/refresh the host-side library capture agent. # # The agent is the only component with the Docker socket and the source # credentials. It runs as this user (no root), listens on one 0600 unix socket and # executes the fixed capture command with the declaration below. Containers get # the socket path only. set -euo pipefail ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) UNIT_DIR="$HOME/.config/systemd/user" SOCKET_DIR="$HOME/.local/share/knowledge-governance/agent" mkdir -p "$UNIT_DIR" "$SOCKET_DIR" chmod 700 "$SOCKET_DIR" echo "=== build libraryctl + libraryagent ===" (cd "$ROOT" && go build -o libraryctl ./cmd/libraryctl && go build -o libraryagent ./cmd/libraryagent) echo "=== systemd user unit ===" cat > "$UNIT_DIR/knowledge-governance-library-agent.service" </dev/null systemctl --user restart knowledge-governance-library-agent.service # Keep the agent running when no login session is open (it owns no privilege # beyond this account, but a stopped agent means the page cannot capture). loginctl enable-linger "$(id -un)" >/dev/null 2>&1 || echo " WARN: enable-linger failed; agent stops with the last session" echo "=== read back ===" for _ in $(seq 1 30); do if [ -S "$SOCKET_DIR/agent.sock" ]; then break; fi sleep 0.2 done [ -S "$SOCKET_DIR/agent.sock" ] || { echo "AGENT_SOCKET_MISSING"; exit 1; } stat -c '%A %n' "$SOCKET_DIR" "$SOCKET_DIR/agent.sock" systemctl --user is-active knowledge-governance-library-agent.service