1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # "lei add-external --mirror" support (also "public-inbox-clone");
5 package PublicInbox::LeiMirror;
8 use parent qw(PublicInbox::IPC);
9 use PublicInbox::Config;
10 use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
11 use IO::Compress::Gzip qw(gzip $GzipError);
12 use PublicInbox::Spawn qw(popen_rd spawn);
14 use Fcntl qw(SEEK_SET O_CREAT O_EXCL O_WRONLY);
18 sub _wq_done_wait { # dwaitpid callback (via wq_eof)
20 my ($mrr, $lei) = @$arg;
21 my $f = "$mrr->{dst}/mirror.done";
23 $lei->child_error($?);
24 } elsif (!unlink($f)) {
25 warn("unlink($f): $!\n") unless $!{ENOENT};
27 if ($lei->{cmd} ne 'public-inbox-clone') {
28 # calls _finish_add_external
29 $lei->lazy_cb('add-external', '_finish_'
30 )->($lei, $mrr->{dst});
32 $lei->qerr("# mirrored $mrr->{src} => $mrr->{dst}");
37 # for old installations without manifest.js.gz
40 my $uri = URI->new($self->{src});
41 my $lei = $self->{lei};
42 my $curl = $self->{curl} //= PublicInbox::LeiCurl->new($lei) or return;
43 my $cmd = $curl->for_uri($lei, $uri, '--compressed');
44 my $opt = { 0 => $lei->{0}, 2 => $lei->{2} };
45 my $fh = popen_rd($cmd, undef, $opt);
46 my $html = do { local $/; <$fh> } // die "read(curl $uri): $!";
47 close($fh) or return $lei->child_error($?, "@$cmd failed");
49 # we grep with URL below, we don't want Subject/From headers
50 # making us clone random URLs
51 my @html = split(/<hr>/, $html);
52 my @urls = ($html[-1] =~ m!\bgit clone --mirror ([a-z\+]+://\S+)!g);
53 my $url = $uri->as_string;
54 chop($url) eq '/' or die "BUG: $uri not canonicalized";
56 # since this is for old instances w/o manifest.js.gz, try v1 first
57 return clone_v1($self) if grep(m!\A\Q$url\E/*\z!, @urls);
58 if (my @v2_urls = grep(m!\A\Q$url\E/[0-9]+\z!, @urls)) {
60 my ($n) = (m!/([0-9]+)\z!);
61 $n => [ URI->new($_), '' ]
63 clone_v2($self, \%v2_epochs);
64 reap_live() while keys(%LIVE);
68 # filter out common URLs served by WWW (e.g /$MSGID/T/)
69 if (@urls && $url =~ s!/+[^/]+\@[^/]+/.*\z!! &&
70 grep(m!\A\Q$url\E/*\z!, @urls)) {
72 E: confused by scraping <$uri>, did you mean <$url>?
76 E: confused by scraping <$uri>, got ambiguous results:
79 die "E: scraping <$uri> revealed nothing\n";
85 $opt->{$_} = $lei->{$_} for (0..2);
86 # we support "-c $key=$val" for arbitrary git config options
87 # e.g.: git -c http.proxy=socks5h://127.0.0.1:9050
88 push(@cmd, '-c', $_) for @{$lei->{opt}->{c} // []};
89 push @cmd, qw(clone --mirror);
90 push @cmd, '-q' if $lei->{opt}->{quiet} ||
91 ($lei->{opt}->{jobs} // 1) > 1;
92 push @cmd, '-v' if $lei->{opt}->{verbose};
93 # XXX any other options to support?
94 # --reference is tricky with multiple epochs...
99 my ($ft, $dst, $open_mode) = @_;
100 my $fn = $ft->filename;
102 my $mode = @st ? ($st[2] & 07777) : ($open_mode & ~umask);
103 chmod($mode, $ft) or croak "E: chmod $fn: $!";
104 rename($fn, $dst) or croak "E: rename($fn => $ft): $!";
105 $ft->unlink_on_destroy(0);
108 sub _get_txt_start { # non-fatal
109 my ($self, $endpoint, $file, $mode) = @_;
110 my $uri = URI->new($self->{cur_src} // $self->{src});
111 my $lei = $self->{lei};
112 my $path = $uri->path;
113 chop($path) eq '/' or die "BUG: $uri not canonicalized";
114 $uri->path("$path/$endpoint");
115 my $dst = $self->{cur_dst} // $self->{dst};
116 my $ft = File::Temp->new(TEMPLATE => "$file-XXXX", DIR => $dst);
117 my $opt = { 0 => $lei->{0}, 1 => $lei->{1}, 2 => $lei->{2} };
118 my $cmd = $self->{curl}->for_uri($lei, $uri,
119 qw(--compressed -R -o), $ft->filename);
120 $self->{-get_txt} = [ $ft, $cmd, $uri, $file, $mode ];
121 $lei->qerr("# @$cmd");
122 spawn($cmd, undef, $opt);
125 sub _get_txt_done { # returns true on error (non-fatal), undef on success
127 my ($ft, $cmd, $uri, $file, $mode) = @{delete $self->{-get_txt}};
130 return warn("$uri missing\n") if ($cerr >> 8) == 22;
131 return warn("# @$cmd failed (non-fatal)\n") if $cerr;
132 my $dst = $self->{cur_dst} // $self->{dst};
133 ft_rename($ft, "$dst/$file", $mode);
137 # tries the relatively new /$INBOX/_/text/config/raw endpoint
138 sub _try_config_start {
140 _get_txt_start($self, qw(_/text/config/raw inbox.config.example), 0444);
143 sub _try_config_done {
145 _get_txt_done($self) and return;
146 my $dst = $self->{cur_dst} // $self->{dst};
147 my $f = "$dst/inbox.config.example";
148 my $cfg = PublicInbox::Config->git_config_dump($f, $self->{lei}->{2});
149 my $ibx = $self->{ibx} = {};
150 for my $sec (grep(/\Apublicinbox\./, @{$cfg->{-section_order}})) {
151 for (qw(address newsgroup nntpmirror)) {
152 $ibx->{$_} = $cfg->{"$sec.$_"};
157 sub set_description ($) {
159 my $dst = $self->{cur_dst} // $self->{dst};
160 my $f = "$dst/description";
161 open my $fh, '+>>', $f or die "open($f): $!";
162 seek($fh, 0, SEEK_SET) or die "seek($f): $!";
163 chomp(my $d = do { local $/; <$fh> } // die "read($f): $!");
164 if ($d eq '($INBOX_DIR/description missing)' ||
165 $d =~ /^Unnamed repository/ || $d !~ /\S/) {
166 seek($fh, 0, SEEK_SET) or die "seek($f): $!";
167 truncate($fh, 0) or die "truncate($f): $!";
168 my $src = $self->{cur_src} // $self->{src};
169 print $fh "mirror of $src\n" or die "print($f): $!";
170 close $fh or die "close($f): $!";
174 sub index_cloned_inbox {
175 my ($self, $iv) = @_;
176 my $lei = $self->{lei};
177 eval { set_description($self) };
180 # n.b. public-inbox-clone works w/o (SQLite || Xapian)
181 # lei is useless without Xapian + SQLite
182 if ($lei->{cmd} ne 'public-inbox-clone') {
183 my $ibx = delete($self->{ibx}) // {
184 address => [ 'lei@example.com' ],
187 $ibx->{inboxdir} = $self->{cur_dst} // $self->{dst};
188 PublicInbox::Inbox->new($ibx);
189 PublicInbox::InboxWritable->new($ibx);
191 for my $sw ($lei->index_opt) {
192 my ($k) = ($sw =~ /\A([\w-]+)/);
193 $opt->{$k} = $lei->{opt}->{$k};
195 # force synchronous dwaitpid for v2:
196 local $PublicInbox::DS::in_loop = 0;
197 my $cfg = PublicInbox::Config->new(undef, $lei->{2});
198 my $env = PublicInbox::Admin::index_prepare($opt, $cfg);
199 local %ENV = (%ENV, %$env) if $env;
200 PublicInbox::Admin::progress_prepare($opt, $lei->{2});
201 PublicInbox::Admin::index_inbox($ibx, undef, $opt);
203 return if defined $self->{cur_dst};
204 open my $x, '>', "$self->{dst}/mirror.done"; # for _wq_done_wait
208 my ($lei, $cmd, $opt) = @_;
209 $lei->qerr("# @$cmd");
210 waitpid(spawn($cmd, undef, $opt), 0) // die "waitpid: $!";
212 $? = 0; # don't let it influence normal exit
217 my ($self, $nohang) = @_;
218 my $lei = $self->{lei};
219 my $curl = $self->{curl} //= PublicInbox::LeiCurl->new($lei) or return;
220 my $uri = URI->new($self->{cur_src} // $self->{src});
221 defined($lei->{opt}->{epoch}) and
222 die "$uri is a v1 inbox, --epoch is not supported\n";
223 my $pfx = $curl->torsocks($lei, $uri) or return;
224 my $dst = $self->{cur_dst} // $self->{dst};
225 my $fini = PublicInbox::OnDestroy->new($$, \&v1_done, $self);
226 my $jobs = $self->{lei}->{opt}->{jobs} // 1;
227 my $cmd = [ @$pfx, clone_cmd($lei, my $opt = {}), "$uri", $dst ];
228 $lei->qerr("# @$cmd");
229 $LIVE{spawn($cmd, undef, $opt)} = [ \&reap_clone, $lei, $cmd, $fini ];
230 reap_live() while keys(%LIVE) >= $jobs;
232 # wait for `git clone' to mkdir $dst (TODO: inotify/kevent?)
233 select(undef, undef, undef, 0.011) until -d $dst;
234 $LIVE{_try_config_start($self)} = [ \&_try_config_done, $self, $fini ];
235 reap_live() while keys(%LIVE) >= $jobs;
236 $LIVE{_get_txt_start($self, qw(description description), 0666)} =
237 [ \&_get_txt_done, $self, $fini ];
238 reap_live() until ($nohang || !keys(%LIVE));
241 sub parse_epochs ($$) {
242 my ($opt_epochs, $v2_epochs) = @_; # $epochs "LOW..HIGH"
243 $opt_epochs // return; # undef => all epochs
244 my ($lo, $dotdot, $hi, @extra) = split(/(\.\.)/, $opt_epochs);
245 undef($lo) if ($lo // '') eq '';
246 my $re = qr/\A~?[0-9]+\z/;
247 if (@extra || (($lo // '0') !~ $re) ||
248 (($hi // '0') !~ $re) ||
249 !(grep(defined, $lo, $hi))) {
251 --epoch=$opt_epochs not in the form of `LOW..HIGH', `LOW..', nor `..HIGH'
254 my @n = sort { $a <=> $b } keys %$v2_epochs;
255 for (grep(defined, $lo, $hi)) {
258 "`$_' exceeds maximum available epoch ($n[-1])\n";
260 "`$_' is lower than minimum available epoch ($n[0])\n";
261 } elsif (/\A~([0-9]+)/) {
263 $n[$off] // die "`$_' is out of range\n";
265 } else { die "`$_' not understood\n" }
267 defined($lo) && defined($hi) && $lo > $hi and die
268 "low value (`$lo') exceeds high (`$hi')\n";
269 $lo //= $n[0] if $dotdot;
270 $hi //= $n[-1] if $dotdot;
274 if (defined $v2_epochs->{$_}) {
278 "# epoch $_ is not available (non-fatal, $lo..$hi)\n";
284 sub init_placeholder ($$) {
285 my ($src, $edst) = @_;
286 PublicInbox::Import::init_bare($edst);
287 my $f = "$edst/config";
288 open my $fh, '>>', $f or die "open($f): $!";
289 print $fh <<EOM or die "print($f): $!";
292 fetch = +refs/*:refs/*
295 ; This git epoch was created read-only and "public-inbox-fetch"
296 ; will not fetch updates for it unless write permission is added.
298 close $fh or die "close:($f): $!";
301 sub reap_clone { # async, called via SIGCHLD
302 my ($lei, $cmd) = @_;
304 $? = 0; # don't let it influence normal exit
306 kill('TERM', keys %LIVE);
307 $lei->child_error($cerr, "@$cmd failed");
311 sub v1_done { # called via OnDestroy
313 my $dst = $self->{cur_dst} // $self->{dst};
314 write_makefile($dst, 1);
315 index_cloned_inbox($self, 1);
318 sub v2_done { # called via OnDestroy
320 require PublicInbox::MultiGit;
321 my $dst = $self->{cur_dst} // $self->{dst};
322 my $mg = PublicInbox::MultiGit->new($dst, 'all.git', 'git');
323 $mg->fill_alternates;
324 for my $i ($mg->git_epochs) { $mg->epoch_cfg_set($i) }
325 for my $edst (@{delete($self->{-read_only}) // []}) {
326 my @st = stat($edst) or die "stat($edst): $!";
327 chmod($st[2] & 0555, $edst) or die "chmod(a-w, $edst): $!";
329 write_makefile($dst, 2);
330 delete $self->{-locked} // die "BUG: $dst not locked"; # unlock
331 index_cloned_inbox($self, 2);
335 my $pid = waitpid(-1, 0) // die "waitpid(-1): $!";
336 if (my $x = delete $LIVE{$pid}) {
340 warn "reaped unknown PID=$pid ($?)\n";
344 sub clone_v2 ($$;$) {
345 my ($self, $v2_epochs, $m) = @_; # $m => manifest.js.gz hashref
346 my $lei = $self->{lei};
347 my $curl = $self->{curl} //= PublicInbox::LeiCurl->new($lei) or return;
348 my $first_uri = (map { $_->[0] } values %$v2_epochs)[0];
349 my $pfx = $curl->torsocks($lei, $first_uri) or return;
350 my $dst = $self->{cur_dst} // $self->{dst};
351 my $want = parse_epochs($lei->{opt}->{epoch}, $v2_epochs);
352 my $task = $m ? bless { %$self }, __PACKAGE__ : $self;
353 my (@src_edst, @skip);
354 for my $nr (sort { $a <=> $b } keys %$v2_epochs) {
355 my ($uri, $key) = @{$v2_epochs->{$nr}};
356 my $src = $uri->as_string;
358 $src =~ m!/([0-9]+)(?:\.git)?\z! or die <<"";
359 failed to extract epoch number from $src
361 $1 + 0 == $nr or die "BUG: <$uri> miskeyed $1 != $nr";
362 $edst .= "/git/$nr.git";
363 if (!$want || $want->{$nr}) {
364 push @src_edst, $src, $edst;
365 } else { # create a placeholder so users only need to chmod +w
366 init_placeholder($src, $edst);
367 push @{$task->{-read_only}}, $edst;
371 # filter out the epochs we skipped
372 $self->{-culled_manifest} = 1 if delete(@$m{@skip});
374 if (!-d $dst || !mkdir($dst)) {
376 File::Path::mkpath($dst);
377 -d $dst or die "mkpath($dst): $!\n";
379 my $lk = bless { lock_path => "$dst/inbox.lock" }, 'PublicInbox::Lock';
380 my $fini = PublicInbox::OnDestroy->new($$, \&v2_done, $task);
381 my $jobs = $self->{lei}->{opt}->{jobs} // 1;
382 $LIVE{_try_config_start($task)} = [ \&_try_config_done, $task, $fini ];
383 reap_live() while keys(%LIVE) >= $jobs;
384 $LIVE{_get_txt_start($self, qw(description description), 0666)} =
385 [ \&_get_txt_done, $self, $fini ];
386 $task->{-locked} = $lk->lock_for_scope($$);
387 my @cmd = clone_cmd($lei, my $opt = {});
389 reap_live() while keys(%LIVE) >= $jobs;
390 while (keys(%LIVE) < $jobs && @src_edst &&
391 !$lei->{child_error}) {
392 my $cmd = [ @$pfx, @cmd, splice(@src_edst, 0, 2) ];
393 $lei->qerr("# @$cmd");
394 $LIVE{spawn($cmd, undef, $opt)} = [ \&reap_clone,
397 } while (@src_edst && !$lei->{child_error});
400 sub decode_manifest ($$$) {
401 my ($fh, $fn, $uri) = @_;
403 my $gz = do { local $/; <$fh> } // die "slurp($fn): $!";
404 gunzip(\$gz => \$js, MultiStream => 1) or
405 die "gunzip($uri): $GunzipError\n";
406 my $m = eval { PublicInbox::Config->json->decode($js) };
407 die "$uri: error decoding `$js': $@\n" if $@;
408 ref($m) eq 'HASH' or die "$uri unknown type: ".ref($m);
412 sub multi_inbox ($$$) {
413 my ($self, $path, $m) = @_;
414 my $incl = $self->{lei}->{opt}->{include};
415 my $excl = $self->{lei}->{opt}->{exclude};
417 # assuming everything not v2 is v1, for now
418 my @v1 = sort grep(!m!.+/git/[0-9]+\.git\z!, keys %$m);
419 my @v2_epochs = sort grep(m!.+/git/[0-9]+\.git\z!, keys %$m);
423 m!\A(/.+)/git/[0-9]+\.git\z! or die "BUG: $_";
424 push @{$v2->{$1}}, $_;
426 my $n = scalar(keys %$v2) + scalar(@v1);
427 my @orig = defined($incl // $excl) ? (keys %$v2, @v1) : ();
429 my $re = '(?:'.join('|', map {
430 $self->{lei}->glob2re($_) // qr/\A\Q$_\E\z/
432 my @gone = delete @$v2{grep(!/$re/, keys %$v2)};
433 delete @$m{map { @$_ } @gone} and $self->{-culled_manifest} = 1;
434 delete @$m{grep(!/$re/, @v1)} and $self->{-culled_manifest} = 1;
435 @v1 = grep(/$re/, @v1);
438 my $re = '(?:'.join('|', map {
439 $self->{lei}->glob2re($_) // qr/\A\Q$_\E\z/
441 my @gone = delete @$v2{grep(/$re/, keys %$v2)};
442 delete @$m{map { @$_ } @gone} and $self->{-culled_manifest} = 1;
443 delete @$m{grep(/$re/, @v1)} and $self->{-culled_manifest} = 1;
444 @v1 = grep(!/$re/, @v1);
446 my $ret; # { v1 => [ ... ], v2 => { "/$inbox_name" => [ epochs ] }}
447 $ret->{v1} = \@v1 if @v1;
448 $ret->{v2} = $v2 if keys %$v2;
449 $ret //= @orig ? "Nothing to clone, available repositories:\n\t".
450 join("\n\t", sort @orig)
451 : "Nothing available to clone\n";
454 # PSGI mount prefixes and manifest.js.gz prefixes don't always align...
456 until (grep(m!\A\Q$$path\E/git/[0-9]+\.git\z!,
457 @v2_epochs) == @v2_epochs) {
458 $$path =~ s!\A(/[^/]+)/!/! or last;
462 while (!defined($m->{$$path}) && $$path =~ s!\A(/[^/]+)/!/!) {
466 ($path_pfx, $n, $ret);
469 # FIXME: this gets confused by single inbox instance w/ global manifest.js.gz
472 my $uri = URI->new($self->{src});
473 my $lei = $self->{lei};
474 my $curl = $self->{curl} //= PublicInbox::LeiCurl->new($lei) or return;
475 my $path = $uri->path;
476 chop($path) eq '/' or die "BUG: $uri not canonicalized";
477 $uri->path($path . '/manifest.js.gz');
478 my $pdir = $lei->rel2abs($self->{dst});
479 $pdir =~ s!/[^/]+/?\z!!;
480 my $ft = File::Temp->new(TEMPLATE => 'm-XXXX',
481 UNLINK => 1, DIR => $pdir, SUFFIX => '.tmp');
482 my $fn = $ft->filename;
483 my ($bn) = ($fn =~ m!/([^/]+)\z!);
484 my $cmd = $curl->for_uri($lei, $uri, '-R', '-o', $bn);
485 my $opt = { -C => $pdir };
486 $opt->{$_} = $lei->{$_} for (0..2);
487 my $cerr = run_reap($lei, $cmd, $opt);
490 return try_scrape($self) if ($cerr >> 8) == 22; # 404 missing
491 return $lei->child_error($cerr, "@$cmd failed");
493 my $m = eval { decode_manifest($ft, $fn, $uri) };
496 return try_scrape($self);
498 my ($path_pfx, $n, $multi) = multi_inbox($self, \$path, $m);
499 return $lei->child_error(1, $multi) if !ref($multi);
500 my $jobs = $self->{lei}->{opt}->{jobs} // 1;
501 if (my $v2 = delete $multi->{v2}) {
502 for my $name (sort keys %$v2) {
503 my $epochs = delete $v2->{$name};
504 my %v2_epochs = map {
505 $uri->path($n > 1 ? $path_pfx.$path.$_
507 my ($e) = ("$uri" =~ m!/([0-9]+)\.git\z!);
508 $e // die "no [0-9]+\.git in `$uri'";
509 $e => [ $uri->clone, $_ ];
511 ("$uri" =~ m!\A(.+/)git/[0-9]+\.git\z!) or
512 die "BUG: `$uri' !~ m!/git/[0-9]+.git!";
513 local $self->{cur_src} = $1;
514 local $self->{cur_dst} = $self->{dst};
515 if ($n > 1 && $uri->path =~ m!\A\Q$path_pfx$path\E/(.+)/
516 git/[0-9]+\.git\z!x) {
517 $self->{cur_dst} .= "/$1";
519 index($self->{cur_dst}, "\n") >= 0 and die <<EOM;
520 E: `$self->{cur_dst}' must not contain newline
522 clone_v2($self, \%v2_epochs, $m);
523 reap_live() while keys(%LIVE) >= $jobs;
524 return if $self->{lei}->{child_error};
527 if (my $v1 = delete $multi->{v1}) {
528 my $p = $path_pfx.$path;
529 chop($p) if substr($p, -1, 1) eq '/';
531 for my $name (@$v1) {
532 reap_live() while keys(%LIVE) >= $jobs;
533 return if $self->{lei}->{child_error};
535 my $task = bless { %$self }, __PACKAGE__;
536 $task->{cur_src} = "$uri";
537 $task->{cur_dst} = $task->{dst};
539 $task->{cur_dst} .= $name;
540 $task->{cur_src} .= $name;
542 index($task->{cur_dst}, "\n") >= 0 and die <<EOM;
543 E: `$task->{cur_dst}' must not contain newline
545 $task->{cur_src} .= '/';
549 reap_live() while keys(%LIVE);
550 return if $self->{lei}->{child_error};
552 if (delete $self->{-culled_manifest}) { # set by clone_v2/-I/--exclude
553 # write the smaller manifest if epochs were skipped so
554 # users won't have to delete manifest if they +w an
555 # epoch they no longer want to skip
556 my $json = PublicInbox::Config->json->encode($m);
557 my $mtime = (stat($fn))[9];
558 gzip(\$json => $fn) or die "gzip: $GzipError";
559 utime($mtime, $mtime, $fn) or die "utime(..., $fn): $!";
561 ft_rename($ft, "$self->{dst}/manifest.js.gz", 0666);
562 open my $x, '>', "$self->{dst}/mirror.done"; # for _wq_done_wait
565 sub start_clone_url {
567 return try_manifest($self) if $self->{src} =~ m!\Ahttps?://!;
568 die "TODO: non-HTTP/HTTPS clone of $self->{src} not supported, yet";
571 sub do_mirror { # via wq_io_do
573 my $lei = $self->{lei};
574 umask($lei->{client_umask}) if defined $lei->{client_umask};
576 my $iv = $lei->{opt}->{'inbox-version'};
579 return clone_v1($self) if $iv == 1;
580 return try_scrape($self) if $iv == 2;
581 die "bad --inbox-version=$iv\n";
583 return start_clone_url($self) if $self->{src} =~ m!://!;
584 die "TODO: cloning local directories not supported, yet";
586 $lei->fail($@) if $@;
590 my ($cls, $lei, $src, $dst) = @_;
591 my $self = bless { src => $src, dst => $dst }, $cls;
592 if ($src =~ m!https?://!) {
594 require PublicInbox::LeiCurl;
596 require PublicInbox::Lock;
597 require PublicInbox::Inbox;
598 require PublicInbox::Admin;
599 require PublicInbox::InboxWritable;
601 my ($op_c, $ops) = $lei->workers_start($self, 1);
603 $self->wq_io_do('do_mirror', []);
605 $lei->wait_wq_events($op_c, $ops);
608 sub ipc_atfork_child {
610 $self->{lei}->_lei_atfork_child;
611 $self->SUPER::ipc_atfork_child;
615 my ($dir, $ibx_ver) = @_;
616 my $f = "$dir/Makefile";
617 if (sysopen my $fh, $f, O_CREAT|O_EXCL|O_WRONLY) {
618 print $fh <<EOM or die "print($f) $!";
619 # This is a v$ibx_ver public-inbox, see the public-inbox-v$ibx_ver-format(5)
620 # manpage for more information on the format. This Makefile is
621 # intended as a familiar wrapper for users unfamiliar with
622 # public-inbox-* commands.
624 # See the respective manpages for public-inbox-fetch(1),
625 # public-inbox-index(1), etc for more information on
626 # some of the commands used by this Makefile.
628 # This Makefile will not be modified nor read by public-inbox,
629 # so you may edit it freely with your own convenience targets
630 # and notes. public-inbox-fetch will recreate it if removed.
632 print $fh <<'EOM' or die "print($f): $!";
633 # the default target:
635 @echo Common targets:
636 @echo ' make fetch - fetch from remote git repostorie(s)'
637 @echo ' make update - fetch and update index '
639 @echo Rarely needed targets:
640 @echo ' make reindex - may be needed for new features/bugfixes'
641 @echo ' make compact - rewrite Xapian storage to save space'
646 @if ! public-inbox-fetch --exit-code; \
649 test $$c -eq 127 && exit 0; \
651 elif test -f msgmap.sqlite3 || test -f public-inbox/msgmap.sqlite3; \
653 public-inbox-index; \
655 echo 'public-inbox index not initialized'; \
656 echo 'see public-inbox-index(1) man page'; \
659 public-inbox-index --reindex
663 .PHONY : help fetch update reindex compact
665 close $fh or die "close($f): $!";
667 die "open($f): $!" unless $!{EEXIST};