# Install the pixy client on Windows. # # irm https://get.demotwo.site/install.ps1 | iex # # Installs to %LOCALAPPDATA%\Programs\pixy and adds it to the user PATH. # No administrator rights are needed. $ErrorActionPreference = 'Stop' $BaseUrl = if ($env:PIXY_BASE_URL) { $env:PIXY_BASE_URL } else { 'https://get.demotwo.site' } $Dest = if ($env:PIXY_INSTALL) { $env:PIXY_INSTALL } else { Join-Path $env:LOCALAPPDATA 'Programs\pixy' } function Info($m) { Write-Host " $m" } function Die($m) { Write-Host "error: $m" -ForegroundColor Red; exit 1 } # TLS 1.2 is not the default on older Windows PowerShell and the download fails # without it. try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } catch {} $arch = switch ($env:PROCESSOR_ARCHITECTURE) { 'AMD64' { 'amd64' } 'ARM64' { 'arm64' } 'x86' { Die '32-bit Windows is not supported' } default { 'amd64' } } $asset = "pixy-windows-$arch.exe" $tmp = Join-Path ([IO.Path]::GetTempPath()) "pixy-$([guid]::NewGuid().ToString('N')).exe" Write-Host '' Info "downloading $asset" try { Invoke-WebRequest -Uri "$BaseUrl/$asset" -OutFile $tmp -UseBasicParsing } catch { Die "download failed: $BaseUrl/$asset`n $($_.Exception.Message)" } # Verify against the published checksum list when it is reachable. try { $sums = (Invoke-WebRequest -Uri "$BaseUrl/checksums.txt" -UseBasicParsing).Content $want = ($sums -split "`n" | Where-Object { $_ -match [regex]::Escape($asset) } | Select-Object -First 1) -replace '\s.*$', '' if ($want) { $got = (Get-FileHash -Path $tmp -Algorithm SHA256).Hash.ToLower() if ($got -ne $want.ToLower()) { Remove-Item $tmp -Force Die "checksum mismatch for $asset" } Info 'checksum verified' } } catch { Info 'could not fetch checksums.txt; skipping verification' } New-Item -ItemType Directory -Force -Path $Dest | Out-Null $target = Join-Path $Dest 'pixy.exe' # A running pixy.exe cannot be overwritten, so say so plainly rather than # failing with a generic access error. try { Move-Item -Path $tmp -Destination $target -Force } catch { Remove-Item $tmp -Force -ErrorAction SilentlyContinue Die "could not write $target (is pixy still running?)`n $($_.Exception.Message)" } Info "installed $target" # Add to the *user* PATH, persistently, without duplicating the entry. $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') if ($userPath -notlike "*$Dest*") { $newPath = if ([string]::IsNullOrEmpty($userPath)) { $Dest } else { "$userPath;$Dest" } [Environment]::SetEnvironmentVariable('Path', $newPath, 'User') Info "added $Dest to your PATH" $pathChanged = $true } # Make it usable in this session too, so the next command just works. if ($env:Path -notlike "*$Dest*") { $env:Path = "$env:Path;$Dest" } Write-Host '' Write-Host ' pixy installed' -ForegroundColor Green Write-Host '' Write-Host ' Next:' Write-Host ' pixy login --token ' Write-Host ' pixy' Write-Host '' if ($pathChanged) { Write-Host ' (Open a new terminal for PATH changes to apply everywhere.)' Write-Host '' }