]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei_mirror: support --remote-manifest=URL
authorEric Wong <e@80x24.org>
Tue, 21 Feb 2023 12:17:44 +0000 (12:17 +0000)
committerEric Wong <e@80x24.org>
Tue, 21 Feb 2023 23:42:19 +0000 (23:42 +0000)
Since PublicInbox::WWW already generates manifest.js.gz, I'm
using an alternate path with PublicInbox::WwwStatic to host the
manifest.js.gz for coderepos at an alternate location.  The
following snippet lets me host
https://yhbt.net/lore/pub/manifest.js.gz for mirrored git
repositories, while https://yhbt.net/lore/manifest.js.gz
(no `pub') remains for inbox mirroring.

==> sample.psgi <==
use PublicInbox::WWW;
use PublicInbox::WwwStatic;
my $www = PublicInbox::WWW->new; # use default PI_CONFIG
my $st = PublicInbox::WwwStatic->new(docroot => '/path/to/code');
my $www_cb = sub {
my ($env) = @_;
if ($env->{PATH_INFO} eq '/pub/manifest.js.gz') {
local $env->{PATH_INFO} = '/manifest.js.gz';
my $res = $st->call($env);
return $res if $res->[0] != 404;
}
$www->call($env);
};
builder {
enable 'ReverseProxy';
enable 'Head';
mount '/lore' => $www_cb;
}

lib/PublicInbox/LeiMirror.pm
script/public-inbox-clone

index 4dedac9b36c5be711a19844d3b471806726712ef..e4aa620e7a7b7f76f6dc2770e6b857b6f49ddb1e 100644 (file)
@@ -1110,7 +1110,13 @@ sub try_manifest {
        $self->{-torsocks} //= $curl->torsocks($lei, $uri) or return;
        my $path = $uri->path;
        chop($path) eq '/' or die "BUG: $uri not canonicalized";
-       $uri->path($path . '/manifest.js.gz');
+       my $rmf = $lei->{opt}->{'remote-manifest'} // '/manifest.js.gz';
+       if ($rmf =~ m!\A[^/:]+://!) {
+               $uri = URI->new($rmf);
+       } else {
+               $rmf = "/$rmf" if index($rmf, '/') != 0;
+               $uri->path($path.$rmf);
+       }
        my $manifest = $self->{-manifest} // "$self->{dst}/manifest.js.gz";
        my %opt = (UNLINK => 1, SUFFIX => '.tmp', TMPDIR => 1);
        if (!$self->{dry_run} && $manifest =~ m!\A(.+?)/[^/]+\z! and -d $1) {
index 598979bc1a467a0e308e1278a98e6e93f154bf36..10ad34878e13f57b33dc77b49b4d8cf212363e99 100755 (executable)
@@ -27,7 +27,7 @@ EOF
 # support both :/
 GetOptions($opt, qw(help|h quiet|q verbose|v+ C=s@ c=s@ include|I=s@ exclude=s@
        inbox-config=s inbox-version=i objstore=s manifest=s
-       project-list|projectslist=s post-update-hook=s@
+       remote-manifest=s project-list|projectslist=s post-update-hook=s@
        prune|p keep-going|k exit-code
        dry-run|n jobs|j=i no-torsocks torsocks=s epoch=s)) or die $help;
 if ($opt->{help}) { print $help; exit };