install-process-compose.ps1 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <#
  2. .SYNOPSIS
  3. Download, verify, and install a specific Process Compose version on Windows.
  4. .DESCRIPTION
  5. 1. Downloads the release zip and checksums file from GitHub.
  6. 2. Verifies SHA-256 against the published checksums.txt.
  7. 3. Extracts the .exe.
  8. 4. Records the .exe's own hash for future re-verification.
  9. 5. Writes VERIFICATION.md.
  10. The result is a verified binary in <target>/bin/, ready to commit to your repo.
  11. .PARAMETER Version
  12. Version tag (e.g. "v1.110.0"). Required — never auto-pick latest.
  13. .PARAMETER TargetDir
  14. Where to put bin/. Defaults to current directory.
  15. .EXAMPLE
  16. .\install-process-compose.ps1 -Version v1.110.0 -TargetDir X:\my-stack
  17. #>
  18. [CmdletBinding()]
  19. param(
  20. [Parameter(Mandatory)][string]$Version,
  21. [string]$TargetDir = (Get-Location).Path
  22. )
  23. $ErrorActionPreference = 'Stop'
  24. $binDir = Join-Path $TargetDir 'bin'
  25. New-Item -ItemType Directory -Force -Path $binDir | Out-Null
  26. $base = "https://github.com/F1bonacc1/process-compose/releases/download/$Version"
  27. $zipName = "process-compose_windows_amd64.zip"
  28. $checksumsName = "process-compose_checksums.txt"
  29. $zipPath = Join-Path $binDir $zipName
  30. $checksumsPath = Join-Path $binDir $checksumsName
  31. Write-Host "Downloading Process Compose $Version..." -ForegroundColor Cyan
  32. Invoke-WebRequest -Uri "$base/$zipName" -OutFile $zipPath
  33. Invoke-WebRequest -Uri "$base/$checksumsName" -OutFile $checksumsPath
  34. Write-Host "Verifying SHA-256..." -ForegroundColor Cyan
  35. $expected = (Select-String -Pattern $zipName -Path $checksumsPath).Line.Split()[0].ToLower()
  36. $actual = (Get-FileHash $zipPath -Algorithm SHA256).Hash.ToLower()
  37. if ($expected -ne $actual) {
  38. Remove-Item $zipPath -Force
  39. throw "CHECKSUM MISMATCH - aborting install. Expected $expected, got $actual."
  40. }
  41. Write-Host " Match: $actual" -ForegroundColor Green
  42. Write-Host "Extracting..." -ForegroundColor Cyan
  43. Expand-Archive $zipPath -DestinationPath $binDir -Force
  44. # Clean up bundled docs (we don't ship upstream's LICENSE/README in our repo)
  45. Remove-Item (Join-Path $binDir 'LICENSE') -ErrorAction SilentlyContinue
  46. Remove-Item (Join-Path $binDir 'README.md') -ErrorAction SilentlyContinue
  47. Remove-Item $zipPath -Force
  48. # Record version
  49. $Version | Out-File -FilePath (Join-Path $binDir 'VERSION') -NoNewline -Encoding ascii
  50. # Record the .exe's hash for re-verification
  51. $exePath = Join-Path $binDir 'process-compose.exe'
  52. $exeHash = (Get-FileHash $exePath -Algorithm SHA256).Hash.ToLower()
  53. $exeHash | Out-File -FilePath (Join-Path $binDir 'EXE_HASH') -NoNewline -Encoding ascii
  54. Write-Host "Runtime check..." -ForegroundColor Cyan
  55. $versionOutput = & $exePath version 2>&1 | Where-Object { $_ -notmatch 'level.*debug' }
  56. Write-Host $versionOutput
  57. # Write VERIFICATION.md
  58. $verifPath = Join-Path $binDir 'VERIFICATION.md'
  59. @"
  60. # Process Compose Binary Verification
  61. ## $Version
  62. | Field | Value |
  63. |---|---|
  64. | Pinned | $(Get-Date -Format 'yyyy-MM-dd') |
  65. | Source | https://github.com/F1bonacc1/process-compose/releases/tag/$Version |
  66. | ZIP SHA-256 | ``$actual`` |
  67. | EXE SHA-256 | ``$exeHash`` |
  68. | Runtime check | ``$($versionOutput -join '; ')`` |
  69. Trust anchor: GitHub Releases (HTTPS, requires repo write access to tamper).
  70. Note: Process Compose releases are not GPG-signed.
  71. ## Re-verify
  72. ``````powershell
  73. `$expected = (Get-Content bin/EXE_HASH).Trim()
  74. `$actual = (Get-FileHash bin/process-compose.exe -Algorithm SHA256).Hash.ToLower()
  75. if (`$expected -ne `$actual) { throw "binary tampered" }
  76. ``````
  77. "@ | Out-File -FilePath $verifPath -Encoding utf8
  78. Write-Host ""
  79. Write-Host "Done. Binary committed to: $binDir" -ForegroundColor Green
  80. Write-Host "Files: process-compose.exe, $checksumsName, VERSION, EXE_HASH, VERIFICATION.md"
  81. Write-Host ""
  82. Write-Host "Next: git add bin/; git commit -m 'feat: pin process-compose $Version, verified'"