chiark / gitweb /
Rerun autoconf2.13 on etch and consequently refresh configure-hostname patch
[inn-innduct.git] / innfeed / procbatch.in
1 #! /usr/bin/perl
2 # fixscript will replace this line with require innshellvars.pl
3
4 # Author:       James Brister <brister@vix.com> -- berkeley-unix --
5 # Start Date:   Thu May 16 10:32:02 1996 +0200
6 # Project:      INN -- innfeed
7 # File:         procbatch.pl
8 # RCSId:        $Id: procbatch.in 6648 2004-01-25 20:07:11Z rra $
9 #
10 # Description: Take a file of the form generated by innd in the out.going
11 #              directory ("Wnm*") and separate it into tape files for inn.
12 #
13 # Thanks to Clayton O'Neill <coneill@premier.net> for serious speed
14 # improvments. 
15
16
17 #
18 #       Hmm, perhaps we should try to read "backlog-directory"
19 #       from innfeed.conf. Oh well.
20 #
21 $tapeDir = $inn'pathspool . "/innfeed"; #'
22 $destDir = $inn'spooltemp ; #'
23 $spoolArts = $inn'patharticles ; #'
24 $outGoing = $inn'pathoutgoing; #'
25
26 ##
27 ## Everything below here should probably be left alone.
28 ##
29
30 $0 =~ s!.*/!! ;
31
32 require 'getopts.pl' ;
33
34 $usage = "$0 [ -q ][ -v ][ -u ][ -e host ][ -d dir ][ -c [ -s dir ]][ -m [-t dir ]] inn-batchfile\n
35   -e host    to process on entries for only that host
36   -d dir     to put the output file(s) in that directory ($destDir)
37   -c         to check pathnames of articles before storing them
38   -s dir     to specify where the news articles are
39              ($spoolArts)
40   -m         to have $0 move the new files to the backlog directory.
41   -t dir     to specify the backlog directory ($tapeDir)
42   -u         to unlink the input files when finished
43   -v         for verbosity
44   -q         quiet mode; only display error messages. Good for cron jobs.
45
46 $0 will take an inn funnel file (normally a file in
47 $outGoing), or an innfeed ``dropped'' file, 
48 which is presumed to be of the format:
49
50         pathname message-id peer1 peer2 peer3 ...
51
52 and will break it up into files peer1.tmp peer2.tmp peer3.tmp... Each of
53 these files wil be of the format:
54
55         pathname message-id
56
57 that is the same as innfeed's backlog file format. Simply rename these files
58 to peer1 peer2 peer3 in a running innfeed's backlog directory and they will be
59 picked up automatically and processed by innfeed. Use the '-m' flag and
60 they'll be moved automatically.
61 " ;
62
63 $opt_u = $opt_h = "";  # shut up, perl -w
64 &Getopts ("he:t:s:d:cvumq") || die $usage ;
65
66 die $usage if ( $opt_h ) ;
67 die "Cannot specify both -q and -v\n\n" . $usage if ($opt_q && $opt_v);
68
69 $spoolArts = $opt_s if $opt_s ;
70 $destDir = $opt_d if $opt_d ;
71 $tapeDir = $opt_t if $opt_t ;
72 $inputFile = shift ;
73
74 die $usage if !$inputFile ;
75 unless (-f $inputFile) {
76        exit if $opt_q;
77        die "No such file: $inputFile\n\n" . $usage;
78 }
79 die "No such directory: $spoolArts\n\n" . $usage if ( ! -d $spoolArts && $opt_c ) ;
80 die "No such directory: $destDir\n\n" . $usage if ( ! -d $destDir ) ;
81 die "No such directory: $tapeDir\n\n" . $usage if ( ! -d $tapeDir && $opt_m ) ;
82
83 print "Using $inputFile\n" if $opt_v ;
84 open (INPUT,"<$inputFile") || die "$0: open ($inputFile): $!\n" ;
85
86 while (<INPUT>) {
87         chop ;
88         @F = split ;
89
90         # Check the format of the line vigorously       
91         next unless (m!^\S+/\d+ <.+@.+> \S+! || m!^@[0-9A-F]+@ <.+@.+> \S+!) ;  
92
93         if ( $opt_c ) {
94                 if ( ! -f "$spoolArts/$F[0]" )  {
95                         $missing++ ;
96                         print "Dropping file: $spoolArts/$F[0]\n" if $opt_v ;
97                         next ;
98                 }
99         }
100
101         for ($i = 2 ; $i <= $#F ; $i++) {
102                 $host = $F[$i] ;
103                 next if ($opt_e && $opt_e ne $host) ;
104
105                 # Keep out host names with any funny characters (from 
106                 # corrupted files)
107                 if ($host !~ /^[-\._0-9A-Za-z]+$/) {
108                         warn "$0: bad site name ignored: \"$host\"\n";
109                         next;
110                 }
111
112                 if ($hosts{$host}) {
113                         print {$hosts{$host}} "$F[0] $F[1]\n";
114                 } else {
115                         $outputFile = "$destDir/$host.tmp" ;
116                         print "Starting $host\n" if ($opt_v);
117                         $hosts{$host}=$host;
118                         open ($hosts{$host},">>$outputFile") || 
119                                 die "open >>$outputFile: $!\n" ;
120                         print {$hosts{$host}} "$F[0] $F[1]\n";
121                 }
122         }
123 }
124 close (INPUT) ;
125
126 foreach $host (keys %hosts) {
127         close($hosts{$host});
128         $outputFile = "$destDir/$host.tmp" ;
129         $tmpTape = "$tapeDir/$host.tmp" ;
130         $tapeFile = "$tapeDir/$host" ;
131         if ( $opt_m ) {
132                 if ($outputFile ne $tmpTape) {
133                         $cmd = "mv $outputFile $tmpTape" ;
134                         system ($cmd) ;
135                         die "$0: $cmd: failed\n" unless ($? == 0) ;
136                 }
137
138                 $cmd = "cat $tmpTape |sort -u >> $tapeFile && rm -f $tmpTape" ;
139                 system ($cmd) ;
140                 die "$0: $cmd: failed\n" unless ($? == 0) ;
141         }
142 }
143
144 unlink($inputFile) if ($opt_u);
145
146 print "$missing articles dropped\n" if ( $opt_v && $missing > 0 ) ;