]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/rsync.pm
8dd983be783d85343f61afa18a1c179d655cb637
[ikiwiki.git] / IkiWiki / Plugin / rsync.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::rsync;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7
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 }
13
14 sub getsetup () {
15         return
16                 plugin => {
17                         safe => 0,
18                         rebuild => 0,
19                         section => "special-purpose",
20                 },
21                 rsync_command => {
22                         type => "string",
23                         example => "rsync -qa --delete . user\@host:/path/to/docroot/",
24                         description => "command to run to sync updated pages",
25                         safe => 0,
26                         rebuild => 0,
27                 },
28 }
29
30 my $ran=0;
31
32 sub postrefresh () {
33         if (defined $config{rsync_command} && ! $ran) {
34                 $ran=1;
35                 chdir($config{destdir}) || error("chdir: $!");
36                 system $config{rsync_command};
37                 if ($? == -1) {
38                         warn(sprintf(gettext("failed to execute rsync_command: %s"), $!))."\n";
39                 }
40                 elsif ($? != 0) {
41                         warn(sprintf(gettext("rsync_command exited %d"), $? >> 8))."\n";
42                 }
43         }
44 }
45
46 1