use v5.10.1;
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
use Fcntl qw(:DEFAULT);
-my $usage = 'public-inbox-init NAME INBOX_DIR HTTP_URL ADDRESS [ADDRESS..]';
my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
-usage: $usage
+usage: public-inbox-init NAME INBOX_DIR HTTP_URL ADDRESS [ADDRESS..]
Initialize a public-inbox
-V2 use scalable public-inbox-v2-format(5)
-L LEVEL index level `basic', `medium', or `full' (default: full)
+ --ng NEWSGROUP set NNTP newsgroup name
--skip-artnum=NUM NNTP article numbers to skip
--skip-epoch=NUM epochs to skip (-V2 only)
-J JOBS number of indexing jobs (-V2 only), (default: 4)
PublicInbox::Admin::require_or_die('-base');
my ($version, $indexlevel, $skip_epoch, $skip_artnum, $jobs, $show_help);
+my $skip_docdata;
+my $ng = '';
my %opts = (
'V|version=i' => \$version,
'L|index-level|indexlevel=s' => \$indexlevel,
'S|skip|skip-epoch=i' => \$skip_epoch,
- 'N|skip-artnum=i' => \$skip_artnum,
+ 'skip-artnum=i' => \$skip_artnum,
'j|jobs=i' => \$jobs,
- 'help|?' => \$show_help,
+ 'ng|newsgroup=s' => \$ng,
+ 'skip-docdata' => \$skip_docdata,
+ 'help|h' => \$show_help,
);
my $usage_cb = sub {
- print STDERR "Usage: $usage\n";
+ print STDERR $help;
exit 1;
};
GetOptions(%opts) or $usage_cb->();
my $http_url = shift @ARGV or $usage_cb->();
my (@address) = @ARGV;
@address or $usage_cb->();
-my %seen;
+
+$ng =~ m![^A-Za-z0-9/_\.\-\~\@\+\=:]! and
+ die "--newsgroup `$ng' is not valid\n";
+($ng =~ m!\A\.! || $ng =~ m!\.\z!) and
+ die "--newsgroup `$ng' must not start or end with `.'\n";
require PublicInbox::Config;
my $pi_config = PublicInbox::Config->default_file;
exit(255);
};
my $auto_unlink = UnlinkMe->new($lockfile);
-my $perm;
+my ($perm, %seen);
if (-e $pi_config) {
open(my $oh, '<', $pi_config) or die "unable to read $pi_config: $!\n";
my @st = stat($oh);
my $pfx = "publicinbox.$name";
my @x = (qw/git config/, "--file=$pi_config_tmp");
-require Cwd;
-$inboxdir = Cwd::abs_path($inboxdir);
+require File::Spec;
+$inboxdir = File::Spec->canonpath($inboxdir);
+
die "`\\n' not allowed in `$inboxdir'\n" if $inboxdir =~ /\n/s;
if (-f "$inboxdir/inbox.lock") {
if (!defined $version) {
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 Cwd;
+my $tmp = Cwd::abs_path($inboxdir);
+defined($tmp) or die "failed to resolve $inboxdir: $!\n";
+$inboxdir = $tmp;
+die "`\\n' not allowed in `$inboxdir'\n" if $inboxdir =~ /\n/s;
# needed for git prior to v2.1.0
umask(0077) if defined $perm;
if (defined($indexlevel)) {
PublicInbox::Import::run_die([@x, "$pfx.indexlevel", $indexlevel]);
}
+PublicInbox::Import::run_die([@x, "$pfx.newsgroup", $ng]) if $ng ne '';
# needed for git prior to v2.1.0
if (defined $perm) {