File: cleannewsgroups.in

package info (click to toggle)
inn2 2.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,720 kB
  • ctags: 8,983
  • sloc: ansic: 92,499; sh: 13,509; perl: 12,921; makefile: 2,985; yacc: 842; python: 342; lex: 255
file content (45 lines) | stat: -rw-r--r-- 1,538 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/perl -w
# fixscript will replace this line with code to load INN::Config

# This script cleans the newsgroups file:
#   * Groups no longer in the active file are removed.
#   * Duplicate entries are removed.  The last of a set of duplicates
#     is the one retained.  That way, you could simply append the
#     new/revised entries from a docheckgroups run and then this script
#     will remove the old ones.
#   * Groups with no description are removed.
#   * Groups matching the $remove regexp are removed.

$remove='';
# $remove='^alt\.';

open ACT, $INN::Config::active  or die "Can't open $INN::Config::active: $!\n";
while(<ACT>) {
    ($group) = split;
    $act{$group} = 1 unless($remove ne "" && $group =~ /$remove/o);
}
close ACT;

open NG, $INN::Config::newsgroups  or die "Can't open $INN::Config::newsgroups: $!\n";
while(<NG>) {
    chomp;
    ($group, $desc) = split /\s+/,$_,2;
    next unless(defined $act{$group});

    next if(!defined $desc);
    next if($desc =~ /^[?\s]*$/);
    next if($desc =~ /^no desc(ription)?(\.)?$/i);

    $hist{$group} = $desc;
}
close NG;

open NG, ">$INN::Config::newsgroups.new"  or die "Can't open $INN::Config::newsgroups.new for write: $!\n";
foreach $group (sort keys %act) {
    if(defined $hist{$group}) {
	print NG "$group\t$hist{$group}\n" or die "Can't write: $!\n";
    }
}
close NG or die "Can't close: $!\n";

rename "$INN::Config::newsgroups.new", $INN::Config::newsgroups  or die "Can't rename $INN::Config::newsgroups.new to $INN::Config::newsgroups: $!\n";