2 # Perl wrapper around rsh/remsh to export DISPLAY and run an xterm
4 # remoteshell hostname [-l remoteuser]
9 $rsh= shift if $ARGV[0] =~ s/^-r//;
10 $usesh= shift if $ARGV[0] =~ s/^-s//;
12 ($remotehost= shift) || die "need hostname\n";
13 $remotehost= (gethostbyname($remotehost))[0] || $remotehost;
15 if ($ARGV[0] eq '-l') {
17 ($remoteuser= shift) || die "need username after -l\n";
18 $remoteuser= "-l $remoteuser";
19 } elsif (open(H,"$ENV{'HOME'}/.rhosts")) {
21 m/^(\S+)\s+(\S+)\s*$/ || next;
22 if (&canon($1) eq &canon($remotehost)) {
30 m/:/ || die "\$DISPLAY variable format `$_' bad";
31 $ENV{'DISPLAY'}= &canon($`).':'.$';
36 chomp($h= `hostname`) unless length($h);
37 @h= gethostbyname($h);
39 @v= gethostbyaddr($h[4],$h[2]);
41 # unless ($v =~ m/\./) {
49 open(U,"|$rsh $remotehost $remoteuser perl")
50 || die "failed to run $rsh: $!";
53 $_= <DATA>; chop; @ar= split(/\0/,$_) if length($_);
54 $_= <DATA>; chop; $ENV{'DISPLAY'}= $_;
55 $_= <DATA>; chop; $usesh= $_;
56 $host= <DATA>; chop($host);
57 $pcmd= '. .configs/setenvir; echo ok $PATH';
59 $pout =~ m/^ok (\S+)\n$/ || die "pcmd gave `$pout'";
61 open(X,"|xauth nmerge -");
62 while (<DATA>) { print X; }
64 $? && die "xauth gave code $?";
65 defined($c= fork) || die "fork: $!";
67 close(STDIN); close(STDOUT);
68 open(STDIN,"</dev/null") || die "/dev/null for stdin: $!";
69 open(STDOUT,">>.remoteshell-errors") || die "append .remoteshell-errors: $!";
70 chmod(0600,".remoteshell-errors");
71 close(STDERR); open(STDERR,">&STDOUT");
73 exec('close3onwards','xterm','-T',$host,@ar,'-e','.configs/rxprofile');
75 exec('close3onwards',$usesh,'-xc','. .configs/setenvir; exec "$@"','-',@ar);
77 print STDERR "close3onwards: $!\n";
82 print U join("\0",@ARGV),"\n";
83 print U $ENV{'DISPLAY'},"\n";
85 print U $remotehost,"\n";
86 print U `xauth nextract - $ENV{'DISPLAY'}`;
89 $? && die "remoteshell $rsh gave code $?";