Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .ruby_version

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
20 changes: 10 additions & 10 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions libraries/provider_chruby_exec.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions libraries/resource_chruby_exec.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 13 additions & 11 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -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'
33 changes: 17 additions & 16 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
25 changes: 0 additions & 25 deletions recipes/system.rb

This file was deleted.

24 changes: 9 additions & 15 deletions templates/default/chruby.sh.erb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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" %>