diff options
author | V <v@unfathomable.blue> | 2021-06-09 15:43:16 +0200 |
---|---|---|
committer | V <v@unfathomable.blue> | 2021-08-17 03:09:34 +0200 |
commit | ec0965e2672899d25a5a3a8c072de3ea734076a2 (patch) | |
tree | ddf53e6cc5ae47fa1a925f7a7d6414ba03718a84 /fleet/pkgs/public-inbox-init-lite | |
parent | db7c54f92f386a94db8af7a12626d2657b4dd640 (diff) | |
download | unf-legacy-ec0965e2672899d25a5a3a8c072de3ea734076a2.tar.zst |
fleet: init
Co-authored-by: edef <edef@unfathomable.blue> Change-Id: I36d2c4cca542ed91630b1b832f3c7a7b97b33c65
Diffstat (limited to 'fleet/pkgs/public-inbox-init-lite')
-rw-r--r-- | fleet/pkgs/public-inbox-init-lite/default.nix | 18 | ||||
-rw-r--r-- | fleet/pkgs/public-inbox-init-lite/public-inbox-init-lite | 60 |
2 files changed, 78 insertions, 0 deletions
diff --git a/fleet/pkgs/public-inbox-init-lite/default.nix b/fleet/pkgs/public-inbox-init-lite/default.nix new file mode 100644 index 0000000..8704ea3 --- /dev/null +++ b/fleet/pkgs/public-inbox-init-lite/default.nix @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: V <v@unfathomable.blue> +# SPDX-License-Identifier: OSL-3.0 + +{ lib, substituteAll, public-inbox, runCommand, makeWrapper, git, xapian }: + +let + perl = public-inbox.fullperl.withPackages + (ps: with ps; [ public-inbox URI DBDSQLite SearchXapian ]); + + subbed = substituteAll { + src = ./public-inbox-init-lite; + isExecutable = true; + inherit (perl) interpreter; + }; +in runCommand "public-inbox-init-lite" { nativeBuildInputs = [ makeWrapper ]; } '' + makeWrapper ${subbed} $out/bin/public-inbox-init-lite \ + --prefix PATH : ${lib.makeBinPath [ git xapian ]} +'' diff --git a/fleet/pkgs/public-inbox-init-lite/public-inbox-init-lite b/fleet/pkgs/public-inbox-init-lite/public-inbox-init-lite new file mode 100644 index 0000000..f6fd560 --- /dev/null +++ b/fleet/pkgs/public-inbox-init-lite/public-inbox-init-lite @@ -0,0 +1,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)); |