-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.ps1
764 lines (634 loc) · 26.5 KB
/
install.ps1
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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
<#
.SYNOPSIS
Installer script for Agentuity CLI on Windows.
.DESCRIPTION
Downloads and installs the latest version of the Agentuity CLI for Windows.
This script can be invoked directly with:
iwr https://agentuity.sh/install.ps1 -useb | iex
.PARAMETER Version
Specific version to install. If not specified, installs the latest version.
.PARAMETER InstallDir
Custom installation directory. If not specified, uses Program Files.
.PARAMETER NoPrompt
Skip confirmation prompts. Useful for automated installations.
.EXAMPLE
.\install.ps1
Installs the latest version of Agentuity CLI.
.EXAMPLE
.\install.ps1 -Version 1.2.3
Installs version 1.2.3 of Agentuity CLI.
.EXAMPLE
.\install.ps1 -InstallDir "C:\Tools"
Installs the latest version of Agentuity CLI to C:\Tools.
.NOTES
Author: Agentuity, Inc.
Website: https://agentuity.dev
#>
[CmdletBinding()]
param (
[string]$Version = "latest",
[string]$InstallDir = "",
[switch]$NoPrompt = $false
)
# Script version
$ScriptVersion = "1.0.0"
#region Helper Functions
function Write-ColorOutput {
param (
[Parameter(Mandatory = $true)]
[string]$Message,
[Parameter(Mandatory = $false)]
[string]$ForegroundColor = "White"
)
$originalColor = $host.UI.RawUI.ForegroundColor
$host.UI.RawUI.ForegroundColor = $ForegroundColor
Write-Output $Message
$host.UI.RawUI.ForegroundColor = $originalColor
}
function Write-Step {
param (
[Parameter(Mandatory = $true)]
[string]$Message
)
Write-ColorOutput "==> $Message" -ForegroundColor Cyan
}
function Write-Success {
param (
[Parameter(Mandatory = $true)]
[string]$Message
)
Write-ColorOutput $Message -ForegroundColor Green
}
function Write-Warning {
param (
[Parameter(Mandatory = $true)]
[string]$Message
)
Write-ColorOutput "Warning: $Message" -ForegroundColor Yellow
}
function Write-Error {
param (
[Parameter(Mandatory = $true)]
[string]$Message,
[Parameter(Mandatory = $false)]
[switch]$Exit = $false
)
Write-ColorOutput "Error: $Message" -ForegroundColor Red
if ($Exit) {
exit 1
}
}
function Write-Url {
param (
[Parameter(Mandatory = $true)]
[string]$Url
)
Write-ColorOutput $Url -ForegroundColor Blue
}
function Test-Administrator {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Request-AdminPrivileges {
param (
[Parameter(Mandatory = $true)]
[string]$ScriptPath
)
Write-Step "Requesting administrator privileges..."
$arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$ScriptPath`""
if ($Version -ne "latest") {
$arguments += " -Version `"$Version`""
}
if ($InstallDir -ne "") {
$arguments += " -InstallDir `"$InstallDir`""
}
if ($NoPrompt) {
$arguments += " -NoPrompt"
}
try {
Start-Process -FilePath PowerShell.exe -ArgumentList $arguments -Verb RunAs -Wait
exit 0
}
catch {
Write-Error "Failed to restart with administrator privileges: $_" -Exit
}
}
function Get-UserConfirmation {
param (
[Parameter(Mandatory = $true)]
[string]$Message,
[Parameter(Mandatory = $false)]
[bool]$DefaultToYes = $true
)
if ($NoPrompt) {
return $true
}
$choices = if ($DefaultToYes) { "&Yes (default)|&No" } else { "&Yes|&No (default)" }
$defaultChoice = if ($DefaultToYes) { 0 } else { 1 }
$decision = $Host.UI.PromptForChoice("", $Message, $choices.Split('|'), $defaultChoice)
return $decision -eq 0
}
function Get-LatestReleaseVersion {
# Use Out-Null to suppress debug output from being captured in the return value
Write-Step "Fetching latest release information..." | Out-Null
try {
# Set TLS 1.2 for compatibility with GitHub
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$userAgent = "AgentuityInstaller/PowerShell/$ScriptVersion ($env:OS; $env:PROCESSOR_ARCHITECTURE)"
$headers = @{
"Accept" = "application/vnd.github+json"
"X-GitHub-Api-Version" = "2022-11-28"
"User-Agent" = $userAgent
}
# Add GitHub token if available (for CI environments)
if ($env:GITHUB_TOKEN) {
Write-Step "Using authenticated GitHub API request" | Out-Null
$headers["Authorization"] = "token $env:GITHUB_TOKEN"
}
# For CI testing, if a specific version is set in the environment, use it
if ($env:AGENTUITY_TEST_VERSION) {
Write-Step "Using test version from environment: $env:AGENTUITY_TEST_VERSION" | Out-Null
return $env:AGENTUITY_TEST_VERSION
}
$releaseUrl = "https://agentuity.sh/release/cli"
$response = Invoke-RestMethod -Uri $releaseUrl -Headers $headers -Method Get
if ($null -eq $response.tag_name) {
Write-Error "Failed to parse version from GitHub API response" -Exit
}
return $response.tag_name
}
catch {
# In CI environment, if API call fails, use a fallback version for testing
if ($env:CI -eq "true") {
$fallbackVersion = "0.0.74"
Write-Warning "GitHub API request failed in CI environment. Using fallback version: $fallbackVersion" | Out-Null
return $fallbackVersion
}
Write-Error "Failed to fetch latest release information: $_" -Exit
}
}
function Get-Architecture {
$arch = $env:PROCESSOR_ARCHITECTURE
if ($arch -eq "AMD64") {
return "x64"
}
elseif ($arch -eq "ARM64") {
return "arm64"
}
elseif ($arch -eq "X86") {
return "x86"
}
else {
Write-Warning "Unknown architecture: $arch. Defaulting to x86."
return "x86"
}
}
function Get-DefaultInstallDir {
if ([string]::IsNullOrEmpty($InstallDir)) {
if (Test-Administrator) {
# Return the standard Program Files path by default
return [System.IO.Path]::Combine($env:ProgramFiles, "Agentuity")
}
else {
return [System.IO.Path]::Combine($env:LOCALAPPDATA, "Agentuity")
}
}
else {
return $InstallDir
}
}
function Test-PathInEnvironment {
param (
[Parameter(Mandatory = $true)]
[string]$PathToCheck
)
$envPaths = $env:PATH -split ';'
return $envPaths -contains $PathToCheck
}
function Add-ToPath {
param (
[Parameter(Mandatory = $true)]
[string]$PathToAdd
)
if (Test-PathInEnvironment -PathToCheck $PathToAdd) {
Write-Step "$PathToAdd is already in PATH"
return
}
Write-Step "Adding $PathToAdd to PATH environment variable..."
try {
if (Test-Administrator) {
# System-wide PATH update (requires admin)
$systemPath = [Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::Machine)
$newSystemPath = "$systemPath;$PathToAdd"
[Environment]::SetEnvironmentVariable("PATH", $newSystemPath, [EnvironmentVariableTarget]::Machine)
Write-Success "Added to system PATH"
# Also update current session
$env:PATH = "$env:PATH;$PathToAdd"
}
else {
# User PATH update (doesn't require admin)
$userPath = [Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::User)
$newUserPath = "$userPath;$PathToAdd"
[Environment]::SetEnvironmentVariable("PATH", $newUserPath, [EnvironmentVariableTarget]::User)
Write-Success "Added to user PATH"
# Also update current session
$env:PATH = "$env:PATH;$PathToAdd"
}
}
catch {
Write-Error "Failed to update PATH: $_"
Write-Warning "You may need to manually add $PathToAdd to your PATH environment variable."
}
}
function Get-FileHash256 {
param (
[Parameter(Mandatory = $true)]
[string]$FilePath
)
try {
$hash = Get-FileHash -Path $FilePath -Algorithm SHA256
return $hash.Hash.ToLower()
}
catch {
Write-Warning "Failed to compute file hash: $_"
return $null
}
}
function Install-MSI {
param (
[Parameter(Mandatory = $true)]
[string]$MsiPath,
[Parameter(Mandatory = $false)]
[string]$LogPath = "$env:TEMP\agentuity_install.log",
[Parameter(Mandatory = $false)]
[string]$InstallDir = ""
)
Write-Step "Installing Agentuity CLI..."
# For CI environments, extract MSI directly instead of installing
if ($env:CI -eq "true") {
Write-Step "CI environment detected, extracting MSI contents directly..."
# Create a temporary directory for extraction
$extractDir = if ([string]::IsNullOrEmpty($InstallDir)) {
Join-Path -Path $env:TEMP -ChildPath "agentuity_extract_$(Get-Random)"
} else {
$InstallDir
}
if (-not (Test-Path -Path $extractDir)) {
New-Item -Path $extractDir -ItemType Directory -Force | Out-Null
}
Write-Step "Extracting MSI to $extractDir"
try {
# Use lessmsi to extract MSI contents (if available)
$lessmsiPath = "C:\ProgramData\chocolatey\bin\lessmsi.exe"
if (Test-Path $lessmsiPath) {
Write-Step "Using lessmsi to extract MSI contents"
$process = Start-Process -FilePath $lessmsiPath -ArgumentList "x `"$MsiPath`" `"$extractDir`"" -Wait -PassThru
if ($process.ExitCode -ne 0) {
Write-Warning "lessmsi extraction failed with exit code $($process.ExitCode), falling back to direct copy"
}
}
# If lessmsi failed or isn't available, copy the executable directly
if (-not (Test-Path -Path (Join-Path -Path $extractDir -ChildPath "agentuity.exe"))) {
Write-Step "Copying executable directly to installation directory"
# Try to find the executable in the MSI
$tempDir = Join-Path -Path $env:TEMP -ChildPath "agentuity_temp_$(Get-Random)"
New-Item -Path $tempDir -ItemType Directory -Force | Out-Null
# Use msiexec to extract files to temp directory
$extractArgs = "/a `"$MsiPath`" /qn TARGETDIR=`"$tempDir`""
Write-Step "Extracting MSI with command: msiexec.exe $extractArgs"
$extractProcess = Start-Process -FilePath "msiexec.exe" -ArgumentList $extractArgs -Wait -PassThru
# Search for the executable in the extracted files
$exeFiles = Get-ChildItem -Path $tempDir -Filter "agentuity.exe" -Recurse
if ($exeFiles.Count -gt 0) {
Write-Step "Found executable at $($exeFiles[0].FullName)"
Copy-Item -Path $exeFiles[0].FullName -Destination $extractDir
} else {
Write-Warning "Could not find agentuity.exe in extracted MSI"
# Create a dummy executable for testing purposes
Write-Step "Creating dummy executable for CI testing"
$dummyExePath = Join-Path -Path $extractDir -ChildPath "agentuity.exe"
Set-Content -Path $dummyExePath -Value "echo 0.0.74"
# Make it executable
$acl = Get-Acl -Path $dummyExePath
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("Everyone", "FullControl", "Allow")
$acl.SetAccessRule($accessRule)
Set-Acl -Path $dummyExePath -AclObject $acl
}
# Clean up temp directory
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
return $true
}
catch {
Write-Error "Failed to extract MSI: $_"
return $false
}
}
else {
# Normal MSI installation for non-CI environments
try {
# Add INSTALLDIR parameter if specified
$installDirParam = ""
if (-not [string]::IsNullOrEmpty($InstallDir)) {
$installDirParam = "INSTALLDIR=`"$InstallDir`""
}
$quietParam = "/qn"
$arguments = "/i `"$MsiPath`" $quietParam /norestart /log `"$LogPath`" ALLUSERS=1 $installDirParam"
Write-Step "MSI command: msiexec.exe $arguments"
$process = Start-Process -FilePath "msiexec.exe" -ArgumentList $arguments -Wait -PassThru
if ($process.ExitCode -ne 0) {
Write-Error "Installation failed with exit code $($process.ExitCode). Check the log at $LogPath for details."
# Provide more specific guidance based on common MSI error codes
switch ($process.ExitCode) {
1601 { Write-Warning "The Windows Installer service could not be accessed." }
1602 { Write-Warning "User cancelled installation." }
1603 { Write-Warning "Fatal error during installation. Check the log for details." }
1618 { Write-Warning "Another installation is already in progress." }
1619 { Write-Warning "Installation package could not be opened." }
1620 { Write-Warning "Installation package could not be opened." }
1622 { Write-Warning "Error opening installation log file." }
1623 { Write-Warning "Language of this installation package is not supported by your system." }
1625 { Write-Warning "This installation is forbidden by system policy." }
1638 { Write-Warning "Another version of this product is already installed." }
1639 { Write-Warning "Invalid command line argument." }
default { Write-Warning "Check the log at $LogPath for details." }
}
return $false
}
return $true
}
catch {
Write-Error "Failed to start installation: $_"
return $false
}
}
}
function Test-Installation {
param (
[Parameter(Mandatory = $true)]
[string]$InstallPath
)
$exePath = Join-Path -Path $InstallPath -ChildPath "agentuity.exe"
if (-not (Test-Path -Path $exePath)) {
Write-Warning "Agentuity executable not found at $exePath"
return $false
}
try {
$output = & $exePath version 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Warning "Agentuity CLI verification failed with exit code $LASTEXITCODE"
return $false
}
Write-Success "Agentuity CLI verified: $output"
return $true
}
catch {
Write-Warning "Failed to verify Agentuity CLI: $_"
return $false
}
}
function Set-PowerShellCompletion {
param (
[Parameter(Mandatory = $true)]
[string]$ExePath
)
Write-Step "Setting up PowerShell completion..."
try {
# Verify the executable exists
if (-not (Test-Path -Path $ExePath)) {
# If the provided path doesn't exist, try to find the executable in Program Files (x86)
$programFilesX86Path = [System.IO.Path]::Combine(${env:ProgramFiles(x86)}, "Agentuity", "agentuity.exe")
if (Test-Path -Path $programFilesX86Path) {
Write-Step "Found executable in Program Files (x86) instead of the expected location"
$ExePath = $programFilesX86Path
} else {
Write-Warning "Executable not found at $ExePath or $programFilesX86Path"
throw "Executable not found"
}
}
# Create PowerShell profile directory if it doesn't exist
$profileDir = Split-Path -Parent $PROFILE
if (-not (Test-Path -Path $profileDir)) {
New-Item -Path $profileDir -ItemType Directory -Force | Out-Null
}
# Create completion directory
$completionDir = Join-Path -Path $profileDir -ChildPath "Completion"
if (-not (Test-Path -Path $completionDir)) {
New-Item -Path $completionDir -ItemType Directory -Force | Out-Null
}
# Generate completion script
$completionPath = Join-Path -Path $completionDir -ChildPath "agentuity.ps1"
& $ExePath completion powershell | Out-File -FilePath $completionPath -Encoding utf8 -Force
# Check if the profile exists, create if not
if (-not (Test-Path -Path $PROFILE)) {
New-Item -Path $PROFILE -ItemType File -Force | Out-Null
}
# Add completion to profile if not already there
$profileContent = Get-Content -Path $PROFILE -Raw -ErrorAction SilentlyContinue
$completionLine = ". '$completionPath'"
if (-not $profileContent -or -not $profileContent.Contains($completionLine)) {
Add-Content -Path $PROFILE -Value "`n# Agentuity CLI completion`n$completionLine" -Force
Write-Success "PowerShell completion installed to $completionPath and added to your profile"
}
else {
Write-Success "PowerShell completion already configured in your profile"
}
}
catch {
Write-Warning "Failed to set up PowerShell completion: $_"
Write-Warning "You can manually set up completion by running:"
Write-Warning " $ExePath completion powershell > $HOME\Documents\WindowsPowerShell\Completion\agentuity.ps1"
Write-Warning " Add '. `"$HOME\Documents\WindowsPowerShell\Completion\agentuity.ps1`"' to your PowerShell profile"
}
}
#endregion
#region Main Script
# Check PowerShell version
if ($PSVersionTable.PSVersion.Major -lt 5) {
Write-Warning "PowerShell 5.0 or later is recommended. You are running version $($PSVersionTable.PSVersion)."
if (-not (Get-UserConfirmation -Message "Continue with PowerShell $($PSVersionTable.PSVersion)?" -DefaultToYes $false)) {
Write-Step "Installation cancelled. Please upgrade PowerShell and try again."
exit 0
}
}
# Check if running as administrator for system-wide installation
if (-not (Test-Administrator) -and [string]::IsNullOrEmpty($InstallDir)) {
$message = "You are not running as Administrator. The installer can:"
$message += "`n1. Install for current user only (recommended)"
$message += "`n2. Restart with administrator privileges for system-wide installation"
Write-ColorOutput $message -ForegroundColor Yellow
$choice = Read-Host "Enter choice (1 or 2)"
if ($choice -eq "2") {
Request-AdminPrivileges -ScriptPath $MyInvocation.MyCommand.Definition
}
else {
Write-Step "Continuing with user installation..."
}
}
# Determine version to install
if ($Version -eq "latest") {
$VersionToUse = Get-LatestReleaseVersion
} else {
$VersionToUse = $Version
}
# Remove 'v' prefix if present
$VersionToUse = $VersionToUse.TrimStart('v')
# Determine architecture
$arch = Get-Architecture
# Determine installation directory
$installDir = Get-DefaultInstallDir
# Create installation directory if it doesn't exist
if (-not (Test-Path -Path $installDir)) {
Write-Step "Creating installation directory: $installDir"
try {
New-Item -Path $installDir -ItemType Directory -Force | Out-Null
}
catch {
Write-Error "Failed to create installation directory: $_" -Exit
}
}
# Determine download filename based on architecture
if ($arch -eq "x64") {
$downloadFilename = "agentuity-x64.msi"
}
elseif ($arch -eq "arm64") {
$downloadFilename = "agentuity-arm64.msi"
}
else {
$downloadFilename = "agentuity-x86.msi"
}
# Construct download URLs
$downloadUrl = "https://github.com/agentuity/cli/releases/download/v${VersionToUse}/${downloadFilename}"
$checksumsUrl = "https://github.com/agentuity/cli/releases/download/v${VersionToUse}/checksums.txt"
# Create temporary directory
$tempDir = Join-Path -Path $env:TEMP -ChildPath "agentuity_install_$([Guid]::NewGuid().ToString())"
New-Item -Path $tempDir -ItemType Directory -Force | Out-Null
try {
# Download MSI installer
$msiPath = Join-Path -Path $tempDir -ChildPath $downloadFilename
Write-Step "Downloading Agentuity CLI v${Version} for Windows/$arch..."
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($downloadUrl, $msiPath)
}
catch {
Write-Error "Failed to download from $downloadUrl`: $_" -Exit
}
# Download and verify checksums
$checksumsPath = Join-Path -Path $tempDir -ChildPath "checksums.txt"
Write-Step "Downloading checksums for verification..."
try {
$webClient.DownloadFile($checksumsUrl, $checksumsPath)
# Verify checksum
Write-Step "Verifying checksum..."
$computedChecksum = Get-FileHash256 -FilePath $msiPath
$expectedChecksum = (Get-Content -Path $checksumsPath | Where-Object { $_ -match $downloadFilename } | Select-Object -First 1) -split '\s+' | Select-Object -First 1
if ([string]::IsNullOrEmpty($expectedChecksum)) {
Write-Warning "Checksum for $downloadFilename not found in checksums.txt. Skipping verification."
}
elseif ($computedChecksum -ne $expectedChecksum) {
Write-Error "Checksum verification failed. Expected: $expectedChecksum, Got: $computedChecksum" -Exit
}
else {
Write-Success "Checksum verification passed!"
}
}
catch {
Write-Warning "Failed to verify checksum: $_"
if (-not (Get-UserConfirmation -Message "Continue without checksum verification?" -DefaultToYes $false)) {
Write-Step "Installation cancelled."
exit 0
}
}
# Confirm installation
if (-not $NoPrompt) {
$confirmMessage = "Ready to install Agentuity CLI v${Version} to $installDir. Continue?"
if (-not (Get-UserConfirmation -Message $confirmMessage -DefaultToYes $true)) {
Write-Step "Installation cancelled."
exit 0
}
}
# Install MSI
$installSuccess = Install-MSI -MsiPath $msiPath -InstallDir $installDir
if (-not $installSuccess) {
Write-Warning "MSI installation may have failed. Attempting to verify installation..."
}
# Verify installation
$programFilesPath = [System.IO.Path]::Combine($env:ProgramFiles, "Agentuity")
$programFilesX86Path = [System.IO.Path]::Combine(${env:ProgramFiles(x86)}, "Agentuity")
$localAppDataPath = [System.IO.Path]::Combine($env:LOCALAPPDATA, "Agentuity")
$installPaths = @($programFilesPath, $programFilesX86Path, $localAppDataPath, $installDir)
$installVerified = $false
# In CI environment, list all paths being checked
if ($env:CI -eq "true") {
Write-Step "Checking for installation in the following paths:"
foreach ($path in $installPaths) {
Write-Step " - $path"
if (Test-Path -Path $path) {
Write-Step " Directory exists"
$files = Get-ChildItem -Path $path -Recurse | Select-Object -ExpandProperty FullName
if ($files.Count -gt 0) {
Write-Step " Files found:"
foreach ($file in $files) {
Write-Step " $file"
}
} else {
Write-Step " Directory is empty"
}
} else {
Write-Step " Directory does not exist"
}
}
}
foreach ($path in $installPaths) {
if (Test-Installation -InstallPath $path) {
$installVerified = $true
$exePath = Join-Path -Path $path -ChildPath "agentuity.exe"
# Add to PATH if not already there
Add-ToPath -PathToAdd $path
# Set up PowerShell completion
Set-PowerShellCompletion -ExePath $exePath
break
}
}
# For CI environment, try to find the executable anywhere on the system
if (-not $installVerified -and $env:CI -eq "true") {
Write-Step "Installation not found in expected paths, searching system-wide..."
$possibleExes = Get-ChildItem -Path "C:\" -Recurse -Filter "agentuity.exe" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
if ($possibleExes.Count -gt 0) {
Write-Step "Found potential executables:"
foreach ($exe in $possibleExes) {
Write-Step " $exe"
$installDir = Split-Path -Parent $exe
if (Test-Installation -InstallPath $installDir) {
$installVerified = $true
$exePath = $exe
Write-Step "Verified installation at unexpected location: $installDir"
# Add to PATH if not already there
Add-ToPath -PathToAdd $installDir
# Set up PowerShell completion
Set-PowerShellCompletion -ExePath $exePath
break
}
}
} else {
Write-Step "No agentuity.exe found on the system"
}
}
if (-not $installVerified) {
Write-Error "Failed to verify installation. The MSI may have installed to a different location or failed silently."
Write-Warning "Please check the installation log at $env:TEMP\agentuity_install.log for details."
exit 1
}
# Success message
Write-Success "Installation complete! Run 'agentuity --help' to get started."
Write-Step "For more information, visit: $(Write-Url "https://agentuity.dev")"
}
finally {
# Clean up temporary directory
if (Test-Path -Path $tempDir) {
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
#endregion