]> Sergey Matveev's repositories - public-inbox.git/commitdiff
init: support --newsgroup option
authorEric Wong <e@yhbt.net>
Thu, 20 Aug 2020 20:24:39 +0000 (20:24 +0000)
committerEric Wong <e@yhbt.net>
Thu, 20 Aug 2020 21:11:04 +0000 (21:11 +0000)
We can reduce the need to edit the config file for NNTP group names
this way.

Documentation/public-inbox-config.pod
Documentation/public-inbox-init.pod
script/public-inbox-init
t/imapd.t
t/nntpd.t

index 05b8481910cacf9250ac6d86790129810a14f91b..1dfb926ebcacb6389c066faf6c1a6de93ce05438 100644 (file)
@@ -63,7 +63,7 @@ Default: none, optional
 =item publicinbox.<name>.newsgroup
 
 The NNTP group name for use with L<public-inbox-nntpd(8)>.  This
-may be any newsgroup name with hierarchies delimited by '.'.
+may be any newsgroup name with hierarchies delimited by C<.>.
 For example, the newsgroup for L<mailto:meta@public-inbox.org>
 is: C<inbox.comp.mail.public-inbox.meta>
 
index d0c87563be509c96bf15c84093d8a8fd69ec4493..ea2b38dd27dbf60ccbe52ce4c0dde29435cf80ae 100644 (file)
@@ -39,6 +39,21 @@ See L<public-inbox-config(5)> for more information.
 
 Default: C<full>
 
+=item --ng, --newsgroup NEWSGROUP
+
+The NNTP group name for use with L<public-inbox-nntpd(8)>.  This
+may be any newsgroup name with hierarchies delimited by C<.>.
+For example, the newsgroup for L<mailto:meta@public-inbox.org>
+is: C<inbox.comp.mail.public-inbox.meta>
+
+This may be set after-the-fact via C<publicinbox.$NAME.newsgroup>
+in the configuration file.  See L<public-inbox-config(5)> for more
+info.
+
+Available since public-inbox 1.6.0 (PENDING).
+
+Default: none.
+
 =item -N, --skip-artnum
 
 This option allows archivists to publish incomplete archives
@@ -94,10 +109,12 @@ Used to override the default C<~/.public-inbox/config> value.
 
 =head1 LIMITATIONS
 
-This tool predates NNTP support in public-inbox and is missing
-C<newsgroup> and many of the options documented in
-L<public-inbox-config(5)>.  See L<public-inbox-config(5)> for all the
-options which may be applied to a given inbox.
+Some of the options documented in L<public-inbox-config(5)>
+require editing the config file.  Old versions lack the
+C<--ng>/C<--newsgroup> parameter
+
+See L<public-inbox-config(5)> for all the options which may be applied
+to a given inbox.
 
 =head1 CONTACT
 
index 6852f64a9e5793b13a3077524f8ab1fa15c5ef70..90b32be8e2e46f033e7a40acc36a8e81542079b1 100755 (executable)
@@ -22,6 +22,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,12 +34,14 @@ require PublicInbox::Admin;
 PublicInbox::Admin::require_or_die('-base');
 
 my ($version, $indexlevel, $skip_epoch, $skip_artnum, $jobs, $show_help);
+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,
        'j|jobs=i' => \$jobs,
+       'ng|newsgroup=s' => \$ng,
        'help|?' => \$show_help,
 );
 my $usage_cb = sub {
@@ -53,7 +56,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 +91,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);
@@ -185,6 +192,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) {
index 6cfced411c2288e73877392aab33062eedfdd405..4d627af7f102fb2bb80c5d5c934c45bbad0bb3cb 100644 (file)
--- a/t/imapd.t
+++ b/t/imapd.t
@@ -39,11 +39,9 @@ for my $V (@V) {
        my $url = "http://example.com/i$V";
        my $inboxdir = "$tmpdir/$name";
        my $folder = "inbox.i$V";
-       my $cmd = ['-init', "-V$V", "-L$level", $name, $inboxdir, $url, $addr];
+       my $cmd = ['-init', "-V$V", "-L$level", "--ng=$folder",
+               $name, $inboxdir, $url, $addr];
        run_script($cmd) or BAIL_OUT("init $name");
-       xsys(qw(git config), "--file=$ENV{HOME}/.public-inbox/config",
-                       "publicinbox.$name.newsgroup", $folder) == 0 or
-                       BAIL_OUT("setting newsgroup $V");
        if ($V == 1) {
                xsys(qw(git config), "--file=$ENV{HOME}/.public-inbox/config",
                        'publicinboxmda.spamcheck', 'none') == 0 or
index b9b9a63d34ad38f5f2ce0aeb4efafa9043ec5b81..74e21a4193738e439c1e04d5bb4567678458a322 100644 (file)
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -46,14 +46,11 @@ my $ibx = {
 $ibx = PublicInbox::Inbox->new($ibx);
 {
        local $ENV{HOME} = $home;
-       my @cmd = ('-init', $group, $inboxdir, 'http://example.com/', $addr);
-       push @cmd, "-V$version", '-Lbasic';
+       my @cmd = ('-init', $group, $inboxdir, 'http://example.com/', $addr,
+               "-V$version", '-Lbasic', '--newsgroup', $group);
        ok(run_script(\@cmd), 'init OK');
-       is(xsys(qw(git config), "--file=$home/.public-inbox/config",
-                       "publicinbox.$group.newsgroup", $group),
-               0, 'enabled newsgroup');
-       my $len;
 
+       my $len;
        $ibx = PublicInbox::InboxWritable->new($ibx);
        my $im = $ibx->importer(0);