# Install the prebuilt `instinct` binary from a GitHub release. No Rust needed.
#
# Invoke-WebRequest https://raw.githubusercontent.com/koscak-labs/instinct/main/install.ps1 -OutFile install.ps1
# powershell -ExecutionPolicy Bypass -File .\install.ps1
#
# Environment:
# INSTINCT_VERSION release tag such as v0.3.0 (default: the latest release)
# INSTINCT_INSTALL_DIR where to put instinct.exe (default: $env:LOCALAPPDATA\instinct\bin)
# INSTINCT_RELEASE_BASE for tests only: a directory or URL holding the release assets
#
# Verifies the release SHA256SUMS before installing. Writes only to the install dir and a
# temp dir that is removed afterwards. It never changes PATH; it prints what to do.
$ErrorActionPreference = 'Stop'
$Repo = 'koscak-labs/instinct'
function Fail($message) {
[Console]::Error.WriteLine("install.ps1: $message")
exit 1
}
# Only the 64-bit Intel/AMD Windows build is published.
$arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }
if ($arch -ne 'AMD64') {
Fail "unsupported CPU architecture: $arch. Fallback with Rust 1.89 or later: cargo install --locked instinct-cli"
}
$target = 'x86_64-pc-windows-msvc'
function Fetch($source, $dest) {
if ($source -match '^https?://') {
Invoke-WebRequest -UseBasicParsing -Uri $source -OutFile $dest
} else {
Copy-Item -LiteralPath ($source -replace '^file://', '') -Destination $dest
}
}
$tmp = Join-Path ([IO.Path]::GetTempPath()) ("instinct-install-" + [Guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $tmp | Out-Null
try {
$tag = $env:INSTINCT_VERSION
if (-not $tag) {
if ($env:INSTINCT_RELEASE_BASE) { Fail 'set INSTINCT_VERSION when INSTINCT_RELEASE_BASE is used' }
$latest = Invoke-RestMethod -UseBasicParsing -Uri "https://api.github.com/repos/$Repo/releases/latest"
$tag = $latest.tag_name
if (-not $tag) { Fail 'the GitHub API reply had no tag_name; set INSTINCT_VERSION=v0.3.0' }
}
if (-not $tag.StartsWith('v')) { $tag = "v$tag" }
$base = if ($env:INSTINCT_RELEASE_BASE) { $env:INSTINCT_RELEASE_BASE } else { "https://github.com/$Repo/releases/download/$tag" }
$asset = "instinct-cli-$target-$tag.zip"
Write-Host "Installing instinct $tag for $target"
Fetch "$base/$asset" (Join-Path $tmp $asset)
Fetch "$base/SHA256SUMS" (Join-Path $tmp 'SHA256SUMS')
$expected = $null
foreach ($line in Get-Content (Join-Path $tmp 'SHA256SUMS')) {
$parts = $line -split '\s+', 2
if ($parts.Count -eq 2 -and ($parts[1].TrimStart('*') -eq $asset)) { $expected = $parts[0]; break }
}
if (-not $expected) { Fail "SHA256SUMS has no line for $asset; refusing to install" }
$actual = (Get-FileHash -Algorithm SHA256 -LiteralPath (Join-Path $tmp $asset)).Hash
if ($actual.ToLower() -ne $expected.ToLower()) {
Fail "checksum mismatch for $asset (expected $expected, got $actual); refusing to install"
}
Write-Host "Checksum OK ($actual)"
$unpack = Join-Path $tmp 'unpack'
Expand-Archive -LiteralPath (Join-Path $tmp $asset) -DestinationPath $unpack
if (-not (Test-Path (Join-Path $unpack 'instinct.exe'))) { Fail 'the archive has no instinct.exe' }
$dir = if ($env:INSTINCT_INSTALL_DIR) { $env:INSTINCT_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'instinct\bin' }
New-Item -ItemType Directory -Force -Path $dir | Out-Null
Copy-Item -LiteralPath (Join-Path $unpack 'instinct.exe') -Destination (Join-Path $dir 'instinct.exe') -Force
Write-Host "Installed $dir\instinct.exe"
$onPath = @($env:PATH -split ';' | Where-Object { $_.TrimEnd('\') -ieq $dir.TrimEnd('\') }).Count -gt 0
if ($onPath) {
Write-Host "$dir is on your PATH."
} else {
Write-Host "$dir is not on your PATH. To add it for this session:"
Write-Host " `$env:PATH = `"$dir;`$env:PATH`""
Write-Host 'To keep it, add the folder under Settings > System > About > Advanced system settings > Environment Variables. This script does not change it.'
}
Write-Host 'Next: instinct starter --apply'
} finally {
Remove-Item -Recurse -Force -LiteralPath $tmp -ErrorAction SilentlyContinue
}