summary refs log tree commit diff
path: root/fleet/pkgs/public-inbox-init-lite
diff options
context:
space:
mode:
Diffstat (limited to 'fleet/pkgs/public-inbox-init-lite')
-rw-r--r--fleet/pkgs/public-inbox-init-lite/default.nix18
-rw-r--r--fleet/pkgs/public-inbox-init-lite/public-inbox-init-lite60
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));