aboutsummaryrefslogtreecommitdiff
path: root/contrib/win-installer/build.ps1
blob: ba1b9754817b9cc7b4b432abcd4d0e8dababa2b4 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
function ExitOnError() {
    if ($LASTEXITCODE -ne 0) {
        Exit 1
    }
}

function FetchPanel() {
    Remove-Item -Recurse -Force -Path fetch -ErrorAction SilentlyContinue | Out-Null
    New-Item -Force -ItemType Directory fetch | Out-Null
    Push-Location fetch

    $ProgressPreference = 'SilentlyContinue'
    Invoke-WebRequest -UseBasicParsing -OutFile nuget.exe -ErrorAction Stop `
        -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

    .\nuget.exe install PanelSwWixExtension
    $code = $LASTEXITCODE
    Pop-Location
    if ($code -gt 0) {
        Exit 1
    }
    $loc = Get-ChildItem -Recurse -Path fetch -Name PanelSwWixExtension.dll
    if (!$loc) {
        Write-Host "Could not locate PanelSwWixExtension.dll"
        Exit 1
    }

    Copy-Item -Path fetch/$loc -Destination artifacts/PanelSwWixExtension.dll -ErrorAction Stop
}

function SignItem() {
    param(
        [Parameter(Mandatory)]
        [string[]]$fileNames
    )

    foreach ($val in $ENV:APP_ID, $ENV:TENANT_ID, $ENV:CLIENT_SECRET, $ENV:CERT_NAME) {
        if (!$val) {
            Write-Host "Skipping signing (no config)"
            Return
        }
    }

    CheckCommand AzureSignTool.exe "AzureSignTool"

    AzureSignTool.exe sign -du "https://github.com/containers/podman" `
        -kvu "https://$ENV:VAULT_ID.vault.azure.net" `
        -kvi $ENV:APP_ID `
        -kvt $ENV:TENANT_ID `
        -kvs $ENV:CLIENT_SECRET `
        -kvc $ENV:CERT_NAME `
        -tr http://timestamp.digicert.com $fileNames

    ExitOnError
}

function CheckCommand() {
    param(
        [Parameter(Mandatory)]
        [string] $cmd,
        [Parameter(Mandatory)]
        [string] $description
    )

    if (! (Get-Command $cmd -errorAction SilentlyContinue)) {
        Write-Host "Required dep `"$description`" is not installed"
        Exit 1
    }
}

function CheckRequirements() {
    CheckCommand "gcc" "MingW CC"
    CheckCommand "candle" "WiX Toolset"
    CheckCommand "go" "Golang"
}


if ($args.Count -lt 1 -or $args[0].Length -lt 1) {
    Write-Host "Usage: " $MyInvocation.MyCommand.Name "<version> [dev|prod] [release_dir]"
    Write-Host
    Write-Host 'Uses Env Vars: '
    Write-Host '   $ENV:FETCH_BASE_URL - GitHub Repo Address to locate release on'
    Write-Host 'Env Settings for signing (optional)'
    Write-Host '   $ENV:VAULT_ID'
    Write-Host '   $ENV:APP_ID'
    Write-Host '   $ENV:TENANT_ID'
    Write-Host '   $ENV:CLIENT_SECRET'
    Write-Host '   $ENV:CERT_NAME'
    Write-Host
    Write-Host "Example: Download and build from the official Github release (dev output): "
    Write-Host " .\build.ps1 4.2.0"
    Write-Host
    Write-Host "Example: Build a dev build from a pre-download release "
    Write-Host " .\build.ps1 4.2.0 dev fetchdir"
    Write-Host

    Exit 1
}

# Pre-set to standard locations in-case build env does not refresh paths
$Env:Path="$Env:Path;C:\Program Files (x86)\WiX Toolset v3.11\bin;C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin;;C:\Program Files\Go\bin"

CheckRequirements

$version = $args[0]

if ($version[0] -eq "v") {
    $version = $version.Substring(1)
}

$suffix = "-dev"
if ($args.Count -gt 1 -and $args[1] -eq "prod") {
    $suffix = ""
}

$releaseDir = ""
if ($args.Count -gt 2) {
    $releaseDir = $args[2]
}

.\process-release.ps1 $version $releaseDir
if ($LASTEXITCODE -eq 2) {
    Write-Host "Skip signaled, relaying skip"
    Exit 2
}
if ($ENV:INSTVER -eq "") {
    Write-Host "process-release did not define an install version!"
    Exit 1
}

FetchPanel

.\build-hooks.bat; ExitOnError
SignItem @("artifacts/win-sshproxy.exe",
          "artifacts/podman.exe",
          "artifacts/podman-msihooks.dll",
          "artifacts/podman-wslkerninst.exe")

.\build-msi.bat $ENV:INSTVER; ExitOnError
SignItem @("podman.msi")

.\build-burn.bat $ENV:INSTVER; ExitOnError
insignia -ib podman-setup.exe -o engine.exe; ExitOnError
SignItem @("engine.exe")

$file = "podman-$version$suffix-setup.exe"
insignia -ab engine.exe podman-setup.exe -o $file; ExitOnError
SignItem @("$file")

if (Test-Path -Path shasums) {
    $hash = (Get-FileHash -Algorithm SHA256 $file).Hash.ToLower()
    Write-Output "$hash  $file" | Out-File -Append -FilePath shasums
}

Write-Host "Complete"
Get-ChildItem "podman-$version$suffix-setup.exe"