diff --git a/libraries/chef_rvm_set_helpers.rb b/libraries/chef_rvm_set_helpers.rb new file mode 100644 index 00000000..67e1d60b --- /dev/null +++ b/libraries/chef_rvm_set_helpers.rb @@ -0,0 +1,15 @@ +class Chef + module RVM + module SetHelpers + def rvm_do(user = nil) + # Use Gem's version comparing code to compare the two strings + if Gem::Version.new(VersionCache.fetch_version(user)) < Gem::Version.new("1.8.6") + "exec" + else + "do" + end + end + + end + end +end diff --git a/libraries/chef_rvm_version_helpers.rb b/libraries/chef_rvm_version_helpers.rb new file mode 100644 index 00000000..088fc5ac --- /dev/null +++ b/libraries/chef_rvm_version_helpers.rb @@ -0,0 +1,43 @@ +class Chef + module RVM + module ShellHelpers + # stub to satisfy VersionCache (library load order not guarenteed) + end + + module VersionHelpers + def rvm_version(user = nil) + VersionCache.fetch_version(user) + end + end + + class VersionCache + class << self + include Chef::Mixin::ShellOut + include Chef::RVM::ShellHelpers + end + + def self.fetch_version(user = nil) + @@version ||= rvm_version(user) + end + + def self.rvm_version(user = nil) + cmd = "rvm version | cut -d ' ' -f 2" + + if user + user_dir = Etc.getpwnam(user).dir + environment = { 'USER' => user, 'HOME' => user_dir } + else + user_dir = nil + environment = nil + end + + version = shell_out!( + rvm_wrap_cmd(cmd, user_dir), :env => environment).stdout.strip + + Chef::Log.debug "RVM version = #{version}" + + version + end + end + end +end diff --git a/libraries/rvm_rubygems_package.rb b/libraries/rvm_rubygems_package.rb index f351afab..a8ba5977 100644 --- a/libraries/rvm_rubygems_package.rb +++ b/libraries/rvm_rubygems_package.rb @@ -24,15 +24,20 @@ module RVM module ShellHelpers # stub to satisfy RVMRubygems (library load order not guarenteed) end + module SetHelpers + # stub to satisfy RVMRubygems (library load order not guarenteed) + end end class Provider class Package class RVMRubygems < Chef::Provider::Package::Rubygems include Chef::RVM::ShellHelpers + include Chef::RVM::SetHelpers class RVMGemEnvironment < AlternateGemEnvironment include Chef::RVM::ShellHelpers + include Chef::RVM::SetHelpers attr_reader :ruby_strings, :user @@ -44,7 +49,7 @@ def initialize(gem_binary_location, ruby_strings, user = nil) def gem_paths cmd = "rvm #{ruby_strings.join(',')} " - cmd << "exec #{@gem_binary_location} env gempath" + cmd << "#{rvm_do} #{@gem_binary_location} env gempath" if user user_dir = Etc.getpwnam(user).dir @@ -64,7 +69,7 @@ def gem_paths def gem_platforms cmd = "rvm #{ruby_strings.join(',')} " - cmd << "exec #{@gem_binary_location} env" + cmd << "#{rvm_do} #{@gem_binary_location} env" if user user_dir = Etc.getpwnam(user).dir @@ -134,7 +139,7 @@ def install_via_gem_command(name, version) src = @new_resource.source && " --source=#{@new_resource.source} --source=http://rubygems.org" - cmd = %{rvm #{ruby_strings.join(',')} #{gem_binary_path}} + cmd = %{rvm #{ruby_strings.join(',')} #{rvm_do} #{gem_binary_path}} cmd << %{ install #{name} -q --no-rdoc --no-ri -v "#{version}"} cmd << %{#{src}#{opts}} @@ -154,7 +159,7 @@ def remove_package(name, version) end def uninstall_via_gem_command(name, version) - cmd = %{rvm #{ruby_strings.join(',')} #{gem_binary_path}} + cmd = %{rvm #{ruby_strings.join(',')} #{rvm_do} #{gem_binary_path}} cmd << %{ uninstall #{name} -q -x -I} if version cmd << %{ -v "#{version}"#{opts}}