rye 0.8.18 → 0.8.19

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,5 +1,11 @@
1
1
  RYE, CHANGES
2
2
 
3
+ #### 0.8.19 (2010-06-28) #############################
4
+
5
+ * ADDED: Rye::Box#root?
6
+ * ADDED: Better sudo handling.
7
+
8
+
3
9
  #### 0.8.18 (2010-06-19) #############################
4
10
 
5
11
  * FIXED: Authentication would never succeed if the first password attempt failed.
data/README.rdoc CHANGED
@@ -166,7 +166,6 @@ The return value is a Rye::Rap object (just like with Rye::Box) so you have acce
166
166
  ret.class # => Rye::Rap
167
167
 
168
168
 
169
-
170
169
  == About Safe-Mode
171
170
 
172
171
  In safe-mode:
data/lib/rye.rb CHANGED
@@ -42,7 +42,7 @@ require 'esc'
42
42
  module Rye
43
43
  extend self
44
44
 
45
- VERSION = "0.8.18".freeze unless defined?(VERSION)
45
+ VERSION = "0.8.19".freeze unless defined?(VERSION)
46
46
 
47
47
  @@sysinfo = nil
48
48
  @@agent_env = Hash.new # holds ssh-agent env vars
data/lib/rye/box.rb CHANGED
@@ -33,6 +33,11 @@ module Rye
33
33
  def opts; @rye_opts; end
34
34
  def safe; @rye_safe; end
35
35
  def user; @rye_user; end
36
+ def root?; user.to_s == "root" end
37
+
38
+ def enable_sudo; @rye_sudo = true; end
39
+ def disable_sudo; @rye_sudo = false; end
40
+ def sudo?; @rye_sudo == true end
36
41
 
37
42
  # Returns the current value of the stash +@rye_stash+
38
43
  def stash; @rye_stash; end
@@ -84,6 +89,7 @@ module Rye
84
89
  # * :error => an IO object to print Rye::Box errors to. Default: STDERR
85
90
  # * :getenv => pre-fetch +host+ environment variables? (default: true)
86
91
  # * :password => the user's password (ignored if there's a valid private key)
92
+ # * :sudo => Run all commands via sudo (default: false)
87
93
  #
88
94
  # NOTE: +opts+ can also contain any parameter supported by
89
95
  # Net::SSH.start that is not already mentioned above.
@@ -121,7 +127,7 @@ module Rye
121
127
  @rye_info, @rye_error = @rye_opts.delete(:info), @rye_opts.delete(:error)
122
128
  @rye_getenv = {} if @rye_opts.delete(:getenv) # Enable getenv with a hash
123
129
  @rye_ostype, @rye_impltype = @rye_opts.delete(:ostype), @rye_opts.delete(:impltype)
124
- @rye_quiet = @rye_opts.delete(:quiet)
130
+ @rye_quiet, @rye_sudo = @rye_opts.delete(:quiet), @rye_opts.delete(:sudo)
125
131
 
126
132
  # Just in case someone sends a true value rather than IO object
127
133
  @rye_debug = STDERR if @rye_debug == true
@@ -430,10 +436,16 @@ module Rye
430
436
  # We need to rewind so that all of the StringIO object is uploaded
431
437
  authorized_keys.rewind
432
438
 
433
- self.mkdir(:p, :m, '700', File.dirname(akey_path))
434
- self.file_upload(authorized_keys, "#{homedir}/#{akey_path}")
435
- self.chmod('0600', akey_path)
436
- self.chown(:R, this_user.to_s, File.dirname(akey_path))
439
+ full_path = "#{homedir}/#{akey_path}"
440
+ temp_path = "/tmp/rye-#{user}-#{File.basename(akey_path)}"
441
+
442
+ sudo do
443
+ mkdir :p, :m, '700', File.dirname(akey_path)
444
+ file_upload authorized_keys, temp_path
445
+ mv temp_path, full_path
446
+ chmod '0600', akey_path
447
+ chown :R, this_user.to_s, File.dirname(akey_path)
448
+ end
437
449
  end
438
450
 
439
451
  # And let's return to the directory we came from.
@@ -587,6 +599,24 @@ module Rye
587
599
  ret
588
600
  end
589
601
 
602
+ # Like batch, except it enables sudo mode before executing the block.
603
+ # If the user is already root, this has no effect. Otherwise all
604
+ # commands executed in the block will run via sudo.
605
+ #
606
+ # If no block is specified then sudo is called just like a regular
607
+ # command.
608
+ def sudo(*args, &block)
609
+ if block.nil?
610
+ __allow('sudo', args);
611
+ else
612
+ previous_state = @rye_sudo
613
+ enable_sudo
614
+ ret = self.instance_exec *args, &block
615
+ @rye_sudo = previous_state
616
+ ret
617
+ end
618
+ end
619
+
590
620
  # instance_exec for Ruby 1.8 written by Mauricio Fernandez
591
621
  # http://eigenclass.org/hiki/instance_exec
592
622
  if RUBY_VERSION =~ /1.8/
@@ -816,7 +846,7 @@ module Rye
816
846
  def prep_args(*args)
817
847
  args = args.flatten.compact
818
848
  args = args.first.to_s.split(/\s+/) if args.size == 1
819
- cmd = args.shift
849
+ cmd = sudo? ? :sudo : args.shift
820
850
 
821
851
  # Symbols to switches. :l -> -l, :help -> --help
822
852
  args.collect! do |a|
data/lib/rye/cmd.rb CHANGED
@@ -48,7 +48,6 @@ module Rye;
48
48
 
49
49
  #def kill(*args); __allow('kill', args); end
50
50
  def rake(*args); __allow('rake', args); end
51
- def sudo(*args); __allow('sudo', args); end
52
51
  def grep(*args); __allow('grep', args); end
53
52
  def date(*args); __allow('date', args); end
54
53
  def ruby(*args); __allow('ruby', args); end
data/lib/rye/set.rb CHANGED
@@ -50,6 +50,7 @@ module Rye
50
50
 
51
51
  def opts; @opts; end
52
52
  def user; (@opts || {})[:user]; end
53
+ def root?; user.to_s == "root" end
53
54
 
54
55
  # * +boxes+ one or more boxes. Rye::Box objects will be added directly
55
56
  # to the set. Hostnames will be used to create new instances of Rye::Box
data/rye.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "rye"
3
3
  s.rubyforge_project = "rye"
4
- s.version = "0.8.18"
4
+ s.version = "0.8.19"
5
5
  s.summary = "Rye: Safely run SSH commands on a bunch of machines at the same time (from Ruby)."
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rye
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.18
4
+ version: 0.8.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-06-19 00:00:00 -04:00
12
+ date: 2010-06-27 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency