<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; "checkconfig", id =&gt; "rsync", call =&gt; \&amp;checkconfig);
	hook(type =&gt; "postrefresh", 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 /path/to/destdir/ user\@host:/path/to/docroot/",
			description =&gt; "unattended command to upload regenerated pages",
			safe =&gt; 0,
			rebuild =&gt; 0,
		},
}

sub checkconfig {
	if (! exists $config{rsync_command} ||
	    ! defined $config{rsync_command}) {
		error("Must specify rsync_command");
	}
}

sub postrefresh () {
	system $config{rsync_command};
	if ($? == -1) {
		error("failed to execute rsync_command: $!");
	} elsif ($? != 0) {
		error(sprintf("rsync_command exited %d", $? &gt;&gt; 8));
	}
}

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