Don't error out, either warn or say nothing, depending.
[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 => "postrefresh", id => "rsync", call => \&postrefresh);
11 }
12
13 sub getsetup () {
14         return
15                 plugin => {
16                         safe => 0,
17                         rebuild => 0,
18                 },
19                 rsync_command => {
20                         type => "string",
21                         example => "rsync -qa --delete /path/to/destdir/ user\@host:/path/to/docroot/",
22                         description => "unattended command to upload regenerated pages",
23                         safe => 0,
24                         rebuild => 0,
25                 },
26 }
27
28 sub postrefresh () {
29         if (defined $config{rsync_command}) {
30                 system $config{rsync_command};
31                 if ($? == -1) {
32                         warn("failed to execute rsync_command: $!");
33                 } elsif ($? != 0) {
34                         warn(sprintf("rsync_command exited %d", $? >> 8));
35                 }
36         }
37 }
38
39 1