Added gpotp.
[utils.git] / rsc
CommitLineData
bae800dc 1#!/usr/bin/perl
df499390 2
bae800dc 3use MIME::Base64;
535cc97f 4
bae800dc
FT
5if(@ARGV < 1) {
6 print STDERR "usage: rsc HOST CMD ARG...\n";
7 exit 1;
8}
df499390 9
bae800dc
FT
10if($ARGV[0] eq "-s") {
11 if(!defined($ARGV[1])) {
12 print STDERR "rsc: server side needs arguments\n";
13 exit 1
14 }
15 $arg = decode_base64($ARGV[1]);
16 $c = "";
17 for (split /\n/, $arg) {
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;
35 $arg = "";
36 for (@ARGV) {
37 s/([\\\n])/\\$1/g;
38 $arg .= "$_\n";
39 }
40 $ea = encode_base64($arg);
41 $ea =~ s/\n//g;
42 if(-t STDIN) {
43 push @sshopts, "-t";
44 }
45 push @sshopts, "-q";
46 exec "ssh", @sshopts, "$host", "rsc", "-s", $ea;
47 die "$!";
48}