summary refs log tree commit diff
path: root/fleet/pkgs/public-inbox-init-lite/public-inbox-init-lite
blob: f6fd5604f69ce2890f55f4c66c6305dc2e873373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! @interpreter@ -w
# SPDX-FileCopyrightText: (C) 2014-2021 all contributors <meta@public-inbox.org>
# SPDX-License-Identifier: AGPL-3.0-or-later

use strict;
use v5.10.1;
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
use Fcntl qw(:DEFAULT);

require PublicInbox::Admin;
PublicInbox::Admin::require_or_die('-base');

my ($indexlevel, $skip_epoch, $skip_artnum, $jobs, $skip_docdata);
my %opts = (
	'indexlevel=s' => \$indexlevel,
	'skip-epoch=i' => \$skip_epoch,
	'skip-artnum=i' => \$skip_artnum,
	'jobs=i' => \$jobs,
	'skip-docdata' => \$skip_docdata,
);
GetOptions(%opts) or exit 1;
PublicInbox::Admin::indexlevel_ok_or_die($indexlevel) if defined $indexlevel;
my $name = shift @ARGV or exit 1;
my $inboxdir = shift @ARGV or exit 1;
my $primary_address = shift @ARGV or exit 1;
# TODO(V): Error if any more arguments are passed

$inboxdir = PublicInbox::Config::rel2abs_collapsed($inboxdir);
die "`\\n' not allowed in `$inboxdir'\n" if index($inboxdir, "\n") >= 0;

if (-d "$inboxdir/objects") {
	die "$inboxdir is a -V1 inbox\n"
}

my $ibx = PublicInbox::Inbox->new({
	inboxdir => $inboxdir,
	name => $name,
	version => 2,
	-primary_address => $primary_address,
	indexlevel => $indexlevel,
});

my $creat_opt = {};
if (defined $jobs) {
	die "--jobs=$jobs must be >= 1\n" if $jobs <= 0;
	$creat_opt->{nproc} = $jobs;
}

require PublicInbox::InboxWritable;
$ibx = PublicInbox::InboxWritable->new($ibx, $creat_opt);
if ($skip_docdata) {
	$ibx->{indexlevel} //= 'full'; # ensure init_inbox writes xdb
	$ibx->{indexlevel} eq 'basic' and
		die "--skip-docdata ignored with --indexlevel=basic\n";
	$ibx->{-skip_docdata} = $skip_docdata;
}
$ibx->init_inbox(0, $skip_epoch, $skip_artnum);

require PublicInbox::Spawn;
PublicInbox::Spawn->import(qw(run_die));