summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/rsync.pm
blob: f14989ff835ac929675666ee91cd3a5d68f8261b (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 => "postrefresh", id => "rsync", call => \&postrefresh);
  9. }
  10. sub getsetup () {
  11. return
  12. plugin => {
  13. safe => 0,
  14. rebuild => 0,
  15. },
  16. rsync_command => {
  17. type => "string",
  18. example => "rsync -qa --delete . user\@host:/path/to/docroot/ --exclude ikiwiki.cgi",
  19. description => "command to run to sync updated pages",
  20. safe => 0,
  21. rebuild => 0,
  22. },
  23. }
  24. sub postrefresh () {
  25. if (defined $config{rsync_command}) {
  26. chdir($config{destdir}) || error("chdir: $!");
  27. system $config{rsync_command};
  28. if ($? == -1) {
  29. warn(sprintf(gettext("failed to execute rsync_command: %s"), $!))."\n";
  30. }
  31. elsif ($? != 0) {
  32. warn(sprintf(gettext("rsync_command exited %d"), $? >> 8))."\n";
  33. }
  34. }
  35. }
  36. 1