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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/rosh.rb', line 10
def initialize(*args)
@interval = 3
@ssh_opts = []
@base_ssh_opts = []
@local_forward_specs = []
@remote_forward_specs = []
alive_interval = 5
@escape = '^t'
@tmux_socket_name = nil
OptionParser.new("test").tap do |opt|
opt.banner = 'Usage: rosh [options] hostname [session-name]'
opt.on('-a alive-interval'){|v| alive_interval = v.to_i}
opt.on('-e escape'){|v| @escape = v}
opt.on('-I interval'){|v| @interval = v.to_f}
opt.on('-V'){|v| @verbose = true}
opt.on('-S'){|v| @screen = true}
opt.on('-L socket-name'){|v| @tmux_socket_name = v}
end.parse! args
@host, @name = *args, :default
abort 'hostname is required' if @host == :default
@base_ssh_opts << "-o ServerAliveInterval=#{alive_interval}"
@base_ssh_opts << "-o ServerAliveCountMax=1"
alias_name = @host
config = Net::SSH::Config.for(@host)
if @verbose
puts "ssh-config: #{config}"
end
@oom_reported = false
@last_exit_status = nil
@local_forward_specs = local_forwards(alias_name)
@remote_forward_specs = remote_forwards(alias_name)
@host = config[:host_name] if config[:host_name]
@base_ssh_opts << "-l #{config[:user]}" if config[:user]
@base_ssh_opts << "-p #{config[:port]}" if config[:port]
if proxy_option = ssh_proxy_option(config[:proxy])
@base_ssh_opts << proxy_option
end
if keys = config[:keys]
keys.each{|k| @base_ssh_opts << "-i #{k}"}
end
refresh_ssh_opts!
if @verbose
puts "host: #{@host}"
puts "name: #{@name}"
puts "interval: #{@interval}"
puts "alive_interval: #{alive_interval}"
puts "options: #{@ssh_opts*' '}"
end
@first_try = true
end
|