Files
lib-privatebin/scripts/gen_checksums.ps1

38 lines
863 B
PowerShell

param(
[Parameter(Mandatory=$true)][string]$ZipPath,
[Parameter(Mandatory=$true)][string]$BinDir
)
$ErrorActionPreference = 'Stop'
if (-not (Test-Path -LiteralPath $ZipPath)) {
throw "ZIP not found: $ZipPath"
}
if (-not (Test-Path -LiteralPath $BinDir)) {
throw "BinDir not found: $BinDir"
}
function Write-ChecksumFile {
param(
[Parameter(Mandatory=$true)][string]$Path
)
$hash = (Get-FileHash -Algorithm SHA256 -LiteralPath $Path).Hash.ToLower()
$outfile = "$Path.sha256"
$line = "$hash $([System.IO.Path]::GetFileName($Path))"
Set-Content -Path $outfile -NoNewline -Encoding ASCII -Value $line
Write-Host "Wrote $outfile"
}
# ZIP checksum
Write-ChecksumFile -Path $ZipPath
# Binaries checksums
Get-ChildItem -LiteralPath $BinDir -File | ForEach-Object {
Write-ChecksumFile -Path $_.FullName
}