chocolateyInstall.ps1 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. $registryKeyName = 'Git_is1'
  2. $packageId = 'git.install'
  3. $fileType = 'exe'
  4. $fileArgs = $(
  5. '/VERYSILENT /NORESTART /NOCANCEL /SP- ' +
  6. '/COMPONENTS="icons,icons\quicklaunch,ext,ext\shellhere,ext\guihere,assoc,assoc_sh" /LOG'
  7. )
  8. $url = 'https://github.com/git-for-windows/git/releases/download/v2.9.3.windows.1/Git-2.9.3-32-bit.exe'
  9. $url64 = 'https://github.com/git-for-windows/git/releases/download/v2.9.3.windows.1/Git-2.9.3-64-bit.exe'
  10. $softwareName = 'Git*'
  11. $checksum = 'd6b4a19536ad408018688f1242ab0d1f5dc5544109662bfddf915f685eba58a9'
  12. $checksum64 = '1a642cf2914e18fa868b1ed2c6d1df4a46ba8ef30355fd1965850895a658e024'
  13. $checksumType = 'sha256'
  14. $arguments = @{};
  15. # /GitOnlyOnPath /GitAndUnixToolsOnPath /NoAutoCrlf
  16. $packageParameters = $env:chocolateyPackageParameters;
  17. # Default the values
  18. $useWindowsTerminal = $false
  19. $gitCmdOnly = $false
  20. $unixTools = $false
  21. $noAutoCrlf = $false # this does nothing unless true
  22. # Now parse the packageParameters using good old regular expression
  23. if ($packageParameters) {
  24. $match_pattern = "\/(?<option>([a-zA-Z]+)):(?<value>([`"'])?([a-zA-Z0-9- _\\:\.]+)([`"'])?)|\/(?<option>([a-zA-Z]+))"
  25. #"
  26. $option_name = 'option'
  27. $value_name = 'value'
  28. if ($packageParameters -match $match_pattern ){
  29. $results = $packageParameters | Select-String $match_pattern -AllMatches
  30. $results.matches | % {
  31. $arguments.Add(
  32. $_.Groups[$option_name].Value.Trim(),
  33. $_.Groups[$value_name].Value.Trim())
  34. }
  35. }
  36. else
  37. {
  38. throw "Package Parameters were found but were invalid (REGEX Failure)"
  39. }
  40. if ($arguments.ContainsKey("GitOnlyOnPath")) {
  41. Write-Host "You want Git on the command line"
  42. $gitCmdOnly = $true
  43. }
  44. if ($arguments.ContainsKey("WindowsTerminal")) {
  45. Write-Host "You do not want to use MinTTY terminal"
  46. $useWindowsTerminal = $true
  47. }
  48. if ($arguments.ContainsKey("GitAndUnixToolsOnPath")) {
  49. Write-Host "You want Git and Unix Tools on the command line"
  50. $unixTools = $true
  51. }
  52. if ($arguments.ContainsKey("NoAutoCrlf")) {
  53. Write-Host "Ensuring core.autocrlf is false on first time install only"
  54. Write-Host " This setting will not adjust an already existing .gitconfig setting."
  55. $noAutoCrlf = $true
  56. }
  57. } else {
  58. Write-Debug "No Package Parameters Passed in";
  59. }
  60. $is64bit = (Get-ProcessorBits) -eq 64
  61. $installKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$registryKeyName"
  62. if ($is64bit -eq $true -and $env:chocolateyForceX86 -eq $true) {
  63. $installKey = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$registryKeyName"
  64. }
  65. $userInstallKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\$registryKeyName"
  66. if (Test-Path $userInstallKey) {
  67. $installKey = $userInstallKey
  68. }
  69. if ( -not (Test-Path $installKey)) {
  70. New-Item -Path $installKey | Out-Null
  71. }
  72. if ($gitCmdOnly) {
  73. # update registry so installer picks it up automatically
  74. New-ItemProperty $installKey -Name "Inno Setup CodeFile: Path Option" -Value "Cmd" -PropertyType "String" -Force | Out-Null
  75. }
  76. if ($useWindowsTerminal) {
  77. # update registry so installer picks it up automatically
  78. New-ItemProperty $installKey -Name "Inno Setup CodeFile: Bash Terminal Option" -Value "ConHost" -PropertyType "String" -Force | Out-Null
  79. }
  80. if ($unixTools) {
  81. # update registry so installer picks it up automatically
  82. New-ItemProperty $installKey -Name "Inno Setup CodeFile: Path Option" -Value "CmdTools" -PropertyType "String" -Force | Out-Null
  83. }
  84. if ($noAutoCrlf) {
  85. # update registry so installer picks it up automatically
  86. New-ItemProperty $installKey -Name "Inno Setup CodeFile: CRLF Option" -Value "CRLFCommitAsIs" -PropertyType "String" -Force | Out-Null
  87. }
  88. # Make our install work properly when running under SYSTEM account (Chef Cliet Service, Puppet Service, etc)
  89. # Add other items to this if block or use $IsRunningUnderSystemAccount to adjust existing logic that needs changing
  90. $IsRunningUnderSystemAccount = ([System.Security.Principal.WindowsIdentity]::GetCurrent()).IsSystem
  91. If ($IsRunningUnderSystemAccount)
  92. {
  93. #strip out quicklaunch parameter as it causes a hang under SYSTEM account
  94. $fileArgs = $fileArgs.replace('icons\quicklaunch,','')
  95. If ($fileArgs -inotlike "*/SUPPRESSMSGBOXES*")
  96. {
  97. $fileArgs = $fileArgs + ' /SUPPRESSMSGBOXES'
  98. }
  99. }
  100. If ([bool](get-process ssh-agent -ErrorAction SilentlyContinue))
  101. {
  102. Write-Output "Killing any git ssh-agent instances for install."
  103. (get-process ssh-agent | where {$_.Path -ilike "*\git\usr\bin\*"}) | stop-process
  104. }
  105. Install-ChocolateyPackage -PackageName $packageId `
  106. -FileType $fileType `
  107. -SilentArgs $fileArgs `
  108. -Url $url `
  109. -Url64bit $url64 `
  110. -Checksum $checksum `
  111. -ChecksumType $checksumType `
  112. -Checksum64 $checksum64 `
  113. -ChecksumType64 $checksumType
  114. if (Test-Path $installKey) {
  115. $keyNames = Get-ItemProperty -Path $installKey
  116. if ($gitCmdOnly -eq $false -and $unixTools -eq $false) {
  117. $installLocation = $keyNames.InstallLocation
  118. if ($installLocation -ne '') {
  119. $gitPath = Join-Path $installLocation 'cmd'
  120. Install-ChocolateyPath $gitPath 'Machine'
  121. }
  122. }
  123. }
  124. Write-Warning "Git installed - You may need to close and reopen your shell for PATH changes to take effect."