RiotGamesCookbooks / rbenv-cookbook

Installs and configures rbenv
http://community.opscode.com/cookbooks/rbenv
Apache License 2.0
137 stars 109 forks source link

Why `/etc/profile.d/rbenv.sh` and not `/etc/bash.bashrc`? #103

Open andrewhavens opened 10 years ago

andrewhavens commented 10 years ago

I'm working with someone on a chef project. He suggested we add some code to initialize rbenv for all users. I thought this cookbook was already doing that by adding the /etc/profile.d/rbenv.sh file. He said that those files only load for interactive sessions, but not all (i.e. ssh $node "command").

Here's the code that he wrote. I hate to have duplicate/unnecessary code. Is this something that can/should be incorporated into the official rbenv cookbook, or is it an appropriate supplement to the cookbook?

# install Ruby
include_recipe 'rbenv::default'
include_recipe 'rbenv::ruby_build'

rbenv_ruby '2.1.2' do
  ruby_version '2.1.2'
  global true
end

rbenv_gem 'bundler' do
  version '1.6.2'
  ruby_version '2.1.2'
  action :install
end

# initialize rbenv for all users

execute 'add rbenv to $PATH' do
  command 'echo \'export PATH="/opt/rbenv/bin:$PATH"\' >> /etc/bash.bashrc'
  not_if 'grep -F "rbenv/bin" /etc/bash.bashrc'
end

execute "add rbenv to global .bashrc" do
  command 'echo \'eval "$(rbenv init -)"\' >> /etc/bash.bashrc'
  not_if 'grep -F "rbenv init" /etc/bash.bashrc'
end

execute "add rbenv to global .profile" do
  command 'echo \'eval "$(rbenv init -)"\' >> /etc/profile'
  not_if 'grep -F "rbenv init" /etc/profile'
end
andrewhavens commented 10 years ago

I found this rbenv wiki article which list the various initialization scenarios https://github.com/sstephenson/rbenv/wiki/Unix-shell-initialization#shell-init-files. I don't see /etc/profile.d in the list, so I'm not sure where it falls in the load order.

I also found this helpful article which lists the various profile/rc files: http://bencane.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/

nicka commented 9 years ago

@andrewhavens May I ask what you ended up using?

andrewhavens commented 9 years ago

@nicka Sorry, I don't even remember! I'm not an expert on this kind of stuff so I deferred to the person responsible for implementation.