From 1e931eaba6031ead2e7b9d630e69ffe1fd995f9b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 25 Jan 2011 11:43:25 -0800 Subject: [PATCH] chmod and execute shell provisioning script in a single session --- lib/vagrant/provisioners/shell.rb | 8 ++++---- test/vagrant/provisioners/shell_test.rb | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/vagrant/provisioners/shell.rb b/lib/vagrant/provisioners/shell.rb index 04723ca0a..9f6c8ce67 100644 --- a/lib/vagrant/provisioners/shell.rb +++ b/lib/vagrant/provisioners/shell.rb @@ -31,16 +31,16 @@ module Vagrant end def provision! + commands = ["chmod +x #{config.upload_path}", config.upload_path] + # Upload the script to the VM vm.ssh.upload!(config.expanded_path.to_s, config.upload_path) # Execute it with sudo vm.ssh.execute do |ssh| - ssh.sudo!("chmod +x #{config.upload_path}") - - ssh.sudo!(config.upload_path) do |ch, type, data| + ssh.sudo!(commands) do |ch, type, data| if type == :exit_status - ssh.check_exit_status(data, config.upload_path) + ssh.check_exit_status(data, commands) else env.ui.info(data) end diff --git a/test/vagrant/provisioners/shell_test.rb b/test/vagrant/provisioners/shell_test.rb index 0b39a2924..ee5732b0d 100644 --- a/test/vagrant/provisioners/shell_test.rb +++ b/test/vagrant/provisioners/shell_test.rb @@ -56,10 +56,11 @@ class ShellProvisionerTest < Test::Unit::TestCase end should "upload the file, chmod, then execute it" do + commands = ["chmod +x #{@config.upload_path}", @config.upload_path] + p_seq = sequence("provisioning") @action.vm.ssh.expects(:upload!).with(@config.expanded_path.to_s, @config.upload_path).in_sequence(p_seq) - @ssh.expects(:sudo!).with("chmod +x #{@config.upload_path}").in_sequence(p_seq) - @ssh.expects(:sudo!).with(@config.upload_path).in_sequence(p_seq) + @ssh.expects(:sudo!).with(commands).in_sequence(p_seq) @action.provision! end