diff --git a/README.md b/README.md index c9d673c..7b42782 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,8 @@ Ensure you set an explicit dependency on the `chruby` cookbook if you are using - `node['chruby']['auto_switch']` - enable automatic switching between Ruby versions per https://github.com/postmodern/chruby#auto-switching - `node['chruby']['rubies']` - an hash of Rubies / Booleans values to install using the `ruby-build` LWRP, and make available to chruby. - `node['chruby']['default']` - specify the default Ruby version for every shell. - +- `node['chruby']['user_rubies']` - an array of directories containing custom rubies + # Recipes ## Default @@ -77,7 +78,7 @@ Builds and makes available the Ruby versions listed in the `node['chruby']['rubi - Author: Stephen Nelson-Smith (LordCope) - Atalanta Systems Ltd () -Copyright 2013, Atalanta Systems Ltd +Copyright 2013, Atalanta Systems Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/attributes/default.rb b/attributes/default.rb index 1b68123..6f751ba 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -5,4 +5,6 @@ default['chruby']['auto_switch'] = true default['chruby']['rubies'] = {'1.9.3-p392' => true} default['chruby']['default'] = 'embedded' -default['chruby']['user_rubies'] = {} +default['chruby']['user_rubies'] = [] +default['chruby']['sh_dir'] = "/etc/profile.d" +default['chruby']['sh_name'] = 'chruby.sh' diff --git a/recipes/default.rb b/recipes/default.rb index 7c46ee1..2b2a2b2 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -20,20 +20,25 @@ ark "chruby" do url "https://github.com/postmodern/chruby/archive/v#{node['chruby']['version']}.tar.gz" + version node['chruby']['version'] action :install_with_make end # Workaround for Github issue 5 https://github.com/Atalanta/chef-chruby/issues/5 link "/usr/local/chruby" do - to "/usr/local/chruby-1" -end + to "/usr/local/chruby-#{node['chruby']['version']}" +end + +sh_owner = node['chruby']['sh_owner'] -directory "/etc/profile.d" do +directory node['chruby']['sh_dir'] do recursive true + owner sh_owner if sh_owner end -template "/etc/profile.d/chruby.sh" do +template File.join(node['chruby']['sh_dir'], node['chruby']['sh_name']) do source "chruby.sh.erb" mode "0644" + owner sh_owner if sh_owner end diff --git a/templates/default/chruby.sh.erb b/templates/default/chruby.sh.erb index b71cd55..d92f775 100644 --- a/templates/default/chruby.sh.erb +++ b/templates/default/chruby.sh.erb @@ -1,5 +1,9 @@ source /usr/local/chruby/share/chruby/chruby.sh +<% if ::File.exists?("/opt/chefdk/embedded") -%> +RUBIES+=(/opt/chefdk/embedded) +<% end -%> + <% if ::File.exists?("/opt/chef/embedded") -%> RUBIES+=(/opt/chef/embedded) <% end -%> @@ -12,7 +16,11 @@ RUBIES+=($HOME/.rvm/rubies/*) RUBIES+=($HOME/.rbenv/rubies/*) <% end -%> -<% if ::File.exists?("/opt/chef/embedded") and node['chruby']['default'] == "embedded" -%> +<% node['chruby']['user_rubies'].each do |directory| -%> +RUBIES+=(<%= directory.sub(/\/\z/, '') %>/*) +<% end -%> + +<% if (::File.exists?("/opt/chef/embedded") or ::File.exists?("/opt/chefdk/embedded")) and node['chruby']['default'] == "embedded" -%> chruby embedded <% elsif node['chruby']['default'] -%> chruby <%= node['chruby']['default'] %>