forked from Dicklesworthstone/coding_agent_session_search
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
106 lines (93 loc) · 3.93 KB
/
Copy pathinstall.ps1
File metadata and controls
106 lines (93 loc) · 3.93 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
Param(
[string]$Version = "",
[string]$Dest = "$HOME/.local/bin",
[string]$Owner = "Dicklesworthstone",
[string]$Repo = "coding_agent_session_search",
[string]$Checksum = "",
[string]$ChecksumUrl = "",
[string]$ArtifactUrl = "",
[switch]$EasyMode,
[switch]$Verify
)
$ErrorActionPreference = "Stop"
$FallbackVersion = "v0.1.54"
# Resolve latest version if not specified
if (-not $Version) {
Write-Host "Resolving latest version..."
try {
# Try GitHub API first
$apiUrl = "https://api.github.com/repos/$Owner/$Repo/releases/latest"
$release = Invoke-RestMethod -Uri $apiUrl -Headers @{"Accept"="application/vnd.github.v3+json"} -ErrorAction Stop
$Version = $release.tag_name
Write-Host "Resolved latest version: $Version"
} catch {
# Fallback: try redirect-based resolution
try {
$redirectUrl = "https://github.com/$Owner/$Repo/releases/latest"
# MaximumRedirection 0 causes error on redirect; we catch it to extract Location header
$response = Invoke-WebRequest -Uri $redirectUrl -MaximumRedirection 0 -ErrorAction Stop
} catch {
if ($_.Exception.Response.Headers.Location) {
$location = $_.Exception.Response.Headers.Location.ToString()
$extracted = $location -replace ".*/tag/", ""
# Validate: must start with 'v' and not contain URL chars (/) to be a valid version
if ($extracted -match "^v[0-9]" -and $extracted -notmatch "/") {
$Version = $extracted
Write-Host "Resolved latest version via redirect: $Version"
}
}
}
if (-not $Version) {
$Version = $FallbackVersion
Write-Warning "Could not resolve latest version; defaulting to $Version"
}
}
}
$os = "windows"
$arch = if ([Environment]::Is64BitProcess) { "x86_64" } else { "x86" }
$zip = "coding-agent-search-$Version-$arch-$os-msvc.zip"
if ($ArtifactUrl) {
$url = $ArtifactUrl
} else {
# cargo-dist usually names windows zips like package-vX.Y.Z-x86_64-pc-windows-msvc.zip
# But we'll use a simpler guess matching install.sh logic or common dist patterns
$target = "x86_64-pc-windows-msvc"
$zip = "coding-agent-search-$target.zip"
$url = "https://github.com/$Owner/$Repo/releases/download/$Version/$zip"
}
$tmp = New-TemporaryFile | Split-Path
$zipFile = Join-Path $tmp $zip
Write-Host "Downloading $url"
Invoke-WebRequest -Uri $url -OutFile $zipFile
$checksumToUse = $Checksum
if (-not $checksumToUse) {
if (-not $ChecksumUrl) { $ChecksumUrl = "$url.sha256" }
Write-Host "Fetching checksum from $ChecksumUrl"
try { $checksumToUse = (Invoke-WebRequest -Uri $ChecksumUrl -UseBasicParsing).Content.Trim().Split(' ')[0] } catch { Write-Error "Checksum file not found or invalid; refusing to install."; exit 1 }
}
$hash = Get-FileHash $zipFile -Algorithm SHA256
if ($hash.Hash.ToLower() -ne $checksumToUse.ToLower()) { Write-Error "Checksum mismatch"; exit 1 }
Add-Type -AssemblyName System.IO.Compression.FileSystem
$extractDir = Join-Path $tmp "extract"
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipFile, $extractDir)
$bin = Get-ChildItem -Path $extractDir -Recurse -Filter "cass.exe" | Select-Object -First 1
if (-not $bin) {
$bin = Get-ChildItem -Path $extractDir -Recurse -Filter "coding-agent-search.exe" | Select-Object -First 1
if ($bin) { Write-Warning "Found coding-agent-search.exe instead of cass.exe; installing as cass.exe" }
}
if (-not $bin) { Write-Error "Binary not found in zip"; exit 1 }
if (-not (Test-Path $Dest)) { New-Item -ItemType Directory -Force -Path $Dest | Out-Null }
Copy-Item $bin.FullName (Join-Path $Dest "cass.exe") -Force
Write-Host "Installed to $Dest\cass.exe"
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
if (-not $path.Contains($Dest)) {
if ($EasyMode) {
[Environment]::SetEnvironmentVariable("PATH", "$path;$Dest", "User")
Write-Host "Added $Dest to PATH (User)"
} else {
Write-Host "Add $Dest to PATH to use cass"
}
}
if ($Verify) {
& "$Dest\cass.exe" --version | Write-Host
}