From: Dobrica Pavlinusic Date: Wed, 17 Feb 2010 19:34:06 +0000 (+0100) Subject: simple listener which store files in git X-Git-Url: http://git.rot13.org/?p=bak-git.git;a=commitdiff_plain;h=2c8b00852dfa96e29a8063d65416d8e3a4c13c17 simple listener which store files in git --- 2c8b00852dfa96e29a8063d65416d8e3a4c13c17 diff --git a/server.pl b/server.pl new file mode 100755 index 0000000..bf8e56d --- /dev/null +++ b/server.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use autodie; +use IO::Socket::INET; +use File::Path; + +my $dir = '../backup'; + +chdir $dir; +system 'git init' unless -e '.git'; + +my $server = IO::Socket::INET->new( + Proto => 'tcp', + LocalPort => 9001, + Listen => SOMAXCONN, + Reuse => 1 +); + +while (my $client = $server->accept()) { + my ($command,$path,$message) = split(/\s+/,<$client>,3); + my $ip = $client->peerhost; + + warn "$ip [$command] $path | $message\n"; + + if ( ! -d $ip ) { + system 'ssh-copy-id', "root\@$ip"; + } + + + my $dir = $path; + $dir =~ s{/[^/]+$}{}; + + mkpath "$ip/$dir" unless -e "$ip/$dir"; + + if ( $command eq 'add' ) { + warn 'rsync', "root\@$ip:$path", "$ip/$path"; + system 'rsync', "root\@$ip:$path", "$ip/$path"; + system 'git', 'add', "$ip/$path"; + } else { + system 'rsync', "root\@$ip:$path", "$ip/$path"; + } + + $message ||= "$command $ip $path"; + system 'git', 'commit', '-m', $message, "$ip/$path"; +} +