lib/shexy.rb in shexy-0.3.3 vs lib/shexy.rb in shexy-0.3.4
- old
+ new
@@ -31,11 +31,11 @@
# Shexy.copy_to 'test@test-host', '/home/rubiojr/my-uber-file', '/tmp/'
#
module Shexy
- VERSION = '0.3.3'
+ VERSION = '0.3.4'
[:user, :password, :key, :cmd, :host].each do |n|
instance_eval %{
def #{n}; Thread.current[:shexy_#{n}]; end
def #{n}=(v); Thread.current[:shexy_#{n}] = v; end
@@ -101,11 +101,15 @@
# http://net-ssh.github.com/net-ssh/classes/Net/SSH/Connection/Channel.html#method-i-request_pty
#
# FIXME: may not be successful, warn about it
ch.request_pty
if sudo?
- if cmd =~ /(&&|\|\||&|\|)/
- self.cmd = cmd.gsub(/(&&|\|\||&|\|)/, $1 + 'sudo')
+ regexp = /(&&|\|\||&|\|)/
+ if cmd =~ regexp
+ new_cmd = cmd.split(regexp).map do |t|
+ t =~ /^(&&|\|\||&|\|)$/ ? t : "sudo #{t}"
+ end
+ self.cmd = new_cmd.join ''
end
self.cmd = "sudo #{cmd}"
puts "SHEXY: #{cmd}" if $DEBUG
end
ch.exec cmd do