# File lib/rye/hop.rb, line 81
 81:     def initialize(host, opts={})
 82:       ssh_opts = ssh_config_options(host)
 83:       @rye_exception_hook = {}
 84:       @rye_host = host
 85:       
 86:       if opts[:user]
 87:         @rye_user = opts[:user]
 88:       else
 89:         @rye_user = ssh_opts[:user] || Rye.sysinfo.user
 90:       end
 91:       
 92:       # These opts are use by Rye::Box and also passed to
 93:       # Net::SSH::Gateway (and Net::SSH)
 94:       @rye_opts = {
 95:         :port => ssh_opts[:port],
 96:         :keys => Rye.keys,
 97:         :via => nil,
 98:         :info => nil,
 99:         :debug => nil,
100:         :error => STDERR,
101:         :getenv => true,
102:         :templates => :erb,
103:         :quiet => false
104:       }.merge(opts)
105: 
106:       @next_port = MAX_PORT
107: 
108:       # Close the SSH session before Ruby exits. This will do nothing
109:       # if disconnect has already been called explicitly. 
110:       at_exit { self.disconnect }
111: 
112:       # Properly handle whether the opt :via is a +Rye::Hop+ or a +String+
113:       # and does nothing if nil
114:       via_hop(@rye_opts.delete(:via))
115: 
116:       # @rye_opts gets sent to Net::SSH so we need to remove the keys
117:       # that are not meant for it. 
118:       @rye_safe, @rye_debug = @rye_opts.delete(:safe), @rye_opts.delete(:debug)
119:       @rye_info, @rye_error = @rye_opts.delete(:info), @rye_opts.delete(:error)
120:       @rye_getenv = {} if @rye_opts.delete(:getenv) # Enable getenv with a hash
121:       @rye_ostype, @rye_impltype = @rye_opts.delete(:ostype), @rye_opts.delete(:impltype)
122:       @rye_quiet, @rye_sudo = @rye_opts.delete(:quiet), @rye_opts.delete(:sudo)
123:       @rye_templates = @rye_opts.delete(:templates)
124:       
125:       # Store the state of the terminal 
126:       @rye_stty_save = `stty -g`.chomp rescue nil
127:       
128:       unless @rye_templates.nil?
129:         require @rye_templates.to_s   # should be :erb
130:       end
131:       
132:       @rye_opts[:logger] = Logger.new(@rye_debug) if @rye_debug # Enable Net::SSH debugging
133:       @rye_opts[:keys] = [@rye_opts[:keys]].flatten.compact
134:       
135:       # Just in case someone sends a true value rather than IO object
136:       @rye_debug = STDERR if @rye_debug == true || DEBUG
137:       @rye_error = STDERR if @rye_error == true
138:       @rye_info = STDOUT if @rye_info == true
139:       
140:       # Add the given private keys to the keychain that will be used for @rye_host
141:       add_keys(@rye_opts[:keys])
142:       
143:       # From: capistrano/lib/capistrano/cli.rb
144:       STDOUT.sync = true # so that Net::SSH prompts show up
145:       
146:       debug "ssh-agent info: #{Rye.sshagent_info.inspect}"
147:       debug @rye_opts.inspect
148:     end