<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
package IkiWiki::Plugin::rsync;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type =&gt; "getsetup", id =&gt; "rsync", call =&gt; \&amp;getsetup);
	hook(type =&gt; "rendered", id =&gt; "rsync", call =&gt; \&amp;postrefresh);
	hook(type =&gt; "delete", id =&gt; "rsync", call =&gt; \&amp;postrefresh);
}

sub getsetup () {
	return
		plugin =&gt; {
			safe =&gt; 0,
			rebuild =&gt; 0,
		},
		rsync_command =&gt; {
			type =&gt; "string",
			example =&gt; "rsync -qa --delete . user\@host:/path/to/docroot/",
			description =&gt; "command to run to sync updated pages",
			safe =&gt; 0,
			rebuild =&gt; 0,
		},
}

my $ran=0;

sub postrefresh () {
	if (defined $config{rsync_command} &amp;&amp; ! $ran) {
		$ran=1;
		chdir($config{destdir}) || error("chdir: $!");
		system $config{rsync_command};
		if ($? == -1) {
			warn(sprintf(gettext("failed to execute rsync_command: %s"), $!))."\n";
		}
		elsif ($? != 0) {
			warn(sprintf(gettext("rsync_command exited %d"), $? &gt;&gt; 8))."\n";
		}
	}
}

1
</pre></body></html>