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
20 changes: 20 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,28 @@
default[:rbenv][:git_revision] = "master"
default[:rbenv][:install_prefix] = "/opt"

# This can be `git` or `file`. If git, rbenv is installed from GitHub
# like a standard install. If `file`, it is installed by using a file
# from the cookbook. See node[:rbenv][:filename] below
default[:rbenv][:install_method] = "git"

# Path to rbenv tar.gz file. Assumed to have an name in the form
# `rbenv-version.tar.gz` which contains a directory
# `rbenv-master`. This is based on what you get when you download
# the master branch as a tarball from GitHub
default[:rbenv][:filename] = nil
default[:rbenv][:cookbook] = nil

default[:ruby_build][:git_repository] = "git://github.com/sstephenson/ruby-build.git"
default[:ruby_build][:git_revision] = "master"

# See node[:rbenv][:install_method] above
default[:ruby_build][:install_method] = "git"
# Path to ruby-build tar.gz file. Assumed to have an name in the form
# `ruby-build-version.tar.gz` which contains a directory
# `ruby-build-version`.
default[:ruby_build][:filename] = nil
default[:ruby_build][:cookbook] = nil

default[:rbenv_vars][:git_repository] = "git://github.com/sstephenson/rbenv-vars.git"
default[:rbenv_vars][:git_revision] = "master"
75 changes: 63 additions & 12 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,71 @@
supports :manage_home => true
end

directory node[:rbenv][:root] do
owner "rbenv"
group "rbenv"
mode "0775"
end
case node[:rbenv][:install_method]
when "git"
directory node[:rbenv][:root] do
owner "rbenv"
group "rbenv"
mode "0775"
end

git node[:rbenv][:root] do
repository node[:rbenv][:git_repository]
reference node[:rbenv][:git_revision]
user "rbenv"
group "rbenv"
action :sync
git node[:rbenv][:root] do
repository node[:rbenv][:git_repository]
reference node[:rbenv][:git_revision]
user "rbenv"
group "rbenv"
action :sync

notifies :create, "template[/etc/profile.d/rbenv.sh]", :immediately
end
when "file"
cache_path = File.join(node[:rbenv][:root], "cache")
node.set[:rbenv][:cache_path] = cache_path


cookbook_file node[:rbenv][:filename] do
owner "rbenv"
group "rbenv"
mode 0644
path File.join(Chef::Config[:file_cache_path], node[:rbenv][:filename])
cookbook node[:rbenv][:cookbook]
end

rbenv_file = node[:rbenv][:filename]
rbenv_version = File.basename(rbenv_file, "tar.gz")
rbenv_dir = File.join(Chef::Config[:file_cache_path], rbenv_version)

bash "extract rbenv" do
cwd Chef::Config[:file_cache_path]
code <<-EOH
tar xzf "#{rbenv_file}"
mv rbenv-master "#{node[:rbenv][:root]}"
EOH
notifies :create, "directory[#{node[:rbenv][:root]}]", :immediately
not_if {
File.exists?(node[:rbenv][:root]) && node[:rbenv][:installed_version] == rbenv_version
}
notifies :create, "template[/etc/profile.d/rbenv.sh]", :immediately
end

directory cache_path do
owner "rbenv"
group "rbenv"
mode 0755
end

directory node[:rbenv][:root] do
owner "rbenv"
group "rbenv"
mode "0775"
recursive true
action :nothing
end

notifies :create, "template[/etc/profile.d/rbenv.sh]", :immediately
node.set[:rbenv][:installed_version] = rbenv_version
else
Chef::Log.error("Invalid install method for rbenv: #{node[:rbenv][:install_method]}")
raise "Invalid install method: #{node[:rbenv][:install_method]}"
end

template "/etc/profile.d/rbenv.sh" do
Expand Down
37 changes: 32 additions & 5 deletions recipes/ruby_build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,41 @@

include_recipe "git"

git "#{Chef::Config[:file_cache_path]}/ruby-build" do
repository node[:ruby_build][:git_repository]
reference node[:ruby_build][:git_revision]
action :sync
Chef::Log.info("Installing ruby-build using #{node[:ruby_build][:install_method]}")
case node[:ruby_build][:install_method]
when "git"

ruby_build_dir = "#{Chef::Config[:file_cache_path]}/ruby-build"
git ruby_build_dir do
repository node[:ruby_build][:git_repository]
reference node[:ruby_build][:git_revision]
action :sync
end
when "file"

cookbook_file node[:ruby_build][:filename] do
mode 0644
cookbook node[:rbenv][:cookbook]
path File.join(Chef::Config[:file_cache_path], node[:ruby_build][:filename])
end

ruby_build_file = node[:ruby_build][:filename]
ruby_build_version = File.basename(ruby_build_file, ".tar.gz")
ruby_build_dir = File.join(Chef::Config[:file_cache_path], ruby_build_version)

extract_command = "tar xzf #{ruby_build_file}"
Chef::Log.debug("Extracting ruby_build with command: #{extract_command}")
bash "extract_ruby_build" do
cwd Chef::Config[:file_cache_path]
code extract_command
end
else
Chef::Log.error("Invalid install method for ruby-build: #{node[:ruby_build][:install_method]}")
raise "Invalid install method: #{node[:ruby_build][:install_method]}"
end

bash "install_ruby_build" do
cwd "#{Chef::Config[:file_cache_path]}/ruby-build"
cwd ruby_build_dir
user "rbenv"
group "rbenv"
code <<-EOH
Expand Down