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