[Windows] Cleanup various scripts (#8942)

* Use Resolve-GithubReleaseAssetUrl more widely

* Add the Get-ChecksumFromUrl function

* Sort exported functions and add docs

* Remove alias and fix typo

* Fix kind checksum url and syntax

* Fix checksums url for gh cli and msys2

* [Windows] Cleanup various scripts

* Add spaces after type specifications

* Rename the Take-Part function
This commit is contained in:
Vasilii Polikarpov
2023-12-04 10:50:53 +01:00
committed by GitHub
parent ed911223ab
commit 5ed2615017
56 changed files with 770 additions and 568 deletions

View File

@@ -33,7 +33,7 @@ function Get-CertificatesWithoutPropId {
$certs | ForEach-Object -Process {
$certHandle = $_.Handle
$isPropertySet = [PKI.Cert]::CertGetCertificateContextProperty(
$certHandle, $CERT_NOT_BEFORE_FILETIME_PROP_ID, $null, [ref]$null
$certHandle, $CERT_NOT_BEFORE_FILETIME_PROP_ID, $null, [ref] $null
)
if (-not $isPropertySet) {
Write-Host "Subject: $($_.Subject)"
@@ -43,31 +43,17 @@ function Get-CertificatesWithoutPropId {
$certsWithoutPropId
}
function Invoke-WithRetry {
<#
.SYNOPSIS
Runs $command block until $BreakCondition or $RetryCount is reached.
#>
param([ScriptBlock]$Command, [ScriptBlock] $BreakCondition, [int] $RetryCount=5, [int] $Sleep=10)
$c = 0
while($c -lt $RetryCount){
$result = & $Command
if(& $BreakCondition){
break
}
Start-Sleep $Sleep
$c++
}
$result
}
function Import-SSTFromWU {
# Serialized Certificate Store File
$sstFile = "$env:TEMP\roots.sst"
# Generate SST from Windows Update
$result = Invoke-WithRetry { certutil.exe -generateSSTFromWU $sstFile } {$LASTEXITCODE -eq 0}
$result = Invoke-ScriptBlockWithRetry -RetryCount 5 -RetryIntervalSeconds 10 -Command {
$r = certutil.exe -generateSSTFromWU $sstFile
if ($LASTEXITCODE -ne 0) {
throw "failed to generate $sstFile sst file`n$o"
}
return $r
}
if ($LASTEXITCODE -ne 0) {
Write-Host "[Error]: failed to generate $sstFile sst file`n$result"
exit $LASTEXITCODE
@@ -88,7 +74,9 @@ function Import-SSTFromWU {
}
function Clear-CertificatesPropId {
param([hashtable]$CertsWithoutPropId)
param(
[hashtable] $CertsWithoutPropId
)
# List installed certificates
$certs = Get-ChildItem -Path Cert:\LocalMachine\Root