|
| 1 | +# ACA CLI Installer for Windows |
| 2 | +param( |
| 3 | + [string]$Version = "latest", |
| 4 | + [string]$InstallDir = "$env:USERPROFILE\.aca\bin", |
| 5 | + [switch]$Uninstall |
| 6 | +) |
| 7 | + |
| 8 | +$ErrorActionPreference = "Stop" |
| 9 | +$Repo = "microsoft/azure-container-apps" |
| 10 | +$Branch = "main" |
| 11 | +$BinaryName = "aca" |
| 12 | + |
| 13 | +function Uninstall-Aca { |
| 14 | + $AcaHome = Split-Path $InstallDir -Parent # ~/.aca |
| 15 | + $ExePath = Join-Path $InstallDir "$BinaryName.exe" |
| 16 | + if (-not (Test-Path $ExePath) -and -not (Test-Path $AcaHome)) { |
| 17 | + Write-Host "$BinaryName is not installed." |
| 18 | + return |
| 19 | + } |
| 20 | + |
| 21 | + # Remove PATH entry |
| 22 | + $UserPath = [Environment]::GetEnvironmentVariable("PATH", "User") |
| 23 | + if ($UserPath -like "*$InstallDir*") { |
| 24 | + $NewPath = ($UserPath -split ';' | Where-Object { $_ -ne $InstallDir }) -join ';' |
| 25 | + [Environment]::SetEnvironmentVariable("PATH", $NewPath, "User") |
| 26 | + Write-Host "Removed $InstallDir from PATH." |
| 27 | + } |
| 28 | + |
| 29 | + # Remove entire .aca directory (binary + config) |
| 30 | + if (Test-Path $AcaHome) { |
| 31 | + Remove-Item -Recurse -Force $AcaHome |
| 32 | + Write-Host "Removed $AcaHome (binary and configuration)." |
| 33 | + } |
| 34 | + |
| 35 | + Write-Host "$BinaryName uninstalled successfully." |
| 36 | +} |
| 37 | + |
| 38 | +function Install-Aca { |
| 39 | + $Platform = "win-x64" |
| 40 | + |
| 41 | + if ($Version -eq "latest") { |
| 42 | + # Fetch latest version from version file (no API, no rate limits) |
| 43 | + $Version = (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/$Repo/$Branch/docs/early/aca-cli/latest-version.txt" -UseBasicParsing).Content.Trim() |
| 44 | + if (-not $Version) { |
| 45 | + throw "Could not determine latest version. Specify manually: -Version aca-cli-v0.1.0-early-access" |
| 46 | + } |
| 47 | + Write-Host "Latest version: $Version" |
| 48 | + } |
| 49 | + $Url = "https://github.com/$Repo/releases/download/$Version/$Version-$Platform.zip" |
| 50 | + |
| 51 | + Write-Host "Downloading $BinaryName from $Url..." |
| 52 | + |
| 53 | + # Create install directory |
| 54 | + if (-not (Test-Path $InstallDir)) { |
| 55 | + New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null |
| 56 | + } |
| 57 | + |
| 58 | + $TmpFile = Join-Path $env:TEMP "$BinaryName-$Platform.zip" |
| 59 | + $TmpDir = Join-Path $env:TEMP "$BinaryName-extract" |
| 60 | + |
| 61 | + try { |
| 62 | + Invoke-WebRequest -Uri $Url -OutFile $TmpFile -UseBasicParsing |
| 63 | + |
| 64 | + if (Test-Path $TmpDir) { Remove-Item -Recurse -Force $TmpDir } |
| 65 | + Expand-Archive -Path $TmpFile -DestinationPath $TmpDir -Force |
| 66 | + |
| 67 | + Copy-Item -Path (Join-Path $TmpDir "$BinaryName.exe") -Destination (Join-Path $InstallDir "$BinaryName.exe") -Force |
| 68 | + } finally { |
| 69 | + Remove-Item -Force $TmpFile -ErrorAction SilentlyContinue |
| 70 | + Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue |
| 71 | + } |
| 72 | + |
| 73 | + # Add to PATH if not already there |
| 74 | + $UserPath = [Environment]::GetEnvironmentVariable("PATH", "User") |
| 75 | + if ($UserPath -notlike "*$InstallDir*") { |
| 76 | + [Environment]::SetEnvironmentVariable("PATH", "$UserPath;$InstallDir", "User") |
| 77 | + $env:PATH = "$env:PATH;$InstallDir" |
| 78 | + Write-Host "Added $InstallDir to PATH." |
| 79 | + } |
| 80 | + |
| 81 | + Write-Host "" |
| 82 | + Write-Host "$BinaryName installed successfully to $InstallDir\$BinaryName.exe" |
| 83 | + Write-Host "" |
| 84 | + Write-Host "Prerequisites:" |
| 85 | + Write-Host " Azure CLI (az) must be installed and logged in." |
| 86 | + Write-Host " Run 'az login' if you haven't already." |
| 87 | + Write-Host "" |
| 88 | + Write-Host "Restart your terminal, then run '$BinaryName --help' to get started." |
| 89 | +} |
| 90 | + |
| 91 | +if ($Uninstall) { |
| 92 | + Uninstall-Aca |
| 93 | +} else { |
| 94 | + Install-Aca |
| 95 | +} |
0 commit comments