Install on client with:
- echo install | nc 10.60.0.92 9001 > bak ; chmod 755 bak
+ echo install | nc 127.0.0.1 9001 > bak ; chmod 755 bak
+
+Start server with:
+
+ ./server.pl /path/to/backup 127.0.0.1
+
+You will want to add following to C<~/.ssh/config>
+
+ RemoteForward 9001 localhost:9001
=cut
use IO::Socket::INET;
use File::Path;
-my $dir = shift @ARGV || die "usage: $0 /backup/directory\n";
+my ( $dir, $server_ip ) = @ARGV;
+die "usage: $0 /backup/directory\n" unless $dir;
+$server_ip ||= '127.0.0.1';
+
+my $shell_client = <<__SHELL_CLIENT__;
+#!/bin/sh
+echo `pwd` \$* | nc $server_ip 9001
+__SHELL_CLIENT__
chdir $dir;
system 'git init' unless -e '.git';
my $server = IO::Socket::INET->new(
Proto => 'tcp',
+ LocalAddr => $server_ip,
LocalPort => 9001,
Listen => SOMAXCONN,
Reuse => 1
) || die $!;
+
+warn "dir: $dir listen: $server_ip:9001\n"
+ , "remote-host> echo install | nc $server_ip 9001 > bak ; chmod 755 bak\n"
+ , $shell_client
+;
+
while (my $client = $server->accept()) {
my ($pwd,$command,$path,$message) = split(/\s+/,<$client>,4);
my $ip = $client->peerhost;
- $message ||= '';
- $path = "$pwd/$path" unless $path =~ m{^/};
-
- if ( $command eq 'install' ) {
- print $client '#!/bin/sh',$/,'echo `pwd` $* | nc 10.60.0.92 9001',$/;
+ if ( $pwd eq 'install' ) {
+ warn "install on $ip\n";
+ print $client $shell_client;
+ close($client);
next;
}
+ $message ||= '';
+ $path = "$pwd/$path" unless $path =~ m{^/};
+
warn "$ip [$command] $path | $message\n";
if ( ! -d $ip ) {