aboutsummaryrefslogtreecommitdiff
path: root/scripts/package_windows_conpty.ps1
blob: a94b609efb9144f88ce01b27f2276e95747f7709 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
param(
    [Parameter(Mandatory = $true)]
    [string]$HerdrExe,

    [Parameter(Mandatory = $true)]
    [string]$PackagePath,

    [Parameter(Mandatory = $true)]
    [string]$StageDir,

    [Parameter(Mandatory = $true)]
    [string]$OutputPath
)

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

function Invoke-NativeChecked {
    param(
        [string]$Command,
        [string[]]$Arguments
    )

    & $Command @Arguments
    if ($LASTEXITCODE -ne 0) {
        throw "$Command failed with exit code $LASTEXITCODE"
    }
}

$packager = Join-Path $PSScriptRoot "package_windows_conpty.py"
Invoke-NativeChecked python @(
    $packager,
    "stage",
    "--package", $PackagePath,
    "--herdr-exe", $HerdrExe,
    "--output-dir", $StageDir
)
Invoke-NativeChecked dotnet @("nuget", "verify", "--all", $PackagePath)

foreach ($relative in @("conpty\conpty.dll", "conpty\x64\OpenConsole.exe", "conpty\arm64\OpenConsole.exe")) {
    $signature = Get-AuthenticodeSignature (Join-Path $StageDir $relative)
    $subject = if ($null -eq $signature.SignerCertificate) { "" } else { $signature.SignerCertificate.Subject }
    if ($signature.Status -ne "Valid" -or $subject -notlike "*Microsoft Corporation*") {
        throw "Invalid Microsoft signature for $relative`: $($signature.Status) $subject"
    }
}

Invoke-NativeChecked python @(
    $packager,
    "archive",
    "--stage-dir", $StageDir,
    "--output", $OutputPath
)