script/public-inbox-init | 79 +++++++++++++++++++++++++++++++++--------------------
diff --git a/script/public-inbox-init b/script/public-inbox-init
index 1c8066df603e121ccfc6ab6af77f7a04becbbf78..6852f64a9e5793b13a3077524f8ab1fa15c5ef70 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -1,57 +1,76 @@
-#!/usr/bin/perl -w
+#!perl -w
# Copyright (C) 2014-2020 all contributors
# License: AGPL-3.0+
-#
-# Initializes a public-inbox, basically a wrapper for git-init(1)
use strict;
-use warnings;
-sub usage {
- print STDERR < \$version,
'L|index-level|indexlevel=s' => \$indexlevel,
'S|skip|skip-epoch=i' => \$skip_epoch,
'N|skip-artnum=i' => \$skip_artnum,
'j|jobs=i' => \$jobs,
+ 'help|?' => \$show_help,
);
-GetOptions(%opts) or usage();
+my $usage_cb = sub {
+ print STDERR "Usage: $usage\n";
+ exit 1;
+};
+GetOptions(%opts) or $usage_cb->();
+if ($show_help) { print $help; exit 0 };
PublicInbox::Admin::indexlevel_ok_or_die($indexlevel) if defined $indexlevel;
-my $name = shift @ARGV or usage();
-my $inboxdir = shift @ARGV or usage();
-my $http_url = shift @ARGV or usage();
+my $name = shift @ARGV or $usage_cb->();
+my $inboxdir = shift @ARGV or $usage_cb->();
+my $http_url = shift @ARGV or $usage_cb->();
my (@address) = @ARGV;
-@address or usage();
+@address or $usage_cb->();
my %seen;
+require PublicInbox::Config;
my $pi_config = PublicInbox::Config->default_file;
-my $dir = dirname($pi_config);
-mkpath($dir); # will croak on fatal errors
+require File::Basename;
+my $dir = File::Basename::dirname($pi_config);
+require File::Path;
+File::Path::mkpath($dir); # will croak on fatal errors
# first, we grab a flock to prevent simultaneous public-inbox-init
# processes from trampling over each other, or exiting with 255 on
# O_EXCL failure below. This gets unlocked automatically on exit:
+require PublicInbox::Lock;
my $lock_obj = { lock_path => "$pi_config.flock" };
PublicInbox::Lock::lock_acquire($lock_obj);
# git-config will operate on this (and rename on success):
+require File::Temp;
my $fh = File::Temp->new(TEMPLATE => 'pi-init-XXXXXXXX', DIR => $dir);
# Now, we grab another lock to use git-config(1) locking, so it won't
@@ -111,7 +130,8 @@
my $pfx = "publicinbox.$name";
my @x = (qw/git config/, "--file=$pi_config_tmp");
-$inboxdir = abs_path($inboxdir);
+require Cwd;
+$inboxdir = Cwd::abs_path($inboxdir);
die "`\\n' not allowed in `$inboxdir'\n" if $inboxdir =~ /\n/s;
if (-f "$inboxdir/inbox.lock") {
if (!defined $version) {
@@ -148,6 +168,7 @@ die "--jobs=$jobs must be >= 1\n" if $jobs <= 0;
$creat_opt->{nproc} = $jobs;
}
+require PublicInbox::InboxWritable;
$ibx = PublicInbox::InboxWritable->new($ibx, $creat_opt);
$ibx->init_inbox(0, $skip_epoch, $skip_artnum);