From e5490544d69338dc6054195c8df6d5df1140d276 Mon Sep 17 00:00:00 2001 From: Jon Topper Date: Mon, 5 May 2014 23:55:16 +0100 Subject: [PATCH 1/5] Use 'tee' to write to /etc/exports --- plugins/hosts/bsd/cap/nfs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hosts/bsd/cap/nfs.rb b/plugins/hosts/bsd/cap/nfs.rb index 260963c15..aef3d9064 100644 --- a/plugins/hosts/bsd/cap/nfs.rb +++ b/plugins/hosts/bsd/cap/nfs.rb @@ -105,7 +105,7 @@ module VagrantPlugins # 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 From 0da334156b1818b48c5950c71f13e1cb39ba9dd0 Mon Sep 17 00:00:00 2001 From: Jon Topper Date: Mon, 5 May 2014 23:56:39 +0100 Subject: [PATCH 2/5] Fix up the Linux host too --- plugins/hosts/linux/cap/nfs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hosts/linux/cap/nfs.rb b/plugins/hosts/linux/cap/nfs.rb index a6e55143b..c88cfe63e 100644 --- a/plugins/hosts/linux/cap/nfs.rb +++ b/plugins/hosts/linux/cap/nfs.rb @@ -40,7 +40,7 @@ module VagrantPlugins 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"]) + system(%Q[echo '#{line}' | tee -a /etc/exports >/dev/null"]) end if nfs_running?(nfs_check_command) From 4a4ca74dea1b12f9dba5be9accd37efb43dc88d1 Mon Sep 17 00:00:00 2001 From: Jon Topper Date: Tue, 6 May 2014 10:05:53 +0100 Subject: [PATCH 3/5] Added missing 'sudo' call. --- plugins/hosts/linux/cap/nfs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hosts/linux/cap/nfs.rb b/plugins/hosts/linux/cap/nfs.rb index c88cfe63e..2c7ee7eeb 100644 --- a/plugins/hosts/linux/cap/nfs.rb +++ b/plugins/hosts/linux/cap/nfs.rb @@ -40,7 +40,7 @@ module VagrantPlugins output.split("\n").each do |line| # This should only ask for administrative permission once, even # though its executed in multiple subshells. - system(%Q[echo '#{line}' | tee -a /etc/exports >/dev/null"]) + system(%Q[echo '#{line}' | sudo tee -a /etc/exports >/dev/null"]) end if nfs_running?(nfs_check_command) From 6ec9e3e279149fe36340b9c2d5ea74170484d3b5 Mon Sep 17 00:00:00 2001 From: Jon Topper Date: Tue, 6 May 2014 12:24:35 +0100 Subject: [PATCH 4/5] Linux stuff now tested and working! --- plugins/hosts/linux/cap/nfs.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/hosts/linux/cap/nfs.rb b/plugins/hosts/linux/cap/nfs.rb index 2c7ee7eeb..adcd97dc2 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 @@ module VagrantPlugins 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[echo '#{line}' | sudo tee -a /etc/exports >/dev/null"]) + line = Vagrant::Util::ShellQuote.escape(line, "'") + system(%Q[echo '#{line}' | sudo tee -a /etc/exports >/dev/null]) end if nfs_running?(nfs_check_command) From d85fa99ffbf18ee0ccba44e2d9720bd89682e124 Mon Sep 17 00:00:00 2001 From: Jon Topper Date: Tue, 6 May 2014 12:43:50 +0100 Subject: [PATCH 5/5] Added example sudoers config to contrib --- contrib/sudoers/linux | 8 ++++++++ contrib/sudoers/osx | 5 +++++ 2 files changed, 13 insertions(+) create mode 100644 contrib/sudoers/linux create mode 100644 contrib/sudoers/osx diff --git a/contrib/sudoers/linux b/contrib/sudoers/linux new file mode 100644 index 000000000..c4e786cf3 --- /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 000000000..96f7f4978 --- /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 +