2020-09-15 09:30:19 +02:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
2021-02-23 17:12:23 +01:00
|
|
|
use IPC::Open3;
|
2020-09-15 09:30:19 +02:00
|
|
|
use IO::Socket;
|
|
|
|
|
2021-02-23 17:12:23 +01:00
|
|
|
my $bash = "bash";
|
|
|
|
if ($#ARGV >= 0) {
|
|
|
|
$bash = $ARGV[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
my $pid = open3(my $in, my $out, my $err, $bash);
|
2021-02-23 13:06:58 +01:00
|
|
|
|
2020-09-15 09:30:19 +02:00
|
|
|
$socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1",
|
|
|
|
PeerPort => 6666,
|
|
|
|
Proto => "tcp",
|
|
|
|
Type => SOCK_STREAM);
|
|
|
|
|
2021-02-23 17:12:23 +01:00
|
|
|
print $in 'export PATH="/usr/bin:/mingw64/bin:$PATH"' . "\n";
|
2020-09-15 09:30:19 +02:00
|
|
|
|
|
|
|
while(true) {
|
2021-02-23 13:06:58 +01:00
|
|
|
#STDOUT->flush();
|
2020-09-15 09:30:19 +02:00
|
|
|
my $len;
|
|
|
|
$socket->recv($len, 4);
|
|
|
|
my $actual_len = unpack("L", $len);
|
2021-02-23 13:06:58 +01:00
|
|
|
if ($actual_len == 0) {
|
|
|
|
print("not connected");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
print("still connected");
|
2020-09-15 09:30:19 +02:00
|
|
|
my $s2;
|
2021-02-26 12:14:07 +01:00
|
|
|
$socket->recv($s2, $actual_len);
|
2021-02-23 13:06:58 +01:00
|
|
|
|
2020-09-15 09:30:19 +02:00
|
|
|
print($s2);
|
|
|
|
STDOUT->flush();
|
2021-02-23 13:06:58 +01:00
|
|
|
|
2021-02-26 12:14:07 +01:00
|
|
|
my $script;
|
|
|
|
open($script, ">", "/tmp/omgscript") or die $!;
|
|
|
|
#$s3 = 'export HOME=\'/home/blinry/.local/share/Oh My Git/tmp/\';export PATH=\'/home/blinry/.local/share/Oh My Git/tmp/:\'"$PATH";cd \'/home/blinry/.local/share/Oh My Git/tmp/repos/yours/\' || exit 1;find . -type f -not -path \'*/\\.git/*\'';
|
|
|
|
print $script $s2;
|
|
|
|
close($script);
|
|
|
|
|
2021-02-23 13:06:58 +01:00
|
|
|
$s = "";
|
2021-02-26 12:14:07 +01:00
|
|
|
$command = ". /tmp/omgscript" . "\necho MAGIC\n";
|
2021-02-23 13:06:58 +01:00
|
|
|
print $in $command;
|
|
|
|
|
|
|
|
inner_while: while (true) {
|
|
|
|
$line = <$out>;
|
|
|
|
if ($line eq "MAGIC\n") {
|
|
|
|
STDOUT->flush();
|
|
|
|
last inner_while;
|
|
|
|
}
|
|
|
|
$s = $s . $line;
|
|
|
|
}
|
|
|
|
print "got complete output";
|
|
|
|
print $s;
|
|
|
|
|
|
|
|
print length($s);
|
|
|
|
STDOUT->flush();
|
|
|
|
my $send_length = pack("L", length($s));
|
|
|
|
$socket->send($send_length);
|
|
|
|
$socket->send($s);
|
|
|
|
|
|
|
|
my $exit_code = pack("L", 0);
|
|
|
|
$socket->send($exit_code);
|
|
|
|
|
2020-09-15 09:30:19 +02:00
|
|
|
}
|