-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$Env:ChocolateyInstall not set #68
Comments
Thanks @Jaykul, I think I get what you're saying. Write-Verbose -Message 'Ensuring chocolatey commands are on the path.'
[string] $chocoPath = ''
if ($chocoPath = [Environment]::GetEnvironmentVariable('ChocolateyInstall','Machine'))
{
Write-Debug -Message ('The Machine Environment variable is already set to: ''{0}''.' -f $chocoPath)
}
else
{
# Checking if it was installed in AllUserProfile/Chocolatey (was default many years ago)
$chocoPath = Join-Path -Path $env:ALLUSERSPROFILE -ChildPath 'Chocolatey'
if (-not (Test-Path -Path $chocoPath))
{
# The AllUserProfile/Chocolatey folder does not exit, let's install in correct default location
$chocoPath = Join-Path -Path $env:ProgramData -ChildPath 'Chocolatey'
}
# Set the Machine-scoped 'ChocolateyInstall' environement variable
Write-Debug -Message ('Setting the Machine & Process Environment variable to: ''{0}''.' -f $chocoPath)
[Environment]::SetEnvironmentVariable('ChocolateyInstall', $chocoPath, 'Machine')
[Environment]::SetEnvironmentVariable('ChocolateyInstall', $chocoPath, 'Process')
}
$chocoExePath = Join-Path -Path $chocoPath -ChildPath 'bin'
if (@($env:Path.ToLower() -split [io.path]::PathSeparator) -notcontains $chocoExePath.ToLower())
{
# we can't see the choco bin folder in $env:Path, trying to load from Machine.
$env:Path = [Environment]::GetEnvironmentVariable('Path', 'Machine')
} The dependency on |
I think that after this: if ($chocoPath = [Environment]::GetEnvironmentVariable('ChocolateyInstall','Machine')) You still need to set it at the process scope, or not depend on it being set. There's some weirdness in environment variables in Guest Configuration. I suspect they are running each resource in a fresh process launched from the root process. If so, that means changes to environment variables DO NOT PERSIST at all, and there's no way to make them persist and have them visible within the same run. If that's true, you have to always explicitly get and set at machine scope to get persistence to follow-on resources. |
This should be fixed in v0.2.0-preview0008 released earlier today. |
I can't decide if I should file this as a bug here, or against Chocolatey or both.
I'll start here, because I think you need to fix it, even if they do.
It looks like you only set it if I hard-code it.
https://github.com/chocolatey-community/Chocolatey/blob/bd094dfa12dfae092244255d693ab7c05f28f772/source/public/Install-ChocolateySoftware.ps1#L250-L254
I don't need to hard code it, because you have code to recover, but your recovery code does not set the ChocolateyInstall environment variable:
https://github.com/chocolatey-community/Chocolatey/blob/bd094dfa12dfae092244255d693ab7c05f28f772/source/public/Install-ChocolateySoftware.ps1#L258-L274
However, you depend on this variable being set (in the process scope):
https://github.com/chocolatey-community/Chocolatey/blob/bd094dfa12dfae092244255d693ab7c05f28f772/source/public/Install-ChocolateyPackage.ps1#L305
I believe the chocolatey installer only sets this in the MACHINE scope, and then tells you to restart your shell. Perhaps you should explicitly read if from there on line 258? In fact, I think you should READ it from the MACHINE and then do your seftey check, and then SET it in MACHINE scope if it was missing or wrong, and PROCESS, regardless.
The text was updated successfully, but these errors were encountered: