hosts/bsd: only use sudo if we can't write /etc/exports [GH-2643]

This commit is contained in:
Mitchell Hashimoto 2014-10-23 17:43:58 -07:00
parent 13dc1832b6
commit aa981cf4ec
2 changed files with 20 additions and 5 deletions

View File

@ -21,6 +21,8 @@ IMPROVEMENTS:
more easily. Vagrant will login for you if you specify auth. [GH-4042]
- providers/docker: `stop_timeout` can be used to modify the `docker stop`
timeout. [GH-4504]
- synced\_folders/nfs: Won't use `sudo` to write to /etc/exports if there
are write privileges. [GH-2643]
- synced\_folders/smb: Credentials from one SMB will be copied to the rest. [GH-4675]
BUG FIXES:

View File

@ -102,10 +102,16 @@ module VagrantPlugins
# First, clean up the old entry
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 the rendered template into the exports
output.split("\n").each do |line|
line = Vagrant::Util::ShellQuote.escape(line, "'")
system("echo '#{line}' | sudo tee -a /etc/exports >/dev/null")
system(
"echo '#{line}' | " +
"#{sudo_command}tee -a /etc/exports >/dev/null")
end
# We run restart here instead of "update" just in case nfsd
@ -165,12 +171,19 @@ module VagrantPlugins
user = Process.uid
command = []
command << "sudo" if !File.writable?("/etc/exports")
command += [
"sed", "-E", "-e",
"/^# VAGRANT-BEGIN:( #{user})? #{id}/," +
"/^# VAGRANT-END:( #{user})? #{id}/ d",
"-ibak",
"/etc/exports"
]
# Use sed to just strip out the block of code which was inserted
# by Vagrant, and restart NFS.
system(
"sudo", "sed", "-E", "-e",
"/^# VAGRANT-BEGIN:( #{user})? #{id}/,/^# VAGRANT-END:( #{user})? #{id}/ d",
"-ibak", "/etc/exports")
system(*command)
end
def self.nfs_checkexports!