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 clone remote public-inboxes
7 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
9 my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
10 usage: public-inbox-clone INBOX_URL [DESTINATION]
12 clone remote public-inboxes
16 --epoch=RANGE range of v2 epochs to clone (e.g `2..5', `~0', `~1..')
17 --objstore [DIR] share storage for coderepos
18 --torsocks VAL whether or not to wrap git and curl commands with
19 torsocks (default: `auto')
20 Must be one of: `auto', `no' or `yes'
21 --dry-run | -n show what would be cloned without cloning
22 --verbose | -v increase verbosity (may be repeated)
23 --quiet | -q increase verbosity (may be repeated)
24 -C DIR chdir to specified directory
26 GetOptions($opt, qw(help|h quiet|q verbose|v+ C=s@ c=s@ include|I=s@ exclude=s@
27 inbox-config=s inbox-version=i objstore:s
28 dry-run|n jobs|j=i no-torsocks torsocks=s epoch=s)) or die $help;
29 if ($opt->{help}) { print $help; exit };
30 require PublicInbox::Admin; # loads Config
31 PublicInbox::Admin::do_chdir(delete $opt->{C});
32 PublicInbox::Admin::setup_signals();
33 $SIG{PIPE} = 'IGNORE';
35 my ($url, $dst, $extra) = @ARGV;
36 die $help if !defined($url) || defined($extra);
37 defined($dst) or ($dst) = ($url =~ m!/([^/]+)/?\z!);
38 index($dst, "\n") >= 0 and die "`\\n' not allowed in `$dst'";
40 # n.b. this is still a truckload of code...
42 require PublicInbox::LEI;
43 require PublicInbox::LeiExternal;
44 require PublicInbox::LeiMirror;
45 require PublicInbox::LeiCurl;
46 require PublicInbox::Lock;
48 $url = PublicInbox::LeiExternal::ext_canonicalize($url);
50 env => \%ENV, opt => $opt, cmd => 'public-inbox-clone',
51 0 => *STDIN{GLOB}, 2 => *STDERR{GLOB},
52 }, 'PublicInbox::LEI';
53 open $lei->{1}, '+<&=', 1 or die "dup: $!";
54 open $lei->{3}, '.' or die "open . $!";
59 }, 'PublicInbox::LeiMirror';
63 $mrr->can('_wq_done_wait')->([$mrr, $lei], $$);
64 exit(($lei->{child_error} // 0) >> 8);