icinga-powershell-framework/lib/core/framework/Test-IcingaZipBinaryChecksum.psm1

47 lines
1.2 KiB
PowerShell
Raw Normal View History

2020-05-22 03:52:48 -04:00
<#
.SYNOPSIS
Compares a binary within a .zip file to a included .md5 to ensure
the checksum is matching
.DESCRIPTION
Compares a possible included .md5 checksum file with the provided binary
to ensure they are identical
.FUNCTIONALITY
Compares a binary within a .zip file to a included .md5 to ensure
the checksum is matching.
.EXAMPLE
PS>Test-IcingaZipBinaryChecksum -Path 'C:\Program Files\icinga-service\icinga-service.exe';
.PARAMETER Path
Path to the binary to be checked for. A Corresponding .md5 file with the
extension added on the file is required, like icinga-service.exe.md5
.INPUTS
System.String
.OUTPUTS
Null
.LINK
https://github.com/Icinga/icinga-powershell-framework
#>
function Test-IcingaZipBinaryChecksum()
{
param(
$Path
);
$MD5Path = [string]::Format('{0}.md5', $Path);
if ((Test-Path $MD5Path) -eq $FALSE) {
return $TRUE;
}
[string]$MD5Checksum = Get-Content $MD5Path;
$MD5Checksum = ($MD5Checksum.Split(' ')[0]).ToLower();
2021-08-06 12:12:27 -04:00
$FileHash = ((Get-IcingaFileHash $Path -Algorithm MD5).Hash).ToLower();
if ($MD5Checksum -ne $FileHash) {
return $FALSE;
}
return $TRUE;
}