| 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 |
Push-Location ${Cygwin} |
| 50 |
try { |
| 51 |
if (-Not (Test-Path .\${Setup} -PathType leaf)) { |
| 52 |
Invoke-WebRequest ${URL}/${Setup} ` |
| 53 |
-OutFile .\${Setup} |
| 54 |
} |
| 55 |
if (-Not (Test-Path .\${Setup}.sig -PathType leaf)) { |
| 56 |
Invoke-WebRequest ${URL}/${Setup}.sig ` |
| 57 |
-OutFile .\${Setup}.sig |
| 58 |
} |
| 59 |
Copy-Item "$PSScriptRoot\cygwin.gpg" -Destination "${Cygwin}" |
| 60 |
& $GPG --homedir ./.gnupg --list-keys |
| 61 |
& $GPG --homedir ./.gnupg --quiet --no-default-keyring ` |
| 62 |
--keyring ./cygwin.gpg ` |
| 63 |
--verify ./${Setup}.sig ./${Setup} |
| 64 |
if ($LastExitCode -ne 0) { |
| 65 |
throw "GPG signature verification failed" |
| 66 |
} |
| 67 |
} catch { |
| 68 |
throw "Failed to fetch and verify Cygwin" |
| 69 |
} finally { |
| 70 |
Pop-Location |
| 71 |
} |
| 72 |
|
| 73 |
# Bootstrap Cygwin. |
| 74 |
Start-Process "${Cygwin}\${Setup}" -Wait -NoNewWindow ` |
| 75 |
-ArgumentList "-dnNOqW -s ${Mirror} -R ${Root} -P ${Packages}" |
| 76 |
|
| 77 |
# Build libfido2. |
| 78 |
$Env:PATH = "${Root}\bin\;" + $Env:PATH |
| 79 |
cmake "-DCMAKE_BUILD_TYPE=${Config}" -B "build-${Config}" |
| 80 |
make -C "build-${Config}" |
| 81 |
make -C "build-${Config}" regress |