rye 0.8.19 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (10) hide show
  1. data/CHANGES.txt +17 -1
  2. data/README.rdoc +2 -29
  3. data/bin/try +42 -13
  4. data/lib/rye/box.rb +318 -224
  5. data/lib/rye/cmd.rb +156 -78
  6. data/lib/rye/rap.rb +10 -6
  7. data/lib/rye.rb +32 -5
  8. data/rye.gemspec +4 -7
  9. metadata +68 -49
  10. data/bin/rye +0 -147
data/bin/rye DELETED
@@ -1,147 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- # Rye -- A CLI for some handy SSH tools
4
- #
5
- # If your reading this via the rdocs you won't be able to see the code
6
- # See: http://github.com/delano/rye/blob/master/bin/rye
7
- #
8
- # Usage: rye
9
- #
10
-
11
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
12
- %w{net-ssh net-scp sysinfo drydock}.each { |dir| $:.unshift File.join(File.dirname(__FILE__), '..', '..', dir, 'lib') }
13
-
14
- require 'stringio'
15
- require 'yaml'
16
- require 'drydock'
17
- require 'rye'
18
-
19
- include Drydock
20
-
21
- global :p, :path, String, "A directory containing SSH private keys or the path to a private key"
22
- global :V, :version, "Display version number" do
23
- puts "Rye version: #{Rye::VERSION}"
24
- exit 0
25
- end
26
-
27
- before do |obj|
28
- # Load private keys if specified
29
- if obj.global.path
30
- keys = Rye.find_private_keys(obj.global.path)
31
- Rye.add_keys(keys)
32
- end
33
- end
34
-
35
- after do
36
-
37
- end
38
-
39
- option :u, :user, String, "User name to connect as"
40
- option :i, :identity, String, "Private key"
41
- argv :host
42
- command :ssh do |obj|
43
- raise "No host supplied" if obj.argv.empty?
44
- opts = { :debug => true }
45
- opts[:user] = obj.option.user || Rye.sysinfo.user
46
- opts[:keys] = [obj.option.identity] || []
47
- obj.argv.each do |host|
48
- rbox = Rye::Box.new host, opts
49
- p rbox.connect
50
- end
51
- end
52
-
53
- about "Add your public keys to one or more remote machines"
54
- usage "rye authorize [username@]host"
55
- argv :hostname
56
- command :authorize do |obj|
57
- raise "You must specify a host" unless obj.argv.hostname
58
- obj.argv.each do |hostname|
59
- if hostname.index('@')
60
- user, host = *hostname.split('@')
61
- else
62
- user, host = user = Rye.sysinfo.user, hostname
63
- end
64
- opts = { :debug => nil, :user => user, :auth_methods => %w(publickey hostbased) }
65
- puts "Authorizing #{user}@#{host}"
66
- rbox = Rye::Box.new(host, opts)
67
- rbox.authorize_keys_remote
68
- puts "Added public keys for: ", Rye.keys
69
- puts "Now try: " << "ssh #{user}@#{host}"
70
- end
71
-
72
- end
73
- command_alias :authorize, :authorise
74
-
75
- about "Add your public keys to your current account on this machine"
76
- command :authorize_local do |obj|
77
- user = Rye.sysinfo.user
78
-
79
- puts "Authorizing #{user}@localhost"
80
- rbox = Rye::Box.new('localhost', :debug => false)
81
- puts "Added public keys for: ", rbox.authorize_keys_local
82
- unless Rye.sysinfo.os == :windows
83
- puts "Now try: " << "ssh #{user}@localhost"
84
- end
85
- end
86
- command_alias :local_authorize, :local_authorise
87
-
88
-
89
- about "Generate a public key from a private key"
90
-
91
-
92
-
93
- about "Fetch the host keys for remote machines (suitable for your ~/.ssh/known_hosts file)"
94
- usage "rye hostkey HOSTNAME [HOSTNAME2 HOSTNAME3 ...]"
95
- argv :hostname
96
- command :hostkeys do |obj|
97
- raise "You must specify a host" unless obj.argv.hostname
98
- ret = Rye.remote_host_keys(obj.argv.hostname)
99
- STDERR.puts $/, ret.stderr, $/
100
- puts ret.stdout
101
- end
102
- command_alias :hostkeys, :hostkey
103
-
104
-
105
- about "Display your private keys"
106
- command :keys do |obj|
107
- Rye.keys.each do |key|
108
- puts key
109
- end
110
- end
111
-
112
- about "Display your public SSH keys"
113
- usage "rye pubkeys [--pem] [KEYPATH]"
114
- option :p, :pem, "Output in PEM format"
115
- argv :keypath
116
- command :pubkeys do |obj|
117
- keys = obj.argv.empty? ? Rye.keys.collect { |k| k[2] } : obj.argv
118
- keys.each do |path|
119
- STDERR.puts "# Public SSH key for #{path}"
120
- k = Rye::Key.from_file(path)
121
- puts obj.option.pem ? k.public_key.to_pem : k.public_key.to_ssh2
122
- end
123
- end
124
- command_alias :pubkeys, :pubkey
125
-
126
-
127
- default :keys
128
- debug :on
129
-
130
- # We call Drydock specifically otherwise it will run at_exit. Rye also
131
- # uses at_exit for shutting down the ssh-agent. Ruby executes at_exit
132
- # blocks in reverse order so if Drydock is required first, it's block
133
- # will run after Rye shuts down the ssh-agent.
134
- begin
135
- Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
136
- rescue Drydock::ArgError, Drydock::OptError=> ex
137
- STDERR.puts ex.message
138
- STDERR.puts ex.usage
139
- rescue => ex
140
- STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}"
141
- STDERR.puts ex.backtrace if Drydock.debug?
142
- rescue Interrupt
143
- puts "#{$/}Exiting... "
144
- exit 1
145
- rescue SystemExit
146
- # Don't balk
147
- end