hosts/linux: don't use sudo to write NFS if writable [GH-2643]
This commit is contained in:
parent
fbd568a03e
commit
cc01f01684
|
@ -38,9 +38,13 @@ module VagrantPlugins
|
||||||
|
|
||||||
nfs_cleanup(id)
|
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|
|
output.split("\n").each do |line|
|
||||||
line = Vagrant::Util::ShellQuote.escape(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
|
end
|
||||||
|
|
||||||
if nfs_running?(nfs_check_command)
|
if nfs_running?(nfs_check_command)
|
||||||
|
@ -92,9 +96,13 @@ module VagrantPlugins
|
||||||
user = Regexp.escape(Process.uid.to_s)
|
user = Regexp.escape(Process.uid.to_s)
|
||||||
id = Regexp.escape(id.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
|
# Use sed to just strip out the block of code which was inserted
|
||||||
# by Vagrant
|
# 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
|
end
|
||||||
|
|
||||||
def self.nfs_opts_setup(folders)
|
def self.nfs_opts_setup(folders)
|
||||||
|
|
Loading…
Reference in New Issue