Skip to content

Commit 978a92f

Browse files
authored
[Windows] Add checksum validation for MSYS2 (#8385)
1 parent 77724a9 commit 978a92f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

images/win/scripts/Installers/Install-Msys2.ps1

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ $origPath = $env:PATH
1212

1313
function Install-Msys2 {
1414
$msys2_release = "https://api.github.com/repos/msys2/msys2-installer/releases/latest"
15-
$msys2Uri = ((Invoke-RestMethod $msys2_release).assets | Where-Object {
16-
$_.name -match "^msys2-x86_64" -and $_.name.EndsWith(".exe") }).browser_download_url
17-
15+
$assets = (Invoke-RestMethod -Uri $msys2_release).assets
16+
$msys2Uri = ($assets | Where-Object { $_.name -match "^msys2-x86_64" -and $_.name.EndsWith(".exe") }).browser_download_url
17+
1818
# Download the latest msys2 x86_64, filename includes release date
1919
Write-Host "Starting msys2 download using $($msys2Uri.split('/')[-1])"
2020
$msys2File = Start-DownloadWithRetry -Url $msys2Uri
2121
Write-Host "Finished download"
2222

23+
#region Supply chain security - Kind
24+
$fileHash = (Get-FileHash -Path $msys2File -Algorithm SHA256).Hash
25+
$hashUrl = ($assets.browser_download_url -match "msys2-checksums.txt") | Select-Object -First 1
26+
$externalHash = (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*msys2-x86_64*" }).Split(' ')[0]
27+
Use-ChecksumComparison $fileHash $externalHash
28+
#endregion
29+
2330
# extract tar.xz to C:\
2431
Write-Host "Starting msys2 installation"
2532
& $msys2File in --confirm-command --accept-messages --root C:/msys64
@@ -89,4 +96,4 @@ Install-MingwPackages -Packages $toolsetContent.mingw
8996
$env:PATH = $origPath
9097
Write-Host "`nMSYS2 installation completed"
9198

92-
Invoke-PesterTests -TestFile "MSYS2"
99+
Invoke-PesterTests -TestFile "MSYS2"

0 commit comments

Comments
 (0)