Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
349 lines (290 loc) · 12.5 KB
/
Copy pathinstall.ps1
File metadata and controls
349 lines (290 loc) · 12.5 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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Aikito Windows one-liner installer.
.DESCRIPTION
Installs Aikito on Windows. Validates Windows Developer Mode (required for
symlink support), cleans up legacy bin/ installations, and installs Aikito
using uv tool (preferred) or an isolated Python virtual environment.
.EXAMPLE
irm https://raw.githubusercontent.com/lsaint/aikito/main/install.ps1 | iex
.EXAMPLE
& ([scriptblock]::Create((irm https://raw.githubusercontent.com/lsaint/aikito/main/install.ps1))) -InstallDir "D:\aikito"
#>
[CmdletBinding()]
param (
# Install a specific version instead of the latest release (e.g. "1.30.0").
[string] $Version = "",
# Install to a custom directory instead of the default when using a virtual environment.
[string] $InstallDir = ""
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
# --- Constants ----------------------------------------------------------------
$DisplayName = "Aikito"
$DefaultDir = Join-Path $env:LOCALAPPDATA "Programs\aikito"
# --- Helpers ------------------------------------------------------------------
function Write-Step([string] $Msg) {
Write-Host " $Msg" -ForegroundColor Cyan
}
function Write-Ok([string] $Msg) {
Write-Host " [OK] $Msg" -ForegroundColor Green
}
function Write-Warn([string] $Msg) {
Write-Host " [WARN] $Msg" -ForegroundColor Yellow
}
function Write-Fail([string] $Msg) {
Write-Host ""
Write-Host " [ERROR] $Msg" -ForegroundColor Red
Write-Host ""
exit 1
}
function Clean-LegacyInstallation([string] $BaseDir) {
$legacyBin = Join-Path $BaseDir "bin"
# 1. Clean legacy aikito\bin entries from User PATH (matches DefaultDir, InstallDir, or any past *\aikito\bin)
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath) {
$parts = $userPath -split ';' | Where-Object {
$entry = $_.Trim().TrimEnd('\')
$entry -and ($entry -ne $legacyBin.TrimEnd('\')) -and ($entry -notmatch '[\\/]aikito[\\/]bin$')
}
$cleanedUserPath = $parts -join ';'
if ($cleanedUserPath -ne $userPath) {
[Environment]::SetEnvironmentVariable("PATH", $cleanedUserPath, "User")
Write-Ok "Removed legacy bin entry from User PATH"
}
}
# Also clean current session env:PATH
$sessionParts = $env:PATH -split ';' | Where-Object {
$entry = $_.Trim().TrimEnd('\')
$entry -and ($entry -ne $legacyBin.TrimEnd('\')) -and ($entry -notmatch '[\\/]aikito[\\/]bin$')
}
$env:PATH = $sessionParts -join ';'
# 2. Check specifically for legacy Aikito stub scripts before removing legacy files
$isLegacyAikito = (Test-Path (Join-Path $legacyBin "aikito.cmd")) -or `
(Test-Path (Join-Path $legacyBin "aikito")) -or `
(Test-Path (Join-Path $legacyBin "aikito.ps1"))
if ($isLegacyAikito) {
Write-Step "Cleaning up legacy installation stubs in $legacyBin ..."
try {
Remove-Item $legacyBin -Recurse -Force -ErrorAction Stop
Write-Ok "Removed legacy $legacyBin"
} catch {
Write-Warn "Could not remove legacy $legacyBin ($_); continuing..."
}
}
}
# --- Banner -------------------------------------------------------------------
Write-Host ""
Write-Host " $DisplayName Installer for Windows" -ForegroundColor White
Write-Host " -----------------------------------------" -ForegroundColor DarkGray
Write-Host ""
# --- Check Developer Mode (symlink support) -----------------------------------
Write-Step "Checking Windows Developer Mode (required for symlinks) ..."
$developerModeOk = $false
# 1. Try registry check first
try {
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
$val = (Get-ItemProperty -Path $regPath -Name "AllowDevelopmentWithoutDevLicense" -ErrorAction Stop).AllowDevelopmentWithoutDevLicense
$developerModeOk = ($val -eq 1)
} catch {}
# 2. Fall back: probe actual symlink creation (works for Administrator sessions)
if (-not $developerModeOk) {
try {
$tmpDir = [System.IO.Path]::GetTempPath()
$probeTarget = Join-Path $tmpDir "aikito-probe-target-$([System.Guid]::NewGuid())"
$probeSrc = Join-Path $tmpDir "aikito-probe-link-$([System.Guid]::NewGuid())"
[void][System.IO.File]::WriteAllText($probeTarget, "probe")
New-Item -ItemType SymbolicLink -Path $probeSrc -Target $probeTarget -ErrorAction Stop | Out-Null
$developerModeOk = $true
Remove-Item $probeSrc -ErrorAction SilentlyContinue
Remove-Item $probeTarget -ErrorAction SilentlyContinue
} catch {}
}
if (-not $developerModeOk) {
Write-Fail @"
Windows Developer Mode is required to create symbolic links without Administrator privileges.
How to enable (choose one):
Option 1 - Settings GUI:
Settings -> System -> For developers -> Developer Mode (toggle ON)
Option 2 - PowerShell as Administrator:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
After enabling Developer Mode, re-run this installer.
"@
}
Write-Ok "Developer Mode / symlink support confirmed"
# --- Cleanup Legacy Installation ---------------------------------------------
Clean-LegacyInstallation $DefaultDir
if ($InstallDir -and ($InstallDir -ne $DefaultDir)) {
Clean-LegacyInstallation $InstallDir
}
# --- Install Package ----------------------------------------------------------
$pkgSpec = if ($Version) { "aikito==$($Version.TrimStart('v'))" } else { "aikito" }
$installedViaUv = $false
$ScriptsDir = $null
if (-not $InstallDir -and (Get-Command uv -ErrorAction SilentlyContinue)) {
Write-Step "Found uv, installing via 'uv tool install' ..."
try {
& uv tool install --force $pkgSpec
if ($LASTEXITCODE -eq 0) {
$installedViaUv = $true
Write-Ok "Installed $pkgSpec via uv tool"
try { & uv tool update-shell 2>$null } catch {}
# Temporarily add candidate uv bin directories to session PATH for immediate verification
$uvBinCandidates = @(
$env:UV_TOOL_BIN_DIR,
(Join-Path $env:USERPROFILE ".local\bin")
) | Where-Object { $_ -and (Test-Path $_) }
foreach ($cand in $uvBinCandidates) {
if ($env:PATH -notlike "*$cand*") {
$env:PATH = "$cand;$env:PATH"
}
}
}
} catch {
Write-Warn "uv tool install failed ($_); falling back to Python virtualenv..."
}
}
if (-not $installedViaUv) {
# --- Check Python 3.12+ ---
Write-Step "Checking Python 3.12+ ..."
$PythonExe = $null
$PythonVer = $null
foreach ($candidate in @("py", "python3", "python")) {
$found = Get-Command $candidate -ErrorAction SilentlyContinue
if ($found) {
try {
$invokeArgs = if ($candidate -eq "py") { @("-3", "-c") } else { @("-c") }
$ver = & $candidate @invokeArgs "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>$null
if ($ver -match "^(\d+)\.(\d+)$") {
$major = [int]$Matches[1]
$minor = [int]$Matches[2]
if ($major -gt 3 -or ($major -eq 3 -and $minor -ge 12)) {
$PythonExe = $candidate
$PythonVer = $ver.Trim()
break
}
}
} catch {}
}
}
if (-not $PythonExe) {
Write-Fail @"
Python 3.12 or later is required but was not found in PATH.
Download from: https://www.python.org/downloads/
Or via winget: winget install Python.Python.3.12
Alternatively, install Astral uv (https://docs.astral.sh/uv/) and re-run this installer.
"@
}
Write-Ok "Python $PythonVer found ($PythonExe)"
if (-not $InstallDir) {
$InstallDir = $DefaultDir
}
Write-Step "Setting up virtual environment at $InstallDir ..."
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
$invokeArgs = if ($PythonExe -eq "py") { @("-3", "-m", "venv", $InstallDir) } else { @("-m", "venv", $InstallDir) }
& $PythonExe @invokeArgs
if ($LASTEXITCODE -ne 0) {
Write-Fail "Failed to create Python virtual environment at $InstallDir."
}
$ScriptsDir = Join-Path $InstallDir "Scripts"
$VenvPython = Join-Path $ScriptsDir "python.exe"
if (-not (Test-Path $VenvPython)) {
Write-Fail "Virtual environment Python executable not found at $VenvPython."
}
Write-Step "Installing $pkgSpec via pip ..."
& $VenvPython -m pip install --upgrade --no-warn-script-location pip
& $VenvPython -m pip install --upgrade --no-warn-script-location $pkgSpec
if ($LASTEXITCODE -ne 0) {
Write-Fail "Failed to install $pkgSpec via pip."
}
Write-Ok "Installed $pkgSpec to $InstallDir"
# --- PATH registration ---
Write-Step "Updating User PATH ..."
$CurrentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($CurrentPath -notlike "*$ScriptsDir*") {
$NewPath = if ($CurrentPath) { "$ScriptsDir;$CurrentPath" } else { $ScriptsDir }
[Environment]::SetEnvironmentVariable("PATH", $NewPath, "User")
$env:PATH = "$ScriptsDir;$env:PATH"
Write-Ok "Added $ScriptsDir to User PATH"
} else {
Write-Ok "$ScriptsDir is already in PATH"
}
}
# --- Smoke test ---------------------------------------------------------------
Write-Step "Verifying installation ..."
$verified = $false
try {
$verLine = & aikito version 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Ok $verLine.ToString().Trim()
$verified = $true
}
} catch {}
if (-not $verified) {
$candidates = @()
if ($ScriptsDir) {
$candidates += (Join-Path $ScriptsDir "aikito.exe")
}
if ($env:UV_TOOL_BIN_DIR) {
$candidates += (Join-Path $env:UV_TOOL_BIN_DIR "aikito.exe")
}
if ($env:USERPROFILE) {
$candidates += (Join-Path $env:USERPROFILE ".local\bin\aikito.exe")
}
foreach ($exe in $candidates) {
if ($exe -and (Test-Path $exe)) {
try {
$verLine = & $exe version 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Ok $verLine.ToString().Trim()
$verified = $true
break
}
} catch {}
}
}
}
if (-not $verified) {
Write-Warn "Could not verify 'aikito version' in current session. Open a new terminal to check."
}
# Check for stale resolution shadowing the new install
$resolved = (Get-Command aikito -ErrorAction SilentlyContinue).Source
$expectedLocation = $false
if ($resolved) {
if ($ScriptsDir -and ($resolved -like "$ScriptsDir*")) {
$expectedLocation = $true
}
if ($env:USERPROFILE -and ($resolved -like "*\.local\bin\*")) {
$expectedLocation = $true
}
if ($env:UV_TOOL_BIN_DIR -and ($resolved -like "$($env:UV_TOOL_BIN_DIR)*")) {
$expectedLocation = $true
}
if (-not $expectedLocation) {
Write-Warn "'aikito' currently resolves to '$resolved' — a stale or conflicting PATH entry may shadow the new installation."
}
}
# --- Done ---------------------------------------------------------------------
Write-Host ""
Write-Host " $DisplayName installed successfully!" -ForegroundColor Green
Write-Host ""
Write-Host " Next steps:" -ForegroundColor White
Write-Host ""
Write-Host " 1. Open a NEW terminal (to pick up the updated PATH)." -ForegroundColor DarkGray
Write-Host ""
Write-Host " 2. Set up your workspace:" -ForegroundColor DarkGray
Write-Host " - Brand new workspace:" -ForegroundColor DarkGray
Write-Host " aikito init workspace" -ForegroundColor Cyan
Write-Host " - Existing workspace:" -ForegroundColor DarkGray
Write-Host " aikito init workspace <workspace-path>" -ForegroundColor Cyan
Write-Host ""
Write-Host " 3. Sync your workspace:" -ForegroundColor DarkGray
Write-Host " aikito sync" -ForegroundColor Cyan
Write-Host ""
Write-Host " 4. (Optional) Enable PowerShell tab completion." -ForegroundColor DarkGray
Write-Host " Run this to append it to your `$PROFILE automatically:" -ForegroundColor DarkGray
Write-Host ' if (!(Test-Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force | Out-Null }; Add-Content $PROFILE "`nInvoke-Expression (& aikito completion powershell | Out-String)"' -ForegroundColor Cyan
Write-Host ""