From 2c72c32df0b3aa1d57ea37409cb41d64166499e1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 12 Feb 2014 14:24:17 -0800 Subject: [PATCH] core: Modify Bundler settings to work with restricted permissions This includes two changes: 1. Change the Vagrant requirement to use the "= VERSION" constraint. The "path:" previously requires write permission in the directory of the gemspec, which we don't have in installers. 2. Set a BUNDLE_APP_CONFIG and BUNDLE_PATH setting. By setting this, Bundler won't ask for sudo password. Bundler never actually needs it; it is just overly aggressive in thinking it does. --- lib/vagrant/bundler.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb index 1567701e4..683d0a623 100644 --- a/lib/vagrant/bundler.rb +++ b/lib/vagrant/bundler.rb @@ -43,6 +43,15 @@ module Vagrant # If we're not enabled, then we don't do anything. return if !@enabled + bundle_path = Vagrant.user_data_path.join("gems") + + # Setup the "local" Bundler configuration. We need to set BUNDLE_PATH + # because the existence of this actually suppresses `sudo`. + @appconfigpath = Dir.mktmpdir + File.open(File.join(@appconfigpath, "config"), "w+") do |f| + f.write("BUNDLE_PATH: \"#{bundle_path}\"") + end + # Setup the Bundler configuration @configfile = File.open(Tempfile.new("vagrant").path + "1", "w+") @configfile.close @@ -53,10 +62,11 @@ module Vagrant @gemfile = build_gemfile(plugins) # Set the environmental variables for Bundler + ENV["BUNDLE_APP_CONFIG"] = @appconfigpath ENV["BUNDLE_CONFIG"] = @configfile.path ENV["BUNDLE_GEMFILE"] = @gemfile.path ENV["GEM_PATH"] = - "#{Vagrant.user_data_path.join("gems")}#{::File::PATH_SEPARATOR}#{@gem_path}" + "#{bundle_path}#{::File::PATH_SEPARATOR}#{@gem_path}" Gem.clear_paths end @@ -160,7 +170,7 @@ module Vagrant gemfile.puts(%Q[source "#{source}"]) end - gemfile.puts(%Q[gem "vagrant", path: "#{Vagrant.source_root}"]) + gemfile.puts(%Q[gem "vagrant", "= #{VERSION}"]) gemfile.puts("group :plugins do") plugins.each do |name, plugin|