Module: Awsome::Ssh

Defined in:
lib/awsome/ssh.rb

Class Method Summary collapse

Class Method Details

.ensure_ssh_env_vars!Object



3
4
5
6
# File 'lib/awsome/ssh.rb', line 3

def self.ensure_ssh_env_vars!
  raise 'SSH_KEY environment variable not set' if ENV['SSH_KEY'].nil?
  raise 'SSH_USER environment varibale not set' if ENV['SSH_USER'].nil?
end

.has_ssh?(host) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/awsome/ssh.rb', line 23

def self.has_ssh?(host)
  Awsome.execute("nc -zw 2 #{host} 22 < /dev/null", system: true, verbose: false)
end

.scp(from, to) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/awsome/ssh.rb', line 13

def self.scp(from, to)
  ensure_ssh_env_vars!
  if File.exists?(from)
    to = "#{ENV['SSH_USER']}@#{to}" 
  else
    from = "#{ENV['SSH_USER']}@#{from}"
  end
  Awsome.execute("scp -i #{ENV['SSH_KEY']} #{from} #{to}", system: true, verbose: false)
end

.ssh(host, *scripts) ⇒ Object



8
9
10
11
# File 'lib/awsome/ssh.rb', line 8

def self.ssh(host, *scripts)
  ensure_ssh_env_vars!
  Awsome.execute("ssh -i #{ENV['SSH_KEY']} #{ENV['SSH_USER']}@#{host} \"#{scripts.join(' && ')}\"")
end