Add rsync plugin, though the only rsync-specific thing about it is the
[ikiwiki.git] / IkiWiki / Plugin / rsync.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::rsync;
3
4 use warnings;
5 no warnings 'redefine';
6 use strict;
7 use IkiWiki 3.00;
8
9 sub import {
10         hook(type => "getsetup", id => "rsync", call => \&getsetup);
11         hook(type => "checkconfig", id => "rsync", call => \&checkconfig);
12         hook(type => "postrefresh", id => "rsync", call => \&postrefresh);
13 }
14
15 sub getsetup () {
16         return
17                 plugin => {
18                         safe => 0,
19                         rebuild => 0,
20                 },
21                 rsync_command => {
22                         type => "string",
23                         example => "rsync -qa --delete /path/to/destdir/ user\@host:/path/to/docroot/",
24                         description => "command to upload regenerated pages to another host",
25                         safe => 0,
26                         rebuild => 0,
27                 },
28 }
29
30 sub checkconfig {
31         if (! exists $config{rsync_command} ||
32             ! defined $config{rsync_command}) {
33                 error("Must specify rsync_command");
34         }
35 }
36
37 sub postrefresh () {
38         debug "in postrefresh hook, gonna run rsync";
39         system $config{rsync_command};
40         if ($? == -1) {
41                 error("failed to execute rsync_command: $!");
42         } elsif ($? != 0) {
43                 error(sprintf("rsync_command exited %d", $? >> 8));
44         }
45 }
46
47 1