diff --git a/contrib/sudoers/linux b/contrib/sudoers/linux new file mode 100644 index 00000000000..c4e786cf31a --- /dev/null +++ b/contrib/sudoers/linux @@ -0,0 +1,8 @@ +# These work with Ubuntu - they might need tweaking for other distributions + +Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports +Cmnd_Alias VAGRANT_NFSD_CHECK = /etc/init.d/nfs-kernel-server status +Cmnd_Alias VAGRANT_NFSD_START = /etc/init.d/nfs-kernel-server start +Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar +Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /etc/exports +%sudo ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY, VAGRANT_EXPORTS_REMOVE diff --git a/contrib/sudoers/osx b/contrib/sudoers/osx new file mode 100644 index 00000000000..96f7f497846 --- /dev/null +++ b/contrib/sudoers/osx @@ -0,0 +1,5 @@ +Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports +Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart +Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports +%admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE + diff --git a/plugins/hosts/bsd/cap/nfs.rb b/plugins/hosts/bsd/cap/nfs.rb index 260963c15a3..aef3d906408 100644 --- a/plugins/hosts/bsd/cap/nfs.rb +++ b/plugins/hosts/bsd/cap/nfs.rb @@ -105,7 +105,7 @@ def self.nfs_export(environment, ui, id, ips, folders) # Output the rendered template into the exports output.split("\n").each do |line| line = Vagrant::Util::ShellQuote.escape(line, "'") - system("sudo", "-s", "--", "echo '#{line}' >> /etc/exports") + system("echo '#{line}' | sudo tee -a /etc/exports >/dev/null") end # We run restart here instead of "update" just in case nfsd diff --git a/plugins/hosts/linux/cap/nfs.rb b/plugins/hosts/linux/cap/nfs.rb index a6e55143b1a..adcd97dc26c 100644 --- a/plugins/hosts/linux/cap/nfs.rb +++ b/plugins/hosts/linux/cap/nfs.rb @@ -1,4 +1,5 @@ require "vagrant/util" +require "vagrant/util/shell_quote" require "vagrant/util/retryable" module VagrantPlugins @@ -38,9 +39,8 @@ def self.nfs_export(env, ui, id, ips, folders) nfs_cleanup(id) output.split("\n").each do |line| - # This should only ask for administrative permission once, even - # though its executed in multiple subshells. - system(%Q[sudo su root -c "echo '#{line}' >> /etc/exports"]) + line = Vagrant::Util::ShellQuote.escape(line, "'") + system(%Q[echo '#{line}' | sudo tee -a /etc/exports >/dev/null]) end if nfs_running?(nfs_check_command)