@@ -69,24 +69,64 @@ param (
6969 [string ]$file
7070 )
7171 $downloader = new-object System.Net.WebClient
72+ $proxyurl = " "
73+ if (Test-Path env:http_proxy) {
74+ $proxyurl = $env: http_proxy
75+ }
76+ if ($proxyurl.length -gt 0 ) {
77+ $proxy = new-object System.Net.WebProxy
78+ $proxy.Address = $proxyurl
79+ $proxy.useDefaultCredentials = $true
80+ $downloader.proxy = $proxy
81+ }
7282 $defaultCreds = [System.Net.CredentialCache ]::DefaultCredentials
7383 if ($defaultCreds -ne $null ) {
7484 $downloader.Credentials = $defaultCreds
7585 }
76- $downloader.DownloadFile ($url , $file )
86+ Try {
87+ $downloader.DownloadFile ($url , $file )
88+ }
89+ Catch
90+ {
91+ Write-Host " ERROR" - ForegroundColor Red
92+ Write-Host $_.Exception.Message - ForegroundColor Red
93+ exit 1
94+ }
7795}
7896
97+ Write-Host - NoNewline " Downloading '$gitInstallerURL '..."
7998Download- File $gitInstallerURL $gitInstallerEXE
99+ Write-Output " OK"
80100
101+ function Check-SHA256 {
102+ param (
103+ [string ]$file
104+ )
105+ # Code snippet found here: https://github.com/FuzzySecurity/PowerShell-Suite/blob/master/Calculate-Hash.ps1
106+ $stream = [system.io.file ]::openread((resolve-path $file ))
107+ $algorithm = [System.Security.Cryptography.HashAlgorithm ]::create(" SHA256" )
108+ $hash = $algorithm.ComputeHash ($stream )
109+ $stream.close ()
110+ $stream.dispose ()
111+ $hash = [system.bitconverter ]::tostring($hash ).replace(' -' , ' ' )
112+ return $hash.ToLower ()
113+ }
114+
115+ Write-Host - NoNewline " Verifying SHA256 checksum of 'Git for Windows' installer..."
81116if ($PSVersionTable.PSVersion.Major -ge 4 ) {
82- $hash = Get-FileHash $gitInstallerEXE - Algorithm SHA256
83- if ($hash.Hash -ne $gitInstallerHash ) {
84- Write-Output " ERROR: SHA256 hash of the Git for Windows installer does not match."
85- exit
86- }
87- } else {
88- Write-Output " WARNING: SHA256 hash of the Git for Windows installer cannot be checked as your Powershell version is outdated (expected on Windows 7 and below)."
117+ $hash = (Get-FileHash $gitInstallerEXE - Algorithm SHA256).Hash
118+ }
119+ else {
120+ $hash = Check- SHA256 $gitInstallerEXE
121+ }
122+ if ($hash -ne $gitInstallerHash ) {
123+ Write-Host " ERROR" - ForegroundColor Red
124+ Write-Host " SHA256 hash of the 'Git for Windows' installer does not match:" - ForegroundColor Red
125+ Write-Host " Downloaded: $hash " - ForegroundColor Red
126+ Write-Host " Expected: $gitInstallerHash " - ForegroundColor Red
127+ exit 1
89128}
129+ Write-Output " OK"
90130
91131Set-Content $bootstrap " @echo off" - Encoding ASCII
92132Add-Content $bootstrap " `" $gitInstallerEXE `" /SILENT /COMPONENTS=`" icons,icons\desktop,ext,ext\shellhere,ext\guihere,assoc,assoc_sh`" " - Encoding ASCII
0 commit comments