X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=bak-git-server.pl;h=1c8efc1303b5560ad340f3564bd7736bba45827b;hb=b3e5588a5f136f8c1c72f693327c39c8937ef9c1;hp=50425517befabf24210cb3e21da0b64d0d829b28;hpb=d660b279881be61696581461689011234cf971bd;p=bak-git.git diff --git a/bak-git-server.pl b/bak-git-server.pl index 5042551..1c8efc1 100755 --- a/bak-git-server.pl +++ b/bak-git-server.pl @@ -26,8 +26,12 @@ bak command overview: bak ch[anges] bak revert [host:]/path + bak cat [host:]/path + bak - push all changed files to server +See L for more information + =cut use warnings; @@ -158,6 +162,7 @@ while (my $client = $server->accept()) { $command = 'log --patch-with-stat' if $command =~ m/^ch/; pull_changes( $hostname ) if $command eq 'diff'; if ( $on_host ) { + system 'rsync', '-avv', "root\@$hostname:$path", "$hostname/$path"; system 'rsync', '-avv', "root\@$on_host:$path", "$on_host/$path"; open(my $diff, '-|', "diff -Nuw $hostname$path $on_host$path"); while(<$diff>) { @@ -165,7 +170,7 @@ while (my $client = $server->accept()) { } } else { # commands without path will show host-wide status/changes - my $backup_path = $rel_path ? $backup_path : "$hostname/"; + my $backup_path = $path ? "$hostname/$path" : "$hostname/"; # hostname must end with / to prevent error from git: # ambiguous argument 'arh-hw': both revision and filename # to support branches named as hosts @@ -178,6 +183,13 @@ while (my $client = $server->accept()) { print $client git "checkout -- $hostname/$path"; system 'rsync', '-avv', "$hostname/$path", "root\@$hostname:$path"; } + } elsif ( $command eq 'cat' ) { + my $file_path = ( $on_host ? $on_host : $hostname ) . "/$path"; + open(my $file, '<', $file_path) || warn "ERROR $file_path: $!"; + while(<$file>) { + print $client $_; + } + close($file); } else { print $client "Unknown command: $command\n"; }