1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # common stuff for administrative command-line tools
5 # Unstable internal API
6 package PublicInbox::Admin;
10 use base qw(Exporter);
11 our @EXPORT_OK = qw(resolve_repo_dir);
13 sub resolve_repo_dir {
15 my $prefix = defined $cd ? $cd : './';
16 if (-d $prefix && -f "$prefix/inbox.lock") { # v2
18 return abs_path($prefix);
21 my @cmd = qw(git rev-parse --git-dir);
22 my $cmd = join(' ', @cmd);
23 my $pid = open my $fh, '-|';
24 defined $pid or die "forking $cmd failed: $!\n";
27 chdir $cd or die "chdir $cd failed: $!\n";
30 die "Failed to exec $cmd: $!\n";
36 close $fh or die "error in $cmd: $!\n";
39 return abs_path($cd) if ($dir eq '.' && defined $cd);
44 # TODO: make Devel::Peek optional, only used for daemon
45 my @base_mod = qw(Email::MIME Date::Parse Devel::Peek);
46 my @over_mod = qw(DBD::SQLite DBI);
48 -index => [ @base_mod, @over_mod ],
50 -search => [ @base_mod, @over_mod, 'Search::Xapian' ],
53 sub scan_ibx_modules ($$) {
54 my ($mods, $ibx) = @_;
55 if (!$ibx->{indexlevel} || $ibx->{indexlevel} ne 'basic') {
56 $mods->{'Search::Xapian'} = 1;
58 $mods->{$_} = 1 foreach @over_mod;
65 while (my $mod = shift @mods) {
66 if (my $groups = $mod_groups{$mod}) {
70 $err->{$mod} = $@ if $@;
73 scalar keys %$err ? $err : undef;
78 my @mods = map { "`$_'" } sort keys %$err;
80 @mods ? (join(', ', @mods)."' and $last") : $last
84 my $err = check_require(@_) or return;
85 die missing_mod_msg($err)." required for $0\n";
88 sub indexlevel_ok_or_die ($) {
89 my ($indexlevel) = @_;
91 if ($indexlevel eq 'basic') {
93 } elsif ($indexlevel =~ /\A(?:medium|full)\z/) {
97 invalid indexlevel=$indexlevel (must be `basic', `medium', or `full')
100 my $err = check_require($req) or return;
101 die missing_mod_msg($err) ." required for indexlevel=$indexlevel\n";