Created
October 5, 2014 15:37
-
-
Save rutan/91901905c34e67236c8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
rbenv_user = (node[:rtn_rbenv][:system] ? 'root' : node[:rtn_rbenv][:user]) | |
if rbenv_user == 'root' | |
rbenv_root = '/usr/local/rbenv' | |
profile_path = '/etc/profile.d/rbenv.sh' | |
else | |
rbenv_root = "/home/#{rbenv_user}/.rbenv" | |
profile_path = "/home/#{rbenv_user}/.bash_profile" | |
end | |
# packages --------------------------------------------------------------------- | |
packages = | |
case os[:family] | |
when %r(debian|ubuntu) | |
%w(git openssl-dev readline) | |
when %r(redhat|fedora) | |
%w(git openssl-devel readline) | |
end | |
packages.each do |package_name| | |
package package_name do | |
action :install | |
end | |
end | |
# rbenv + ruby_build ----------------------------------------------------------- | |
execute 'install rbenv' do | |
command "git clone https://github.com/sstephenson/rbenv.git #{rbenv_root}" | |
user rbenv_user | |
not_if "test -e #{rbenv_root}" | |
end | |
execute 'install ruby-build' do | |
command "git clone git://github.com/sstephenson/ruby-build.git #{rbenv_root}/plugins/ruby-build" | |
user rbenv_user | |
not_if "test -e #{rbenv_root}/plugins/ruby-build" | |
end | |
execute 'update rbenv' do | |
command "cd #{rbenv_root} && git fetch && git pull origin master" | |
user rbenv_user | |
end | |
execute 'update ruby-build' do | |
command "cd #{rbenv_root}/plugins/ruby-build && git fetch && git pull origin master" | |
user rbenv_user | |
end | |
rbenv_setting = <<"EOS" | |
# rbenv | |
export RBENV_ROOT=#{rbenv_root} | |
export PATH="$RBENV_ROOT/bin:$PATH" | |
eval "$(rbenv init -)" | |
EOS | |
if rbenv_user == 'root' | |
execute "create #{profile_path}" do | |
command "echo '#{rbenv_setting}' >> #{profile_path}" | |
user rbenv_user | |
not_if "test -e #{profile_path}" | |
end | |
else | |
execute "add #{profile_path}" do | |
command "echo '#{rbenv_setting}' >> #{profile_path}" | |
user rbenv_user | |
not_if "test `cat #{profile_path} | grep 'rbenv' -c` != 0" | |
end | |
end | |
execute "init rbenv" do | |
command "source #{profile_path} && eval \"$(rbenv init -)\"" | |
user rbenv_user | |
end | |
# ruby ------------------------------------------------------------------------- | |
(node[:rtn_rbenv][:install] || {}).each do |ruby_version, gem_list| | |
execute "install Ruby #{ruby_version}" do | |
command "source #{profile_path} && rbenv install #{ruby_version}" | |
user rbenv_user | |
not_if "test `source #{profile_path} && rbenv versions | grep '#{ruby_version}' -c` != 0" | |
end | |
(gem_list || {}).each do |gem_name, gem_version| | |
gem_version = nil if gem_version == '*' | |
force = (gem_name =~ /\A(bundler|rake)\z/) | |
execute "install #{gem_name}#{gem_version ? " v.#{gem_version}" : ''}" do | |
command "source #{profile_path} && rbenv shell #{ruby_version} && gem install #{gem_name}#{gem_version ? " -v #{gem_version}" : ''}#{force ? ' --force' : ''}" | |
user rbenv_user | |
end | |
end | |
end | |
# glonal ----------------------------------------------------------------------- | |
if global_version = node[:rtn_rbenv][:global] | |
execute "rbenv global #{global_version}" do | |
command "source #{profile_path} && rbenv global #{global_version}" | |
user rbenv_user | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment