Sha256: 45387160164c3b40c655de19b55dfbdc6b8732fb7dc0983a3d9e32224a44b8fb

Contents?: true

Size: 1017 Bytes

Versions: 43

Compression:

Stored size: 1017 Bytes

Contents

module Incline
  class CLI
    class Prepare
      private
      
      def ssh_copy_id(shell)
        my_id_file = File.expand_path('~/.ssh/rsa_id.pub')
        if File.exist?(my_id_file)
          my_id = File.read(my_id_file)
          shell.with_stat('Enabling public key authentication') do
            
            shell.exec 'if [ ! -d ~/.ssh ]; then mkdir ~/.ssh; fi'
            shell.exec 'chmod 700 ~/.ssh'
            
            contents = shell.read_file("#{shell.home_path}/.ssh/authorized_keys")
            if contents
              unless contents.split("\n").find{|k| k.to_s.strip == my_id.strip}
                contents += "\n" unless contents[-1] == "\n"
                contents += my_id.strip + "\n"
                shell.write_file("#{shell.home_path}/.ssh/authorized_keys", contents)
              end
            else
              shell.write_file("#{shell.home_path}/.ssh/authorized_keys", my_id + "\n")
            end
            
          end
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
incline-0.3.14 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.13 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.12 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.11 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.10 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.9 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.8 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.7 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.6 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.5 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.4 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.3 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.2 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.1 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.3.0 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.2.36 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.2.35 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.2.34 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.2.28 lib/incline/cli/prepare/ssh_copy_id.rb
incline-0.2.27 lib/incline/cli/prepare/ssh_copy_id.rb