Class: Pairzone::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/pairzone/shell.rb

Instance Method Summary collapse

Constructor Details

#initialize(identity) ⇒ Shell

Returns a new instance of Shell.



3
4
5
# File 'lib/pairzone/shell.rb', line 3

def initialize(identity)
  @identity = identity
end

Instance Method Details

#git(cmd) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/pairzone/shell.rb', line 14

def git(cmd)
  git_ssh = Tempfile.new('git_ssh')
  git_ssh.puts %{#!/bin/bash\nexec ssh -i #{@identity} $1 "bash --login -c '$2'"}
  git_ssh.close
  `chmod +x #{git_ssh.path}`
  run "GIT_SSH='#{git_ssh.path}' #{cmd}"
end

#remote(ip, command) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/pairzone/shell.rb', line 22

def remote(ip, command)
  output = ''
  remote_log(ip, command)
  Net::SSH.start(ip, 'pairzone', :auth_methods => ['publickey'], :keys => [@identity]) do |ssh|
    output = (ssh.exec!("bash --login -c '#{command}'") || "").strip
  end
  remote_log(ip, "#=> #{output}")
  return output
end

#remote_log(ip, msg) ⇒ Object



32
33
34
# File 'lib/pairzone/shell.rb', line 32

def remote_log(ip, msg)
  Logger.debug("<%= color('[pairzone@#{ip}]:', CYAN + BOLD) %> #{msg}")
end

#run(cmd) ⇒ Object



7
8
9
10
11
12
# File 'lib/pairzone/shell.rb', line 7

def run(cmd)
  Logger.debug(cmd)
  output = `#{cmd}`
  Logger.debug("#=> #{output}")
  output
end