What is OPAM's shell hook? - opam

During initialization of OPAM I got this message:
A hook can be added to opam's init scripts to ensure that the shell
remains in sync with the opam environment when they are loaded. Set
that up? [y/N]
Could you clarify what does this mean?
I've tried to find out it here: https://github.com/ocaml/opam/search?q=hook&unscoped_q=hook
I heard this word before, but what is "shell hook"? What it is used for? Why it asks me to choose? :)

env_hook.sh adds the hook, at least in bash, scripts for other shells are similar.
This will run eval $(opam env) every time the prompt is displayed.
You can run opam env and check what it does, it sets some environment variables.
You need this hook for local switches, it will update the switch based on your current directory. See issue #3573 for discussion about this topic.
It's possible to change this configuration option later, just re-run opam init.

Related

Is an opam pin project needed when one wants to install an opam project with opam reinstall or 'make'?

I am trying to understand when one needs to pin an opam package.
I am seeing some code that pins a package, e.g., with
command = (['opam', 'pin', '-y']
+ root_option()
+ ['--switch', switch]
+ [coq_package_name, coq_package_pin_path])
And then it tries to reinstall it with:
command: list = ['opam',
'reinstall',
root_option(),
'--yes',
'--switch',
switch,
'--keep-build-dir',
coq_package_name]
Is the pin really needed for the opam reinstallation to work? What might be the rationale to do such a pin before the opam reinstallation?
In addition I am also installing some packages with make and am wondering if that is needed:
command: list = ['make', '-C', coq_proj_path]
My guess based on the related OCaml forum thread (URL below)
The OCaml forum thread says:
As the documentation states, opam pin “allows local customisation of the packages in a given switch” (or “divert any package definition”, in the part you quoted). So, if you do not need to replace an official package definition with your own customization, just use opam install.
In my case, I am downloading the Coq project source and then installing it myself from it -- either with opam install or make. With make I can just pass the direct path. With opam install, the pin command actually "maps" the name to the exact path of the project. So my guess is that in my application (due to using the Coq projects myself) I do need the opam pin.
Related:
(OCaml forum thread) What is the difference between opam pin and opam install, when to use one vs the other?
related, gitissue that inspired this: https://github.com/IBM/pycoq/issues/6
My understanding is that there are multiple ways to install an ocaml package.
opam install uses the ocaml_pkg.opam file. Usually the build command is there and the build is done with opam and made aware to opam. Specific versions can be made according to the official opam repo on the internet too!
opam pin usually installs pkgs that require specific local or online version (e.g. through git commits). Opam will be made the install.
I assume reinstall works similarly to opam install.
Building through source by say cloning pkg/proj and running the build command directly (e.g. if it has a opam file running that or running make in the home of the or some variant of it of make proj/pkg )

Having trouble setting up chocolateyinstall.ps1 to link path enviorment variable with program file

Having trouble setting automatically set PATH to programFiles\veyon after installation. I would like to use the veyon-ctl command line with out having to manually link it.
The code that you have highlighted seems to be working exactly as expected. I have just taken that code, and added it to a package and installed it. The result was the following...
As you will see mentioned in the output, this environment variable will not be available in the current shell until you open/close the shell. I suspect that this is the problem that you are running into.
Chocolatey does provide a helper function called refreshenv which would allow you to force the reloading of the environment variables into the current shell, however, this isn't enabled by default. You can find out how to do this by reading the article here:
https://chocolatey.org/docs/troubleshooting#i-cant-get-the-powershell-tab-completion-working
But what it comes down to is that you need to load the following into your PowerShell Profile:
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
Once this is loaded, after seeing output similar to the following when installing a Chocolatey package, you can execute the command refreshenv and the new environment variables will be available in the current shell.

Make command wait for confirmation before running next line in batch file

I have searched high and low for what I thought would be a common question but can only find answers regarding user confirmation, not system confirmation.
I would like the following commands to run in sequential order, waiting for a response before moving onto the next command:
npm config set https-proxy http://example.com:8080
npm config set proxy http://example.com:8080
npm config set sslVerify false
npm config set strict-ssl false
set HTTP_PROXY=http://example.com:8080
set HTTPS_PROXY=http://example.com:8080
I have added the commands to the batch file in sequential order on new lines, but when executing it does not pause on each command to wait for a response. How do I force the script to wait on each command until it’s confirmed by the system?
Unqualified names like npm or doSomething may map to scripts written in various languages, including batch files. Use the call command to invoke these and cmd.exe will always wait for whatever child process is started.
It's not uncommon for .exe's to be scattered across multiple directories that would bloat the path environment variable, so many installations will lay down alias scripts in a single directory added to the path and when you invoke the command, it figures out what executables to run and launches those.
It's also common to use wrapper scripts to simplify executable invocations, add some logging, or temporarily map the command to a different version (upgrades/testing).
In the case of npm, I believe it's mostly written in JavaScript, so an appropriate scripting engine has to be launched to run the npm commands. This may be boot-strapped from a batch script or it could be invoked automagically by the OS, based on whatever file extension it has. The details from one version or installation to the next may vary and usually don't matter to the casual user invoking them from the command line, but script behavior can vary noticeably.
Unless you use a fully qualified path/filename to launch something from a command script, and generally even if you do, you should simply default to using the call command to invoke it. Then all of the above circumstance are covered and your script will always behave as expected.
call npm config set https-proxy http://example.com:8080
call npm config set proxy http://example.com:8080
call npm config set sslVerify false
call npm config set strict-ssl false
set HTTP_PROXY=http://example.com:8080
set HTTPS_PROXY=http://example.com:8080
Note that it is still possible that a script or program could pass work along to another process and then return immediately, but that kind of behavior will normally be the same, whether launched interactively or from a script.

LLDB Pass-thru Environment Vars

How can I get LLDB to pass its environment to the executable it runs?
As in, if I run FOO=BAR lldb a.out, I want a.out's environment to have FOO=BAR.
I know I can do this using process launch -v FOO=BAR, but I have quite a few env vars and don't want to type it every time.
lldb should do this by default. There is a setting to control this behavior:
settings set target.inherit-env {true/false}
but the default is "true" so this should already be happening (it does for me...)
Note it doesn't make as much sense to pass the environment to a remote process, so Xcode may defeat this setting for iOS debugging.

Jenkins Post Build Task access jenkins environment variables like JOB_NAME

I want to get the job details in Post Build Task plugin and pass the details to the batch/ powershell for further processing.
I am not able to access the Jenkins environment variables like JOB_NAME, JOB_ID etc.
In Post Build Plugin task
Log text "BUILD SUCCESSFUL"
OPTION
Script Block:
run.bat $JOB_NAME-$JOB_ID
I need to pass the $JOB_NAME-$JOB_ID to the script.
Build Parameters are accesses as $Name in the Execute shell and post build section.
You can use
$JOB_NAME
$BUILD_NUMBER
for name of job and build number which is same as JOB_ID.
Also Set "Jenkins user build variables" to get more info regarding Environment variables.
Generally the sintax for accessing variables is the following:
${VARIABLE}
but in some cases, especially when you are trying to access variables using during the build, this sintax can be used:
${ENV, var="VARIABLE"}
That in my case is working also when you have a parameterized build.

Resources