Use ChocolateyInstall env variable after installation (#27812)
* Use ChocolateyInstall env variable after installation Fixes #19725 Custom install locations specified by the ChocolateyInstall env variable in win_chocolatey After an initial install of chocolatey, use the ChocolateyInstall environment variable when assigning $script:executable . * Improve process of locating "choco.exe" post-initial install Implement feedback for locating choco: * Check if choco.exe is in PATH, if there use this * If not in path and ChocolateyInstall var is available, use that * Otherwise, use the equivalent of Windows Special Folder CommonApplicationData for locating chocolatey. (Chocolatey install (v0.10.7) uses CommonApplicationData when ChocolateyInstall is not set.)
This commit is contained in:
parent
4cec83471c
commit
241d38077f
1 changed files with 24 additions and 1 deletions
|
@ -77,9 +77,32 @@ Function Chocolatey-Install-Upgrade
|
|||
Fail-Json $result "Chocolatey bootstrap installation failed."
|
||||
}
|
||||
$result.changed = $true
|
||||
$script:executable = "C:\ProgramData\chocolatey\bin\choco.exe"
|
||||
Add-Warning $result 'Chocolatey was missing from this system, so it was installed during this task run.'
|
||||
|
||||
# locate the newly installed choco.exe
|
||||
$command = Get-Command -Name "choco.exe"
|
||||
if ($command)
|
||||
{
|
||||
$path = $command.Path
|
||||
}
|
||||
else
|
||||
{
|
||||
$env_value = $env:ChocolateyInstall
|
||||
if ($env_value)
|
||||
{
|
||||
$path = "$env_value\bin\choco.exe"
|
||||
}
|
||||
else
|
||||
{
|
||||
$path = "$env:SYSTEMDRIVE\ProgramData\Chocolatey\bin\choco.exe"
|
||||
}
|
||||
}
|
||||
if (-not (Test-Path -Path $path))
|
||||
{
|
||||
Fail-Json -obj $result -message "failed to find choco.exe, make sure it is added to the PATH or the env var ChocolateyInstall is set"
|
||||
}
|
||||
|
||||
$script:executable = $path
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue