validate.ps1 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. $ErrorActionPreference = "Stop"
  2. # Get the root directory and third_party directory
  3. $ROOT_DIR = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent | Split-Path -Parent | Split-Path -Parent -Resolve
  4. # Include the common functions
  5. . "$ROOT_DIR/hack/lib/windows/init.ps1"
  6. function Validate {
  7. param (
  8. [string]$file
  9. )
  10. # Generate the current checksum
  11. $currentChecksum = Get-FileHash -Path $file -Algorithm SHA256
  12. $generatedChecksumFile = "${file}.generated.sha256sum"
  13. $currentChecksum.Hash | Out-File -FilePath $generatedChecksumFile
  14. # Compare with the expected checksum
  15. $expectedChecksumFile = "${file}.sha256sum"
  16. $expectedChecksum = Get-Content -Path $expectedChecksumFile
  17. if ($currentChecksum.Hash -eq $expectedChecksum.Trim()) {
  18. GPUStack.Log.Info "Checksums match."
  19. Remove-Item -Path $generatedChecksumFile
  20. }
  21. else {
  22. GPUStack.Log.Fatal "Checksums do not match!`nPlease run 'Get-FileHash -Path install.ps1 -Algorithm SHA256 | Select -ExpandProperty Hash > install.ps1.sha256sum' to update the checksum."
  23. }
  24. }
  25. #
  26. # main
  27. #
  28. GPUStack.Log.Info "+++ VALIDATE +++"
  29. try {
  30. Validate -file "install.ps1"
  31. }
  32. catch {
  33. GPUStack.Log.Fatal "failed to test: $($_.Exception.Message)"
  34. }
  35. GPUStack.Log.Info "--- VALIDATE ---"