+my @x = (qw/git config/, "--file=$pi_config_tmp");
+
+$inboxdir = PublicInbox::Config::rel2abs_collapsed($inboxdir);
+die "`\\n' not allowed in `$inboxdir'\n" if index($inboxdir, "\n") >= 0;
+
+if (-f "$inboxdir/inbox.lock") {
+ if (!defined $version) {
+ $version = 2;
+ } elsif ($version != 2) {
+ die "$inboxdir is a -V2 inbox, -V$version specified\n"
+ }
+} elsif (-d "$inboxdir/objects") {
+ if (!defined $version) {
+ $version = 1;
+ } elsif ($version != 1) {
+ die "$inboxdir is a -V1 inbox, -V$version specified\n"
+ }
+}
+
+$version = 1 unless defined $version;
+
+if ($version == 1 && defined $skip_epoch) {
+ die "--skip-epoch is only supported for -V2 inboxes\n";
+}
+
+my $ibx = PublicInbox::Inbox->new({
+ inboxdir => $inboxdir,
+ name => $name,
+ version => $version,
+ -primary_address => $address[0],
+ indexlevel => $indexlevel,
+});
+
+my $creat_opt = {};
+if (defined $jobs) {
+ die "--jobs is only supported for -V2 inboxes\n" if $version == 1;
+ 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);
+
+my $f = "$inboxdir/description";
+if (sysopen $fh, $f, O_CREAT|O_EXCL|O_WRONLY) {
+ print $fh "public inbox for $address[0]\n" or die "print($f): $!";
+ close $fh or die "close($f): $!";
+}
+
+# needed for git prior to v2.1.0
+umask(0077) if defined $perm;
+
+require PublicInbox::Spawn;
+PublicInbox::Spawn->import(qw(run_die));
+