# Installs the Inferam CLI on Windows. Source: https://inferam.ai/install.ps1 # Everything runs inside one script block, so a download cut off mid-script runs nothing. & { $ErrorActionPreference = "Stop" $ProgressPreference = "SilentlyContinue" [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 function Fail($msg) { throw "inferam install: $msg" } $base = if ($env:INFERAM_RELEASES) { $env:INFERAM_RELEASES } else { "https://inferam.ai/releases" } $dir = if ($env:INFERAM_INSTALL_DIR) { $env:INFERAM_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA "Programs\inferam" } $arch = switch ([Runtime.InteropServices.RuntimeInformation]::OSArchitecture) { "X64" { "amd64" } "Arm64" { "arm64" } default { Fail "unsupported CPU: $_" } } $file = "inferam_windows_$arch.exe" $tmp = Join-Path ([IO.Path]::GetTempPath()) ("inferam-" + [Guid]::NewGuid()) New-Item -ItemType Directory -Path $tmp | Out-Null try { try { Invoke-WebRequest -UseBasicParsing -Uri "$base/$file" -OutFile "$tmp\inferam.exe" } catch { Fail "download failed: $_" } try { $sums = (Invoke-WebRequest -UseBasicParsing -Uri "$base/checksums.txt").Content } catch { Fail "checksum download failed: $_" } if ($sums -is [byte[]]) { $sums = [Text.Encoding]::UTF8.GetString($sums) } $want = foreach ($line in $sums -split "\r?\n") { $f = $line -split "\s+"; if ($f.Count -eq 2 -and $f[1] -eq $file) { $f[0] } } $got = (Get-FileHash -Algorithm SHA256 "$tmp\inferam.exe").Hash.ToLower() if (-not $want -or $want -ne $got) { Fail "checksum mismatch for $file" } New-Item -ItemType Directory -Force -Path $dir | Out-Null $exe = Join-Path $dir "inferam.exe" # A running inferam.exe can't be overwritten, but it can be renamed. if (Test-Path $exe) { Remove-Item -Force "$exe.old" -ErrorAction SilentlyContinue; Move-Item -Force $exe "$exe.old" } Move-Item "$tmp\inferam.exe" $exe } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } Write-Host "Installed $(& $exe version) to $exe" # Add to the user's PATH, keeping its entries unexpanded (%USERPROFILE%...) as Windows stores them. $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Environment", $true) $path = [string]$key.GetValue("Path", "", "DoNotExpandEnvironmentNames") if (($path -split ";") -notcontains $dir) { $entries = @($path.TrimEnd(";"), $dir) | Where-Object { $_ } $key.SetValue("Path", ($entries -join ";"), "ExpandString") # Setting a user variable tells open programs that the environment changed, so new terminals see the PATH. [Environment]::SetEnvironmentVariable("INFERAM_INSTALL", "1", "User") [Environment]::SetEnvironmentVariable("INFERAM_INSTALL", $null, "User") Write-Host "Added $dir to your PATH; open a new terminal to use it." } $key.Close() if (($env:Path -split ";") -notcontains $dir) { $env:Path = "$env:Path;$dir" } Write-Host "Next: inferam auth login" }