-
Notifications
You must be signed in to change notification settings - Fork 1
/
scala-checksum.ps1
39 lines (34 loc) · 1.44 KB
/
scala-checksum.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[CmdletBinding()]
Param (
[ValidateSet('2.12.15', '2.13.7', '2.13.8')]
[string]$version = '2.13.8',
[ValidateSet('md5', 'sha256')]
[string]$algorithm = 'md5'
)
$algorithm = $algorithm.ToUpper()
$TempFolder = Join-Path $env:TEMP -ChildPath 'scala-checksum'
if (-Not (Test-Path -Path $TempFolder)) {
New-Item -Path $TempFolder -ItemType Directory
}
$MsiName = "scala-$version.msi";
$MsiUri = "https://github.com/michelou/wix-examples/releases/download/scala-$version.msi/$MsiName";
$MsiFile = Join-Path -Path $TempFolder -ChildPath $MsiName;
$ChecksumName = "$MsiName.$algorithm";
$ChecksumUri = "$MsiUri.$algorithm";
$ChecksumFile = Join-Path -Path $TempFolder -ChildPath $ChecksumName;
$ProgressPreference = 'SilentlyContinue'
Invoke-RestMethod -UserAgent 'Mozilla 5.0' -Uri $MsiUri -OutFile $MsiFile
Invoke-RestMethod -UserAgent 'Mozilla 5.0' -Uri $ChecksumUri -OutFile $ChecksumFile
$fh = Get-FileHash $MsiFile -Algorithm $algorithm;
$path = Get-Item $fh.Path;
$ComputedHash = $fh.Hash+' '+$path.Basename+$path.Extension;
## Out-String option '-NoNewline' only available in PowerShell 6.0
$ChecksumHash = Get-Content -Path $ChecksumFile -First 1 | Out-String
$ChecksumHash = $ChecksumHash.Substring(0, $ComputedHash.length)
Write-Host "Computed: $ComputedHash"
Write-Host "$algorithm file: $ChecksumHash"
if ($ComputedHash.Equals($ChecksumHash)) {
Write-Host 'The two checksums are equal';
} else {
Write-Host 'The two checksums differ';
}