From 78c801dc7446e8232fb6b70a27838536cb9a5132 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sun, 30 Sep 2007 15:23:17 +0000 Subject: [PATCH] Fix cap shell to properly recognize sudo prompt (closes #9637) git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@7696 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- CHANGELOG | 2 ++ .../configuration/actions/invocation.rb | 10 ++++----- lib/capistrano/shell.rb | 22 +++++-------------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2f290ba0..fdb7db34 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix cap shell to properly recognize sudo prompt [Mark Imbriaco, barnaby, Jamis Buck] + * Git SCM module [Garry Dolley, Geoffrey Grosenbach, Scott Chacon] * Use the --password switch for subversion by default, but add :scm_prefer_prompt variable (defaults to false) [Jamis Buck] diff --git a/lib/capistrano/configuration/actions/invocation.rb b/lib/capistrano/configuration/actions/invocation.rb index 1eddf493..b2f4f342 100644 --- a/lib/capistrano/configuration/actions/invocation.rb +++ b/lib/capistrano/configuration/actions/invocation.rb @@ -124,12 +124,10 @@ module Capistrano options end - private - - # Returns the prompt text to use with sudo - def sudo_prompt - fetch(:sudo_prompt, "sudo password: ") - end + # Returns the prompt text to use with sudo + def sudo_prompt + fetch(:sudo_prompt, "sudo password: ") + end end end end diff --git a/lib/capistrano/shell.rb b/lib/capistrano/shell.rb index 01a3bf15..2015946b 100644 --- a/lib/capistrano/shell.rb +++ b/lib/capistrano/shell.rb @@ -166,24 +166,12 @@ HELP # Execute a command on the given list of servers. def exec_command(command, servers) - processor = Proc.new do |ch, stream, out| - # TODO: more robust prompt detection - out.each do |line| - if stream == :out - if out =~ /Password:\s*/i - ch.send_data "#{configuration[:password]}\n" - else - puts "[#{ch[:server]}] #{line.chomp}" - end - elsif stream == :err - puts "[#{ch[:server]} ERR] #{line.chomp}" - end - end - end - - previous = trap("INT") { cmd.stop! } + command = command.gsub(/\bsudo\b/, "sudo -p '#{configuration.sudo_prompt}'") + processor = configuration.sudo_behavior_callback(Configuration.default_io_proc) sessions = servers.map { |server| configuration.sessions[server] } - Command.process(command, sessions, :logger => configuration.logger, &Capistrano::Configuration.default_io_proc) + cmd = Command.new(command, sessions, :logger => configuration.logger, &processor) + previous = trap("INT") { cmd.stop! } + cmd.process! rescue Capistrano::Error => error warn "error: #{error.message}" ensure