]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/rsync.pm
graphviz: Fix display of preexisting images in preview mode.
[git.ikiwiki.info.git] / IkiWiki / Plugin / rsync.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::rsync;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 sub import {
9         hook(type => "getsetup", id => "rsync", call => \&getsetup);
10         hook(type => "change", id => "rsync", call => \&postrefresh);
11         hook(type => "delete", id => "rsync", call => \&postrefresh);
12 }
14 sub getsetup () {
15         return
16                 plugin => {
17                         safe => 0,
18                         rebuild => 0,
19                 },
20                 rsync_command => {
21                         type => "string",
22                         example => "rsync -qa --delete . user\@host:/path/to/docroot/",
23                         description => "command to run to sync updated pages",
24                         safe => 0,
25                         rebuild => 0,
26                 },
27 }
29 my $ran=0;
31 sub postrefresh () {
32         if (defined $config{rsync_command} && ! $ran) {
33                 $ran=1;
34                 chdir($config{destdir}) || error("chdir: $!");
35                 system $config{rsync_command};
36                 if ($? == -1) {
37                         warn(sprintf(gettext("failed to execute rsync_command: %s"), $!))."\n";
38                 }
39                 elsif ($? != 0) {
40                         warn(sprintf(gettext("rsync_command exited %d"), $? >> 8))."\n";
41                 }
42         }
43 }
45 1