]> Sergey Matveev's repositories - public-inbox.git/blob - scripts/import_vger_from_mbox
ensure Xapian and SQLite are still optional for v1 tests
[public-inbox.git] / scripts / import_vger_from_mbox
1 #!/usr/bin/perl -w
2 # Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use warnings;
6 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
7 use PublicInbox::MIME;
8 use PublicInbox::InboxWritable;
9 use PublicInbox::Import;
10 use PublicInbox::MDA;
11 my $usage = "usage: $0 NAME EMAIL DIR <MBOX\n";
12 my $dry_run;
13 my $version = 2;
14 my $variant = 'mboxrd';
15 my %opts = (
16         'n|dry-run' => \$dry_run,
17         'V|version=i' => \$version,
18         'F|format=s' => \$variant,
19 );
20 GetOptions(%opts) or die $usage;
21 if ($variant ne 'mboxrd' && $variant ne 'mboxo') {
22         die "Unsupported mbox variant: $variant\n";
23 }
24 my $name = shift or die $usage; # git
25 my $email = shift or die $usage; # git@vger.kernel.org
26 my $mainrepo = shift or die $usage; # /path/to/v2/repo
27 my $ibx = {
28         mainrepo => $mainrepo,
29         name => $name,
30         version => $version,
31         address => [ $email ],
32         filter => 'PublicInbox::Filter::Vger',
33 };
34 $ibx = PublicInbox::Inbox->new($ibx);
35 unless ($dry_run) {
36         if ($version >= 2) {
37                 require PublicInbox::V2Writable;
38                 PublicInbox::V2Writable->new($ibx, 1)->init_inbox(0);
39         } else {
40                 system(qw(git init --bare -q), $mainrepo) == 0 or die;
41         }
42 }
43 $ibx = PublicInbox::InboxWritable->new($ibx);
44 binmode STDIN;
45 $ibx->import_mbox(\*STDIN, $variant);