Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

install.ps1 sets ChocolateyInstall environment in user contest #283

Open
DavidS opened this issue Apr 25, 2013 · 12 comments
Open

install.ps1 sets ChocolateyInstall environment in user contest #283

DavidS opened this issue Apr 25, 2013 · 12 comments

Comments

@DavidS
Copy link

DavidS commented Apr 25, 2013

Hi,

when installing chocolatey via the install.ps1 from http://chocolatey.org/install.ps1, the ChocolateyInstall env variable is set in the user context. This leads to the chocolatey puppet provider not working as puppet runs as "Local System" and not the user doing the first deployment.

Thanks for this great tool, David

@ferventcoder
Copy link
Contributor

We have an open PR to evaluate doing this at system - #135

@DavidS
Copy link
Author

DavidS commented Apr 25, 2013

To summarize, the problem is that setting a system var requires admin rights, which are not available when the user installs chocolatey without elevating the shell which is used to install it.

Have I got that right?

@ferventcoder
Copy link
Contributor

@DavidS you have that correct. And the secondary issue is that the user may not have admin privileges on their machine.

@apxltd
Copy link

apxltd commented Dec 12, 2013

Any updates on this?

For our use case it's odd, b/c Chocolatey is designed to be installed once per machine (based on default of C:\Chocolatey instead of local apps), but there is no way to detect if it installed since this variable is set as a user variable.

@codearoo
Copy link

I have my own script to make the setting in the System env.

However I also use 'choco /?' to determine if it's installed. (preferred to use something like 'choco -version' but that does not quite do same thing)

choco /? will return %errorlevel% of 0 if it found the command, and 9009 otherwise but you can just check for the success/fail like this:

choco /? || install-choco

where "install-choco" is the big powershell string you can paste in to install or maybe some other way you want to install.

@apxltd
Copy link

apxltd commented Dec 12, 2013

Thanks; any suggestion on how to reliably detect the installation directory of chocoaltey? That’s what we’re mostly looking to do…

@codearoo
Copy link

YES!! and I just found it by searching for "Windows version of which"

C:\software>where choco
c:\chocolatey\bin\choco
c:\chocolatey\bin\choco.bat

where /? for more help.

@apxltd
Copy link

apxltd commented Dec 12, 2013

I had considered that... but that basically just searches PATH (a user variable), so this only works for the user that installed chocolatey.

@ferventcoder
Copy link
Contributor

Yes, that is one way to know if chocolatey is installed. We are looking to go to system path for installs so it is available for all.

@codearoo
Copy link

oh yeah. So as mentioned, when I install it, I wrapped it in a script that calls a .VBS script to put the path in the System env:

ENV_VARIABLE = WScript.Arguments.Item(0)
ENV_VALUE = WScript.Arguments.Item(1)
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("SYSTEM")
WshEnv(ENV_VARIABLE) = ENV_VALUE

Use it like this:
cscript set-system-env.vbs ENVVARNAME ANDTHEVALUE

which would set whatever env var to the value you specify in the System section.

And then can use this .BAT logic to only do that if it's not already there in the current session:
:append-system-path-if-needed
setlocal ENABLEDELAYEDEXPANSION
set NEWVALUE=%*
:: start with value and remove all quotes
set x=%PATH:"=%
:: now remove all spaces
set x=%x: =%
set y=%x:!NEWVALUE!=%
if "%x%" == "%y%" echo adding && cscript set-system-env.vbs PATH "%PATH%;%NEWVALUE%" || exit /b
endlocal
exit /b

To use that "function" it would look like this:
call :append-system-path-if-needed C:\Chocolatey

@codearoo
Copy link

And regarding testing if it's installed... forgot that you don't need the /? this works just as well:

choco || install-choco

@codearoo
Copy link

And finally... :) You can use this to actually FIND it installed and in what dir:

C:>dir /s/b choco.bat
C:\Chocolatey\bin\choco.bat

unless you also need to search other drive letters.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants