forked from joakimk/solokit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh.rb
38 lines (31 loc) · 961 Bytes
/
ssh.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Solokit
class SSH
def initialize(ip, user, debug)
@ip, @user, @debug = ip, user, debug
end
def run(command, quiet = true)
run_command("ssh #{ssh_opts} #{@user}@#{@ip} '#{command}' #{supress_output(quiet)}")
end
def rsync(source, target, quiet = false)
run_command("rsync -e 'ssh #{ssh_opts}' -az #{source} #{@user}@#{@ip}:#{target} #{supress_output(quiet)}")
end
def reverse_rsync(source, target, quiet = false)
run_command("rsync -e 'ssh #{ssh_opts}' -az #{@user}@#{@ip}:#{source} #{target} #{supress_output(quiet)}")
end
private
def supress_output(hide_stdout)
if @debug
""
else
"#{hide_stdout ? '2> /dev/null 1> /dev/null' : '2> /dev/null'}"
end
end
def run_command(cmd)
puts "SSH | #{cmd}" if @debug
system(cmd)
end
def ssh_opts
"-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
end
end
end