# ============================================================= # Causari one-line installer (Windows / PowerShell) # # Usage: # iwr -useb https://causari.dev/install.ps1 | iex # # Optional: # $env:CAUSARI_VERSION = "v0.1.0" # pin version # $env:CAUSARI_BIN_DIR = "C:\bin" # custom install dir # $env:CAUSARI_SKIP_VERIFY = "1" # bypass the sha256 check (not recommended) # # What you get: one program under two names, causari.exe and re.exe (the # short alias every example uses). The archive's sha256 is verified against # SHA256SUMS.txt published with each release; both carry a signed SLSA # provenance attestation: gh attestation verify --repo croviatrust/causari # To review the code first, build from source instead: # cargo install --git https://github.com/croviatrust/causari # ============================================================= $ErrorActionPreference = 'Stop' $Repo = 'croviatrust/causari' $Version = if ($env:CAUSARI_VERSION) { $env:CAUSARI_VERSION } else { $null } $BinDir = if ($env:CAUSARI_BIN_DIR) { $env:CAUSARI_BIN_DIR } else { Join-Path $env:LOCALAPPDATA 'Programs\causari' } function Say($msg) { Write-Host "causari: $msg" -ForegroundColor Cyan } function Warn($msg) { Write-Host "causari: $msg" -ForegroundColor Yellow } function Die($msg) { Write-Host "causari: $msg" -ForegroundColor Red; exit 1 } # ---- detect arch ---- $arch = if ([Environment]::Is64BitOperatingSystem) { 'x86_64' } else { Die 'only x86_64 Windows binaries are published — try `cargo install --git https://github.com/croviatrust/causari`' } $target = "$arch-pc-windows-msvc" # ---- resolve version ---- # The release page redirects to the latest tag without touching the API, # so a shared address (CI runner, office NAT) that has used up the # unauthenticated API quota still installs. The API is the fallback. if (-not $Version) { $loc = $null try { $resp = Invoke-WebRequest "https://github.com/$Repo/releases/latest" -Method Head -MaximumRedirection 0 -UseBasicParsing -ErrorAction Stop $loc = [string]$resp.Headers['Location'] } catch { # Windows PowerShell 5.1 and some PowerShell 7 builds throw on a 302 when # redirects are off; the response with the Location header is on the error. try { $loc = [string]$_.Exception.Response.Headers['Location'] } catch { $loc = $null } if (-not $loc) { try { $loc = [string]$_.Exception.Response.Headers.Location } catch { $loc = $null } } } if ($loc -match '/releases/tag/(v[0-9][^/?]*)') { $Version = $Matches[1] } if (-not $Version) { $rel = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest" -UseBasicParsing $Version = $rel.tag_name } if (-not $Version) { Die 'could not resolve the latest release tag (set $env:CAUSARI_VERSION to pin one)' } } Say "installing $Repo $Version ($target)" # ---- download ---- # Releases from v0.2.0 ship causari--.zip (causari.exe + re.exe); # older ones shipped re--.zip (re.exe only). Try the new name first. $tmp = New-Item -ItemType Directory -Path (Join-Path $env:TEMP "causari-$([guid]::NewGuid())") -Force $zip = Join-Path $tmp 'causari.zip' $base = "https://github.com/$Repo/releases/download/$Version" $asset = $null foreach ($candidate in @("causari-$Version-$target.zip", "re-$Version-$target.zip")) { try { Invoke-WebRequest -Uri "$base/$candidate" -OutFile $zip -UseBasicParsing $asset = $candidate break } catch { } } if (-not $asset) { Die "download failed: $base/causari-$Version-$target.zip" } # ---- verify sha256 (required by default) ---- if ($env:CAUSARI_SKIP_VERIFY -eq '1') { Warn 'CAUSARI_SKIP_VERIFY=1 set — installing WITHOUT checksum verification' } else { $sumsUrl = "https://github.com/$Repo/releases/download/$Version/SHA256SUMS.txt" $sumsFile = Join-Path $tmp 'SHA256SUMS.txt' try { Invoke-WebRequest -Uri $sumsUrl -OutFile $sumsFile -UseBasicParsing } catch { Die "could not download SHA256SUMS.txt for $Version — refusing to install unverified (set `$env:CAUSARI_SKIP_VERIFY='1' to override, or build from source: cargo install --git https://github.com/$Repo)" } $line = Select-String ([regex]::Escape($asset) + '$') $sumsFile | Select-Object -First 1 if (-not $line) { Die "no checksum for $asset in SHA256SUMS.txt — refusing to install unverified" } $expected = $line.Line.Split(' ')[0].ToLower() $actual = (Get-FileHash $zip -Algorithm SHA256).Hash.ToLower() if ($expected -ne $actual) { Die "sha256 mismatch — refusing to install (expected $expected, got $actual)" } Say "sha256 verified ($actual)" } # ---- extract ---- Expand-Archive -Path $zip -DestinationPath $tmp -Force $src = Join-Path $tmp 're.exe' if (-not (Test-Path $src)) { Die 'extracted archive did not contain re.exe' } # ---- install ---- New-Item -ItemType Directory -Path $BinDir -Force | Out-Null $dst = Join-Path $BinDir 're.exe' Move-Item -Path $src -Destination $dst -Force $srcC = Join-Path $tmp 'causari.exe' $dstC = Join-Path $BinDir 'causari.exe' if (Test-Path $srcC) { Move-Item -Path $srcC -Destination $dstC -Force } else { Copy-Item -Path $dst -Destination $dstC -Force } Say "installed $dstC and $dst (same program)" # ---- PATH ---- $userPath = [Environment]::GetEnvironmentVariable('PATH','User') if ($userPath -notlike "*$BinDir*") { $newPath = if ($userPath) { "$userPath;$BinDir" } else { $BinDir } [Environment]::SetEnvironmentVariable('PATH', $newPath, 'User') Say "added $BinDir to your user PATH (open a new terminal to pick it up)" } # ---- cleanup ---- Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue # ---- git on PATH ---- $gitCmd = Get-Command git -ErrorAction SilentlyContinue if (-not $gitCmd) { Warn 'git was not found on PATH. Causari reads git history; install Git for Windows, then open a new terminal. Until git is on PATH, re audit cannot read a repository.' } else { Say "git: $($gitCmd.Source)" } # ---- post ---- try { & $dst --version } catch { } Say "installed $dst" Say 'this window may not see the updated user PATH yet. Open a new terminal, then run:' Say ' re audit owner/repo' Say "until that terminal exists, the full command is: & '$dst' audit owner/repo"