-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
checkhashes.ps1
68 lines (63 loc) · 2.24 KB
/
checkhashes.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<#
.SYNOPSIS
Check hashes of all URLs inside manifest.
.DESCRIPTION
Check hashes of all URLs inside manifest.
Script will download every URL and then calculate hash of them.
.PARAMETER Manifest
Specify the name of manifest to be checked.
Placeholders are supported.
.PARAMETER Dir
Specify the directory with manifests.
Default to bucket folder.
.PARAMETER Rest
-u - Update hashes if there are mismatched ones.
-f - Update hashes always (even without mismatch).
-k - Use cache.
.EXAMPLE
PS BUCKETDIR> .\bin\checkhashes.ps1
Check URLs of all manifests.
.EXAMPLE
PS BUCKETDIR> .\bin\checkhashes.ps1 MAN
Check URLs of manifests MAN.json inside bucket root.
.EXAMPLE
PS BUCKETDIR> .\bin\checkhashes.ps1 MAN TODO
Check URLs of manifests MAN.json inside folder ./BUCKETROOT/TODO.
.EXAMPLE
PS BUCKETDIR> .\bin\checkhashes.ps1 MAN -u
Check URLs of manifests MAN and update if there are some mismatches.
.EXAMPLE
PS BUCKETDIR> .\bin\checkhashes.ps1 MAN -f
Check URLs of manifests MAN and update even if every hash is correct.
.EXAMPLE
PS BUCKETDIR> .\bin\checkhashes.ps1 MAN -k
Check URLs of manifests MAN and keep it's downloaded files.
#>
param(
[Parameter(ValueFromPipeline = $true)]
[Alias('App', 'Name')]
[String[]] $Manifest = '*',
[ValidateScript( { if ( Test-Path $_ -Type Container) { $true } else { $false } })]
[String] $Dir = "$PSScriptRoot\..\bucket",
[Switch] $Recurse,
[Parameter(ValueFromRemainingArguments)]
[String[]] $Rest
)
begin {
. "$PSScriptRoot\Helpers.ps1"
if (-not $env:SCOOP_HOME) {
if (-not (Get-Command 'scoop' -ErrorAction SilentlyContinue)) { throw 'Scoop installation or SCOOP_HOME environment is required' }
$env:SCOOP_HOME = scoop prefix scoop | Resolve-Path
}
$Dir = Resolve-Path $Dir
$Script = "$env:SCOOP_HOME\bin\checkhashes.ps1"
$Rest = ($Rest | Select-Object -Unique) -join ' '
}
process {
if ($Recurse) {
Get-RecursiveFolder | ForEach-Object { Invoke-Expression -Command "$Script -Dir ""$_"" $Rest" }
} else {
foreach ($man in $Manifest) { Invoke-Expression -Command "$Script -App ""$man"" -Dir ""$Dir"" $Rest" }
}
}
end { Write-Host 'DONE' -ForegroundColor Yellow }