summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2012-01-23 19:40:06 -0800
committerBryan McLellan <btm@opscode.com>2012-01-25 18:27:08 -0800
commit4fe87f0d8464e31a6e7e7cb802f5aad2ec1991d8 (patch)
tree23656b19ed6ae28da7027e3ed6f338506510efc9
parent3528a2656aab895a579ac326e065f97acdf192c0 (diff)
downloadchef-4fe87f0d8464e31a6e7e7cb802f5aad2ec1991d8.tar.gz
Use first gem in path as system gem when on Omnibus
-rw-r--r--chef/lib/chef/provider/package/rubygems.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/chef/lib/chef/provider/package/rubygems.rb b/chef/lib/chef/provider/package/rubygems.rb
index c08f86a656..6c7f91ca92 100644
--- a/chef/lib/chef/provider/package/rubygems.rb
+++ b/chef/lib/chef/provider/package/rubygems.rb
@@ -311,11 +311,37 @@ class Chef
raise ArgumentError, msg
end
@gem_env = AlternateGemEnvironment.new(new_resource.gem_binary)
+ elsif is_omnibus?
+ # Opscode Omnibus - The ruby that ships inside omnibus is only used for Chef
+ # Default to installing somewhere more functional
+ @gem_env = AlternateGemEnvironment.new(find_gem_by_path)
else
@gem_env = CurrentGemEnvironment.new
end
end
+ def is_omnibus?
+ if RbConfig::CONFIG['bindir'] == "/opt/opscode/embedded/bin"
+ Chef::Log.debug("#{@new_resource} detected omnibus installation in #{RbConfig::CONFIG['bindir']}")
+ # Omnibus installs to a static path because of linking on unix, find it.
+ true
+ elsif RbConfig::CONFIG['bindir'].sub(/^[\w]:/, '') == "/opscode/chef/embedded/bin"
+ Chef::Log.debug("#{@new_resource} detected omnibus installation in #{RbConfig::CONFIG['bindir']}")
+ # windows, with the drive letter removed
+ true
+ else
+ false
+ end
+ end
+
+ def find_gem_by_path
+ Chef::Log.debug("#{@new_resource} searching for 'gem' binary in path: #{ENV['PATH']}")
+ separator = ::File::ALT_SEPARATOR ? ::File::ALT_SEPARATOR : ::File::SEPARATOR
+ path_to_first_gem = ENV['PATH'].split(::File::PATH_SEPARATOR).select { |path| ::File.exists?(path + separator + "gem") }.first
+ raise Chef::Exceptions::FileNotFound, "Unable to find 'gem' binary in path: #{ENV['PATH']}" if path_to_first_gem.nil?
+ path_to_first_gem + separator + "gem"
+ end
+
def gem_dependency
Gem::Dependency.new(@new_resource.package_name, @new_resource.version)
end