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