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:
parent
c09e810abc
commit
f9d2af0b24
4 changed files with 10 additions and 8 deletions
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue