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

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
This commit is contained in:
Jamis Buck 2007-09-30 15:23:17 +00:00
parent 3a2df2deb9
commit 78c801dc74
3 changed files with 11 additions and 23 deletions

View file

@ -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]

View file

@ -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

View file

@ -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