2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Wrapper to git fetch remote public-inboxes
6 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
8 my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
9 usage: public-inbox-fetch -C DESTINATION
11 fetch remote public-inboxes
15 --torsocks VAL whether or not to wrap git and curl commands with
16 torsocks (default: `auto')
17 Must be one of: `auto', `no' or `yes'
18 -T NAME Name of remote(s) to try (may be repeated)
19 default: `origin' and `_grokmirror'
20 --exit-code exit with 127 if no updates
21 --verbose | -v increase verbosity (may be repeated)
22 --quiet | -q increase verbosity (may be repeated)
23 -C DIR chdir to specified directory
25 GetOptions($opt, qw(help|h quiet|q verbose|v+ C=s@ c=s@ try-remote|T=s@
26 no-torsocks torsocks=s exit-code)) or die $help;
27 if ($opt->{help}) { print $help; exit };
28 require PublicInbox::Fetch; # loads Admin
29 PublicInbox::Admin::do_chdir(delete $opt->{C});
30 PublicInbox::Admin::setup_signals();
31 $SIG{PIPE} = 'IGNORE';
34 env => \%ENV, opt => $opt, cmd => 'public-inbox-fetch',
35 0 => *STDIN{GLOB}, 1 => *STDOUT{GLOB}, 2 => *STDERR{GLOB},
36 }, 'PublicInbox::LEI';
37 PublicInbox::Fetch->do_fetch($lei, '.');
38 exit(($lei->{child_error} // 0) >> 8);