From fb96396f656dfdcf96b0e68293d0f65c44f1e200 Mon Sep 17 00:00:00 2001 From: Michal Papis Date: Fri, 19 Jul 2013 03:35:37 +0200 Subject: [PATCH] implemetn array arguments from #1569 --- plugins/provisioners/shell/provisioner.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/provisioners/shell/provisioner.rb b/plugins/provisioners/shell/provisioner.rb index f62fa1a69..cb41c62ff 100644 --- a/plugins/provisioners/shell/provisioner.rb +++ b/plugins/provisioners/shell/provisioner.rb @@ -5,8 +5,11 @@ module VagrantPlugins module Shell class Provisioner < Vagrant.plugin("2", :provisioner) def provision - args = "" - args = " #{config.args}" if config.args + case config.args + when String then args = " #{config.args}" + when Array then args = " #{config.args.map{|arg| quote_and_escape(arg)}.join(" ")}" + else args = "" + end command = "chmod +x #{config.upload_path} && #{config.upload_path}#{args}" with_script_file do |path| @@ -44,6 +47,11 @@ module VagrantPlugins protected + # Quote and escape strings for shell execution, thanks to @capistrano + def quote_and_escape(text, quote = '"') + "#{quote}#{text.gsub(/#{quote}/) { |m| "#{m}\\#{m}#{m}" }}#{quote}" + end + # This method yields the path to a script to upload and execute # on the remote server. This method will properly clean up the # script file if needed.