Debian Codegraph @

extra/libfido2/libfido2-1.15.0/windows/cygwin.ps1

raw
1 # Copyright (c) 2021 Yubico AB. All rights reserved.
2 # Use of this source code is governed by a BSD-style
3 # license that can be found in the LICENSE file.
4 # SPDX-License-Identifier: BSD-2-Clause
5
6 param(
7 [string]$GPGPath = "C:\Program Files (x86)\GnuPG\bin\gpg.exe",
8 [string]$Config = "Release"
9 )
10
11 $ErrorActionPreference = "Stop"
12 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
13
14 # Cygwin coordinates.
15 $URL = 'https://www.cygwin.com'
16 $Setup = 'setup-x86_64.exe'
17 $Mirror = 'https://mirrors.kernel.org/sourceware/cygwin/'
18 $Packages = 'gcc-core,pkg-config,cmake,make,libcbor-devel,libssl-devel,zlib-devel'
19
20 # Work directories.
21 $Cygwin = "$PSScriptRoot\..\cygwin"
22 $Root = "${Cygwin}\root"
23
24 # Find GPG.
25 $GPG = $(Get-Command gpg -ErrorAction Ignore | `
26 Select-Object -ExpandProperty Source)
27 if ([string]::IsNullOrEmpty($GPG)) {
28 $GPG = $GPGPath
29 }
30 if (-Not (Test-Path $GPG)) {
31 throw "Unable to find GPG at $GPG"
32 }
33
34 Write-Host "Config: $Config"
35 Write-Host "GPG: $GPG"
36
37 # Create work directories.
38 New-Item -Type Directory "${Cygwin}" -Force
39 New-Item -Type Directory "${Root}" -Force
40
41 # Create GNUPGHOME with an empty common.conf to disable use-keyboxd.
42 # Recent default is to enable keyboxd which in turn ignores --keyring
43 # arguments.
44 $GpgHome = "${Cygwin}\.gnupg"
45 New-Item -Type Directory "${GpgHome}" -Force
46 New-Item -Type File "${GpgHome}\common.conf" -Force
47
48 # Fetch and verify Cygwin.
49 try {
50 if (-Not (Test-Path ${Cygwin}\${Setup} -PathType leaf)) {
51 Invoke-WebRequest ${URL}/${Setup} `
52 -OutFile ${Cygwin}\${Setup}
53 }
54 if (-Not (Test-Path ${Cygwin}\${Setup}.sig -PathType leaf)) {
55 Invoke-WebRequest ${URL}/${Setup}.sig `
56 -OutFile ${Cygwin}\${Setup}.sig
57 }
58 & $GPG --homedir ${GpgHome} --list-keys
59 & $GPG --homedir ${GpgHome} --quiet --no-default-keyring `
60 --keyring ${PSScriptRoot}/cygwin.gpg `
61 --verify ${Cygwin}\${Setup}.sig ${Cygwin}\${Setup}
62 if ($LastExitCode -ne 0) {
63 throw "GPG signature verification failed"
64 }
65 } catch {
66 throw "Failed to fetch and verify Cygwin"
67 }
68
69 # Bootstrap Cygwin.
70 Start-Process "${Cygwin}\${Setup}" -Wait -NoNewWindow `
71 -ArgumentList "-dnNOqW -s ${Mirror} -R ${Root} -P ${Packages}"
72
73 # Build libfido2.
74 $Env:PATH = "${Root}\bin\;" + $Env:PATH
75 cmake "-DCMAKE_BUILD_TYPE=${Config}" -B "build-${Config}"
76 make -C "build-${Config}"
77 make -C "build-${Config}" regress