-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·418 lines (370 loc) · 14.2 KB
/
install.sh
File metadata and controls
executable file
·418 lines (370 loc) · 14.2 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#!/usr/bin/env bash
set -euo pipefail
# mind-map installer
# Downloads a release binary. Defaults to the latest release.
#
# Usage:
# curl -fsSL https://github.com/aniongithub/mind-map/releases/latest/download/install.sh | bash
# curl -fsSL ... | bash -s -- --install-dir /usr/local/bin
# curl -fsSL ... | bash -s -- --version v0.49 # pin a specific release
# MINDMAP_VERSION=v0.49 curl -fsSL ... | bash # env var equivalent
REPO="aniongithub/mind-map"
INSTALL_DIR="${HOME}/.local/bin"
SKIP_MCP_CONFIG=false
# Pre-seed VERSION from the environment so users can `MINDMAP_VERSION=... curl | bash`
# without needing `bash -s --` plumbing. The --version flag overrides if both are set.
VERSION="${MINDMAP_VERSION:-}"
# Parse args
while [[ $# -gt 0 ]]; do
case "$1" in
--install-dir) INSTALL_DIR="$2"; shift 2 ;;
--skip-mcp-config) SKIP_MCP_CONFIG=true; shift ;;
--version) VERSION="$2"; shift 2 ;;
--help|-h)
echo "Usage: install.sh [--install-dir DIR] [--skip-mcp-config] [--version TAG]"
echo " --install-dir Installation directory (default: ~/.local/bin)"
echo " --skip-mcp-config Skip MCP client configuration (used by install.ps1)"
echo " --version TAG Install a specific release tag (e.g. v0.49). Defaults"
echo " to the latest release. Useful for testing prereleases."
echo " Equivalent env var: MINDMAP_VERSION"
exit 0
;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
# Detect OS and architecture
detect_platform() {
local os arch
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux) os="linux" ;;
Darwin) os="darwin" ;;
*) echo "Error: Unsupported OS: $os"; exit 1 ;;
esac
case "$arch" in
x86_64|amd64) arch="x64" ;;
aarch64|arm64) arch="arm64" ;;
*) echo "Error: Unsupported architecture: $arch"; exit 1 ;;
esac
echo "${os}-${arch}"
}
# Get latest release tag from GitHub
get_latest_version() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed -E 's/.*"tag_name": *"([^"]+)".*/\1/'
}
PLATFORM="$(detect_platform)"
echo "==> Detected platform: ${PLATFORM}"
if [[ -n "$VERSION" ]]; then
echo "==> Using pinned version: ${VERSION}"
else
VERSION="$(get_latest_version)"
if [[ -z "$VERSION" ]]; then
echo "Error: Could not determine latest release version."
echo "Check: https://github.com/${REPO}/releases"
exit 1
fi
echo "==> Latest version: ${VERSION}"
fi
TARBALL_NAME="mind-map-${PLATFORM}.tar.gz"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${TARBALL_NAME}"
# Create install directory
mkdir -p "$INSTALL_DIR"
# Ensure ~/.mind-map exists and is owned by the current user.
# This must happen before any sudo commands that might create it as root.
mkdir -p "${HOME}/.mind-map"
# Stop existing service before replacing the binary
if [ -f "${INSTALL_DIR}/mind-map" ]; then
# On macOS the service is a user LaunchAgent; sudo would look for the plist
# under /var/root instead of ~/Library/LaunchAgents, so don't use sudo.
if [[ "$(uname -s)" == "Darwin" ]]; then
"${INSTALL_DIR}/mind-map" service stop 2>/dev/null && \
echo "==> Stopped existing mind-map service" || true
else
sudo "${INSTALL_DIR}/mind-map" service stop 2>/dev/null && \
echo "==> Stopped existing mind-map service" || true
fi
fi
echo "==> Downloading ${TARBALL_NAME}..."
curl -fsSL "$DOWNLOAD_URL" | tar xz -C "${INSTALL_DIR}"
# Rename platform-specific binary to just "mind-map"
if [[ -f "${INSTALL_DIR}/mind-map-${PLATFORM}" ]]; then
mv "${INSTALL_DIR}/mind-map-${PLATFORM}" "${INSTALL_DIR}/mind-map"
fi
chmod +x "${INSTALL_DIR}/mind-map"
# macOS: ad-hoc codesign to avoid Gatekeeper "Killed: 9"
if [[ "$(uname -s)" == "Darwin" ]]; then
codesign -s - "${INSTALL_DIR}/mind-map" 2>/dev/null && \
echo "==> Codesigned binary for macOS" || true
fi
echo "==> Installed mind-map to ${INSTALL_DIR}/mind-map"
# Verify
if "${INSTALL_DIR}/mind-map" --help >/dev/null 2>&1; then
echo "==> mind-map is working"
else
echo "Warning: Binary downloaded but failed to run. Check platform compatibility."
fi
# Check PATH
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then
echo ""
echo "Note: ${INSTALL_DIR} is not in your PATH. Add it with:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
# Install SKILL.md for agent discovery. Fetch from the same git ref as the
# binary so the documented tool surface matches what got installed. Tags
# are valid refs on raw.githubusercontent.com.
SKILL_URL="https://raw.githubusercontent.com/${REPO}/${VERSION}/SKILL.md"
SKILL_DIRS=(
"${HOME}/.copilot/skills/mind-map"
"${HOME}/.claude/skills/mind-map"
"${HOME}/.agents/skills/mind-map"
"${HOME}/.config/opencode/skills/mind-map"
)
echo ""
echo "==> Installing SKILL.md for agent discovery..."
for dir in "${SKILL_DIRS[@]}"; do
mkdir -p "$dir"
curl -fsSL -o "${dir}/SKILL.md" "$SKILL_URL" 2>/dev/null && \
echo " ${dir}/SKILL.md" || true
done
# ---------------------------------------------------------------------------
# Interactive: set up as a persistent service
# ---------------------------------------------------------------------------
DEFAULT_PORT="4242"
DEFAULT_WIKI_DIR="${HOME}/.mind-map/wiki"
SERVICE_PORT="$DEFAULT_PORT"
# Check whether a TCP port is available
port_available() {
if command -v nc >/dev/null 2>&1; then
! nc -z 127.0.0.1 "$1" 2>/dev/null
elif command -v ss >/dev/null 2>&1; then
! ss -tlnH "sport = :$1" 2>/dev/null | grep -q .
else
# No checker available — assume available
return 0
fi
}
echo ""
printf "Would you like to install mind-map as a persistent service? [y/N] "
read -r INSTALL_SERVICE < /dev/tty || INSTALL_SERVICE="n"
if [[ "$INSTALL_SERVICE" =~ ^[Yy]$ ]]; then
# --- Port ---
if ! port_available "$DEFAULT_PORT"; then
echo " Warning: Port ${DEFAULT_PORT} is already in use."
fi
while true; do
if port_available "$DEFAULT_PORT"; then
printf "Port [${DEFAULT_PORT}] (enter nothing to auto-pick a free port): "
else
printf "Enter a port (or nothing to auto-pick a free port): "
fi
read -r SERVICE_PORT < /dev/tty || SERVICE_PORT=""
if [[ -z "$SERVICE_PORT" ]] && ! port_available "$DEFAULT_PORT"; then
# Auto-pick: scan from 8080 upward
for p in $(seq 8080 8180); do
if port_available "$p"; then
SERVICE_PORT="$p"
echo " Auto-selected port ${SERVICE_PORT}"
break
fi
done
if [[ -z "$SERVICE_PORT" ]]; then
echo " Could not find a free port. Please enter one manually."
continue
fi
fi
SERVICE_PORT="${SERVICE_PORT:-$DEFAULT_PORT}"
if ! [[ "$SERVICE_PORT" =~ ^[0-9]+$ ]]; then
echo " Invalid port number."
continue
fi
if ! port_available "$SERVICE_PORT"; then
echo " Port ${SERVICE_PORT} is already in use."
continue
fi
break
done
printf "Wiki directory [${DEFAULT_WIKI_DIR}]: "
read -r SERVICE_WIKI_DIR < /dev/tty || SERVICE_WIKI_DIR=""
SERVICE_WIKI_DIR="${SERVICE_WIKI_DIR:-$DEFAULT_WIKI_DIR}"
# Build service flags
SVC_FLAGS=(--addr "127.0.0.1:${SERVICE_PORT}" --dir "${SERVICE_WIKI_DIR}")
# Use the built-in service manager (kardianos/service)
# System services require elevated privileges on Linux
if [[ "$(uname -s)" == "Linux" ]]; then
echo "==> Installing service (requires sudo)..."
# Ensure wiki dir exists and is owned by the current user
mkdir -p "${SERVICE_WIKI_DIR}"
# Uninstall existing service if present (handles reinstall)
sudo "${INSTALL_DIR}/mind-map" service stop 2>/dev/null || true
sudo "${INSTALL_DIR}/mind-map" service uninstall 2>/dev/null || true
sudo "${INSTALL_DIR}/mind-map" service install "${SVC_FLAGS[@]}" && \
sudo "${INSTALL_DIR}/mind-map" service start "${SVC_FLAGS[@]}"
# Fix ownership: the service runs as root but agents run as the user.
# Both need write access to the wiki dir and SQLite database.
sudo chown -R "$(id -u):$(id -g)" "${SERVICE_WIKI_DIR}"
sudo chown -R "$(id -u):$(id -g)" "${HOME}/.mind-map"
else
"${INSTALL_DIR}/mind-map" service stop 2>/dev/null || true
"${INSTALL_DIR}/mind-map" service uninstall 2>/dev/null || true
"${INSTALL_DIR}/mind-map" service install "${SVC_FLAGS[@]}" && \
"${INSTALL_DIR}/mind-map" service start "${SVC_FLAGS[@]}"
fi
echo ""
echo " Web UI: http://localhost:${SERVICE_PORT}"
echo ""
echo " Manage with: sudo mind-map service status|stop|start|uninstall"
fi
# ---------------------------------------------------------------------------
# Auto-configure MCP clients (skipped when called from install.ps1)
# ---------------------------------------------------------------------------
if [ "$SKIP_MCP_CONFIG" = true ]; then
echo ""
echo "==> Skipping MCP client configuration (--skip-mcp-config)"
echo ""
echo "Done! mind-map binary is installed."
exit 0
fi
# Configure MCP clients
configure_mcp_client() {
local config_file="$1"
local client_name="$2"
local mcp_entry
mcp_entry="{\"type\": \"local\", \"command\": \"${INSTALL_DIR}/mind-map\", \"args\": [], \"tools\": [\"*\"]}"
if [ ! -f "$config_file" ]; then
mkdir -p "$(dirname "$config_file")"
cat > "$config_file" << MCPEOF
{
"mcpServers": {
"mind-map": ${mcp_entry}
}
}
MCPEOF
echo " + ${client_name} -- created ${config_file}"
elif command -v python3 >/dev/null 2>&1; then
# Pass values via env vars to avoid shell-quoting the JSON literal into
# Python source code (which breaks on every embedded double-quote).
MM_CFG="$config_file" MM_ENTRY="$mcp_entry" MM_CLIENT="$client_name" \
python3 -c '
import json, os
path = os.environ["MM_CFG"]
client = os.environ["MM_CLIENT"]
with open(path) as f:
data = json.load(f)
servers = data.setdefault("mcpServers", {})
servers["mind-map"] = json.loads(os.environ["MM_ENTRY"])
with open(path, "w") as f:
json.dump(data, f, indent=2)
print(f" + {client} -- updated {path}")
' || echo " ! ${client_name} -- could not update ${config_file}"
else
echo " ! ${client_name} -- exists but python3 not available to merge"
fi
}
# OpenCode uses a different MCP config shape than Claude/Copilot/VS Code/Cursor:
# - Top-level key is "mcp" (not "mcpServers")
# - command is an array (not a string + separate args)
# - "enabled": true is expected on the entry
# - JSONC (JSON with comments) is supported but we always emit plain JSON
# See https://opencode.ai/docs/mcp-servers
configure_opencode() {
local config_file="$1"
# OpenCode entry, written with command as a JSON array.
local mcp_entry
mcp_entry="{\"type\": \"local\", \"command\": [\"${INSTALL_DIR}/mind-map\"], \"enabled\": true}"
if [ ! -f "$config_file" ]; then
mkdir -p "$(dirname "$config_file")"
cat > "$config_file" << OPENCODEEOF
{
"\$schema": "https://opencode.ai/config.json",
"mcp": {
"mind-map": ${mcp_entry}
}
}
OPENCODEEOF
echo " + OpenCode -- created ${config_file}"
elif command -v python3 >/dev/null 2>&1; then
MM_CFG="$config_file" MM_ENTRY="$mcp_entry" \
python3 -c '
import json, os
path = os.environ["MM_CFG"]
with open(path) as f:
data = json.load(f)
servers = data.setdefault("mcp", {})
servers["mind-map"] = json.loads(os.environ["MM_ENTRY"])
with open(path, "w") as f:
json.dump(data, f, indent=2)
print(f" + OpenCode -- updated {path}")
' || echo " ! OpenCode -- could not update ${config_file}"
else
echo " ! OpenCode -- exists but python3 not available to merge"
fi
}
echo ""
echo "==> Configuring MCP clients..."
# GitHub Copilot CLI
if [ -d "${HOME}/.copilot" ]; then
configure_mcp_client "${HOME}/.copilot/mcp-config.json" "GitHub Copilot"
fi
# VS Code
if [[ "$(uname -s)" == "Darwin" ]]; then
VSCODE_DIR="${HOME}/Library/Application Support/Code/User"
else
VSCODE_DIR="${HOME}/.config/Code/User"
fi
if [ -d "$VSCODE_DIR" ]; then
configure_mcp_client "${VSCODE_DIR}/mcp.json" "VS Code"
fi
# Cursor
if [ -d "${HOME}/.cursor" ]; then
configure_mcp_client "${HOME}/.cursor/mcp.json" "Cursor"
fi
# Claude Code (CLI). Gate on ~/.claude existing so we don't create a stray
# config file for users who don't actually have Claude Code installed.
if [ -d "${HOME}/.claude" ] || [ -f "${HOME}/.claude.json" ]; then
configure_mcp_client "${HOME}/.claude.json" "Claude Code"
fi
# Claude Desktop (separate product from Claude Code). Uses the same
# "mcpServers" shape but lives at a different path, and only on macOS/Windows
# — Anthropic does not ship a Linux build, so this branch is macOS-only here.
# We gate on the Claude Desktop app-support directory existing rather than
# auto-creating it: users who haven't installed Claude Desktop shouldn't get
# a phantom config file under ~/Library/Application Support/Claude.
if [[ "$(uname -s)" == "Darwin" ]]; then
CLAUDE_DESKTOP_DIR="${HOME}/Library/Application Support/Claude"
if [ -d "$CLAUDE_DESKTOP_DIR" ]; then
configure_mcp_client "${CLAUDE_DESKTOP_DIR}/claude_desktop_config.json" "Claude Desktop"
fi
fi
# OpenCode (https://opencode.ai). The studio reads opencode.json first, then
# opencode.jsonc. If neither exists but the binary is on PATH or the config
# directory has been created, we write the canonical .json so future runs
# pick it up.
OPENCODE_CFG=""
if [ -f "${HOME}/.config/opencode/opencode.json" ]; then
OPENCODE_CFG="${HOME}/.config/opencode/opencode.json"
elif [ -f "${HOME}/.config/opencode/opencode.jsonc" ]; then
OPENCODE_CFG="${HOME}/.config/opencode/opencode.jsonc"
elif [ -d "${HOME}/.config/opencode" ] || command -v opencode >/dev/null 2>&1; then
OPENCODE_CFG="${HOME}/.config/opencode/opencode.json"
fi
if [ -n "$OPENCODE_CFG" ]; then
configure_opencode "$OPENCODE_CFG"
fi
echo ""
if [ "$INSTALL_SERVICE" = "y" ] || [ "$INSTALL_SERVICE" = "Y" ]; then
echo "Done! mind-map is running as a service."
else
echo "Done! mind-map is ready."
echo ""
echo " Start the web UI: mind-map serve"
fi
echo ""
echo "To uninstall mind-map completely:"
echo " sudo mind-map service uninstall # remove service (if installed)"
echo " rm ${INSTALL_DIR}/mind-map # remove binary"
echo " rm -rf ~/.mind-map # remove wiki data"
echo " rm -rf ~/.copilot/skills/mind-map ~/.claude/skills/mind-map ~/.agents/skills/mind-map ~/.config/opencode/skills/mind-map"
echo ""