-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathinstall.ps1
More file actions
223 lines (193 loc) · 7.87 KB
/
Copy pathinstall.ps1
File metadata and controls
223 lines (193 loc) · 7.87 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
<#
.SYNOPSIS
Uteke Windows installer — installs uteke CLI, server, and MCP binaries
.DESCRIPTION
Downloads and installs the latest uteke release for Windows x64 from GitHub.
Usage: Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass; irm https://raw.githubusercontent.com/codecoradev/uteke/main/install.ps1 | iex
Or: powershell -ExecutionPolicy Bypass -Command "irm https://raw.githubusercontent.com/codecoradev/uteke/main/install.ps1 | iex"
#>
[CmdletBinding()]
param(
[Parameter()]
[string]$Version = "",
[Parameter()]
[string]$InstallDir = "$env:USERPROFILE\.local\bin",
[Parameter()]
[switch]$NoPathUpdate
)
$ErrorActionPreference = "Stop"
function Write-Info { param([string]$msg) Write-Host "[INFO] $msg" -ForegroundColor Green }
function Write-Warn { param([string]$msg) Write-Host "[WARN] $msg" -ForegroundColor Yellow }
function Write-ErrorMsg { param([string]$msg) Write-Host "[ERROR] $msg" -ForegroundColor Red; exit 1 }
$REPO = "codecoradev/uteke"
$BINARIES = @("uteke.exe", "uteke-serve.exe", "uteke-mcp.exe")
# Use gh token for authenticated API requests if available
$env:GH_TOKEN = $env:GH_TOKEN
if (-not $env:GH_TOKEN) {
try { $env:GH_TOKEN = gh auth token 2>$null } catch {}
}
function Invoke-GitHubApi {
param([string]$Uri)
$params = @{ Uri = $Uri; UseBasicParsing = $true }
if ($env:GH_TOKEN) {
$params.Headers = @{ Authorization = "Bearer $env:GH_TOKEN" }
}
return Invoke-WebRequest @params
}
# Detect architecture
$ARCH = [Environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
if ($ARCH -eq "AMD64" -or $ARCH -eq "x86_64") {
$TARGET = "x86_64-pc-windows-msvc"
$ARTIFACT = "uteke-x86_64-pc-windows-msvc"
} elseif ($ARCH -eq "ARM64") {
Write-ErrorMsg "ARM64 Windows builds not yet published. Install via cargo: cargo install --path crates/uteke-cli"
} else {
Write-ErrorMsg "Unsupported architecture: $ARCH"
}
# Get latest version from GitHub
function Get-LatestVersion {
Write-Info "Fetching latest release from GitHub..."
try {
$apiUrl = "https://api.github.com/repos/$REPO/releases?per_page=30"
$response = Invoke-GitHubApi -Uri $apiUrl
$releases = $response.Content | ConvertFrom-Json
foreach ($release in $releases) {
if ($release.assets.Count -gt 0) {
foreach ($asset in $release.assets) {
if ($asset.name -like "*x86_64-pc-windows-msvc*") {
Write-Info "Found version: $($release.tag_name)"
return $release.tag_name
}
}
}
}
Write-ErrorMsg "No release with Windows binary found on GitHub."
} catch {
Write-Warn "GitHub API failed: $($_.Exception.Message)"
Write-ErrorMsg "Failed to get latest version. Set -Version v0.10.0 to pin a version."
}
}
# Download and verify
function Install-Uteke {
param([string]$Version)
Write-Info "Detected: Windows $ARCH"
Write-Info "Target: $TARGET"
Write-Info "Version: $Version"
$archiveName = "${ARTIFACT}-${Version}.zip"
$downloadUrl = "https://github.com/$REPO/releases/download/$Version/$archiveName"
$checksumsUrl = "https://github.com/$REPO/releases/download/$Version/checksums-sha256.txt"
$tempDir = [System.IO.Path]::GetTempPath()
$archivePath = Join-Path $tempDir $archiveName
$checksumPath = Join-Path $tempDir "checksums-sha256.txt"
$extractDir = Join-Path $tempDir "uteke-extract"
Write-Info "Downloading from: $downloadUrl"
try {
Invoke-WebRequest -Uri $downloadUrl -OutFile $archivePath -ErrorAction Stop
} catch {
Write-ErrorMsg "Failed to download $archiveName. Check version exists: https://github.com/$REPO/releases/tag/$Version"
}
# Download and verify checksum
Write-Info "Downloading checksums..."
try {
Invoke-WebRequest -Uri $checksumsUrl -OutFile $checksumPath -ErrorAction Stop
$checksums = Get-Content $checksumPath -Raw
# Split on whitespace (handles both spaces and tabs)
$expectedHash = ($checksums -split "`n" | Where-Object { $_ -like "*$archiveName*" } | ForEach-Object { $_ -split '\s+' })[0]
if ($expectedHash) {
Write-Info "Verifying SHA256 checksum..."
$actualHash = (Get-FileHash -Algorithm SHA256 $archivePath).Hash.ToLower()
if ($actualHash -ne $expectedHash.ToLower()) {
Write-ErrorMsg "Checksum mismatch! Expected: $expectedHash, Got: $actualHash"
}
Write-Info "Checksum verified: $expectedHash"
} else {
Write-Warn "Checksum for $archiveName not found in checksums file"
}
} catch {
Write-Warn "Failed to download/verify checksums - skipping verification"
}
# Extract
Write-Info "Extracting..."
if (Test-Path $extractDir) { Remove-Item $extractDir -Recurse -Force }
New-Item -ItemType Directory -Path $extractDir | Out-Null
Expand-Archive -Path $archivePath -DestinationPath $extractDir -Force
# Install binaries
Write-Info "Installing to $InstallDir..."
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
foreach ($binary in $BINARIES) {
$src = Join-Path $extractDir $binary
$dest = Join-Path $InstallDir $binary
if (Test-Path $src) {
Copy-Item $src $dest -Force
Write-Info "Installed $binary"
} else {
Write-Warn "$binary not found in archive"
}
}
# Cleanup
Remove-Item $archivePath -Force -ErrorAction SilentlyContinue
Remove-Item $checksumPath -Force -ErrorAction SilentlyContinue
Remove-Item $extractDir -Recurse -Force -ErrorAction SilentlyContinue
}
# Update PATH
function Update-Path {
param([string]$InstallDir)
if ($NoPathUpdate) {
Write-Warn 'Skipping PATH update (--NoPathUpdate specified)'
return
}
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -split ";" | Where-Object { $_ -eq $InstallDir }) {
Write-Info "$InstallDir already in user PATH"
return
}
Write-Info "Adding $InstallDir to user PATH..."
$newPath = $currentPath + ";" + $InstallDir
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
Write-Warn "PATH updated. Restart your terminal or run: `$env:PATH = [Environment]::GetEnvironmentVariable('Path','User')"
}
# Verify installation
function Verify-Install {
param([string]$InstallDir)
Write-Info "Verifying installation..."
$versionFlags = @{
"uteke.exe" = "--version"
"uteke-serve.exe" = "--help"
"uteke-mcp.exe" = "--help"
}
foreach ($binary in $BINARIES) {
$path = Join-Path $InstallDir $binary
if (Test-Path $path) {
try {
$flag = $versionFlags[$binary]
$version = & $path $flag 2>&1 | Select-Object -First 1
Write-Info (" {0}: {1}" -f $binary, $version)
} catch {
Write-Info (" {0}: installed" -f $binary)
}
} else {
Write-Warn (" {0}: NOT FOUND" -f $binary)
}
}
}
# Main
Write-Info "Installing uteke..."
if ($Version) {
Write-Info "Using pinned version: $Version"
} else {
$Version = Get-LatestVersion
if (-not $Version) { Write-ErrorMsg "Could not determine version" }
}
Install-Uteke -Version $Version
Update-Path -InstallDir $InstallDir
Verify-Install -InstallDir $InstallDir
Write-Host ""
Write-Info "Installation complete!"
Write-Host "Run 'uteke --help' to get started." -ForegroundColor Cyan
Write-Host ""
Write-Host "Quick start:" -ForegroundColor Cyan
Write-Host " uteke remember \"Deploy v2.1 to staging at 3pm\""
Write-Host " uteke recall \"when do we deploy?\""
Write-Host ""
Write-Host "MCP Server (for AI agents):" -ForegroundColor Cyan
Write-Host " uteke-mcp"