class Pushwagner::Hooks::Remote
Attributes
after[R]
before[R]
environment[R]
sudo[R]
Public Class Methods
new(env, remote)
click to toggle source
# File lib/pushwagner/hooks.rb, line 39 def initialize(env, remote) @environment = env @before = remote['before'] || [] @after = remote['after'] || [] end
Public Instance Methods
gets_sudo_passwd()
click to toggle source
# File lib/pushwagner/hooks.rb, line 50 def gets_sudo_passwd if ENV['PUSHWAGNER_SUDO'] @sudo = ENV['PUSHWAGNER_SUDO'] elsif @sudo.nil? puts Pushwagner.severe "<<< WARNING: this operation requires privileges >>>" Pushwagner.warning "Enter Ctrl+C to abort." print "Enter sudo-passwd: " begin system 'stty -echo' rescue # windoz end @sudo = STDIN.gets.chomp puts begin system 'stty echo' rescue # windoz end end @sudo end
run(target)
click to toggle source
# File lib/pushwagner/hooks.rb, line 46 def run(target) ssh_exec(method(target).call) end
ssh_exec(cmds)
click to toggle source
# File lib/pushwagner/hooks.rb, line 75 def ssh_exec(cmds) environment.hosts.each do |host| cmds.each do |cmd| # Run each cmd in a separate 'transaction' Pushwagner.begin_info "Executing `#{cmd}` on #{host}" Net::SSH.start(host, environment.user) do |ssh| ssh.open_channel do |ch| ch.request_pty do |pty_ch, success| raise "FATAL: could not execute #{cmd}" unless success puts ch.exec("#{cmd}") do |ch, success_exec| raise "FATAL: failed on execution of #{cmd}" unless success_exec end ch.on_extended_data do |data_ch, type, data| if data =~ /\[sudo\] password/i gets_sudo_passwd unless sudo ch.send_data("#{sudo}\n") elsif type == :stderr print "ERROR: #{data}" else print data end end end end ssh.loop end Pushwagner.ok end end end