Packer.Images/scripts/Update-Manifest.ps1
djpbessems 0cf09c5ff9
All checks were successful
continuous-integration/drone/push Build is passing
Delete commit history (containing proprietary code)
2021-01-23 16:04:42 +01:00

56 lines
1.4 KiB
PowerShell

#Requires -Modules 'powershell-yaml'
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[ValidateScript({
If (Test-Path($_)) {
$True
} Else {
Throw "'$_' is not a valid filename (within working directory '$PWD'), or access denied; aborting."
}
})]
[string]$ManifestFileName
)
$GetItemSplat = @{
Path = $ManifestFileName
}
$ManifestFile = Get-Item @GetItemSplat
$SetLocationSplat = @{
Path = $ManifestFile.DirectoryName
}
Set-Location @SetLocationSplat
$GetContentSplat = @{
Path = $ManifestFile.FullName
}
$Manifest = Get-Content @GetContentSplat
$UpdatedManifest = ForEach ($Line in $Manifest) {
Write-Host "Processing '$($Line)' ..."
If ($Line -match '^SHA256\((.+)\)= ([0-9a-fA-F]{64})$') {
If (Test-Path $Matches[1]) {
$GetFileHashSplat = @{
Path = $Matches[1]
Algorithm = 'SHA256'
}
Write-Host "Updating checksum..."
"SHA256($($Matches[1]))= $((Get-FileHash @GetFileHashSplat).Hash)"
}
}
}
If ($UpdatedManifest -ne $Null) {
$SetContentSplat = @{
Path = $ManifestFile.FullName
Value = $UpdatedManifest
Force = $True
Confirm = $False
}
Set-Content @SetContentSplat
} Else {
Write-Host "Failed updating manifest."
Exit 1
}