2009-09-10 23:34:52 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::rsync;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use IkiWiki 3.00;
|
|
|
|
|
|
|
|
sub import {
|
|
|
|
hook(type => "getsetup", id => "rsync", call => \&getsetup);
|
2009-09-12 00:29:56 +02:00
|
|
|
hook(type => "change", id => "rsync", call => \&postrefresh);
|
|
|
|
hook(type => "delete", id => "rsync", call => \&postrefresh);
|
2009-09-10 23:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub getsetup () {
|
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 0,
|
|
|
|
rebuild => 0,
|
|
|
|
},
|
|
|
|
rsync_command => {
|
|
|
|
type => "string",
|
2009-09-12 06:24:57 +02:00
|
|
|
example => "rsync -qa --delete . user\@host:/path/to/docroot/",
|
2009-09-12 00:19:21 +02:00
|
|
|
description => "command to run to sync updated pages",
|
2009-09-10 23:34:52 +02:00
|
|
|
safe => 0,
|
|
|
|
rebuild => 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2009-09-12 00:29:56 +02:00
|
|
|
my $ran=0;
|
|
|
|
|
2009-09-10 23:34:52 +02:00
|
|
|
sub postrefresh () {
|
2009-09-12 00:29:56 +02:00
|
|
|
if (defined $config{rsync_command} && ! $ran) {
|
|
|
|
$ran=1;
|
2009-09-12 00:20:23 +02:00
|
|
|
chdir($config{destdir}) || error("chdir: $!");
|
2009-09-11 23:42:51 +02:00
|
|
|
system $config{rsync_command};
|
|
|
|
if ($? == -1) {
|
2009-09-12 00:22:06 +02:00
|
|
|
warn(sprintf(gettext("failed to execute rsync_command: %s"), $!))."\n";
|
2009-09-12 00:20:23 +02:00
|
|
|
}
|
|
|
|
elsif ($? != 0) {
|
2009-09-12 00:22:06 +02:00
|
|
|
warn(sprintf(gettext("rsync_command exited %d"), $? >> 8))."\n";
|
2009-09-11 23:42:51 +02:00
|
|
|
}
|
2009-09-10 23:34:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1
|