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