summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/rsync.pm
blob: e38801e4a110b0b9e4790935de65f08bce30441e (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 => "change", id => "rsync", call => \&postrefresh);
  9. hook(type => "delete", 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 . user\@host:/path/to/docroot/",
  20. description => "command to run to sync updated pages",
  21. safe => 0,
  22. rebuild => 0,
  23. },
  24. }
  25. my $ran=0;
  26. sub postrefresh () {
  27. if (defined $config{rsync_command} && ! $ran) {
  28. $ran=1;
  29. chdir($config{destdir}) || error("chdir: $!");
  30. system $config{rsync_command};
  31. if ($? == -1) {
  32. warn(sprintf(gettext("failed to execute rsync_command: %s"), $!))."\n";
  33. }
  34. elsif ($? != 0) {
  35. warn(sprintf(gettext("rsync_command exited %d"), $? >> 8))."\n";
  36. }
  37. }
  38. }
  39. 1