Initial implementation of rsync-shell functionality.
authormwolson_admin <mwolson_admin@deleuze.hcoop.net>
Wed, 3 Sep 2008 07:55:11 +0000 (03:55 -0400)
committermwolson_admin <mwolson_admin@deleuze.hcoop.net>
Wed, 3 Sep 2008 07:55:11 +0000 (03:55 -0400)
rsync-shell [new file with mode: 0755]

diff --git a/rsync-shell b/rsync-shell
new file mode 100755 (executable)
index 0000000..71482d3
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings FATAL => 'all';
+
+use constant LOGFILE => '/var/log/rsync-shell.log';
+
+my %commands = (
+    "backup" => \&backup,
+    "rsync"  => \&rsync,
+);
+
+sub backup {
+  exec '/usr/bin/sudo',
+    '/afs/hcoop.net/common/etc/scripts/hcoop-backup-wrapper';
+}
+
+sub rsync {
+  my ($cmdline) = @_;
+
+  if ( $cmdline !~ m!^--server --sender -vre\.iL \. /vicepa/hcoop-backups/files/[0-9]{4}\.[0-9]{2}\.[0-9]{2}$!s ) {
+    die "Incorrect arguments to rsync.\n";
+  }
+
+  exec '/usr/bin/rsync', split(' ', $cmdline)
+    or die "Could not run rsync command.\n";
+}
+
+sub main {
+  -f LOGFILE && open (LOG, '>>', LOGFILE)
+    or die "Can't open log file.\n";
+
+  print LOG "Session started on ", `date`;
+  print LOG "Commands: ", map { "<$_> " } @ARGV;
+  print LOG "\n";
+
+  $ARGV[1] =~ /^([^ ]+) *(.*?)$/s;
+  my $cmd = $commands{$1}
+    or die "Unsupported command.\n";
+
+  $cmd->($2);
+}
+
+main()
+