-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·186 lines (153 loc) · 7.59 KB
/
install.sh
File metadata and controls
executable file
·186 lines (153 loc) · 7.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env bash
# SPDX-License-Identifier: PMPL-1.0-or-later
# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
#
# coord-tui installer — sets up BoJ local-coord-mcp + coord-tui on a new machine.
#
# Run from the boj-server repo root:
# bash coord-tui/install.sh
# Or from anywhere with a full path:
# bash /path/to/boj-server/coord-tui/install.sh
#
# What this script does:
# 1. Builds the Zig coord adapter (local-coord-mcp, port 7745)
# 2. Builds the Rust coord-tui binary
# 3. Installs both to ~/.local/bin/
# 4. Installs a systemd user service to keep the adapter running
# 5. Installs shell hooks (~/.config/coord-tui/coord-hooks.sh)
# 6. Sources the hooks from ~/.bashrc and ~/.zshrc
#
# Requirements: cargo (Rust), zig, systemd (optional but recommended)
set -euo pipefail
# ── Paths ──────────────────────────────────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BOJ_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
ADAPTER_DIR="$BOJ_ROOT/cartridges/local-coord-mcp/adapter"
LOCAL_BIN="${HOME}/.local/bin"
SYSTEMD_DIR="${HOME}/.config/systemd/user"
HOOKS_DEST="${HOME}/.config/coord-tui/coord-hooks.sh"
SERVICE_FILE="$SYSTEMD_DIR/local-coord-mcp.service"
# ── Helpers ────────────────────────────────────────────────────────────────────
say() { printf '\e[1;36m▶\e[0m %s\n' "$*"; }
ok() { printf '\e[1;32m✓\e[0m %s\n' "$*"; }
warn() { printf '\e[1;33m!\e[0m %s\n' "$*"; }
die() { printf '\e[1;31m✗\e[0m %s\n' "$*" >&2; exit 1; }
require() {
command -v "$1" >/dev/null 2>&1 \
|| die "Required tool not found: $1 — please install it first."
}
patch_rc() {
local rc="$1"
local marker="# coord-tui hooks"
grep -qF "$marker" "$rc" 2>/dev/null && return
printf '\n%s\n[ -f "%s" ] && source "%s"\n' \
"$marker" "$HOOKS_DEST" "$HOOKS_DEST" >> "$rc"
ok "Patched $rc"
}
# ── Preflight ──────────────────────────────────────────────────────────────────
printf '\n'
say "BoJ coord-tui installer"
printf '\n'
require cargo
require zig
[ -d "$ADAPTER_DIR" ] \
|| die "Coord adapter not found at $ADAPTER_DIR — is boj-server fully cloned?"
[ -f "$SCRIPT_DIR/Cargo.toml" ] \
|| die "coord-tui Cargo.toml not found at $SCRIPT_DIR — something is wrong."
# ── Build Zig adapter ──────────────────────────────────────────────────────────
say "Building Zig coord adapter…"
(cd "$ADAPTER_DIR" && zig build -Doptimize=ReleaseSafe)
ADAPTER_BIN="$ADAPTER_DIR/zig-out/bin/local_coord_adapter"
[ -f "$ADAPTER_BIN" ] \
|| die "Zig build succeeded but binary not found at $ADAPTER_BIN"
ok "Zig adapter: $ADAPTER_BIN"
# ── Build coord-tui ────────────────────────────────────────────────────────────
say "Building coord-tui (Rust)…"
(cd "$SCRIPT_DIR" && cargo build --release --quiet)
TUI_BIN="$SCRIPT_DIR/target/release/coord-tui"
[ -f "$TUI_BIN" ] \
|| die "Cargo build succeeded but binary not found at $TUI_BIN"
ok "coord-tui: $TUI_BIN"
# ── Install binaries ───────────────────────────────────────────────────────────
say "Installing symlinks to $LOCAL_BIN…"
mkdir -p "$LOCAL_BIN"
ln -sf "$TUI_BIN" "$LOCAL_BIN/coord-tui"
ln -sf "$ADAPTER_BIN" "$LOCAL_BIN/local_coord_adapter"
ok "coord-tui → $LOCAL_BIN/coord-tui"
ok "adapter → $LOCAL_BIN/local_coord_adapter"
if ! printf '%s' "$PATH" | grep -qF "$LOCAL_BIN"; then
warn "$LOCAL_BIN is not on your PATH. Add to your shell rc:"
warn " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
# ── Systemd user service ───────────────────────────────────────────────────────
say "Installing systemd user service…"
mkdir -p "$SYSTEMD_DIR"
cat > "$SERVICE_FILE" <<EOF
# SPDX-License-Identifier: PMPL-1.0-or-later
[Unit]
Description=BoJ local-coord-mcp adapter (AI multi-instance coordination)
After=network.target
[Service]
ExecStart=${ADAPTER_BIN}
Restart=on-failure
RestartSec=3
[Install]
WantedBy=default.target
EOF
ok "Service: $SERVICE_FILE"
if command -v systemctl >/dev/null 2>&1; then
systemctl --user daemon-reload
systemctl --user enable --now local-coord-mcp
ok "Service enabled and started (port 7745)"
else
warn "systemctl not available — start the adapter manually before using coord-tui:"
warn " $ADAPTER_BIN &"
fi
# ── BoJ REST server service ────────────────────────────────────────────────────
say "Installing BoJ REST server service (port 7700)…"
BOJ_REST_SERVICE_SRC="$BOJ_ROOT/elixir/boj-rest.service"
BOJ_REST_SERVICE_DST="$SYSTEMD_DIR/boj-rest.service"
if [ ! -f "$BOJ_REST_SERVICE_SRC" ]; then
warn "boj-rest.service template not found at $BOJ_REST_SERVICE_SRC — skipping."
else
mkdir -p "${HOME}/.local/share/boj-server"
BOJ_ROOT="$BOJ_ROOT" HOME="$HOME" envsubst < "$BOJ_REST_SERVICE_SRC" > "$BOJ_REST_SERVICE_DST"
ok "Service: $BOJ_REST_SERVICE_DST"
if command -v systemctl >/dev/null 2>&1; then
systemctl --user daemon-reload
systemctl --user enable --now boj-rest
ok "Service enabled and started (port 7700)"
else
warn "systemctl not available — start the server manually:"
warn " cd $BOJ_ROOT/elixir && MIX_ENV=dev mix run --no-halt"
fi
fi
# ── Shell hooks ────────────────────────────────────────────────────────────────
say "Installing shell hooks…"
mkdir -p "$(dirname "$HOOKS_DEST")"
cp "$SCRIPT_DIR/shell/coord-hooks.sh" "$HOOKS_DEST"
ok "Hooks: $HOOKS_DEST"
for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
[ -f "$rc" ] && patch_rc "$rc"
done
# ── Done ───────────────────────────────────────────────────────────────────────
printf '\n'
ok "Installation complete."
printf '\n'
printf ' Services running:\n'
printf ' boj-rest — Elixir REST server on :7700 (112 cartridges)\n'
printf ' local-coord-mcp — Zig coord adapter on :7745\n'
printf '\n'
printf ' Open a new shell (or run: source %s)\n' "$HOOKS_DEST"
printf ' then launch a tool to auto-register:\n\n'
printf ' claude # registers + sets window title to "claude [<peer_id>]"\n'
printf ' gemini # same for Gemini\n'
printf ' cursor # same for Cursor / Vibe\n'
printf ' codex # same for Codex\n'
printf ' coord-tui # interactive TUI (see all peers + claims)\n'
printf '\n'
printf ' Check services:\n'
printf ' systemctl --user status boj-rest\n'
printf ' systemctl --user status local-coord-mcp\n'
printf ' curl http://localhost:7700/health\n'
printf '\n'