Merge commit 'schmonz/master'
[ikiwiki] / 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 => "checkconfig", id => "rsync", call => \&checkconfig);
11         hook(type => "postrefresh", 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 /path/to/destdir/ user\@host:/path/to/docroot/",
23                         description => "unattended command to upload regenerated pages",
24                         safe => 0,
25                         rebuild => 0,
26                 },
27 }
28
29 sub checkconfig {
30         if (! exists $config{rsync_command} ||
31             ! defined $config{rsync_command}) {
32                 error("Must specify rsync_command");
33         }
34 }
35
36 sub postrefresh () {
37         system $config{rsync_command};
38         if ($? == -1) {
39                 error("failed to execute rsync_command: $!");
40         } elsif ($? != 0) {
41                 error(sprintf("rsync_command exited %d", $? >> 8));
42         }
43 }
44
45 1