diff --git a/plugins/hosts/linux/cap/nfs.rb b/plugins/hosts/linux/cap/nfs.rb index 6b1c95c43..1216ce04f 100644 --- a/plugins/hosts/linux/cap/nfs.rb +++ b/plugins/hosts/linux/cap/nfs.rb @@ -38,9 +38,13 @@ module VagrantPlugins nfs_cleanup(id) + # Only use "sudo" if we can't write to /etc/exports directly + sudo_command = "" + sudo_command = "sudo " if !File.writable?("/etc/exports") + output.split("\n").each do |line| line = Vagrant::Util::ShellQuote.escape(line, "'") - system(%Q[echo '#{line}' | sudo tee -a /etc/exports >/dev/null]) + system(%Q[echo '#{line}' | #{sudo_command}tee -a /etc/exports >/dev/null]) end if nfs_running?(nfs_check_command) @@ -92,9 +96,13 @@ module VagrantPlugins user = Regexp.escape(Process.uid.to_s) id = Regexp.escape(id.to_s) + # Only use "sudo" if we can't write to /etc/exports directly + sudo_command = "" + sudo_command = "sudo " if !File.writable?("/etc/exports") + # Use sed to just strip out the block of code which was inserted # by Vagrant - system("sudo sed -r -e '\\\x01^# VAGRANT-BEGIN:( #{user})? #{id}\x01,\\\x01^# VAGRANT-END:( #{user})? #{id}\x01 d' -ibak /etc/exports") + system("#{sudo_command}sed -r -e '\\\x01^# VAGRANT-BEGIN:( #{user})? #{id}\x01,\\\x01^# VAGRANT-END:( #{user})? #{id}\x01 d' -ibak /etc/exports") end def self.nfs_opts_setup(folders)