verify sha256 checksums for windows users
feat: Add PowerShell script to verify file hashes This commit adds a PowerShell script that can be used to verify the hash sums of model files on Windows. The script reads the 'SHA256SUMS' file with the expected hash sums and filenames, calculates the SHA256 hash of each file using `certUtil`, and compares it with the expected hash. The output is a table with the filename, valid checksum (if the hash matches), and file missing (if the file is not found).
This commit is contained in:
parent
c4fe84fb0d
commit
86fc970126
1 changed files with 69 additions and 0 deletions
69
check_SHA256_windows.ps1
Normal file
69
check_SHA256_windows.ps1
Normal file
|
@ -0,0 +1,69 @@
|
|||
# Get the working directory
|
||||
$modelsPath = $pwd
|
||||
|
||||
# Define the file with the list of hashes and filenames
|
||||
$hashListPath = "SHA256SUMS"
|
||||
|
||||
# Check if the hash list file exists
|
||||
if (-not(Test-Path -Path $hashListPath)) {
|
||||
Write-Error "Hash list file not found: $hashListPath"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Read the hash file content and split it into an array of lines
|
||||
$hashList = Get-Content -Path $hashListPath
|
||||
$hashLines = $hashList -split "`n"
|
||||
|
||||
# Create an array to store the results
|
||||
$results = @()
|
||||
|
||||
# Loop over each line in the hash list
|
||||
foreach ($line in $hashLines) {
|
||||
|
||||
# Split the line into hash and filename
|
||||
$hash, $filename = $line -split " "
|
||||
|
||||
# Get the full path of the file by joining the models path and the filename
|
||||
$filePath = Join-Path -Path $modelsPath -ChildPath $filename
|
||||
|
||||
# Informing user of the progress of the integrity check
|
||||
Write-Host "Verifying the checksum of $filePath"
|
||||
|
||||
# Check if the file exists
|
||||
if (Test-Path -Path $filePath) {
|
||||
|
||||
# Calculate the SHA256 checksum of the file using certUtil
|
||||
$fileHash = certUtil -hashfile $filePath SHA256 | Select-Object -Index 1
|
||||
|
||||
# Remove any spaces from the hash output
|
||||
$fileHash = $fileHash -replace " ", ""
|
||||
|
||||
# Compare the file hash with the expected hash
|
||||
if ($fileHash -eq $hash) {
|
||||
$validChecksum = "V"
|
||||
$fileMissing = ""
|
||||
}
|
||||
else {
|
||||
$validChecksum = ""
|
||||
$fileMissing = "X"
|
||||
}
|
||||
}
|
||||
else {
|
||||
$validChecksum = ""
|
||||
$fileMissing = "X"
|
||||
}
|
||||
|
||||
# Add the results to the array
|
||||
$results += [PSCustomObject]@{
|
||||
"filename" = $filename
|
||||
"valid checksum" = $validChecksum
|
||||
"file missing" = $fileMissing
|
||||
}
|
||||
}
|
||||
|
||||
# Output the results as a table
|
||||
$results | Format-Table `
|
||||
-Property @{Expression={$_.filename}; Label="filename"; Alignment="left"}, `
|
||||
@{Expression={$_."valid checksum"}; Label="valid checksum"; Alignment="center"}, `
|
||||
@{Expression={$_."file missing"}; Label="file missing"; Alignment="center"} `
|
||||
-AutoSize
|
Loading…
Add table
Add a link
Reference in a new issue