Created
August 8, 2018 09:20
-
-
Save lennybacon/93de5c166404cf713fa76662c1497bcf to your computer and use it in GitHub Desktop.
Install or update git for windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$gitSetupDirectory = "C:\Windows\temp" | |
$ino = "Inno Setup CodeFile:" | |
$params = @{ | |
"$ino Bash Terminal Option" = "ConHost"; | |
"$ino CRLF Option" = "CRLFAlways"; | |
"$ino CURL Option" = "WinSSL"; | |
"$ino Editor Option" = "VisualStudioCode"; | |
"$ino Enable Symlinks" = "Enabled"; | |
"$ino Path Option" = "Cmd"; | |
"$ino Performance Tweaks FSCache" = "Enabled"; | |
"$ino Performance SSH Option" = "OpenSSH"; | |
"$ino Use Credential Manager" = "Enabled"; | |
"$ino Deselected Components" = "icons,icons\desktop,ext,ext\shellhere,ext\guihere,autoupdate"; | |
"$ino Icon Group" = "Git"; | |
"$ino Language" = "default"; | |
"$ino Selected Components" = "gitlfs,assoc,assoc_sh,consolefont"; | |
}; | |
$regHiveGit = "Microsoft\Windows\CurrentVersion\Uninstall\Git_is1" | |
$gitReleasesUrl = "https://github.com/git-for-windows/git/releases/latest" | |
$latesReleasesMarkup = (New-Object System.Net.WebClient).DownloadString($gitReleasesUrl); | |
Write-Host "GIT 32 Bit install..." | |
$regHive32 = "HKLM:\SOFTWARE\WOW6432Node"; | |
$installKey32 = "$regHive32\$regHiveGit" | |
if ((Test-Path $installKey32) -eq $false) { | |
$r = md $installKey32 | |
} | |
foreach ($h in $params.GetEnumerator()) { | |
$r = New-ItemProperty $installKey32 -Name $h.Name -Value $h.Value -Force | |
} | |
$git32SetupPath = "$gitSetupDirectory\git32.exe" | |
$regex32 = new-object System.Text.RegularExpressions.Regex( | |
'\<a\shref=\"(?<url>.*-32-bit\.exe)\"\srel=.*', | |
[System.Text.RegularExpressions.RegexOptions]::IgnoreCase); | |
$match32 = $regex32.Match($latesReleasesMarkup); | |
$32BitUrl = "https://github.com$($match32.Groups["url"].Value)" | |
if(Test-Path -Path $git32SetupPath){ | |
Remove-Item $git32SetupPath -Force | |
} | |
Write-Host "Downloading $32BitUrl" -ForegroundColor Gray | |
(New-Object System.Net.WebClient).DownloadFile($32BitUrl, $git32SetupPath); | |
Write-Host "Starting the Git 32 bit setup " -ForegroundColor Gray | |
$git32SetupProcess = Start-Process ` | |
-FilePath $git32SetupPath ` | |
-Wait ` | |
-PassThru ` | |
-ArgumentList @( | |
"/VERYSILENT", | |
"/NORESTART" | |
"/NOCANCEL", | |
"/SP-" | |
"/CLOSEAPPLICATIONS", | |
"/RESTARTAPPLICATIONS" | |
); | |
$git32SetupProcess.WaitForExit(); | |
if(Test-Path -Path $git32SetupPath){ | |
Remove-Item $git32SetupPath -Force | |
} | |
Write-Host "$([IO.Path]::GetFileName($git32SetupPath)) exited with code: $($git32SetupProcess.ExitCode)" -ForegroundColor Gray | |
Write-Host "GIT 64 Bit install..." | |
$regHive64 = "HKLM:\SOFTWARE"; | |
$installKey64 = "$regHive64\$regHiveGit" | |
if ((Test-Path $installKey64) -eq $false) { | |
$r = md $installKey64 | |
} | |
foreach ($h in $params.GetEnumerator()) { | |
$r = New-ItemProperty $installKey64 -Name $h.Name -Value $h.Value -Force | |
} | |
$git64SetupPath = "$gitSetupDirectory\git64.exe" | |
$regex64 = new-object System.Text.RegularExpressions.Regex( | |
'\<a\shref=\"(?<url>.*-64-bit\.exe)\"\srel=.*', | |
[System.Text.RegularExpressions.RegexOptions]::IgnoreCase); | |
$match64 = $regex64.Match($latesReleasesMarkup); | |
$64BitUrl = "https://github.com$($match64.Groups["url"].Value)" | |
if(Test-Path -Path $git64SetupPath){ | |
Remove-Item $git64SetupPath -Force | |
} | |
Write-Host "Downloading $64BitUrl" -ForegroundColor Gray | |
(New-Object System.Net.WebClient).DownloadFile($64BitUrl, $git64SetupPath); | |
Write-Host "Starting the Git 64 bit setup " -ForegroundColor Gray | |
$git64SetupProcess = Start-Process ` | |
-FilePath $git64SetupPath ` | |
-Wait ` | |
-PassThru ` | |
-ArgumentList @( | |
"/VERYSILENT", | |
"/NORESTART" | |
"/NOCANCEL", | |
"/SP-" | |
"/CLOSEAPPLICATIONS", | |
"/RESTARTAPPLICATIONS" | |
); | |
$git64SetupProcess.WaitForExit(); | |
if(Test-Path -Path $git64SetupPath){ | |
Remove-Item $git64SetupPath -Force | |
} | |
Write-Host "$([IO.Path]::GetFileName($git64SetupPath)) exited with code: $($git64SetupProcess.ExitCode)" -ForegroundColor Gray |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment