xref: /freebsd/contrib/libfido2/windows/cygwin.ps1 (revision 7ef62cebc2f965b0f640263e179276928885e33d)
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 
5 param(
6 	[string]$GPGPath = "C:\Program Files (x86)\GnuPG\bin\gpg.exe",
7 	[string]$Config = "Release"
8 )
9 
10 $ErrorActionPreference = "Stop"
11 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
12 
13 # Cygwin coordinates.
14 $URL = 'https://www.cygwin.com'
15 $Setup = 'setup-x86_64.exe'
16 $Mirror = 'https://mirrors.kernel.org/sourceware/cygwin/'
17 $Packages = 'gcc-core,pkg-config,cmake,make,libcbor-devel,libssl-devel,zlib-devel'
18 
19 # Work directories.
20 $Cygwin = "$PSScriptRoot\..\cygwin"
21 $Root = "${Cygwin}\root"
22 
23 # Find GPG.
24 $GPG = $(Get-Command gpg -ErrorAction Ignore | `
25     Select-Object -ExpandProperty Source)
26 if ([string]::IsNullOrEmpty($GPG)) {
27 	$GPG = $GPGPath
28 }
29 if (-Not (Test-Path $GPG)) {
30 	throw "Unable to find GPG at $GPG"
31 }
32 
33 Write-Host "Config: $Config"
34 Write-Host "GPG: $GPG"
35 
36 # Create work directories.
37 New-Item -Type Directory "${Cygwin}" -Force
38 New-Item -Type Directory "${Root}" -Force
39 
40 # Fetch and verify Cygwin.
41 try {
42 	if (-Not (Test-Path ${Cygwin}\${Setup} -PathType leaf)) {
43 		Invoke-WebRequest ${URL}/${Setup} `
44 		    -OutFile ${Cygwin}\${Setup}
45 	}
46 	if (-Not (Test-Path ${Cygwin}\${Setup}.sig -PathType leaf)) {
47 		Invoke-WebRequest ${URL}/${Setup}.sig `
48 		    -OutFile ${Cygwin}\${Setup}.sig
49 	}
50 	& $GPG --list-keys
51 	& $GPG --quiet --no-default-keyring `
52 	    --keyring ${PSScriptRoot}/cygwin.gpg `
53 	    --verify ${Cygwin}\${Setup}.sig ${Cygwin}\${Setup}
54 	if ($LastExitCode -ne 0) {
55 		throw "GPG signature verification failed"
56 	}
57 } catch {
58 	throw "Failed to fetch and verify Cygwin"
59 }
60 
61 # Bootstrap Cygwin.
62 Start-Process "${Cygwin}\${Setup}" -Wait -NoNewWindow `
63     -ArgumentList "-dnNOqW -s ${Mirror} -R ${Root} -P ${Packages}"
64 
65 # Build libfido2.
66 $Env:PATH = "${Root}\bin\;" + $Env:PATH
67 cmake "-DCMAKE_BUILD_TYPE=${Config}" -B "build-${Config}"
68 make -C "build-${Config}"
69