Provide a UUID in edittemplate templates.
[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 => "rendered", 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                 },
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 }
28
29 my $ran=0;
30
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 }
44
45 1