rye 0.8.19 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.txt +17 -1
- data/README.rdoc +2 -29
- data/bin/try +42 -13
- data/lib/rye/box.rb +318 -224
- data/lib/rye/cmd.rb +156 -78
- data/lib/rye/rap.rb +10 -6
- data/lib/rye.rb +32 -5
- data/rye.gemspec +4 -7
- metadata +68 -49
- data/bin/rye +0 -147
data/CHANGES.txt
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
RYE, CHANGES
|
2
2
|
|
3
|
+
|
4
|
+
#### 0.9.0 (2010-08-19) #############################
|
5
|
+
|
6
|
+
* FIXED: Pubkeys correctly added for first connection.
|
7
|
+
(NOTE: some state seems to be maintained by ssh-agent)
|
8
|
+
* ADDED: Interactive and non-interactive shell support (via Net::SSH)
|
9
|
+
* ADDED: Basic readline support for interactive mode
|
10
|
+
* ADDED: New hook for printing STDOUT as it is returned
|
11
|
+
* CHANGE: Removed bin/rye
|
12
|
+
* CHANGE: Removed authorize_keys_remote and authorize_keys_local
|
13
|
+
|
14
|
+
|
15
|
+
#### 0.8.20 (2010-08-17) #############################
|
16
|
+
|
17
|
+
* ADDED: string_append, template_write, template_upload, file_modify
|
18
|
+
|
3
19
|
#### 0.8.19 (2010-06-28) #############################
|
4
20
|
|
5
21
|
* ADDED: Rye::Box#root?
|
@@ -307,7 +323,7 @@ Rye.shell and Rye::Box.run_command (SSH) commands.
|
|
307
323
|
* ADDED: Command switches can now be sent as Symbols (rbox.ls(:h))
|
308
324
|
* ADDED: Rye.host_keys
|
309
325
|
* ADDED: bin/rye
|
310
|
-
* ADDED: commands now raise a Rye::
|
326
|
+
* ADDED: commands now raise a Rye::Err exception
|
311
327
|
when the command returns an exit code greater than 0.
|
312
328
|
* CHANGE: Box.add_command renamed to Box.run_command
|
313
329
|
|
data/README.rdoc
CHANGED
@@ -11,33 +11,6 @@ Rye is a Ruby abstraction for executing shell commands via SSH. By default, Rye
|
|
11
11
|
|
12
12
|
Rye does not require anything to be installed on the server side (other than an SSH daemon) so it can be run from any machine with Ruby, OpenSSL, and OpenSSH.
|
13
13
|
|
14
|
-
=== SSH keys
|
15
|
-
|
16
|
-
You need SSH keys to use Rye. After installing Rye, you can check if you have any by running:
|
17
|
-
|
18
|
-
$ rye
|
19
|
-
|
20
|
-
If you get the message <i>"The agent has no identities"</i> you will need to generate a keypair.
|
21
|
-
|
22
|
-
$ ssh-keygen
|
23
|
-
|
24
|
-
|
25
|
-
=== Passwordless SSH authorization
|
26
|
-
|
27
|
-
The easiest way to work with Rye is to authorize your remote accounts for passwordless logins (otherwise you'll be prompted for a password for every connection).
|
28
|
-
|
29
|
-
Enable passwordless logins to remote HOST1 and HOST2:
|
30
|
-
|
31
|
-
$ rye authorize HOST1 HOST2
|
32
|
-
|
33
|
-
This will copy your public SSH keys to the <tt>~/.ssh/authorized_keys</tt> and <tt>~/.ssh/authorized_keys2</tt> files on the remote machine(s).
|
34
|
-
|
35
|
-
Enable passwordless logins to the local machine:
|
36
|
-
|
37
|
-
$ rye authorize-local
|
38
|
-
|
39
|
-
See <tt>rye -h</tt> for more info.
|
40
|
-
|
41
14
|
|
42
15
|
== Example 1 -- Execute commands on a remote machine
|
43
16
|
|
@@ -53,7 +26,7 @@ The return value for a command is a modified Array containing the contents of ST
|
|
53
26
|
|
54
27
|
ret = rbox.uptime # => "11:02 up 16:01, 3 users"
|
55
28
|
ret.stderr # => []
|
56
|
-
ret.
|
29
|
+
ret.exit_status # => 0
|
57
30
|
ret.stdout # => "11:02 up 16:01, 3 users"
|
58
31
|
ret.stdout.class # => Array
|
59
32
|
ret.class # => Rye::Rap
|
@@ -161,7 +134,7 @@ The first argument must be the command name and the remaining arguments are sent
|
|
161
134
|
The return value is a Rye::Rap object (just like with Rye::Box) so you have access to the exit code and STDERR output:
|
162
135
|
|
163
136
|
ret = Rye.shell :ls, 'nofile'
|
164
|
-
ret.
|
137
|
+
ret.exit_status # => 1
|
165
138
|
ret.stderr # => "sh: nofile: No such file or directory"
|
166
139
|
ret.class # => Rye::Rap
|
167
140
|
|
data/bin/try
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
+
# encoding: UTF-8
|
2
3
|
|
3
4
|
# Rye -- A working example
|
4
5
|
#
|
@@ -61,8 +62,8 @@ rbox_wild = Rye::Box.new('localhost', :safe => false)
|
|
61
62
|
# arguments are thoroughly escaped. This prevents access to
|
62
63
|
# environment variables and file globs (among other things).
|
63
64
|
p rbox_safe.echo('$HOME') # => "$HOME"
|
64
|
-
p rbox_safe['/etc'].ls('host*') rescue Rye::
|
65
|
-
p rbox_safe.ls('-l | wc -l') rescue Rye::
|
65
|
+
p rbox_safe['/etc'].ls('host*') rescue Rye::Err # Doesn't exist
|
66
|
+
p rbox_safe.ls('-l | wc -l') rescue Rye::Err # => '|' is not a valid ls arg
|
66
67
|
|
67
68
|
# Here's the same commands with safe-mode disabled:
|
68
69
|
p rbox_wild.echo('$HOME') # => "/home/rye"
|
@@ -82,7 +83,7 @@ rbox = Rye::Box.new('localhost')
|
|
82
83
|
rbox.add_keys('/private/key/path') # Specify additional private keys
|
83
84
|
|
84
85
|
# There's currently no rye900 command
|
85
|
-
p rbox.
|
86
|
+
p rbox.command?('rye9000') # => false
|
86
87
|
|
87
88
|
# But we can add our own commands to the Rye::Cmd class. They
|
88
89
|
# automatically become available to all Rye::Box objects.
|
@@ -97,7 +98,7 @@ end
|
|
97
98
|
|
98
99
|
# We can now run rye9000 (with arguments)
|
99
100
|
p rbox.rye9000('-a') # => [".", "..", ".bashrc", ...]
|
100
|
-
p rbox.
|
101
|
+
p rbox.command?('rye9000') # => true
|
101
102
|
|
102
103
|
|
103
104
|
puts %Q(
|
@@ -146,12 +147,12 @@ puts %Q(
|
|
146
147
|
rbox = Rye::Box.new('localhost', :safe => false) # Note: safe mode is off
|
147
148
|
|
148
149
|
# Rye follows the standard convention of taking exception to a non-zero
|
149
|
-
# exit code by raising a Rye::
|
150
|
+
# exit code by raising a Rye::Err. In this case, rye9000.test
|
150
151
|
# is not found by the ls command.
|
151
152
|
begin
|
152
153
|
rbox.ls('rye.test')
|
153
|
-
rescue Rye::
|
154
|
-
puts ex.
|
154
|
+
rescue Rye::Err => ex
|
155
|
+
puts ex.exit_status # => 1
|
155
156
|
puts ex.stderr # => ls: rye.test: No such file or directory
|
156
157
|
end
|
157
158
|
|
@@ -164,7 +165,7 @@ puts rbox.uname('-a 1>&2').stdout # =>
|
|
164
165
|
puts rbox.uname('-a 1>&2').stderr # => Darwin ryehost 9.6.0 ...
|
165
166
|
|
166
167
|
# There were no actual errors so the exit code should be 0.
|
167
|
-
puts rbox.uname('-a 1>&2').
|
168
|
+
puts rbox.uname('-a 1>&2').exit_status # => 0
|
168
169
|
|
169
170
|
|
170
171
|
puts %Q(
|
@@ -172,10 +173,10 @@ puts %Q(
|
|
172
173
|
# EXAMPLE 6 -- FILE TRANSFERS
|
173
174
|
#)
|
174
175
|
|
175
|
-
dir_upload = "#{Rye.sysinfo.tmpdir}
|
176
|
-
dir_download = "#{Rye.sysinfo.tmpdir}
|
176
|
+
dir_upload = "#{Rye.sysinfo.tmpdir}rye-upload"
|
177
|
+
dir_download = "#{Rye.sysinfo.tmpdir}rye-download"
|
177
178
|
|
178
|
-
rbox = Rye::Box.new("localhost", :info =>
|
179
|
+
rbox = Rye::Box.new("localhost", :info => STDOUT)
|
179
180
|
|
180
181
|
# Rye ships without an rm method (for safety!). Here
|
181
182
|
# we add the rm method only to this instance of rbox.
|
@@ -201,7 +202,33 @@ p filecontent.read
|
|
201
202
|
|
202
203
|
puts %Q(
|
203
204
|
# ------------------------------------------------------------------
|
204
|
-
# EXAMPLE 7 --
|
205
|
+
# EXAMPLE 7 -- FILE TRANSFERS w/ VARIABLE INTERPOLATION
|
206
|
+
#)
|
207
|
+
|
208
|
+
dir_upload = "#{Rye.sysinfo.tmpdir}rye-upload"
|
209
|
+
dir_download = "#{Rye.sysinfo.tmpdir}rye-download"
|
210
|
+
|
211
|
+
rbox = Rye::Box.new("localhost", :info => STDOUT)
|
212
|
+
|
213
|
+
# Rye ships without an rm method (for safety!). Here
|
214
|
+
# we add the rm method only to this instance of rbox.
|
215
|
+
def rbox.rm(*args); __allow('rm', args); end
|
216
|
+
|
217
|
+
rbox.rm(:r, :f, dir_upload) # Silently delete test dirs
|
218
|
+
rbox.rm(:r, :f, dir_download)
|
219
|
+
|
220
|
+
template = StringIO.new("Can we use templates? <%= 'Yes!' %>")
|
221
|
+
rbox.mkdir dir_upload
|
222
|
+
|
223
|
+
rbox.template_write("#{dir_upload}/template.txt", template)
|
224
|
+
|
225
|
+
p rbox.ls(dir_upload) # => [template.txt]
|
226
|
+
p rbox.cat("#{dir_upload}/template.txt") # => "Can we use templates? Yes!"
|
227
|
+
|
228
|
+
|
229
|
+
puts %Q(
|
230
|
+
# ------------------------------------------------------------------
|
231
|
+
# EXAMPLE 8 -- LOCAL PROCESSES
|
205
232
|
#)
|
206
233
|
|
207
234
|
p Rye.shell :uptime
|
@@ -210,8 +237,10 @@ p Rye.shell :ls, '*'
|
|
210
237
|
p Rye.shell :ls, '-l $HOME'
|
211
238
|
p Rye.shell :ls, :l, '$HOME > crazy.txt'
|
212
239
|
|
240
|
+
Rye.shell :rm, 'crazy.txt'
|
241
|
+
|
213
242
|
ret = Rye.shell :ls, 'nofile'
|
214
|
-
p ret.
|
243
|
+
p ret.exit_status # => 1
|
215
244
|
p ret.stderr # => "sh: nofile: No such file or directory"
|
216
245
|
p ret.class # => Rye::Rap
|
217
246
|
|