chiark / gitweb /
WIP before any changes resulting from reading SM API stuff
[inn-innduct.git] / contrib / cleannewsgroups.in
1 #! /usr/bin/perl
2 # fixscript will replace this line with require innshellvars.pl
3
4 # This script cleans the newsgroups file:
5 #   * Groups no longer in the active file are removed.
6 #   * Duplicate entries are removed.  The last of a set of duplicates
7 #     is the one retained.  That way, you could simply append the
8 #     new/revised entries from a docheckgroups run and then this script
9 #     will remove the old ones.
10 #   * Groups with no description are removed.
11 #   * Groups matching the $remove regexp are removed.
12
13 $remove='';
14 # $remove='^alt\.';
15
16 open ACT, $inn::active  or die "Can't open $inn::active: $!\n";
17 while(<ACT>) {
18     ($group) = split;
19     $act{$group} = 1 unless($remove ne "" && $group =~ /$remove/o);
20 }
21 close ACT;
22
23 open NG, $inn::newsgroups  or die "Can't open $inn::newsgroups: $!\n";
24 while(<NG>) {
25     chomp;
26     ($group, $desc) = split /\s+/,$_,2;
27     next unless(defined $act{$group});
28
29     next if(!defined $desc);
30     next if($desc =~ /^[?\s]*$/);
31     next if($desc =~ /^no desc(ription)?(\.)?$/i);
32
33     $hist{$group} = $desc;
34 }
35 close NG;
36
37 open NG, ">$inn::newsgroups.new"  or die "Can't open $inn::newsgroups.new for write: $!\n";
38 foreach $group (sort keys %act) {
39     if(defined $hist{$group}) {
40         print NG "$group\t$hist{$group}\n" or die "Can't write: $!\n";
41     }
42 }
43 close NG or die "Can't close: $!\n";
44
45 rename "$inn::newsgroups.new", $inn::newsgroups  or die "Can't rename $inn::newsgroups.new to $inn::newsgroups: $!\n";