-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.ps1
More file actions
634 lines (524 loc) · 19.1 KB
/
install.ps1
File metadata and controls
634 lines (524 loc) · 19.1 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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
#Requires -Version 5.1
<#
.SYNOPSIS
Installs supertag-cli and all dependencies (Bun, Playwright, Chromium)
.DESCRIPTION
This script installs supertag-cli and its dependencies on Windows.
It handles Bun runtime installation, Playwright, Chromium browser,
and optionally configures MCP for Claude Desktop, Cursor, and Claude Code.
.PARAMETER Version
Specific version to install (default: latest)
.PARAMETER NoMcp
Skip MCP auto-configuration
.PARAMETER Proxy
HTTP proxy URL for corporate networks (e.g. http://proxy:8080)
.EXAMPLE
irm https://raw.githubusercontent.com/jcfischer/supertag-cli/main/install.ps1 | iex
.EXAMPLE
.\install.ps1 -Version 0.16.0
.EXAMPLE
.\install.ps1 -NoMcp
.EXAMPLE
.\install.ps1 -Proxy http://your-proxy:8080
#>
[CmdletBinding()]
param(
[string]$Version = "latest",
[switch]$NoMcp,
[switch]$Help,
[string]$Proxy
)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
# PowerShell 5.1 defaults to TLS 1.0/1.1 — GitHub requires TLS 1.2+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# =============================================================================
# Configuration
# =============================================================================
$Script:InstallDir = "$env:USERPROFILE\Tools\supertag-cli"
$Script:GitHubRepo = "jcfischer/supertag-cli"
# =============================================================================
# Utility Functions
# =============================================================================
function Write-Info {
param([string]$Message)
Write-Host " → " -ForegroundColor Cyan -NoNewline
Write-Host $Message
}
function Write-Success {
param([string]$Message)
Write-Host " ✓ " -ForegroundColor Green -NoNewline
Write-Host $Message
}
function Write-Warning {
param([string]$Message)
Write-Host " ⚠ " -ForegroundColor Yellow -NoNewline
Write-Host $Message
}
function Write-Error {
param([string]$Message)
Write-Host " ✗ " -ForegroundColor Red -NoNewline
Write-Host $Message
}
function Write-Step {
param([string]$Step, [string]$Description)
Write-Host ""
Write-Host "[$Step] " -ForegroundColor White -NoNewline
Write-Host $Description -ForegroundColor White
}
function Test-Command {
param([string]$Command)
$null = Get-Command $Command -ErrorAction SilentlyContinue
return $?
}
function Get-ProxyParams {
$params = @{}
if ($Script:Proxy) {
$params["Proxy"] = $Script:Proxy
$params["ProxyUseDefaultCredentials"] = $true
}
return $params
}
function Invoke-Download {
param(
[string]$Uri,
[string]$OutFile,
[hashtable]$Headers = @{}
)
$proxyParams = Get-ProxyParams
try {
if ($OutFile) {
Invoke-WebRequest -Uri $Uri -OutFile $OutFile -UseBasicParsing -Headers $Headers @proxyParams
} else {
Invoke-RestMethod -Uri $Uri -Headers $Headers @proxyParams
}
} catch [System.Net.WebException] {
$response = $_.Exception.Response
$status = if ($response) { [int]$response.StatusCode } else { 0 }
if ($status -eq 302 -or $status -eq 407 -or $_.Exception.Message -match "proxy|Umbrella|Zscaler|Forcepoint|gateway") {
Write-Error "HTTP request to $Uri was blocked (possibly by a corporate proxy/firewall)."
Write-Host ""
Write-Host " Workarounds:" -ForegroundColor Yellow
Write-Host " 1. Try with explicit proxy: .\install.ps1 -Proxy http://your-proxy:8080"
Write-Host " 2. Download manually from: https://github.com/$Script:GitHubRepo/releases/latest"
Write-Host " 3. See: https://github.com/$Script:GitHubRepo/blob/main/docs/INSTALL-WINDOWS.md#corporate-proxy"
Write-Host ""
throw "Download blocked by proxy/firewall: $Uri"
}
throw
}
}
function Get-Confirmation {
param(
[string]$Prompt,
[bool]$Default = $true
)
$suffix = if ($Default) { "[Y/n]" } else { "[y/N]" }
$response = Read-Host " $Prompt $suffix"
if ([string]::IsNullOrWhiteSpace($response)) {
return $Default
}
return $response -match "^[Yy]"
}
# =============================================================================
# Detection Functions
# =============================================================================
function Get-Platform {
# Try .NET RuntimeInformation first (PowerShell 7+ / .NET Core)
try {
$arch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture
switch ($arch) {
"X64" { return "windows-x64" }
"Arm64" { return "windows-arm64" }
}
} catch { }
# Fallback for Windows PowerShell 5.1 (.NET Framework)
$envArch = $env:PROCESSOR_ARCHITECTURE
switch ($envArch) {
"AMD64" { return "windows-x64" }
"ARM64" { return "windows-arm64" }
"x86" {
# 32-bit PowerShell on 64-bit OS reports x86, check real arch
if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
return "windows-x64"
}
throw "Unsupported architecture: x86 (32-bit Windows is not supported)"
}
default { throw "Unsupported architecture: $envArch" }
}
}
function Test-BunInstalled {
return Test-Command "bun"
}
function Test-PlaywrightInstalled {
if (-not (Test-BunInstalled)) { return $false }
$result = bun pm ls -g 2>$null | Select-String "playwright"
return $null -ne $result
}
function Test-ChromiumInstalled {
$cacheDir = "$env:LOCALAPPDATA\ms-playwright"
return (Test-Path $cacheDir) -and ((Get-ChildItem $cacheDir -ErrorAction SilentlyContinue).Count -gt 0)
}
function Get-InstalledVersion {
$supertag = Join-Path $Script:InstallDir "supertag.exe"
if (Test-Path $supertag) {
try {
$output = & $supertag --version 2>$null
if ($output -match '(\d+\.\d+\.\d+)') {
return $Matches[1]
}
} catch { }
}
return $null
}
function Resolve-Version {
param([string]$Requested)
if ($Requested -eq "latest") {
try {
$headers = @{ "User-Agent" = "supertag-cli-installer" }
$release = Invoke-Download -Uri "https://api.github.com/repos/$Script:GitHubRepo/releases/latest" -Headers $headers
$tag = $release.tag_name -replace '^v', ''
return $tag
} catch {
throw "Could not fetch latest version from GitHub: $($_.Exception.Message)"
}
}
return $Requested -replace '^v', ''
}
# =============================================================================
# Installation Functions
# =============================================================================
function Install-Bun {
if (Test-BunInstalled) {
$version = (bun --version 2>$null) -join ""
Write-Success "Bun v$version already installed (skipping)"
return
}
Write-Info "Downloading Bun installer..."
try {
irm bun.sh/install.ps1 | iex
} catch {
throw "Failed to install Bun. Visit https://bun.sh/docs/installation for manual installation."
}
# Refresh PATH
$env:BUN_INSTALL = "$env:USERPROFILE\.bun"
$env:PATH = "$env:BUN_INSTALL\bin;$env:PATH"
if (-not (Test-BunInstalled)) {
throw "Bun installation completed but 'bun' command not found. Please restart your terminal."
}
$version = (bun --version 2>$null) -join ""
Write-Success "Bun v$version installed"
}
function Install-Playwright {
if (Test-PlaywrightInstalled) {
Write-Success "Playwright already installed (skipping)"
return
}
Write-Info "Installing Playwright globally..."
try {
bun add -g playwright
} catch {
throw "Failed to install Playwright. Try: bun add -g playwright"
}
Write-Success "Playwright installed"
}
function Install-Chromium {
if (Test-ChromiumInstalled) {
Write-Success "Chromium already installed (skipping)"
return
}
Write-Info "Installing Chromium browser (this may take a minute)..."
try {
bunx playwright install chromium
} catch {
throw "Failed to install Chromium. Try: bunx playwright install chromium"
}
Write-Success "Chromium installed"
}
function Install-Supertag {
param(
[string]$Version,
[string]$Platform
)
$installedVersion = Get-InstalledVersion
if ($installedVersion -eq $Version) {
Write-Success "supertag-cli v$Version already installed (skipping)"
return
}
if ($installedVersion) {
Write-Info "Updating from v$installedVersion to v$Version"
}
$downloadUrl = "https://github.com/$Script:GitHubRepo/releases/download/v$Version/supertag-cli-v$Version-$Platform.zip"
$tempDir = Join-Path $env:TEMP "supertag-install-$(Get-Random)"
$zipFile = Join-Path $tempDir "supertag-cli.zip"
Write-Info "Downloading supertag-cli v$Version for $Platform..."
try {
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
$headers = @{ "User-Agent" = "supertag-cli-installer" }
Invoke-Download -Uri $downloadUrl -OutFile $zipFile -Headers $headers
} catch {
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
throw "Failed to download from $downloadUrl`: $($_.Exception.Message)"
}
Write-Info "Extracting to $Script:InstallDir..."
try {
New-Item -ItemType Directory -Path $Script:InstallDir -Force | Out-Null
Expand-Archive -Path $zipFile -DestinationPath $tempDir -Force
# Find and copy executables
$exes = Get-ChildItem -Path $tempDir -Filter "*.exe" -Recurse
foreach ($exe in $exes) {
Copy-Item -Path $exe.FullName -Destination $Script:InstallDir -Force
}
} catch {
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
throw "Failed to extract archive"
}
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
Write-Success "supertag-cli v$Version installed to $Script:InstallDir"
}
function Set-PathConfiguration {
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($currentPath -like "*$Script:InstallDir*") {
Write-Success "PATH already configured (skipping)"
return
}
Write-Info "Adding $Script:InstallDir to PATH..."
$newPath = "$currentPath;$Script:InstallDir"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
# Also update current session
$env:PATH = "$env:PATH;$Script:InstallDir"
Write-Success "Added to PATH"
Write-Warning "Open a new terminal for PATH changes to take effect"
}
function Set-NodePathConfiguration {
$bunGlobalDir = "$env:USERPROFILE\.bun\install\global\node_modules"
$currentNodePath = [Environment]::GetEnvironmentVariable("NODE_PATH", "User")
if ($currentNodePath -like "*bun*") {
return
}
$newNodePath = if ($currentNodePath) {
"$bunGlobalDir;$currentNodePath"
} else {
$bunGlobalDir
}
[Environment]::SetEnvironmentVariable("NODE_PATH", $newNodePath, "User")
$env:NODE_PATH = $newNodePath
Write-Success "NODE_PATH configured"
}
# =============================================================================
# MCP Configuration
# =============================================================================
function Set-McpConfiguration {
$mcpPath = Join-Path $Script:InstallDir "supertag-mcp.exe"
$configured = @()
# Claude Desktop
$claudeConfig = "$env:APPDATA\Claude\claude_desktop_config.json"
if (Test-Path (Split-Path $claudeConfig -Parent)) {
if (Set-McpClientConfig -ConfigFile $claudeConfig -McpPath $mcpPath) {
$configured += "Claude Desktop"
}
}
# Cursor
$cursorConfig = "$env:APPDATA\Cursor\User\globalStorage\cursor-mcp\config.json"
if (Test-Path (Split-Path $cursorConfig -Parent)) {
if (Set-McpClientConfig -ConfigFile $cursorConfig -McpPath $mcpPath) {
$configured += "Cursor"
}
}
# Claude Code
$claudeCodeConfig = "$env:USERPROFILE\.claude.json"
if (Test-Path $claudeCodeConfig) {
if (Set-McpClientConfig -ConfigFile $claudeCodeConfig -McpPath $mcpPath) {
$configured += "Claude Code"
}
}
if ($configured.Count -eq 0) {
Write-Info "No MCP clients found. You can configure manually later."
} else {
Write-Success "MCP configured for: $($configured -join ', ')"
}
}
function ConvertTo-HashtableRecursive {
param([Parameter(ValueFromPipeline)]$InputObject)
if ($null -eq $InputObject) { return @{} }
if ($InputObject -is [System.Collections.IDictionary]) { return $InputObject }
$hash = @{}
foreach ($prop in $InputObject.PSObject.Properties) {
if ($prop.Value -is [PSCustomObject]) {
$hash[$prop.Name] = ConvertTo-HashtableRecursive $prop.Value
} else {
$hash[$prop.Name] = $prop.Value
}
}
return $hash
}
function Set-McpClientConfig {
param(
[string]$ConfigFile,
[string]$McpPath
)
try {
# Create backup if exists
if (Test-Path $ConfigFile) {
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
Copy-Item -Path $ConfigFile -Destination "$ConfigFile.backup.$timestamp"
}
# Load or create config (compatible with PowerShell 5.1+)
if (Test-Path $ConfigFile) {
$json = Get-Content $ConfigFile -Raw | ConvertFrom-Json
$config = ConvertTo-HashtableRecursive $json
} else {
$config = @{}
}
if (-not $config.ContainsKey("mcpServers")) {
$config["mcpServers"] = @{}
}
if (-not $config["mcpServers"].ContainsKey("supertag")) {
$config["mcpServers"]["supertag"] = @{
command = $McpPath
}
# Ensure directory exists
$configDir = Split-Path $ConfigFile -Parent
if (-not (Test-Path $configDir)) {
New-Item -ItemType Directory -Path $configDir -Force | Out-Null
}
$config | ConvertTo-Json -Depth 10 | Set-Content $ConfigFile
return $true
} else {
# Update path if different
if ($config["mcpServers"]["supertag"]["command"] -ne $McpPath) {
$config["mcpServers"]["supertag"]["command"] = $McpPath
$config | ConvertTo-Json -Depth 10 | Set-Content $ConfigFile
return $true
}
Write-Info "supertag already configured in $(Split-Path $ConfigFile -Leaf)"
return $true
}
} catch {
Write-Warning "Could not configure $ConfigFile`: $_"
return $false
}
}
# =============================================================================
# Verification
# =============================================================================
function Test-Installation {
Write-Host ""
Write-Info "Verifying installation..."
$allGood = $true
# Check supertag binary
$supertag = Join-Path $Script:InstallDir "supertag.exe"
if (Test-Path $supertag) {
try {
$version = (& $supertag --version 2>$null) -join ""
Write-Success "supertag: $version"
} catch {
Write-Success "supertag: ready"
}
} else {
Write-Error "supertag binary not found"
$allGood = $false
}
# Check supertag-export
$supertagExport = Join-Path $Script:InstallDir "supertag-export.exe"
if (Test-Path $supertagExport) {
Write-Success "supertag-export: ready"
} else {
Write-Warning "supertag-export not found (optional)"
}
# Check supertag-mcp
$supertagMcp = Join-Path $Script:InstallDir "supertag-mcp.exe"
if (Test-Path $supertagMcp) {
Write-Success "supertag-mcp: ready"
} else {
Write-Warning "supertag-mcp not found (optional)"
}
# Check if in PATH
if (Test-Command "supertag") {
Write-Success "supertag in PATH"
} else {
Write-Warning "supertag not in PATH yet (open a new terminal)"
}
if (-not $allGood) {
throw "Installation verification failed"
}
}
# =============================================================================
# Output
# =============================================================================
function Write-Banner {
Write-Host ""
Write-Host "Installing supertag-cli" -ForegroundColor White
Write-Host ""
}
function Write-SuccessBanner {
Write-Host ""
Write-Host "Installation complete!" -ForegroundColor Green
Write-Host ""
Write-Host " Commands installed:"
Write-Host " supertag - Query your Tana graph"
Write-Host " supertag-export - Export Tana data"
Write-Host " supertag-mcp - MCP server for AI tools"
Write-Host ""
Write-Host " Next steps:"
Write-Host " 1. Open a new PowerShell window"
Write-Host " 2. Run: supertag-export login"
Write-Host " 3. Run: supertag-export discover"
Write-Host ""
Write-Host " Documentation: " -NoNewline
Write-Host "https://github.com/$Script:GitHubRepo" -ForegroundColor Cyan
Write-Host ""
}
function Write-HelpMessage {
Write-Host "supertag-cli installer"
Write-Host ""
Write-Host "Usage: install.ps1 [options]"
Write-Host ""
Write-Host "Options:"
Write-Host " -Version VERSION Install specific version (default: latest)"
Write-Host " -NoMcp Skip MCP auto-configuration"
Write-Host " -Proxy URL Use HTTP proxy for downloads (e.g. http://proxy:8080)"
Write-Host " -Help Show this help message"
Write-Host ""
Write-Host "Examples:"
Write-Host " irm https://raw.githubusercontent.com/$Script:GitHubRepo/main/install.ps1 | iex"
Write-Host " .\install.ps1 -Version 0.16.0"
Write-Host " .\install.ps1 -Proxy http://your-proxy:8080"
Write-Host ""
}
# =============================================================================
# Main
# =============================================================================
function Main {
if ($Help) {
Write-HelpMessage
return
}
# Store proxy at script scope for helper functions
if ($Proxy) {
$Script:Proxy = $Proxy
}
Write-Banner
$platform = Get-Platform
Write-Info "Detected platform: $platform"
$resolvedVersion = Resolve-Version -Requested $Version
Write-Info "Target version: v$resolvedVersion"
Write-Step "1/6" "Installing Bun"
Install-Bun
Write-Step "2/6" "Installing Playwright"
Install-Playwright
Write-Step "3/6" "Installing Chromium"
Install-Chromium
Write-Step "4/6" "Downloading supertag-cli"
Install-Supertag -Version $resolvedVersion -Platform $platform
Write-Step "5/6" "Configuring PATH"
Set-PathConfiguration
Set-NodePathConfiguration
if (-not $NoMcp) {
Write-Step "6/6" "Configuring MCP"
Set-McpConfiguration
}
Test-Installation
Write-SuccessBanner
}
Main