minisync/c.rb

47 lines
787 B
Ruby
Raw Normal View History

2010-09-27 13:40:21 +02:00
#!/usr/bin/env ruby
2010-09-29 13:33:50 +02:00
libexec = File.expand_path File.dirname( __FILE__)
machine, source, destination = ARGV[0...3]
2010-09-27 16:33:31 +02:00
2010-09-27 15:34:24 +02:00
class IO
def readall
buf = ''
loop do
buf << begin
self.sysread 4096
rescue EOFError
return buf
end
end
end
end
class File
def self.readall file
open( file) {|f| f.readall }
end
end
2010-09-27 16:42:03 +02:00
class String
def shdump
"'#{gsub( /[\\']/, '\'\\\\\&\'')}'"
end
end
2010-09-27 16:33:31 +02:00
$tor = tor = IO.pipe
$tos = tos = IO.pipe
2010-09-27 13:40:21 +02:00
2010-09-30 16:58:20 +02:00
Process.fork do
2010-09-27 13:40:21 +02:00
$stdin.reopen tor.first
2010-09-27 16:33:31 +02:00
tor.last.close
2010-09-27 13:40:21 +02:00
$stdout.reopen tos.last
2010-09-27 16:33:31 +02:00
tos.first.close
2010-09-29 13:33:50 +02:00
exec 'ssh', machine, 'perl', '-e', File.readall( File.join( libexec, 's.pl')).shdump, source.shdump
2010-09-27 16:33:31 +02:00
end
2010-09-30 16:58:20 +02:00
$stdin.reopen tos.first
tos.last.close
$stdout.reopen tor.last
tor.first.close
exec 'perl', File.join( libexec, 'r.pl'), destination