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