]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-index
admin: improve warnings and errors for missing modules
[public-inbox.git] / script / public-inbox-index
index 2f810a564f01367a592c0862705074e077a193c9..cf001cc1504e219cfe384168acd6a19f0a5cf3a1 100755 (executable)
@@ -10,26 +10,24 @@ use strict;
 use warnings;
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 my $usage = "public-inbox-index REPO_DIR";
-use PublicInbox::Config;
 use PublicInbox::Admin qw(resolve_repo_dir);
+PublicInbox::Admin::require_or_die('-index');
+require PublicInbox::Config;
 
 my $config = eval { PublicInbox::Config->new } || eval {
        warn "public-inbox unconfigured for serving, indexing anyways...\n";
        undef;
 };
-eval { require PublicInbox::SearchIdx };
-if ($@) {
-       print STDERR "Search::Xapian required for $0\n";
-       exit 1;
-}
 
 my $reindex;
 my $prune;
 my $jobs = undef;
+my $indexlevel;
 my %opts = (
        '--reindex' => \$reindex,
        '--jobs|j=i' => \$jobs,
        '--prune' => \$prune,
+        'L|indexlevel=s' => \$indexlevel,
 );
 GetOptions(%opts) or die "bad command-line args\n$usage";
 die "--jobs must be positive\n" if defined $jobs && $jobs < 0;
@@ -54,25 +52,41 @@ defined($config) and $config->each_inbox(sub {
        }
 });
 
+my @inboxes;
+my $mods = {};
+
 foreach my $dir (@dirs) {
-       if (!ref($dir) && -f "$dir/inbox.lock") { # v2
-               my $ibx = { mainrepo => $dir, name => 'unnamed' };
-               $dir = PublicInbox::Inbox->new($ibx);
+       my $ibx = $dir;
+       if (!ref($ibx)) {
+               unless (-d $dir) {
+                       die "$dir does not appear to be an inbox repository\n";
+               }
+               $ibx = PublicInbox::Inbox->new({
+                       mainrepo => $dir,
+                       name => 'unnamed',
+                       indexlevel => $indexlevel,
+                       version => -f "$dir/inbox.lock" ? 2 : 1,
+               });
+       } elsif (defined $indexlevel && !defined($ibx->{indexlevel})) {
+               # XXX: users can shoot themselves in the foot, with this...
+               $ibx->{indexlevel} = $indexlevel;
        }
-       index_dir($dir);
+       push @inboxes, $ibx;
+       PublicInbox::Admin::scan_ibx_modules($mods, $ibx);
 }
 
-sub index_dir {
+PublicInbox::Admin::require_or_die(keys %$mods);
+
+require PublicInbox::SearchIdx;
+index_inbox($_) for @inboxes;
+
+sub index_inbox {
        my ($repo) = @_;
-       if (!ref $repo && ! -d $repo) {
-               die "$repo does not appear to be an inbox repository\n";
-       }
        if (ref($repo) && ($repo->{version} || 1) == 2) {
                eval { require PublicInbox::V2Writable };
                die "v2 requirements not met: $@\n" if $@;
                my $v2w = eval {
-                       $jobs and local $ENV{NPROC} = $jobs;
-                       PublicInbox::V2Writable->new($repo);
+                       PublicInbox::V2Writable->new($repo, {nproc=>$jobs});
                };
                if (defined $jobs) {
                        if ($jobs == 0) {