diff --git a/.ruby_version b/.ruby_version deleted file mode 100644 index 650d0c2..0000000 --- a/.ruby_version +++ /dev/null @@ -1 +0,0 @@ -1.9.3-p432 diff --git a/LICENSE b/LICENSE index 02cfb01..9335a08 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ Copyright (C) 2013 Atalanta Systems Ltd +Copyright (C) 2014, 2015 Bloomberg Finance L.P. 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 c1b96d3..6bf4c89 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,10 +1,10 @@ -default['chruby']['version'] = '0.3.4' -default['chruby']['gpg_check'] = false -default['chruby']['use_rvm_rubies'] = false -default['chruby']['use_rbenv_rubies'] = false -default['chruby']['auto_switch'] = true -default['chruby']['rubies'] = {'1.9.3-p392' => true} -default['chruby']['default'] = 'embedded' -default['chruby']['user_rubies'] = {} -default['chruby']['sh_dir'] = "/etc/profile.d" -default['chruby']['sh_name'] = 'chruby.sh' +default['chruby']['source_url'] = 'https://github.com/postmodern/chruby/archive/v%{version}.zip' +default['chruby']['source_checksum'] = nil +default['chruby']['version'] = '0.3.9' +default['chruby']['prefix_path'] = '/usr/local/chruby' +default['chruby']['install_path'] = '/usr/local/src/chruby' + +default['chruby']['sh_profile'] = false +default['chruby']['sh_rubies'] = [] +default['chruby']['sh_default_ruby'] = nil +default['chruby']['sh_auto_switch'] = false diff --git a/libraries/provider_chruby_exec.rb b/libraries/provider_chruby_exec.rb new file mode 100644 index 0000000..e62b917 --- /dev/null +++ b/libraries/provider_chruby_exec.rb @@ -0,0 +1,19 @@ +# +# Cookbook Name:: chruby +# License:: Apache 2.0 +# +# Copyright 2014, 2015 Bloomberg Finance L.P. +# +class Chef::Provider::ChrubyExec < Chef::Provider::LWRPBase + use_inline_resources if defined?(use_inline_resources) + + def whyrun_supported? + true + end + + action :run do + execute "chruby exec-#{new_resource.ruby}[#{new_resource.command}]" do + command %Q(chruby-exec "#{new_resource.ruby}" -- #{new_resource.command}) + end + end +end diff --git a/libraries/resource_chruby_exec.rb b/libraries/resource_chruby_exec.rb new file mode 100644 index 0000000..aad4ce6 --- /dev/null +++ b/libraries/resource_chruby_exec.rb @@ -0,0 +1,14 @@ +# +# Cookbook Name:: chruby +# License:: Apache 2.0 +# +# Copyright 2014, 2015 Bloomberg Finance L.P. +# +class Chef::Resource::ChrubyExec < Chef::Resource::LWRPBase + self.resource_name = :chruby_exec + actions :run + default_action :run + + attribute :command, kind_of: String, name_attribute: true + attribute :ruby, kind_of: String +end diff --git a/metadata.rb b/metadata.rb index dbc83b2..47197c8 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,11 +1,13 @@ -name "chruby" -maintainer "Atalanta Systems Ltd" -maintainer_email "support@atalanta-systems.com" -license "Apache 2.0" -description "Installs/Configures chruby" -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.2.1" -depends "ark" -depends "ruby_build" -supports "centos" -supports "ubuntu" +name 'chruby' +maintainer 'Bloomberg Finance L.P.' +maintainer_email 'webops@bloomberg.net' +license 'Apache 2.0' +description 'Installs/configures chruby' +long_description 'Installs/configures chruby' +version '1.0.0' + +depends 'libarchive' + +supports 'centos' +supports 'redhat' +supports 'ubuntu' diff --git a/recipes/default.rb b/recipes/default.rb index 24ab8d7..da8de78 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -3,6 +3,7 @@ # Recipe:: default # # Copyright (C) 2013 Atalanta Systems Ltd +# Copyright (C) 2014, 2015 Bloomberg Finance L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,29 +16,29 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +# -include_recipe "ark" +include_recipe 'libarchive::default' -ark "chruby" do - url "https://github.com/postmodern/chruby/archive/v#{node['chruby']['version']}.tar.gz" - action :install_with_make +archive = remote_file node['chruby']['source_url'] % { version: node['chruby']['version'] } do + checksum node['chruby']['source_checksum'] end -# Workaround for Github issue 5 https://github.com/Atalanta/chef-chruby/issues/5 - -link "/usr/local/chruby" do - to "/usr/local/chruby-1" +directory node['chruby']['install_path'] do + recursive true end -sh_owner = node['chruby']['sh_owner'] +libarchive_file File.basename(archive.path) do + path archive.path + extract_to File.join(node['chruby']['install_path'], node['chruby']['version']) + action :extract +end -directory node['chruby']['sh_dir'] do - recursive true - owner sh_owner if sh_owner +execute "make install --prefix #{node['chruby']['prefix_path']}" do + cwd File.join(node['chruby']['install_path'], node['chruby']['version']) end -template File.join(node['chruby']['sh_dir'], node['chruby']['sh_name']) do - source "chruby.sh.erb" - mode "0644" - owner sh_owner if sh_owner +template '/etc/profile.d/chruby.sh' do + source 'chruby.sh.erb' + only_if { node['chruby']['sh_profile'] } end diff --git a/recipes/system.rb b/recipes/system.rb deleted file mode 100644 index 1603160..0000000 --- a/recipes/system.rb +++ /dev/null @@ -1,25 +0,0 @@ -# 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. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -include_recipe "ruby_build" - -node['chruby']['rubies'].each do |ruby, flag| - if flag - ruby_build_ruby ruby do - prefix_path "/opt/rubies/#{ruby}" - end - end -end - -include_recipe "chruby" diff --git a/templates/default/chruby.sh.erb b/templates/default/chruby.sh.erb old mode 100644 new mode 100755 index b71cd55..6f96f35 --- a/templates/default/chruby.sh.erb +++ b/templates/default/chruby.sh.erb @@ -1,22 +1,16 @@ -source /usr/local/chruby/share/chruby/chruby.sh +#!/bin/sh +[ -z "$BASH_VERSION" ] && [ -z "$ZSH_VERSION" ] && exit 0 -<% if ::File.exists?("/opt/chef/embedded") -%> -RUBIES+=(/opt/chef/embedded) -<% end -%> +source '<%= node['chruby']['prefix_path'] %>/share/chruby/chruby.sh' -<% if node['chruby']['use_rvm'] && ! Dir["~/.rubies/*"].empty? -%> -RUBIES+=($HOME/.rvm/rubies/*) +<% if node['chruby']['sh_rubies'] -%> +export RUBIES=(<%= node['chruby']['sh_rubies'].join(' ') %>) <% end -%> -<% if node['chruby']['use_rbenv'] && ! Dir["~/.rbenv/versions/*"].empty? -%> -RUBIES+=($HOME/.rbenv/rubies/*) +<% if node['chruby']['sh_auto_switch'] -%> +source '<%= node['chruby']['prefix_path'] %>/share/chruby/auto.sh' <% end -%> -<% if ::File.exists?("/opt/chef/embedded") and node['chruby']['default'] == "embedded" -%> -chruby embedded -<% elsif node['chruby']['default'] -%> -chruby <%= node['chruby']['default'] %> +<% if node['chruby']['sh_default_ruby'] -%> +chruby '<%= node['chruby']['sh_default_ruby'] %>' <% end -%> - -<%= node['chruby']['auto_switch'] && "source /usr/local/chruby/share/chruby/auto.sh" %> -