xref: /freebsd/contrib/libfido2/windows/cygwin.ps1 (revision 61e21613)
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 # Fetch and verify Cygwin.
42 try {
43 	if (-Not (Test-Path ${Cygwin}\${Setup} -PathType leaf)) {
44 		Invoke-WebRequest ${URL}/${Setup} `
45 		    -OutFile ${Cygwin}\${Setup}
46 	}
47 	if (-Not (Test-Path ${Cygwin}\${Setup}.sig -PathType leaf)) {
48 		Invoke-WebRequest ${URL}/${Setup}.sig `
49 		    -OutFile ${Cygwin}\${Setup}.sig
50 	}
51 	& $GPG --list-keys
52 	& $GPG --quiet --no-default-keyring `
53 	    --keyring ${PSScriptRoot}/cygwin.gpg `
54 	    --verify ${Cygwin}\${Setup}.sig ${Cygwin}\${Setup}
55 	if ($LastExitCode -ne 0) {
56 		throw "GPG signature verification failed"
57 	}
58 } catch {
59 	throw "Failed to fetch and verify Cygwin"
60 }
61 
62 # Bootstrap Cygwin.
63 Start-Process "${Cygwin}\${Setup}" -Wait -NoNewWindow `
64     -ArgumentList "-dnNOqW -s ${Mirror} -R ${Root} -P ${Packages}"
65 
66 # Build libfido2.
67 $Env:PATH = "${Root}\bin\;" + $Env:PATH
68 cmake "-DCMAKE_BUILD_TYPE=${Config}" -B "build-${Config}"
69 make -C "build-${Config}"
70 make -C "build-${Config}" regress
71