Skip to content

Commit

Permalink
Add checksum support for Install-FromUri
Browse files Browse the repository at this point in the history
  • Loading branch information
AgenttiX committed Jun 3, 2024
1 parent 8937652 commit 7373e63
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ function Install-FromUri {
[Parameter(mandatory=$true)][string]$Uri,
[Parameter(mandatory=$true)][string]$Filename,
[Parameter(mandatory=$false)][string]$UnzipFolderName,
[Parameter(mandatory=$false)][string]$UnzippedFilePath
[Parameter(mandatory=$false)][string]$UnzippedFilePath,
[Parameter(mandatory=$false)][string]$MD5,
[Parameter(mandatory=$false)][string]$SHA256
)
Show-Output "Downloading ${Name}"
$Path = "${Downloads}\${Filename}"
Expand All @@ -329,6 +331,23 @@ function Install-FromUri {
Show-Output "Downloaded file was not found at ${Path}"
return 1
}
if ($PSBoundParameters.ContainsKey("SHA256")) {
$FileHash = (Get-FileHash -Path "${Path}" -Algorithm "SHA256").Hash
if ($FileHash -eq $SHA256) {
Show-Output "SHA256 checksum OK"
} else {
Show-Output -ForegroundColor Red "Downloaded file has an invalid SHA256 checksum. Expected: ${SHA256}, got: ${FileHash}"
return 1
}
} elseif ($PSBoundParameters.ContainsKey("MD5")) {
$FileHash = (Get-FileHash -Path "${Path}" -Algorithm "MD5").Hash
if ($FileHash -eq $MD5) {
Show-Output "MD5 checksum OK"
} else {
Show-Output -ForegroundColor Red "Downloaded file has an invalid MD5 checksum. Expected: ${MD5}, got: ${FileHash}"
return 1
}
}
if ($File.Extension -eq ".zip") {
if (-not $PSBoundParameters.ContainsKey("UnzipFolderName")) {
Show-Output -ForegroundColor Red "UnzipFolderName was not provided for a zip file."
Expand Down

0 comments on commit 7373e63

Please sign in to comment.