]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/opentelemetry-cpp/tools/vcpkg/scripts/azure-pipelines/osx/Utilities.psm1
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / tools / vcpkg / scripts / azure-pipelines / osx / Utilities.psm1
CommitLineData
1e59de90
TL
1#Requires -Version 6.0
2Set-StrictMode -Version 2
3
4<#
5.SYNOPSIS
6Returns whether the specified command exists in the current environment.
7
8.DESCRIPTION
9Get-CommandExists takes a string as a parameter,
10and returns whether it exists in the current environment;
11either a function, alias, or an executable in the path.
12It's somewhat equivalent to `which`.
13
14.PARAMETER Name
15Specifies the name of the command which may or may not exist.
16
17.INPUTS
18System.String
19 The name of the command.
20
21.OUTPUTS
22System.Boolean
23 Whether the command exists.
24#>
25function Get-CommandExists
26{
27 [CmdletBinding()]
28 [OutputType([Boolean])]
29 Param(
30 [Parameter(ValueFromPipeline)]
31 [String]$Name
32 )
33
34 $null -ne (Get-Command -Name $Name -ErrorAction SilentlyContinue)
35}
36
37<#
38.SYNOPSIS
39Downloads a file and checks its hash.
40
41.DESCRIPTION
42Get-RemoteFile takes a URI and a hash,
43downloads the file at that URI to OutFile,
44and checks that the hash of the downloaded file.
45It then returns a FileInfo object corresponding to the downloaded file.
46
47.PARAMETER OutFile
48Specifies the file path to download to.
49
50.PARAMETER Uri
51The URI to download from.
52
53.PARAMETER Sha256
54The expected SHA256 of the downloaded file.
55
56.INPUTS
57None
58
59.OUTPUTS
60System.IO.FileInfo
61 The FileInfo for the downloaded file.
62#>
63function Get-RemoteFile
64{
65 [CmdletBinding(PositionalBinding=$False)]
66 [OutputType([System.IO.FileInfo])]
67 Param(
68 [Parameter(Mandatory=$True)]
69 [String]$OutFile,
70 [Parameter(Mandatory=$True)]
71 [String]$Uri,
72 [Parameter(Mandatory=$True)]
73 [String]$Sha256
74 )
75
76 Invoke-WebRequest -OutFile $OutFile -Uri $Uri
77 $actualHash = Get-FileHash -Algorithm SHA256 -Path $OutFile
78
79 if ($actualHash.Hash -ne $Sha256) {
80 throw @"
81Invalid hash for file $OutFile;
82 expected: $Hash
83 found: $($actualHash.Hash)
84Please make sure that the hash in the powershell file is correct.
85"@
86 }
87
88 Get-Item $OutFile
89}
90