-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
308 lines (258 loc) · 11.4 KB
/
install.ps1
File metadata and controls
308 lines (258 loc) · 11.4 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
#Requires -Version 5.1
<#
.SYNOPSIS
Windows installer for mind-map.
.DESCRIPTION
Downloads the native Windows binary, configures MCP clients,
and optionally installs mind-map as a persistent service.
.EXAMPLE
irm https://github.com/aniongithub/mind-map/releases/latest/download/install.ps1 | iex
#>
# Auto-elevate to admin (needed for Windows Service installation)
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "Requesting administrative privileges..." -ForegroundColor Yellow
$scriptUrl = "https://github.com/aniongithub/mind-map/releases/latest/download/install.ps1"
Start-Process powershell.exe "-NoExit -NoProfile -ExecutionPolicy Bypass -Command `"& { irm '$scriptUrl' | iex }`"" -Verb RunAs
exit
}
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$Repo = "aniongithub/mind-map"
$InstallDir = "$env:LOCALAPPDATA\mind-map"
$BinaryPath = "$InstallDir\mind-map.exe"
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
function Write-Step { param([string]$Message) Write-Host "==> $Message" -ForegroundColor Cyan }
function Write-Ok { param([string]$Message) Write-Host " $([char]0x2713) $Message" -ForegroundColor Green }
function Write-Warn { param([string]$Message) Write-Host " $([char]0x26A0) $Message" -ForegroundColor Yellow }
# ---------------------------------------------------------------------------
# 1. Detect architecture
# ---------------------------------------------------------------------------
Write-Step "Detecting platform..."
$arch = if ([Environment]::Is64BitOperatingSystem) {
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "x64" }
} else {
Write-Host "Error: 32-bit Windows is not supported." -ForegroundColor Red
exit 1
}
Write-Ok "windows-$arch"
# ---------------------------------------------------------------------------
# 2. Get latest version
# ---------------------------------------------------------------------------
Write-Step "Checking latest version..."
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
$version = $release.tag_name
Write-Ok "Latest version: $version"
# ---------------------------------------------------------------------------
# 3. Stop existing service before replacing binary
# ---------------------------------------------------------------------------
# Stop existing service before replacing binary (ignore errors if not installed)
if (Test-Path $BinaryPath) {
$ErrorActionPreference = "Continue"
& $BinaryPath service stop 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Ok "Stopped existing mind-map service"
}
$ErrorActionPreference = "Stop"
}
# ---------------------------------------------------------------------------
# 4. Download and install binary
# ---------------------------------------------------------------------------
Write-Step "Downloading mind-map-windows-$arch.exe..."
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
$artifact = "mind-map-windows-$arch.exe"
$tarball = "$artifact.tar.gz"
$downloadUrl = "https://github.com/$Repo/releases/download/$version/$tarball"
$tarballPath = "$env:TEMP\$tarball"
Invoke-WebRequest -Uri $downloadUrl -OutFile $tarballPath -UseBasicParsing
# Extract using tar (available on Windows 10+)
tar -xzf $tarballPath -C $InstallDir 2>&1 | Out-Null
# Rename platform-specific binary
if (Test-Path "$InstallDir\$artifact") {
Move-Item -Path "$InstallDir\$artifact" -Destination $BinaryPath -Force
}
Remove-Item $tarballPath -Force -ErrorAction SilentlyContinue
Write-Ok "Installed to $BinaryPath"
# Verify
try {
& $BinaryPath --help | Out-Null
Write-Ok "mind-map is working"
} catch {
Write-Warn "Binary installed but could not verify"
}
# Add to user PATH if not already there
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -notlike "*$InstallDir*") {
[Environment]::SetEnvironmentVariable("PATH", "$InstallDir;$userPath", "User")
$env:PATH = "$InstallDir;$env:PATH"
Write-Ok "Added $InstallDir to user PATH"
}
# ---------------------------------------------------------------------------
# 5. Install SKILL.md for agent discovery
# ---------------------------------------------------------------------------
Write-Step "Installing SKILL.md for agent discovery..."
$SkillUrl = "https://raw.githubusercontent.com/$Repo/main/SKILL.md"
$SkillDirs = @(
"$env:USERPROFILE\.copilot\skills\mind-map"
"$env:USERPROFILE\.claude\skills\mind-map"
"$env:USERPROFILE\.agents\skills\mind-map"
)
foreach ($dir in $SkillDirs) {
try {
New-Item -ItemType Directory -Path $dir -Force | Out-Null
Invoke-RestMethod -Uri $SkillUrl -OutFile "$dir\SKILL.md"
Write-Ok "$dir\SKILL.md"
} catch {
Write-Warn "Could not install to $dir"
}
}
# ---------------------------------------------------------------------------
# 6. Interactive: set up as a persistent service
# ---------------------------------------------------------------------------
$DefaultPort = "4242"
$DefaultWikiDir = "$env:ProgramData\mind-map\wiki"
$servicePort = $DefaultPort
function Test-PortAvailable {
param([int]$Port)
try {
$listener = [System.Net.Sockets.TcpClient]::new()
$listener.Connect("127.0.0.1", $Port)
$listener.Close()
return $false # connection succeeded — port is in use
} catch {
return $true # connection refused — port is free
}
}
Write-Host ""
$installService = Read-Host "Would you like to install mind-map as a persistent service? [y/N]"
if ($installService -match '^[Yy]$') {
# --- Port ---
if (-not (Test-PortAvailable -Port ([int]$DefaultPort))) {
Write-Warn "Port $DefaultPort is already in use."
}
while ($true) {
if (Test-PortAvailable -Port ([int]$DefaultPort)) {
$servicePort = Read-Host "Port [$DefaultPort] (enter nothing to auto-pick a free port)"
} else {
$servicePort = Read-Host "Enter a port (or nothing to auto-pick a free port)"
}
if ([string]::IsNullOrWhiteSpace($servicePort) -and -not (Test-PortAvailable -Port ([int]$DefaultPort))) {
# Auto-pick: scan from 8080 upward
$found = $false
for ($p = 8080; $p -le 8180; $p++) {
if (Test-PortAvailable -Port $p) {
$servicePort = "$p"
Write-Ok "Auto-selected port $servicePort"
$found = $true
break
}
}
if (-not $found) {
Write-Warn "Could not find a free port. Please enter one manually."
continue
}
}
if ([string]::IsNullOrWhiteSpace($servicePort)) { $servicePort = $DefaultPort }
if ($servicePort -notmatch '^\d+$') {
Write-Warn "Invalid port number."
continue
}
if (-not (Test-PortAvailable -Port ([int]$servicePort))) {
Write-Warn "Port $servicePort is already in use."
continue
}
break
}
$serviceWikiDir = Read-Host "Wiki directory [$DefaultWikiDir]"
if ([string]::IsNullOrWhiteSpace($serviceWikiDir)) { $serviceWikiDir = $DefaultWikiDir }
# Build service flags
$svcFlags = @("--addr", "127.0.0.1:$servicePort", "--dir", "$serviceWikiDir")
# Uninstall existing service if present (handles reinstall)
$ErrorActionPreference = "Continue"
& $BinaryPath service stop 2>&1 | Out-Null
& $BinaryPath service uninstall 2>&1 | Out-Null
$ErrorActionPreference = "Stop"
# Install and start the service (already running as admin)
& $BinaryPath service install @svcFlags
& $BinaryPath service start @svcFlags
Write-Host ""
$webUrl = "http://localhost:$servicePort"
Write-Host " Web UI: $webUrl" -ForegroundColor Cyan
Write-Host ""
Write-Host " Manage with: mind-map service status|stop|start|uninstall" -ForegroundColor DarkGray
}
# ---------------------------------------------------------------------------
# 7. Configure MCP clients
# ---------------------------------------------------------------------------
Write-Step "Configuring MCP clients..."
$mcpServerEntry = @{
type = "local"
command = $BinaryPath
args = @()
tools = @("*")
}
function Set-McpConfig {
param(
[string]$ConfigPath,
[string]$ClientName
)
try {
if (Test-Path $ConfigPath) {
$content = Get-Content -Raw $ConfigPath | ConvertFrom-Json
if (-not $content.mcpServers) {
$content | Add-Member -NotePropertyName "mcpServers" -NotePropertyValue ([PSCustomObject]@{})
}
if ($content.mcpServers.PSObject.Properties.Name -contains "mind-map") {
$content.mcpServers.PSObject.Properties.Remove("mind-map")
}
$content.mcpServers | Add-Member -NotePropertyName "mind-map" -NotePropertyValue ([PSCustomObject]$mcpServerEntry)
$content | ConvertTo-Json -Depth 10 | Set-Content $ConfigPath -Encoding UTF8
Write-Ok "$ClientName — configured in $ConfigPath"
} else {
$dir = Split-Path $ConfigPath -Parent
if ($dir) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
$config = [PSCustomObject]@{
mcpServers = [PSCustomObject]@{
"mind-map" = [PSCustomObject]$mcpServerEntry
}
}
$config | ConvertTo-Json -Depth 10 | Set-Content $ConfigPath -Encoding UTF8
Write-Ok "$ClientName — created $ConfigPath"
}
} catch {
Write-Warn "$ClientName — could not update $ConfigPath"
}
}
# Claude Code
Set-McpConfig "$env:USERPROFILE\.claude.json" "Claude Code"
# GitHub Copilot (if .copilot dir exists)
if (Test-Path "$env:USERPROFILE\.copilot") {
Set-McpConfig "$env:USERPROFILE\.copilot\mcp-config.json" "GitHub Copilot"
}
# VS Code (if config dir exists)
$vscodeDir = "$env:APPDATA\Code\User"
if (Test-Path $vscodeDir) {
Set-McpConfig "$vscodeDir\mcp.json" "VS Code"
}
# Cursor (if installed)
if (Test-Path "$env:USERPROFILE\.cursor") {
Set-McpConfig "$env:USERPROFILE\.cursor\mcp.json" "Cursor"
}
# ---------------------------------------------------------------------------
# Done
# ---------------------------------------------------------------------------
Write-Host ""
if ($installService -match '^[Yy]$') {
Write-Host "Done! mind-map is running as a service." -ForegroundColor Green
} else {
Write-Host "Done! mind-map is ready to use." -ForegroundColor Green
Write-Host ""
Write-Host " Start the web UI: mind-map serve" -ForegroundColor DarkGray
}
Write-Host ""
Write-Host "To uninstall mind-map completely:" -ForegroundColor DarkGray
Write-Host " mind-map service uninstall # remove service (if installed)" -ForegroundColor DarkGray
Write-Host " Remove-Item -Recurse '$InstallDir' # remove binary" -ForegroundColor DarkGray
Write-Host " Remove-Item -Recurse '$env:USERPROFILE\.mind-map' # remove wiki data" -ForegroundColor DarkGray
Write-Host " Remove-Item -Recurse '$env:USERPROFILE\.copilot\skills\mind-map', '$env:USERPROFILE\.claude\skills\mind-map', '$env:USERPROFILE\.agents\skills\mind-map'" -ForegroundColor DarkGray