|
| 1 | +# Usage: |
| 2 | +# powershell -ExecutionPolicy ByPass -File install.ps1 |
| 3 | +# powershell -ExecutionPolicy ByPass -File install.ps1 -Version v1.0.0 |
| 4 | + |
| 5 | +param ( |
| 6 | + [string]$Version |
| 7 | +) |
| 8 | + |
| 9 | +$ErrorActionPreference = 'Stop' |
| 10 | +Set-StrictMode -Version Latest |
| 11 | + |
| 12 | +function Show-Error { param([string]$Msg); Write-Host "error: $Msg" -ForegroundColor Red } |
| 13 | +function Show-Success { param([string]$Msg); Write-Host "$Msg" -ForegroundColor Green } |
| 14 | +function Show-Info { param([string]$Msg); Write-Host "$Msg" -ForegroundColor Gray } |
| 15 | +function Show-Bold { param([string]$Msg); Write-Host "$Msg" -ForegroundColor White } |
| 16 | + |
| 17 | +$Arch = $env:PROCESSOR_ARCHITECTURE |
| 18 | +$Target = "" |
| 19 | + |
| 20 | +if ($Arch -eq "AMD64") { |
| 21 | + $Target = "windows-amd64" |
| 22 | +} elseif ($Arch -eq "ARM64") { |
| 23 | + $Target = "windows-arm64" |
| 24 | +} else { |
| 25 | + Show-Error "Unsupported architecture: $Arch" |
| 26 | + exit 1 |
| 27 | +} |
| 28 | + |
| 29 | +$GitHubOrg = "trywpm" |
| 30 | +$Repo = "cli" |
| 31 | +$ExeName = "wpm.exe" |
| 32 | +# Install to %LocalAppData%\wpm (Standard user-level location) |
| 33 | +$InstallDir = Join-Path $env:LOCALAPPDATA "wpm" |
| 34 | +$ExePath = Join-Path $InstallDir $ExeName |
| 35 | + |
| 36 | +$BaseUrl = "https://github.com/$GitHubOrg/$Repo/releases" |
| 37 | +$BinaryName = "wpm-$Target.exe" |
| 38 | + |
| 39 | +if ([string]::IsNullOrEmpty($Version)) { |
| 40 | + $Uri = "$BaseUrl/latest/download/$BinaryName" |
| 41 | +} else { |
| 42 | + $Uri = "$BaseUrl/download/$Version/$BinaryName" |
| 43 | +} |
| 44 | + |
| 45 | +try { |
| 46 | + Show-Info "Installing wpm for $Target..." |
| 47 | + |
| 48 | + if (-not (Test-Path $InstallDir)) { |
| 49 | + New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null |
| 50 | + } |
| 51 | + |
| 52 | + Show-Info "Downloading from $Uri..." |
| 53 | + Invoke-WebRequest -Uri $Uri -OutFile $ExePath |
| 54 | + |
| 55 | + # Check if InstallDir is in the User's persistent Path |
| 56 | + $UserPathArgs = "Path", "User" |
| 57 | + $CurrentPath = [Environment]::GetEnvironmentVariable($UserPathArgs) |
| 58 | + |
| 59 | + if (($CurrentPath -split ';') -notcontains $InstallDir) { |
| 60 | + Show-Info "Adding $InstallDir to User PATH..." |
| 61 | + |
| 62 | + # Add to persistent Registry PATH |
| 63 | + [Environment]::SetEnvironmentVariable("Path", "$CurrentPath;$InstallDir", "User") |
| 64 | + |
| 65 | + $env:Path += ";$InstallDir" |
| 66 | + } |
| 67 | + |
| 68 | + Write-Host "" |
| 69 | + Show-Success "wpm installed to $ExePath" |
| 70 | + |
| 71 | + Write-Host "" |
| 72 | + Show-Info "To get started, run:" |
| 73 | + Write-Host "" |
| 74 | + Show-Bold " wpm --help" |
| 75 | +} catch { |
| 76 | + Show-Error $_.Exception.Message |
| 77 | + exit 1 |
| 78 | +} |
0 commit comments