# Ridgun installer for Windows (www-ridgun FR-DL-003), written by https://ridgun.com/install.ps1 for Ridgun 1.0.9. # # irm https://ridgun.com/install.ps1 | iex # # The same steps as install.sh, in PowerShell 5.1 or later. Into a temporary folder it downloads what omni needs: the # release for this system, the newest libs and the index. It checks the release against its SHA256SUMS before running # anything from it, then hands over to `omni setup`, which checks every signature with the release key built into omni # (ADR-0004) and installs ridgunc, stable and omni in %USERPROFILE%\.local\bin and the standard libraries in # %USERPROFILE%\.local\lib\ridgun (it keeps its own copy in %USERPROFILE%\.omni). Nothing is installed if a check # fails. Nothing else on the system is touched: not even PATH, which it only tells you how to change. & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $version = '1.0.9' $base = 'https://ridgun.com' $files = 'x86_64-linux ridgun-1.0.9-x86_64-linux.tar.gz arm64-linux ridgun-1.0.9-arm64-linux.tar.gz x86_64-macos ridgun-1.0.9-x86_64-macos.tar.gz arm64-macos ridgun-1.0.9-arm64-macos.tar.gz x86_64-windows ridgun-1.0.9-x86_64-windows.tar.gz arm64-windows ridgun-1.0.9-arm64-windows.tar.gz' function Say([string] $m) { Write-Host "ridgun: $m" } function Fail([string] $m) { throw "ridgun: $m" } if (-not $version) { Fail "no Ridgun release is published yet: see $base/download" } # A 32-bit PowerShell on 64-bit Windows names the machine in PROCESSOR_ARCHITEW6432. $machine = $env:PROCESSOR_ARCHITEW6432 if (-not $machine) { $machine = $env:PROCESSOR_ARCHITECTURE } switch ($machine) { 'AMD64' { $arch = 'x86_64' } 'ARM64' { $arch = 'arm64' } default { $arch = "$machine".ToLower() } } $target = "$arch-windows" $file = $null foreach ($line in ($files -split "`n")) { $parts = $line.Trim() -split ' ' if ($parts.Count -eq 2 -and $parts[0] -eq $target) { $file = $parts[1]; break } } if (-not $file) { Fail "Ridgun $version has no download for $target yet: see $base/download" } if (-not (Get-Command tar.exe -ErrorAction SilentlyContinue)) { Fail "needs tar.exe, which comes with Windows 10 (1803) and later" } # Windows PowerShell 5.1 may not offer TLS 1.2 by itself. [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 function Get-To([string] $url, [string] $path) { try { Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $path } catch { return $false } return $true } # The temporary folder is laid out like $base/downloads, so omni reads it as its mirror. $tmp = Join-Path ([IO.Path]::GetTempPath()) ('ridgun-' + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $tmp | Out-Null $hadMirror = Test-Path Env:OMNI_DOWNLOADS_MIRROR $oldMirror = $env:OMNI_DOWNLOADS_MIRROR try { # A release folder: one file with its SHA256SUMS and their signature. function Get-Release([string] $folder, [string] $name) { $dir = Join-Path $tmp $folder New-Item -ItemType Directory -Force -Path $dir | Out-Null if (-not (Get-To "$base/downloads/$folder/$name" (Join-Path $dir $name))) { Fail "could not download $name" } if (-not (Get-To "$base/downloads/$folder/SHA256SUMS" (Join-Path $dir 'SHA256SUMS'))) { Fail "could not download the SHA256SUMS of $name" } if (-not (Get-To "$base/downloads/$folder/SHA256SUMS.minisig" (Join-Path $dir 'SHA256SUMS.minisig'))) { Fail "could not download the signature of $name" } } Say "downloading Ridgun $version for $target" $index = Join-Path $tmp 'index.tsv' if (-not (Get-To "$base/downloads/index.tsv" $index)) { Fail 'could not download the index of releases' } Get-Release $version $file $archive = Join-Path (Join-Path $tmp $version) $file $want = $null foreach ($line in (Get-Content (Join-Path (Join-Path $tmp $version) 'SHA256SUMS'))) { if ($line -match '^([0-9a-f]{64}) (.+)$' -and $Matches[2] -eq $file) { $want = $Matches[1] } } $got = (Get-FileHash -Algorithm SHA256 -Path $archive).Hash.ToLower() if (-not $want -or $want -ne $got) { Fail "the checksum of $file does not match: nothing installed" } # The newest libs in the index (columns: product, version, target, path). $libs = $null; $best = -1 foreach ($line in (Get-Content $index)) { $c = $line -split "`t" if ($c.Count -ge 4 -and $c[0] -eq 'libs' -and $c[1] -match '^(\d+)\.(\d+)\.(\d+)') { $k = [long]$Matches[1] * 1000000 + [long]$Matches[2] * 1000 + [long]$Matches[3] if ($k -ge $best) { $best = $k; $libs = $c[3] } } } if (-not $libs) { Fail 'the index has no standard libraries (libs)' } $libsName = $libs.Substring($libs.LastIndexOf('/') + 1) Say "downloading the standard libraries ($($libsName -replace '\.tar\.gz$', ''))" Get-Release $libs.Substring(0, $libs.LastIndexOf('/')) $libsName & tar.exe -xzf $archive -C $tmp if ($LASTEXITCODE -ne 0) { Fail "could not unpack $file" } $omni = Join-Path $tmp "ridgun-$version\bin\omni.exe" if (-not (Test-Path $omni)) { Fail "this release has no omni: see $base/download" } $env:OMNI_DOWNLOADS_MIRROR = $tmp & $omni setup $target if ($LASTEXITCODE -ne 0) { Fail 'omni setup failed: nothing more was installed' } } finally { if ($hadMirror) { $env:OMNI_DOWNLOADS_MIRROR = $oldMirror } else { Remove-Item Env:OMNI_DOWNLOADS_MIRROR -ErrorAction SilentlyContinue } Remove-Item -Recurse -Force -Path $tmp -ErrorAction SilentlyContinue } $dest = Join-Path $env:USERPROFILE '.local\bin' if (($env:Path -split ';') -contains $dest) { & (Join-Path $dest 'ridgunc.exe') --version } else { Say "add $dest to your PATH, then open a new terminal:" Write-Host " [Environment]::SetEnvironmentVariable('Path', '$dest;' + [Environment]::GetEnvironmentVariable('Path', 'User'), 'User')" } Say "add a library to a project with: omni install ; install a package's programs with: omni install -g (see $base/packages)" }