Created
September 24, 2012 18:06
-
-
Save YannRobert/3777357 to your computer and use it in GitHub Desktop.
Patch to propose to https://github.com/mitchellh/vagrant/issues/1149
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- linux.rb.ori 2012-09-24 19:20:39.094577648 +0200 | |
+++ linux.rb 2012-09-24 19:41:02.079583990 +0200 | |
@@ -42,14 +42,27 @@ | |
@ui.info I18n.t("vagrant.hosts.linux.nfs_export") | |
sleep 0.5 | |
+ # as we are potentially asking for a password when using sudo, the user may appreciate some log info | |
+ | |
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"]) | |
- end | |
+ # printing the content of the modification will not hurt and may save debugging time | |
+ @logger.info("Patching /etc/exports by appending following content : ") | |
+ @logger.info(output) | |
+ | |
+ # now we need to escape some chars to make sure sed will work | |
+ # we know we make use of double-quotes, parenthesis, and multiple lines. So we are going to handle those cases | |
+ output = output.gsub("\"", "\\\"") | |
+ output = output.gsub("(", "\\(") | |
+ output = output.gsub(")", "\\)") | |
+ output = output.gsub("\n", "\\\n") | |
+ | |
+ # printing the sed command will avoid a lot of struggle when debugging | |
+ sed_command = "sudo sed -e '$a#{output}' -ibak /etc/exports" | |
+ @logger.debug("Executing sed command : " + sed_command) | |
+ system(sed_command) | |
+ @logger.info("Restarting NFS server ...") | |
# We run restart here instead of "update" just in case nfsd | |
# is not starting | |
system("sudo #{@nfs_server_binary} restart") | |
@@ -87,6 +100,7 @@ | |
# Use sed to just strip out the block of code which was inserted | |
# by Vagrant | |
+ @logger.info("Cleaning up file /etc/exports ...") | |
system("sudo sed -e '/^# VAGRANT-BEGIN: #{id}/,/^# VAGRANT-END: #{id}/ d' -ibak /etc/exports") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/plugins/hosts/arch/host.rb b/plugins/hosts/arch/host.rb | |
index fe56f31..1dcf1fc 100644 | |
--- a/plugins/hosts/arch/host.rb | |
+++ b/plugins/hosts/arch/host.rb | |
@@ -25,11 +25,14 @@ 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[sudo su root -c "echo '#{line}' >> /etc/exports"]) | |
- end | |
+ # now we need to escape some chars to make sure sed will work | |
+ # we know we make use of double-quotes, parenthesis, and multiple lines. So we are going to handle those cases | |
+ output = output.gsub("\"", "\\\"") | |
+ output = output.gsub("(", "\\(") | |
+ output = output.gsub(")", "\\)") | |
+ output = output.gsub("\n", "\\\n") | |
+ sed_command = "sudo sed -e '$a#{output}' -ibak /etc/exports" | |
+ system(sed_command) | |
if systemd? | |
# Call start to be nice. This will be a no-op if things are | |
diff --git a/plugins/hosts/bsd/host.rb b/plugins/hosts/bsd/host.rb | |
index 28c9a62..88c9660 100644 | |
--- a/plugins/hosts/bsd/host.rb | |
+++ b/plugins/hosts/bsd/host.rb | |
@@ -49,10 +49,14 @@ module VagrantPlugins | |
nfs_cleanup(id) | |
# Output the rendered template into the exports | |
- output.split("\n").each do |line| | |
- line = line.gsub('"', '\"') | |
- system(%Q[sudo su root -c "echo '#{line}' >> /etc/exports"]) | |
- end | |
+ # now we need to escape some chars to make sure sed will work | |
+ # we know we make use of double-quotes, parenthesis, and multiple lines. So we are going to handle those cases | |
+ output = output.gsub("\"", "\\\"") | |
+ output = output.gsub("(", "\\(") | |
+ output = output.gsub(")", "\\)") | |
+ output = output.gsub("\n", "\\\n") | |
+ sed_command = "sudo sed -e '$a#{output}' -ibak /etc/exports" | |
+ system(sed_command) | |
# We run restart here instead of "update" just in case nfsd | |
# is not starting | |
diff --git a/plugins/hosts/linux/host.rb b/plugins/hosts/linux/host.rb | |
index b846d7a..9837714 100644 | |
--- a/plugins/hosts/linux/host.rb | |
+++ b/plugins/hosts/linux/host.rb | |
@@ -45,12 +45,15 @@ 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[sudo su root -c "echo '#{line}' >> /etc/exports"]) | |
- end | |
- | |
+ # now we need to escape some chars to make sure sed will work | |
+ # we know we make use of double-quotes, parenthesis, and multiple lines. So we are going to handle those cases | |
+ output = output.gsub("\"", "\\\"") | |
+ output = output.gsub("(", "\\(") | |
+ output = output.gsub(")", "\\)") | |
+ output = output.gsub("\n", "\\\n") | |
+ sed_command = "sudo sed -e '$a#{output}' -ibak /etc/exports" | |
+ system(sed_command) | |
+ | |
# We run restart here instead of "update" just in case nfsd | |
# is not starting | |
system("sudo #{@nfs_server_binary} restart") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment