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