Initial checkin of miditool.
[utils.git] / rsc
CommitLineData
df499390 1#!/usr/bin/perl
2
535cc97f 3use MIME::Base64;
4
df499390 5if(@ARGV < 1) {
6 print STDERR "usage: rsc HOST CMD ARG...\n";
7 exit 1;
8}
9
10if($ARGV[0] eq "-s") {
535cc97f 11 if(!defined($ARGV[1])) {
12 print STDERR "rsc: server side needs arguments\n";
13 exit 1
14 }
15 $arg = decode_base64($ARGV[1]);
df499390 16 $c = "";
535cc97f 17 for (split /\n/, $arg) {
df499390 18 chomp;
19 s/\\(.)/$1/g;
20 $c .= $_;
21 if(/\\$/) {
22 $c =~ s/\\$/\n/;
23 next;
24 }
25 push @a, $c;
26 $c = "";
27 }
28 for (@a) {
29 exec @a;
30 print STDERR "$a[0]: $!\n";
31 exit 1;
32 }
33} else {
34 $host = shift @ARGV;
535cc97f 35 $arg = "";
df499390 36 for (@ARGV) {
37 s/([\\\n])/\\$1/g;
535cc97f 38 $arg .= "$_\n";
df499390 39 }
222d2034 40 $ea = encode_base64($arg);
41 $ea =~ s/\n//g;
33dc94de 42 if(-t STDIN) {
43 push @sshopts, "-t";
44 }
8e8187f1 45 push @sshopts, "-q";
33dc94de 46 exec "ssh", @sshopts, "$host", "rsc", "-s", $ea;
535cc97f 47 die "$!";
df499390 48}