make install saying CUDADIR environment variable not set, when it is - makefile

I'm currently trying to install MAGMA, however trying to run "sudo make install" gives me the error:
$ sudo make install prefix=/usr/local/magma
make.check-cuda:7: *** Set $CUDADIR, preferably in your environment, e.g.,
run "export CUDADIR=/usr/local/cuda" in ~/.bashrc, or "setenv CUDADIR
/usr/local/cuda" in ~/.cshrc. Stop.
I know for sure that CUDADIR is set, and it's set in ~/.bash_profile, so I'm not sure why it's failing. Is there any reason why it might not being finding it? It seemed to work fine when I ran "make".
$ set | grep CUDADIR
CUDADIR=/usr/local/cuda

It needs to be both set and exported. By looking at the output of set you're just seeing variables which are set in the shell... the shell will only send exported variables to programs (like make) that it invokes. You didn't show us how the variable is set in ~/.bashrc but I assume it's something like this:
CUDADIR=/usr/local/cuda
Change that to:
export CUDADIR=/usr/local/cuda
If you want to see what variables are exported the simplest thing to do is use env, not set, like this:
$ env | grep CUDADIR

Related

Working on Chalice project. Running an env.sh shell script won't set env variables, but running `export DB_USERNAME=example` sets it. Why?

I am working on a chalice project. I need to set environment variables locally in order to connect to the DB using peewee.
I wrote a simple shell script called env.sh:
#!/bin/sh
export APP_NAME=example
export DB_HOST=example
export DB_PORT=example
export DB_NAME=example
export DB_USERNAME=example
export DB_PASSWORD=example
I expected that running ./env.sh will set all the env variables. But when I execute the chalice application, I get errors indicating that these variables are not defined.
If I go into the terminal and run these commands individually like export APP_NAME=example, the variables are set and the application successfully reads them.
I am using a virtual env with poetry (poetry shell) with python3.9, so it might have to do with that, but I am not sure how to wrap my head around this. I also tried poetry run env.sh and removed the shebang from the top of the script, but none of these worked.
Can you help me figure out why this is happening and how to make that script work?

Accessing environment variables in bash script

I have a bash script where I am trying to use values of some environment variables. Those variables are defined - I see the keys and values if I run printenv.
Also, these variables are defined and exported like
export FOO="bar"
in both ~/.bash_profile and ~/.bashrc.
I am trying to execute the script via ./script-name which fails to get the environment variables. If I run sudo -E ./script-name, that somehow gets the script the variables it needs.
Confused as to why these variables aren't available to the script even when they are exported in above files.
The only thing I can think of, is that for some reason, the shell process which you are calling to run the script, does not have full read access to your current environment.
ls -al /usr/bin/bash
ls -al /bin/sh
Assuming neither of them are symlinks, make sure that your current user has read and execute priveleges. A safer (in security terms) option, would be for you to install bash in ~/opt, and use #!~/opt/bin/bash as your shebang line.

How to activate a virtualenv using a makefile?

At the top of my makefile I have this line:
SHELL := /bin/sh
which is needed for most of the commands. However, I would like to also have a make command to activate my virtual env, which is on a different path.
Here is the code that I wrote for it:
activate:
source ~/.envs/$(APP)/bin/activate; \
The problem with this is, that this just prints out what is written here, and it doesn't get executed. I read that it might have something todo with only bash knowing about source, but I can't figure out how to temporarily switch modes within the activate command.
How would I have to write this method, so that it activates my virtualenv?
It does get executed.
Virtualenv works by modifying your current process's environment (that's why you have to "source" it). However, one process cannot modify the environment of the other process. So, to run your recipe make invokes a shell and passes it your virtualenv command, it works, then the shell exits, and your virtualenv is gone.
In short, there's no easy way to do this in a makefile. The simplest thing to do is create a script that first sources the virtualenv then runs make, and run that instead of running make.
Create a file called "make-venv" like this:
#!/bin/bash
source ./.venv/bin/activate
$2
Then add this to the first line of your Makefile
SHELL=./make-venv
Now, make-venv activates virtualenv before every command runs. Probably inefficient, but functional.
You can do it by using set, which allows you to set or unset values of shell options and positional parameters:
set -a && . venv/bin/activate && set +a

What is the best way to export env variable within Chef

I am trying to set env variable within Chef recipe so that after the recipe is run, I can do echo $VAR1
bash 'set_env_var' do
code <<-EOH
echo export VAR1="https://#{node['fqdn']}" >> /etc/profile
source /etc/profile
EOH
not_if "grep -q VAR1="https://#{node['fqdn']}" >> /etc/profile"
end
Please let me know if there is a better way to do the same.
This is not a feature that Unix supports. The closest you can get is writing to something like /etc/profile.d if your distro's default shell RC files support it but that both won't have any effect on the current shell (you would need to start a new one) and doesn't cover all execution scenarios. Environment variables are probably the wrong answer to whatever you are trying to solve.

Unable to export environment variables in cygwin within a shell script

I created a setenvj1.6 shell script in my /usr/local/bin directory, in cygwin (Windows 7).
setenvj1.6:
export PATH=/cygdrive/c/bea/bea10/bea10g3/jdk160_05/bin:$PATH
export JAVA_HOME=/cygdrive/c/bea/bea10/bea10g3/jdk160_05
echo Set for Java 1.6
when I run setenvj1.6, like this:
myuser#mycomp /usr/local/bin
$ setenvj1.6
Set for Java 1.6
I see that the script has run, but when I check if anything is set correctly, I see that my variables are not set:
myuser#mycomp /usr/local/bin
$ echo $JAVA_HOME
Similarly, if I echo $PATH, I get my usual PATH variable but without the directory I tried to add with export.
How do I get this to work?
I need a bash script like the one I specified that I can run after I've run cygwin so that I can change my paths to whatever I want. Thanks.

Resources