From: Fredrik Tolf Date: Mon, 6 Mar 2017 02:50:02 +0000 (+0100) Subject: Revert "Replaced rsc with a bash version without remote dependencies." X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=bae800dc458b8ad539b6c66f3a9b855fdc9f33e6;hp=338cc72b0326d2aa3aeb08b1fa1c11f2a4b6415f;p=utils.git Revert "Replaced rsc with a bash version without remote dependencies." This reverts commit 58f76900e49d86a221d68b015379063b753dda3f. --- diff --git a/rsc b/rsc index faa3264..74be3fd 100755 --- a/rsc +++ b/rsc @@ -1,18 +1,48 @@ -#!/bin/bash +#!/usr/bin/perl -set -e +use MIME::Base64; -if [ $# -lt 2 ]; then - echo "usage: rsc HOST COMMAND ARGS..." >&2 - exit 1 -fi +if(@ARGV < 1) { + print STDERR "usage: rsc HOST CMD ARG...\n"; + exit 1; +} -host="$1"; shift -cmd="$1"; shift - -( - echo -n "$cmd"; echo -ne '\0' - for arg in "$@"; do - echo -n "$arg"; echo -ne '\0' - done -) | exec ssh "$host" "xargs -0x sh -c 'exec \$0 \"\$@\"'" +if($ARGV[0] eq "-s") { + if(!defined($ARGV[1])) { + print STDERR "rsc: server side needs arguments\n"; + exit 1 + } + $arg = decode_base64($ARGV[1]); + $c = ""; + for (split /\n/, $arg) { + chomp; + s/\\(.)/$1/g; + $c .= $_; + if(/\\$/) { + $c =~ s/\\$/\n/; + next; + } + push @a, $c; + $c = ""; + } + for (@a) { + exec @a; + print STDERR "$a[0]: $!\n"; + exit 1; + } +} else { + $host = shift @ARGV; + $arg = ""; + for (@ARGV) { + s/([\\\n])/\\$1/g; + $arg .= "$_\n"; + } + $ea = encode_base64($arg); + $ea =~ s/\n//g; + if(-t STDIN) { + push @sshopts, "-t"; + } + push @sshopts, "-q"; + exec "ssh", @sshopts, "$host", "rsc", "-s", $ea; + die "$!"; +}