#! @interpreter@ -w # SPDX-FileCopyrightText: (C) 2014-2021 all contributors # 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));