Can not set GOPATH with chef - linux

I am trying to use go get which means I have to set the go path. I have tried this through a ton of ways, so please do not mark this as a duplicate unless that solution works. I have tried almost every solution on SO I could find.
My chef code
package 'golang-go'
directory '/work-disk/go' do
owner consul_user
group consul_user
mode '0755'
action :create
end
bash 'go' do
user consul_user
code <<-EOH
export GOPATH=/work-disk/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
EOH
action :run
end
I had export GOPATH=$HOME/go before but that seemed to fail so I created a directory to test with and explicitly said the directory but still no luck
Error message
cannot download, $GOPATH not set. For more details see: go help gopath

This is not how environment variables work. Setting them in a subprocess on affects that subprocess.

Related

RPM build, can I change gsettings in %post?

After installing an rpm package that I built I would like to change some gsettings. I tried doing so in the %post section, but it does not do anything during the install (not even fail).
spec file:
...
%post
echo "test post"
gsettings set org.gnome.desktop.interface cursor-theme 'something-else'
The echo works, and if I manually type the gsettings command into the terminal it works, but during the installation the command does not work. Any ideas?
Aaron is correct in their comment: Even if you can successfully run gsettings in your %post script, you'll be changing settings for the root user.
If you want to change configurations for some other user in an automated fashion, you could drop a script into /etc/profile.d; these scripts are run for new login shells, which will include someone logging into an X session.
You would want to add some conditionals around your gsettings statement to ensure that it only runs successfully once: if it runs on every login, you've made it impossible for someone to undo this particular configuration change, which can be a frustrating experience.
I would argue that this is better solved via documentation ("After installing this package, here's how to activate the new cursor theme...").

my fedora PATH variables went out, how to restore them

I wanted to add php to envirmonment variables
So I wrote:
export PATH=/opt/lampp/bin/
Then I discovered that this was wrong because it relaced the envirmonment variable PATH with only ( /opt/lampp/bin/ ).
Is there a way to restore the path to an earlier version?
restart your shell / exit your terminal. unless you edit your .bashrc file the changes to environment variable via the export command are not permanent

customed command not found in a new terminal

everyone.
I had a basic question want to consult, about the environment variable setting.
After closed my one existed terminal which could execute compile(make) and do customed(mksdboot) command, i can't do mksdboot command anymore(I had execute a predefined setting environment variable shell script i.e. $ . ./arndale_envsetup.sh again) in the new terminal.
Cause i am a beginner in Linux, i am not very clearly about the environment variable setting rules.
i had tried to 'su' or 'sudo' to execute mksdboot, but no luck:(
ps. I had another project needs to compile in my PC(i didn't export PATH to .bashrc, only execute export PATH when i open a new terminal every time), may it efforts the original project's environment variable?
thanks.
[UPDATED]
i tried using $source ./arndale_envsetup.sh, relative commands worked finally.
but i still did't figure out the reason between work or not work. >"<
The command
history
will list what your previous commands where.
This might give you a pointer what set the path in the way you needed it.
You could also try to see where you command is via
locate mksdboot

OpenVPN FreeNAS BSD installation issues

im following this guide to install OpenVPN on my FreeNAS system.
http://joepaetzel.wordpress.com/2013/09/22/openvpn-on-freenas-9-1/
I have ran in to the issues detailed below when trying to create the CA.cert.
[root#freenas] /mnt/NAS/openvpn# chmod -R 755 easy-rsa/2.0/*
[root#freenas] /mnt/NAS/openvpn# cd easy-rsa/2.0
[root#freenas] /mnt/NAS/openvpn/easy-rsa/2.0# sh
#./clean-all
Please source the vars script first (i.e. "source ./vars")
Make sure you have edited it to reflect your configuration.
# . ./vars
NOTE: If you run ./clean-all, I will be doing a rm -rf on /mnt/NAS/openvpn/easyrsa/2.0/keys
# ./build-ca
Please edit the vars script to reflect your configuration,
then source it with "source ./vars".
Next, to start with a fresh PKI configuration and to delete any
previous certificates and keys, run "./clean-all".
Finally, you can run this tool (pkitool) to build certificates/keys.
I have tried creating the keys directory manually as i have read this has worked for others but still no luck. Being new to BSD I've hit a road block and looking for some advice.
Any ideas?
cheers guys
UPDATE:
When trying to source ./vars i get the following output
[root#freenas] /mnt/NAS/openvpn/easy-rsa/2.0# source ./vars
export: Command not found.
export: Command not found.
export: Command not found.
export: Command not found.
EASY_RSA: Undefined variable.
export: Command not found.
EASY_RSA: Undefined variable.
FreeNAS's default shell is not sh, and therefore doesn't support the 'export' command. The ./vars script needs the export command to set environment variables it then needs.
So before you call ./vars (don't call source) call:
sh
This is clearly stated in the site: http://joepaetzel.wordpress.com/2013/09/22/openvpn-on-freenas-9-1/
Not sure about the original issue, i think nrathaus has covered that well.
demonLaMagra - If you want to check if openvpn in running use this command:
service openvpn status
Sorry I couldn't comment on the last answer because of being a new new user, otherwise I would have.

global variable but still can't access in linux

i have trying to use some global variable in my ant file.
when i do login through terminal. i can access those variable like JAVA_HOME
but when i am trying to access variable through the ant command i am not able to find them.
global variable declared in .cshrc
setenv JAVA_HOME jdk_full_path
ant code using variable.
<property environment="env"/>
<property name="ear" value= "true"/>
<property name="home" value="${env.HOME}"/>
<property name="java_home" value="${env.JAVA_HOME}"/>
i can access home variable but i am not able to find JAVA_HOME variable ,i am executing this ant through eclipse
Please suggest me where should i declare the variable so i can access them
The problem is probably that Eclipse doesn't have JAVA_HOME in its environment.
Try logging out and back in again, then run Eclipse.
Alternatively, open a terminal, and run Eclipse from there.
The .cshrc file is only run when you start a new C shell, it is not for global variables. Since you are not starting Eclipse from the C shell it will not see any variables you set there.
Try the ~/.login file or the /etc/profile file in case eclipse starts up using bash. Both of these files are only loaded once when the user logs on so they should effect everything. You may require a restart or even a reboot for changes to these files to take effect.
Environment variables are inherited through process execution, they are not global. So, when you edit your shell's RC file to add a variable, it only takes effect for shells executed AFTER that modification, and for programs executed from those shells. If you started Eclipse from KDE/Gnome, and KDE/Gnome was started before you made that change, then KDE/Gnome never had the definition and therefore Eclipse did not either.
I recommend logging out and back in. Also, depending on your default shell setting, you may find that KDE/Gnome is being started through bash or something else, meaning that you'll need to modify .bashrc instead of .cshrc.
You should define this variables at one of the following files:
~/.profile or ~/.bash_profile runs only with login shells i.e when you first log in into system.
~/.bashrc file runs every time you open a new non-login bash shell such as xterm
So, you should add to this files the line:
export JAVA_HOME=jdk_full_path
You must re-login for the changes take efect

Resources