From 5213ef1798aeb52c43e61b59c4a382cb74c8b015 Mon Sep 17 00:00:00 2001 From: mwolson_admin Date: Wed, 3 Sep 2008 03:55:11 -0400 Subject: [PATCH] Initial implementation of rsync-shell functionality. --- rsync-shell | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 rsync-shell diff --git a/rsync-shell b/rsync-shell new file mode 100755 index 0000000..71482d3 --- /dev/null +++ b/rsync-shell @@ -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() + -- 2.20.1