# Product Codebases CLI installer (Windows). # # irm https://octetdata.net/codebases/install.ps1 | iex # # What it does: downloads octet-codebases-windows-x64.exe and SHA256SUMS from # https://github.com/afisherdev/octet-codebases-releases, checks the SHA-256, and copies the binary to # $HOME\.local\bin (or $env:OCTET_CODEBASES_INSTALL_DIR). It refuses to install if the checksum # doesn't match. It doesn't change your PATH or need administrator rights. # # Options (environment): # OCTET_CODEBASES_INSTALL_DIR where to put the binary (default $HOME\.local\bin) # OCTET_CODEBASES_VERSION a release tag such as v0.3.0 (default: the latest release) # # The CLI makes no network calls while it analyses a repository. $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' function Get-OctetAsset([string]$Arch) { # Windows on ARM runs the x64 build under emulation. switch ($Arch) { 'AMD64' { return 'octet-codebases-windows-x64.exe' } 'ARM64' { return 'octet-codebases-windows-x64.exe' } default { return $null } } } function Install-OctetCodebases { $repo = 'afisherdev/octet-codebases-releases' $arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } $asset = Get-OctetAsset $arch if (-not $asset) { throw "octet-codebases install: no build for Windows $arch. Builds exist for Windows x64." } if ($env:OCTET_CODEBASES_VERSION) { $base = "https://github.com/$repo/releases/download/$($env:OCTET_CODEBASES_VERSION)" } else { $base = "https://github.com/$repo/releases/latest/download" } $dir = if ($env:OCTET_CODEBASES_INSTALL_DIR) { $env:OCTET_CODEBASES_INSTALL_DIR } else { Join-Path $HOME '.local\bin' } $tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("octet-codebases-" + [guid]::NewGuid()) New-Item -ItemType Directory -Path $tmp | Out-Null try { Write-Host "Downloading $asset" [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 Invoke-WebRequest -UseBasicParsing -Uri "$base/$asset" -OutFile (Join-Path $tmp $asset) Invoke-WebRequest -UseBasicParsing -Uri "$base/SHA256SUMS" -OutFile (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].ToLower() } } if (-not $expected) { throw "octet-codebases install: SHA256SUMS has no entry for $asset. Nothing was installed." } $actual = (Get-FileHash -Algorithm SHA256 (Join-Path $tmp $asset)).Hash.ToLower() if ($expected -ne $actual) { throw "octet-codebases install: checksum mismatch for $asset (expected $expected, got $actual). Nothing was installed." } Write-Host "Checksum OK ($actual)" New-Item -ItemType Directory -Force -Path $dir | Out-Null $target = Join-Path $dir 'octet-codebases.exe' Move-Item -Force (Join-Path $tmp $asset) $target Write-Host "Installed octet-codebases to $target" } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } Write-Host '' $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') if (-not (($env:Path -split ';') -contains $dir) -and -not (($userPath -split ';') -contains $dir)) { Write-Host "$dir isn't on your PATH. To add it for your user account, run:" Write-Host " [Environment]::SetEnvironmentVariable('Path', `"$dir;`" + [Environment]::GetEnvironmentVariable('Path', 'User'), 'User')" Write-Host '' } Write-Host 'Next steps:' Write-Host ' cd your-repo' Write-Host ' octet-codebases . # local analysis; no network calls' Write-Host ' octet-codebases --json # machine-readable report' Write-Host ' octet-codebases submit # optional: open the submit page' Write-Host 'Product Codebases only licenses private repositories. Estimates are illustrative, not offers.' } if ($env:OCTET_CODEBASES_SOURCE_ONLY -ne '1') { Install-OctetCodebases }