Skip to content

Commit 852b6aa

Browse files
committed
feat: verify checksums in Windows install script (#42)
1 parent 38c4644 commit 852b6aa

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

install.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ try {
99
$outFile = "envfetch.exe"
1010
Invoke-WebRequest -Uri "https://github.com/ankddev/envfetch/releases/latest/download/envfetch-windows-amd64.exe" -OutFile $outFile
1111

12+
# Check integrity
13+
$expectedChecksum = Invoke-WebRequest -Uri "https://github.com/ankddev/envfetch/releases/latest/download/envfetch-windows-amd64.exe.sha256"
14+
$expectedChecksum = [System.Text.Encoding]::UTF8.GetString($expectedChecksum.Content).TrimEnd()
15+
$actualChecksum = (Get-FileHash -Path $outFile -Algorithm SHA256).Hash.ToLower()
16+
if ($actualChecksum -ne $expectedChecksum) {
17+
Write-Host "Checksum mismatch!"
18+
Write-Host "Expected: \"$expectedChecksum\""
19+
Write-Host "Actual: \"$actualChecksum\""
20+
Write-Host "Please download the file manually and verify its integrity."
21+
exit 1
22+
}
23+
1224
# Add to PATH
1325
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
1426
if ($userPath -notlike "*$envfetchPath*") {

0 commit comments

Comments
 (0)