-
Notifications
You must be signed in to change notification settings - Fork 112
/
chocolateyInstall.ps1
107 lines (88 loc) · 3.88 KB
/
chocolateyInstall.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
try {
$registryKeyName = 'Git_is1'
$packageId = 'git.install'
$fileType = 'exe'
$fileArgs = $(
'/VERYSILENT /NORESTART /NOCANCEL /SP- ' +
'/NOICONS /COMPONENTS="icons,icons\quicklaunch,ext,ext\reg,ext\reg\shellhere,ext\reg\guihere,assoc,assoc_sh" /LOG'
)
$url = 'https://github.com/msysgit/msysgit/releases/download/Git-1.9.5-preview20141217/Git-1.9.5-preview20141217.exe'
$arguments = @{};
# /GitOnlyOnPath /GitAndUnixToolsOnPath /NoAutoCrlf
$packageParameters = $env:chocolateyPackageParameters;
# Default the values
$gitCmdOnly = $false
$unixTools = $false
$noAutoCrlf = $false # this does nothing unless true
# Now parse the packageParameters using good old regular expression
if ($packageParameters) {
$match_pattern = "\/(?<option>([a-zA-Z]+)):(?<value>([`"'])?([a-zA-Z0-9- _\\:\.]+)([`"'])?)|\/(?<option>([a-zA-Z]+))"
$option_name = 'option'
$value_name = 'value'
if ($packageParameters -match $match_pattern ){
$results = $packageParameters | Select-String $match_pattern -AllMatches
$results.matches | % {
$arguments.Add(
$_.Groups[$option_name].Value.Trim(),
$_.Groups[$value_name].Value.Trim())
}
}
else
{
throw "Package Parameters were found but were invalid (REGEX Failure)"
}
if ($arguments.ContainsKey("GitOnlyOnPath")) {
Write-Host "You want Git on the command line"
$gitCmdOnly = $true
}
if ($arguments.ContainsKey("GitAndUnixToolsOnPath")) {
Write-Host "You want Git and Unix Tools on the command line"
$unixTools = $true
}
if ($arguments.ContainsKey("NoAutoCrlf")) {
Write-Host "Ensuring core.autocrlf is false on first time install only"
Write-Host " This setting will not adjust an already existing .gitconfig setting."
$noAutoCrlf = $true
}
} else {
Write-Debug "No Package Parameters Passed in";
}
$is64bit = (Get-ProcessorBits) -eq 64
# there is only a 32-bit version, so we don't need to do any further testing on the two keys
$installKey = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$registryKeyName"
if ($is64bit -eq $false) {
$installKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$registryKeyName"
}
$userInstallKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\$registryKeyName"
if (Test-Path $userInstallKey) {
$installKey = $userInstallKey
}
if ( -not (Test-Path $installKey)) {
New-Item -Path $installKey | Out-Null
}
if ($gitCmdOnly) {
# update registry so installer picks it up automatically
New-ItemProperty $installKey -Name "Inno Setup CodeFile: Path Option" -Value "Cmd" -PropertyType "String" -Force | Out-Null
}
if ($unixTools) {
# update registry so installer picks it up automatically
New-ItemProperty $installKey -Name "Inno Setup CodeFile: Path Option" -Value "CmdTools" -PropertyType "String" -Force | Out-Null
}
if ($noAutoCrlf) {
# update registry so installer picks it up automatically
New-ItemProperty $installKey -Name "Inno Setup CodeFile: CRLF Option" -Value "CRLFCommitAsIs" -PropertyType "String" -Force | Out-Null
}
Install-ChocolateyPackage $packageId $fileType $fileArgs $url
$keyNames = Get-ItemProperty -Path $installKey
if ($gitCmdOnly -eq $false -and $unixTools -eq $false) {
$installLocation = $keyNames.InstallLocation
if ($installLocation -ne '') {
$gitPath = Join-Path $installLocation 'cmd'
Install-ChocolateyPath $gitPath 'Machine'
}
}
Write-Warning "Git installed - You may need to close and reopen your shell for PATH changes to take effect."
} catch {
Write-ChocolateyFailure $packageId $($_.Exception.Message)
throw
}