# File lib/rye/box.rb, line 113
113:     def initialize(host='localhost', opts={})
114:       ssh_opts = ssh_config_options(host)
115:       @rye_exception_hook = {}
116:       @rye_host = host
117:       
118:       if opts[:user]
119:         @rye_user = opts[:user]
120:       else
121:         @rye_user = ssh_opts[:user] || Rye.sysinfo.user
122:       end
123: 
124:       # These opts are use by Rye::Box and also passed to Net::SSH
125:       @rye_opts = {
126:         :safe => true,
127:         :port => ssh_opts[:port],
128:         :keys => Rye.keys,
129:         :via => nil,
130:         :info => nil,
131:         :debug => nil,
132:         :error => STDERR,
133:         :getenv => true,
134:         :templates => :erb,
135:         :quiet => false
136:       }.merge(opts)
137:       
138:       # Close the SSH session before Ruby exits. This will do nothing
139:       # if disconnect has already been called explicitly. 
140:       at_exit { self.disconnect }
141: 
142:       # Properly handle whether the opt :via is a +Rye::Hop+ or a +String+
143:       via_hop(@rye_opts.delete(:via))
144:       
145:       # @rye_opts gets sent to Net::SSH so we need to remove the keys
146:       # that are not meant for it. 
147:       @rye_safe, @rye_debug = @rye_opts.delete(:safe), @rye_opts.delete(:debug)
148:       @rye_info, @rye_error = @rye_opts.delete(:info), @rye_opts.delete(:error)
149:       @rye_getenv = {} if @rye_opts.delete(:getenv) # Enable getenv with a hash
150:       @rye_ostype, @rye_impltype = @rye_opts.delete(:ostype), @rye_opts.delete(:impltype)
151:       @rye_quiet, @rye_sudo = @rye_opts.delete(:quiet), @rye_opts.delete(:sudo)
152:       @rye_templates = @rye_opts.delete(:templates)
153:       
154:       # Store the state of the terminal 
155:       @rye_stty_save = `stty -g`.chomp rescue nil
156:       
157:       unless @rye_templates.nil?
158:         require @rye_templates.to_s   # should be :erb
159:       end
160:       
161:       @rye_opts[:logger] = Logger.new(@rye_debug) if @rye_debug # Enable Net::SSH debugging
162:       @rye_opts[:paranoid] ||= true unless @rye_safe == false # See Net::SSH.start
163:       @rye_opts[:keys] = [@rye_opts[:keys]].flatten.compact
164:       
165:       # Just in case someone sends a true value rather than IO object
166:       @rye_debug = STDERR if @rye_debug == true || DEBUG
167:       @rye_error = STDERR if @rye_error == true
168:       @rye_info = STDOUT if @rye_info == true
169:       
170:       # Add the given private keys to the keychain that will be used for @rye_host
171:       add_keys(@rye_opts[:keys])
172:       
173:       # We don't want Net::SSH to handle the keypairs. This may change
174:       # but for we're letting ssh-agent do it. 
175:       # TODO: Check if this should ot should not be enabled. 
176:       #@rye_opts.delete(:keys)
177:       
178:       # From: capistrano/lib/capistrano/cli.rb
179:       STDOUT.sync = true # so that Net::SSH prompts show up
180:       
181:       debug "ssh-agent info: #{Rye.sshagent_info.inspect}"
182:       debug @rye_opts.inspect
183: 
184:     end