lib/rye/box.rb in rye-0.8.5 vs lib/rye/box.rb in rye-0.8.6

- old
+ new

@@ -118,18 +118,19 @@ @rye_error = STDERR if @rye_error == true @rye_info = STDOUT if @rye_info == true @rye_opts[:logger] = Logger.new(@rye_debug) if @rye_debug # Enable Net::SSH debugging @rye_opts[:paranoid] = true unless @rye_safe == false # See Net::SSH.start + @rye_opts[:keys] = [@rye_opts[:keys]].flatten.compact # Add the given private keys to the keychain that will be used for @rye_host add_keys(@rye_opts[:keys]) # We don't want Net::SSH to handle the keypairs. This may change # but for we're letting ssh-agent do it. # TODO: Check if this should ot should not be enabled. - @rye_opts.delete(:keys) + #@rye_opts.delete(:keys) # From: capistrano/lib/capistrano/cli.rb STDOUT.sync = true # so that Net::SSH prompts show up debug "ssh-agent info: #{Rye.sshagent_info.inspect}" @@ -218,13 +219,18 @@ # Add one or more private keys to the SSH Agent. # * +additional_keys+ is a list of file paths to private keys # Returns the instance of Box def add_keys(*additional_keys) + if Rye.sysinfo.os == :win32 + @rye_opts[:keys] ||= [] + @rye_opts[:keys] += additional_keys.flatten + return @rye_opts[:keys] + end additional_keys = [additional_keys].flatten.compact || [] return if additional_keys.empty? - ret = Rye.add_keys(additional_keys) + ret = Rye.add_keys(additional_keys) if ret.is_a?(Rye::Rap) debug "ssh-add exit_code: #{ret.exit_code}" debug "ssh-add stdout: #{ret.stdout}" debug "ssh-add stderr: #{ret.stderr}" end @@ -381,12 +387,12 @@ self.cp(akey_path, "#{akey_path}-previous") authorized_keys = self.file_download("#{homedir}/#{akey_path}") end authorized_keys ||= StringIO.new - Rye.keys.each do |key| - path = key[2] + Rye.keys.each do |path| + info "# Adding public key for #{path}" k = Rye::Key.from_file(path).public_key.to_ssh2 authorized_keys.puts k end @@ -413,12 +419,11 @@ # Authorize the current user to login to the local machine via # SSH without a password. This is the same functionality as # authorize_keys_remote except run with local shell commands. def authorize_keys_local added_keys = [] - Rye.keys.each do |key| - path = key[2] + Rye.keys.each do |path| debug "# Public key for #{path}" k = Rye::Key.from_file(path).public_key.to_ssh2 Rye.shell(:mkdir, :p, :m, '700', '$HOME/.ssh') # Silently create dir if it doesn't exist Rye.shell(:echo, "'#{k}' >> $HOME/.ssh/authorized_keys") Rye.shell(:echo, "'#{k}' >> $HOME/.ssh/authorized_keys2") @@ -588,11 +593,11 @@ return if @rye_ssh && !reconnect disconnect if @rye_ssh debug "Opening connection to #{@rye_host} as #{@rye_opts[:user]}" highline = HighLine.new # Used for password prompt retried = 0 - + @rye_opts[:keys].compact! # A quick fix in Windows. TODO: Why is there a nil? begin @rye_ssh = Net::SSH.start(@rye_host, @rye_opts[:user], @rye_opts || {}) rescue Net::SSH::HostKeyMismatch => ex STDERR.puts ex.message print "\a" if @rye_info # Ring the bell @@ -631,10 +636,10 @@ return unless @rye_ssh && !@rye_ssh.closed? begin Timeout::timeout(3) do @rye_ssh.loop(0.3) { @rye_ssh.busy?; } end - rescue Timeout::Error => ex + rescue SystemCallError, Timeout::Error => ex error "Disconnect timeout (was something still running?)" end debug "Closing connection to #{@rye_ssh.host}" @rye_ssh.close