1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

make sudo helper play nicely with complex commands

This commit is contained in:
Jamis Buck 2008-04-30 22:40:30 -06:00
parent c09e810abc
commit f9d2af0b24
4 changed files with 10 additions and 8 deletions

View file

@ -1,5 +1,7 @@
*unreleased*
* Make sudo helper play nicely with complex command chains [Jamis Buck]
* Expand file-transfer options with new upload() and download() helpers. [Jamis Buck]
* Allow SCP transfers in addition to SFTP. [Jamis Buck]

View file

@ -82,12 +82,12 @@ module Capistrano
if options[:shell] == false
shell = nil
else
shell = "#{options[:shell] || "sh"} -c"
shell = [options.fetch(:shell, "sh"), "-c"].join(" ")
cmd = cmd.gsub(/[$\\`"]/) { |m| "\\#{m}" }
cmd = "\"#{cmd}\""
end
command_line = [environment, shell, cmd].compact.join(" ")
command_line = [environment, options[:command_prefix], shell, cmd].compact.join(" ")
ch.exec(command_line)
ch.send_data(options[:data]) if options[:data]

View file

@ -70,7 +70,7 @@ module Capistrano
as = options.delete(:as)
user = as && "-u #{as}"
command = [fetch(:sudo, "sudo"), "-p '#{sudo_prompt}'", user, command].compact.join(" ")
options[:command_prefix] = [fetch(:sudo, "sudo"), "-p '#{sudo_prompt}'", user].compact.join(" ")
run(command, options, &sudo_behavior_callback(block))
end

View file

@ -97,29 +97,29 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
end
def test_sudo_should_default_to_sudo
@config.expects(:run).with("sudo -p 'sudo password: ' ls", {})
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'sudo password: '")
@config.sudo "ls"
end
def test_sudo_should_use_sudo_variable_definition
@config.expects(:run).with("/opt/local/bin/sudo -p 'sudo password: ' ls", {})
@config.expects(:run).with("ls", :command_prefix => "/opt/local/bin/sudo -p 'sudo password: '")
@config.options[:sudo] = "/opt/local/bin/sudo"
@config.sudo "ls"
end
def test_sudo_should_interpret_as_option_as_user
@config.expects(:run).with("sudo -p 'sudo password: ' -u app ls", {})
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'sudo password: ' -u app")
@config.sudo "ls", :as => "app"
end
def test_sudo_should_pass_options_through_to_run
@config.expects(:run).with("sudo -p 'sudo password: ' ls", :foo => "bar")
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'sudo password: '", :foo => "bar")
@config.sudo "ls", :foo => "bar"
end
def test_sudo_should_interpret_sudo_prompt_variable_as_custom_prompt
@config.set :sudo_prompt, "give it to me: "
@config.expects(:run).with("sudo -p 'give it to me: ' ls", {})
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'give it to me: '")
@config.sudo "ls"
end