# Xbomly installer for Windows. In PowerShell or Command Prompt: # # powershell -ExecutionPolicy ByPass -c "irm https://xbomly.com/install.ps1 | iex" # # What it does, all inside your user profile (no admin rights): # 1. Installs uv (Astral's Python tool installer) if you don't have it. # uv fetches its own Python 3.12 when yours is missing or older than 3.11. # 2. Installs or upgrades the cbomly command from PyPI. # 3. Installs Syft (Anchore's SBOM tool) with winget or Scoop, or from Anchore's release zip # (checksum verified) into %USERPROFILE%\.local\bin. # 4. Runs `cbomly doctor` and adds Xbomly to the Start menu. # # Options (environment variables): # $env:CBOMLY_NO_SYFT = "1" skip Syft # $env:CBOMLY_VERSION = "x.y.z" install a specific scanner version function Install-Xbomly { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 function Say($m) { Write-Host "==> $m" -ForegroundColor Cyan } function Warn($m) { Write-Host "warning: $m" -ForegroundColor Yellow } function Has($name) { [bool](Get-Command $name -ErrorAction SilentlyContinue) } function Add-SessionPath($dir) { if (($env:Path -split ';') -notcontains $dir) { $env:Path = "$dir;$env:Path" } } $bin = Join-Path $env:USERPROFILE '.local\bin' New-Item -ItemType Directory -Force -Path $bin | Out-Null Add-SessionPath $bin # 1. uv. Its installer runs in a child PowerShell, so a failure there can't close this window. $uvCmd = Get-Command uv -ErrorAction SilentlyContinue if ($uvCmd) { $uv = $uvCmd.Source } else { Say 'Installing uv (Python tool installer from astral.sh)' $env:UV_INSTALL_DIR = $bin $shell = (Get-Process -Id $PID).Path & $shell -NoProfile -ExecutionPolicy ByPass -Command 'irm https://astral.sh/uv/install.ps1 | iex' Remove-Item Env:UV_INSTALL_DIR -ErrorAction SilentlyContinue $uv = Join-Path $bin 'uv.exe' if (-not (Test-Path $uv)) { throw 'could not install uv. See https://xbomly.com/download/ for the manual steps' } } # 2. cbomly. Windows needs 0.3.0 or newer. $spec = 'cbomly>=0.3.0' if ($env:CBOMLY_VERSION) { $spec = "cbomly==$env:CBOMLY_VERSION" } Say "Installing $spec" & $uv tool install --force --upgrade --python '>=3.11' $spec if ($LASTEXITCODE -ne 0 -and -not $env:CBOMLY_VERSION) { # Until 0.3.0 is on PyPI, fall back to the latest release and say what to expect. Warn 'cbomly 0.3.0 (full Windows support) is not on PyPI yet. Installing the latest release instead.' Warn 'If you see an encoding error, run: $env:PYTHONUTF8 = "1" then try again. Run this installer again later to upgrade.' & $uv tool install --force --upgrade --python '>=3.11' cbomly } if ($LASTEXITCODE -ne 0) { throw 'could not install cbomly. Email team@xbomly.com with the output above' } try { & $uv tool update-shell *> $null } catch { } $toolBin = (& $uv tool dir --bin).Trim() Add-SessionPath $toolBin # 3. Syft $wingetLinks = Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links' if ($env:CBOMLY_NO_SYFT) { Say 'Skipping Syft (CBOMLY_NO_SYFT is set)' } elseif ((Has 'syft') -or (Test-Path (Join-Path $wingetLinks 'syft.exe'))) { Say 'Syft is already installed' } else { $done = $false if (Has 'winget') { Say 'Installing Syft with winget' winget install --id Anchore.syft --exact --source winget --silent --accept-source-agreements --accept-package-agreements $done = ($LASTEXITCODE -eq 0) -or (Test-Path (Join-Path $wingetLinks 'syft.exe')) } elseif (Has 'scoop') { Say 'Installing Syft with Scoop' scoop install main/syft $done = ($LASTEXITCODE -eq 0) } if (-not $done) { try { Say "Installing Syft from Anchore's release into $bin" $tag = (Invoke-RestMethod 'https://api.github.com/repos/anchore/syft/releases/latest').tag_name $ver = $tag.TrimStart('v') $base = "https://github.com/anchore/syft/releases/download/$tag" $zipName = "syft_${ver}_windows_amd64.zip" $tmp = Join-Path ([IO.Path]::GetTempPath()) ("cbomly-" + [guid]::NewGuid()) New-Item -ItemType Directory -Force -Path $tmp | Out-Null $zip = Join-Path $tmp $zipName Invoke-WebRequest "$base/$zipName" -OutFile $zip -UseBasicParsing $sums = (Invoke-WebRequest "$base/syft_${ver}_checksums.txt" -UseBasicParsing).Content if ($sums -is [byte[]]) { $sums = [Text.Encoding]::UTF8.GetString($sums) } $want = ($sums -split "`n" | Where-Object { $_ -match ('\s' + [regex]::Escape($zipName) + '\s*$') } | Select-Object -First 1) -replace '\s.*$', '' $got = (Get-FileHash $zip -Algorithm SHA256).Hash if (-not $want -or $got -ne $want.Trim().ToUpper()) { throw 'Syft download failed its checksum check' } Expand-Archive $zip -DestinationPath $tmp -Force Copy-Item (Join-Path $tmp 'syft.exe') (Join-Path $bin 'syft.exe') -Force Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue } catch { Warn "could not install Syft ($_). Scans still work, without the software list" } } if (Test-Path $wingetLinks) { Add-SessionPath $wingetLinks } } # 4. Check Write-Host '' & (Join-Path $toolBin 'cbomly.exe') doctor Write-Host '' & (Join-Path $toolBin 'cbomly.exe') app --add-shortcut *> $null if ($LASTEXITCODE -eq 0) { Say 'Done. Open Xbomly from the Start menu, or in a new terminal run: cbomly scan .\your-project' } else { Say 'Done. Open a new terminal, then run: cbomly scan .\your-project' } } try { Install-Xbomly } catch { Write-Host "error: $_" -ForegroundColor Red }