1+ # !/usr/bin/env pwsh
2+ <#
3+ . SYNOPSIS
4+ Extracts a release zip and validates its packaged IntegrityTree.json.
5+
6+ . PARAMETER ZipPath
7+ Path to the release zip to validate.
8+
9+ . PARAMETER FailOnUnexpectedFiles
10+ Fail validation if extracted files exist outside IntegrityTree.json.
11+ #>
12+
13+ [CmdletBinding ()]
14+ param (
15+ [Parameter (Mandatory , Position = 0 )]
16+ [string ] $ZipPath ,
17+
18+ [switch ] $FailOnUnexpectedFiles
19+ )
20+
21+ $ErrorActionPreference = ' Stop'
22+
23+ if (-not (Test-Path $ZipPath - PathType Leaf)) {
24+ throw " The zip file '$ZipPath ' does not exist."
25+ }
26+
27+ $ZipPath = (Resolve-Path $ZipPath ).Path
28+ $TreeValidatorPath = Join-Path $PSScriptRoot ' verify-integrity-tree.ps1'
29+ if (-not (Test-Path $TreeValidatorPath - PathType Leaf)) {
30+ throw " Integrity validator not found at '$TreeValidatorPath '."
31+ }
32+
33+ $TempExtractPath = Join-Path ([System.IO.Path ]::GetTempPath()) (" unigetui-zip-verify-" + [guid ]::NewGuid())
34+ New-Item $TempExtractPath - ItemType Directory | Out-Null
35+
36+ try {
37+ Expand-Archive - Path $ZipPath - DestinationPath $TempExtractPath - Force
38+
39+ $ValidationPath = $TempExtractPath
40+ if (-not (Test-Path (Join-Path $ValidationPath ' IntegrityTree.json' ) - PathType Leaf)) {
41+ $CandidateDirectories = @ (Get-ChildItem $TempExtractPath - Directory | Where-Object {
42+ Test-Path (Join-Path $_.FullName ' IntegrityTree.json' ) - PathType Leaf
43+ })
44+
45+ if ($CandidateDirectories.Count -ne 1 ) {
46+ throw " Could not locate IntegrityTree.json after extracting '$ZipPath '."
47+ }
48+
49+ $ValidationPath = $CandidateDirectories [0 ].FullName
50+ }
51+
52+ $ValidationParameters = @ { Path = $ValidationPath }
53+ if ($FailOnUnexpectedFiles ) {
54+ $ValidationParameters.FailOnUnexpectedFiles = $true
55+ }
56+
57+ & $TreeValidatorPath @ValidationParameters
58+ }
59+ finally {
60+ Remove-Item $TempExtractPath - Recurse - Force - ErrorAction SilentlyContinue
61+ }
0 commit comments