| 1 | # Andromeda installer (Windows / PowerShell). |
| 2 | # |
| 3 | # Usage: |
| 4 | # irm https://raw.githubusercontent.com/stevedylandev/andromeda/main/install.ps1 | iex |
| 5 | # # then: |
| 6 | # Install-Andromeda sipp |
| 7 | # Install-Andromeda feeds v0.4.0 |
| 8 | # |
| 9 | # Or one-shot: |
| 10 | # & ([scriptblock]::Create((irm https://raw.githubusercontent.com/stevedylandev/andromeda/main/install.ps1))) sipp |
| 11 | # |
| 12 | # Env: |
| 13 | # $env:INSTALL_DIR target dir (default: $env:LOCALAPPDATA\andromeda) |
| 14 | |
| 15 | param( |
| 16 | [Parameter(Position = 0)][string]$App, |
| 17 | [Parameter(Position = 1)][string]$Version |
| 18 | ) |
| 19 | |
| 20 | $ErrorActionPreference = "Stop" |
| 21 | $Repo = "stevedylandev/andromeda" |
| 22 | |
| 23 | function Install-Andromeda { |
| 24 | param( |
| 25 | [Parameter(Mandatory = $true)][string]$App, |
| 26 | [string]$Version |
| 27 | ) |
| 28 | |
| 29 | # Detect arch |
| 30 | $archMap = @{ |
| 31 | "AMD64" = "x86_64" |
| 32 | "ARM64" = "arm64" |
| 33 | } |
| 34 | $procArch = $env:PROCESSOR_ARCHITECTURE |
| 35 | if (-not $archMap.ContainsKey($procArch)) { |
| 36 | throw "Unsupported arch: $procArch" |
| 37 | } |
| 38 | $arch = $archMap[$procArch] |
| 39 | if ($arch -eq "arm64") { |
| 40 | throw "No windows/arm64 build published (goreleaser config ignores it)." |
| 41 | } |
| 42 | |
| 43 | # Resolve version |
| 44 | if (-not $Version) { |
| 45 | Write-Host "Looking up latest $App release..." |
| 46 | $releases = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases?per_page=50" |
| 47 | $match = $releases | Where-Object { $_.tag_name -like "$App/v*" } | Select-Object -First 1 |
| 48 | if (-not $match) { throw "No releases found for $App" } |
| 49 | $Version = ($match.tag_name -split "/", 2)[1] |
| 50 | } |
| 51 | |
| 52 | $verNum = $Version.TrimStart("v") |
| 53 | $tag = "$App/$Version" |
| 54 | $archive = "${App}_${verNum}_windows_${arch}.zip" |
| 55 | $url = "https://github.com/$Repo/releases/download/$tag/$archive" |
| 56 | |
| 57 | $installDir = if ($env:INSTALL_DIR) { $env:INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA "andromeda" } |
| 58 | New-Item -ItemType Directory -Force -Path $installDir | Out-Null |
| 59 | |
| 60 | $tmp = New-Item -ItemType Directory -Path (Join-Path $env:TEMP ([guid]::NewGuid())) |
| 61 | try { |
| 62 | Write-Host "Downloading $url" |
| 63 | $zipPath = Join-Path $tmp $archive |
| 64 | Invoke-WebRequest -Uri $url -OutFile $zipPath -UseBasicParsing |
| 65 | Expand-Archive -Path $zipPath -DestinationPath $tmp -Force |
| 66 | |
| 67 | $exeName = "$App.exe" |
| 68 | $src = Join-Path $tmp $exeName |
| 69 | if (-not (Test-Path $src)) { |
| 70 | throw "Binary $exeName not found in archive" |
| 71 | } |
| 72 | $dest = Join-Path $installDir $exeName |
| 73 | Move-Item -Path $src -Destination $dest -Force |
| 74 | |
| 75 | Write-Host "Installed $App $Version to $dest" |
| 76 | |
| 77 | # PATH hint |
| 78 | $userPath = [Environment]::GetEnvironmentVariable("Path", "User") |
| 79 | if ($userPath -notlike "*$installDir*") { |
| 80 | Write-Host "" |
| 81 | Write-Host "Add to PATH (run once):" -ForegroundColor Yellow |
| 82 | Write-Host " [Environment]::SetEnvironmentVariable('Path', `"`$env:Path;$installDir`", 'User')" |
| 83 | } |
| 84 | } |
| 85 | finally { |
| 86 | Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | # If invoked with args (one-shot mode via scriptblock), run immediately. |
| 91 | if ($App) { |
| 92 | Install-Andromeda -App $App -Version $Version |
| 93 | } |