]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-init
script/*: fold $usage into $help, support `-h' instead of -?
[public-inbox.git] / script / public-inbox-init
index 6852f64a9e5793b13a3077524f8ab1fa15c5ef70..ae4a575ca3ba80423fcc0fa0579256a0386baacb 100755 (executable)
@@ -5,9 +5,8 @@ use strict;
 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
 
@@ -22,6 +21,7 @@ options:
 
   -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)
@@ -33,16 +33,20 @@ require PublicInbox::Admin;
 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->();
@@ -53,7 +57,11 @@ my $inboxdir = shift @ARGV 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;
@@ -84,7 +92,7 @@ sysopen($lockfh, $lockfile, O_RDWR|O_CREAT|O_EXCL) or do {
        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);
@@ -170,6 +178,12 @@ if (defined $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);
 
 # needed for git prior to v2.1.0
@@ -185,6 +199,7 @@ PublicInbox::Import::run_die([@x, "$pfx.inboxdir", $inboxdir]);
 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) {