I'm trying to write a script that does goes through all the steps for installing and setting up a graylog2 server and web interface on CentOS 6.2. Here is the section that I'm having trouble with:
curl -L get.rvm.io | bash -s stable
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
fi
rvm install 1.9.3 --create
rvm use 1.9.3 --default
So when it tries to load the rvm function into the shell as a function, it won't work, causing it to not install ruby. I've tried other methods of loading the function into the shell, as follows:
Manually sourcing the scripts file from a root install
source /usr/local/rvm/scripts/rvm
Manually adding the PATH environment variable to include rvm:
PATH=$PATH:/usr/local/rvm/bin
export PATH
Manually calling the path to the rvm command
/usr/local/rvm/bin/rvm install 1.9.3 --create
Sourcing /etc/profile.d/rvm.sh
source /etc/profile.d/rvm.sh
Note that if I do close out of the shell and log back in, rvm loads just fine, but I need to be able to do it all from within this script without having to log out and log back in. I'm also doing this from as root. You can look at the script I've written so far in it's entirety here.
Any help is appreciated.
EDIT
After adding set -x
to the script, here is the output when it tries to load the function:
+ [[ -s /root/.rvm/scripts/rvm ]]
+ [[ -s /usr/local/rvm/scripts/rvm ]]
+ source /usr/local/rvm/scripts/rvm
++ [[ :braceexpand:hashall:interactive-comments:posix:xtrace: =~ :posix: ]]
++ return 0
+ rvm install 1.9.3 --create
./rvm_test.sh: line 27: rvm: command not found
+ rvm use 1.9.3 --default
./rvm_test.sh: line 28: rvm: command not found
EDIT 2
I looked into the /usr/local/rvm/scripts/rvm file and found this at the very beginning:
# Do not allow sourcing RVM in `sh` - it's not supported
# return 0 to exit from sourcing this script without breaking sh
[[ ":$SHELLOPTS:" =~ ":posix:" ]] && return 0 || true
So I believe this is causing the my problem but I'm not sure. I'm not experienced in bash scripting :\ So the problem I'm guessing is that my shell isn't supported(?) can anybody clarify?
set -x
in the beginning of the script to see how all the variables are expanded and why tests return false. Are you aware of that if you are running as root, the$HOME
variable will give/root
?set -x
@DanielAnderssonset -x
will show you if the test returns true or false. Does it return false even though the file exists and have a size > 0, or what is the problem? You don't actually say what it is that doesn't work.