Module: Blender::Driver::SSHExec

Included in:
Ssh
Defined in:
lib/blender/drivers/ssh_exec.rb

Instance Method Summary collapse

Instance Method Details

#fixup_sudo(command) ⇒ Object



51
52
53
# File 'lib/blender/drivers/ssh_exec.rb', line 51

def fixup_sudo(command)
  command.sub(/^sudo/, 'sudo -p \'blender sudo password: \'')
end

#remote_exec(command, session) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/blender/drivers/ssh_exec.rb', line 21

def remote_exec(command, session)
  password = config[:password]
  command = fixup_sudo(command)
  exit_status = 0
  channel = session.open_channel do |ch|
    ch.request_pty
    ch.exec(command) do |ch, success|
      unless success
        Blender::Log.debug("Command not found:#{success.inspect}")
        exit_status = -1
      end
      ch.on_data do |c, data|
        stdout << data
        c.send_data("#{password}\n") if data =~ /^blender sudo password: /
      end
      ch.on_extended_data do |c, type, data|
        stderr << data
      end
      ch.on_request "exit-status" do |ichannel, data|
        l = data.read_long
        exit_status = [exit_status, l].max
        Blender::Log.debug("exit_status:#{exit_status} , data:#{l}")
      end
    end
    Blender::Log.debug("Exit(#{exit_status}) Command: '#{command}'")
  end
  channel.wait
  exit_status
end