-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·325 lines (282 loc) · 10 KB
/
install.sh
File metadata and controls
executable file
·325 lines (282 loc) · 10 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
#!/usr/bin/env bash
set -euo pipefail
# mind-map installer
# Downloads the latest release binary.
#
# Usage:
# curl -fsSL https://github.com/aniongithub/mind-map/releases/latest/download/install.sh | bash
# curl -fsSL ... | bash -s -- --install-dir /usr/local/bin
REPO="aniongithub/mind-map"
INSTALL_DIR="${HOME}/.local/bin"
SKIP_MCP_CONFIG=false
# Parse args
while [[ $# -gt 0 ]]; do
case "$1" in
--install-dir) INSTALL_DIR="$2"; shift 2 ;;
--skip-mcp-config) SKIP_MCP_CONFIG=true; shift ;;
--help|-h)
echo "Usage: install.sh [--install-dir DIR] [--skip-mcp-config]"
echo " --install-dir Installation directory (default: ~/.local/bin)"
echo " --skip-mcp-config Skip MCP client configuration (used by install.ps1)"
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}"
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}"
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
SKILL_URL="https://raw.githubusercontent.com/${REPO}/main/SKILL.md"
SKILL_DIRS=(
"${HOME}/.copilot/skills/mind-map"
"${HOME}/.claude/skills/mind-map"
"${HOME}/.agents/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
python3 -c "
import json
path = '${config_file}'
with open(path) as f:
data = json.load(f)
servers = data.setdefault('mcpServers', {})
entry = json.loads('${mcp_entry}')
servers['mind-map'] = entry
with open(path, 'w') as f:
json.dump(data, f, indent=2)
print(' + ${client_name} -- updated ${config_file}')
" 2>/dev/null || echo " ! ${client_name} -- could not update ${config_file}"
else
echo " ! ${client_name} -- 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
configure_mcp_client "${HOME}/.claude.json" "Claude Code"
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"
echo ""