# Install harnsy from the latest GitHub release (Windows): # # irm https://harnsy.dev/install.ps1 | iex # # published copy: harnesy/site public/ (keep it equal to this file) # # It downloads the zip for this CPU, checks it against the release's # SHA256SUMS, and runs `harnsy.exe install` from it, which puts harnsy in # %LOCALAPPDATA%\harnsy\bin and starts it at logon. # # $env:HARNSY_VERSION = "v0.1.0" pins a release instead of the latest. # The releases come from harnesy/app, the public demo edition (archives # harnsy-demo_*). $env:HARNSY_REPO = "owner/repo" takes a public repository # with the full edition's archives (harnsy_*) instead. # $env:HARNSY_INSTALL_ARGS = "--dry-run" passes arguments to `harnsy.exe install`. # # Everything runs inside one script block invoked at its end: a download cut # short defines nothing and runs nothing. & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # Windows PowerShell 5.1 may not offer TLS 1.2 by default; GitHub needs it. [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $repo = if ($env:HARNSY_REPO) { $env:HARNSY_REPO } else { 'harnesy/app' } $prefix = if ($repo -eq 'harnesy/app') { 'harnsy-demo' } else { 'harnsy' } # A 32-bit PowerShell on 64-bit Windows reports x86 here; the real CPU is # in PROCESSOR_ARCHITEW6432. $cpu = $env:PROCESSOR_ARCHITEW6432 if (-not $cpu) { $cpu = $env:PROCESSOR_ARCHITECTURE } switch ($cpu) { 'AMD64' { $arch = 'amd64' } 'ARM64' { $arch = 'arm64' } default { throw "unsupported CPU: $cpu" } } $version = $env:HARNSY_VERSION if (-not $version) { # The latest release (pre-releases excluded). try { $version = (Invoke-RestMethod "https://api.github.com/repos/$repo/releases/latest").tag_name } catch { throw "cannot reach the releases of $repo (no network, or the repository is private)" } } if (-not ($version -like 'v*')) { throw "could not find the latest release (got '$version')" } $name = "${prefix}_${version}_windows_${arch}" $url = "https://github.com/$repo/releases/download/$version" $tmp = Join-Path ([IO.Path]::GetTempPath()) ("harnsy-" + [guid]::NewGuid()) New-Item -ItemType Directory -Path $tmp | Out-Null try { Write-Host "Downloading harnsy $version for windows/$arch..." Invoke-WebRequest "$url/$name.zip" -OutFile "$tmp\$name.zip" -UseBasicParsing Invoke-WebRequest "$url/SHA256SUMS" -OutFile "$tmp\SHA256SUMS" -UseBasicParsing $line = Get-Content "$tmp\SHA256SUMS" | Where-Object { $_ -match " $([regex]::Escape($name)).zip$" } if (-not $line) { throw "$name.zip is not in the release's SHA256SUMS" } $want = ($line -split '\s+')[0] $got = (Get-FileHash "$tmp\$name.zip" -Algorithm SHA256).Hash.ToLower() if ($got -ne $want.ToLower()) { throw "checksum mismatch for $name.zip" } Write-Host 'Checksum OK.' Expand-Archive "$tmp\$name.zip" -DestinationPath $tmp $installArgs = @('install') if ($env:HARNSY_INSTALL_ARGS) { $installArgs += ($env:HARNSY_INSTALL_ARGS -split '\s+') } & "$tmp\$name\harnsy.exe" @installArgs if ($LASTEXITCODE -ne 0) { throw "harnsy install exited with $LASTEXITCODE" } } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } }