# Installs the somaro CLI from https://somaro.ai into ~\.somaro\bin and onto your PATH. $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # Invoke-WebRequest's progress bar slows a download many times over $dir = if ($env:SOMARO_BIN) { $env:SOMARO_BIN } else { Join-Path $HOME '.somaro\bin' } New-Item -ItemType Directory -Force -Path $dir | Out-Null $url = 'https://somaro.ai/cli/somaro-windows-amd64.exe' $new = Join-Path $dir 'somaro.exe.new' Write-Host "downloading $url (14.4 MB; through a slow link this can take a few minutes)" for ($i = 1; ; $i++) { try { Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $new; break } catch { if ($i -ge 4) { throw } Write-Host "the download failed ($($_.Exception.Message)); trying again in $(2 * $i) s" Start-Sleep -Seconds (2 * $i) } } $want = 'bf186a7b5b57694f98ca6c8e6645f8ba39b4ba42ca3729bbcdc5724cddcad5af' if ($want) { # .NET's, not Get-FileHash: Windows PowerShell 5.1 under PowerShell 7's module path does not find that $sha = [System.Security.Cryptography.SHA256]::Create() $file = [System.IO.File]::OpenRead($new) try { $got = -join ($sha.ComputeHash($file) | ForEach-Object { $_.ToString('x2') }) } finally { $file.Close() } if ($got -ne $want) { Remove-Item -Force $new; throw "the download's checksum is $got, the server's ${want}: nothing installed; run the line again" } } $exe = Join-Path $dir 'somaro.exe' Move-Item -Force $new $exe Write-Host "installed $exe ($(& $exe version))" $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') if (-not (($userPath -split ';') -contains $dir)) { [Environment]::SetEnvironmentVariable('Path', (($userPath, $dir) | Where-Object { $_ }) -join ';', 'User') Write-Host "added $dir to your PATH for new terminals" } if (-not (($env:Path -split ';') -contains $dir)) { $env:Path += ";$dir" } # The server this came from is remembered beside the passport, where the # CLI looks when SOMARO_API is not set (#273). $mine = if ($env:USERPROFILE) { $env:USERPROFILE } else { $HOME } $remembered = Join-Path $mine '.somaro\server' New-Item -ItemType Directory -Force -Path (Split-Path $remembered) | Out-Null [System.IO.File]::WriteAllText($remembered, 'https://somaro.ai') Write-Host "this server, https://somaro.ai, is remembered in ${remembered}: somaro talks to it with nothing to set" if ($env:SOMARO_API -and $env:SOMARO_API -ne 'https://somaro.ai') { Write-Host "SOMARO_API is set in this shell to $($env:SOMARO_API), and where it is set it is used instead" } Write-Host "then: somaro manual"