d45d9114fc02cf768bf0a13f55eaf69cdb29870b
[usenet/newsstats.git] / install / install.pl
1 #! /usr/bin/perl -W
2 #
3 # install.pl
4 #
5 # This script will create database tables as necessary.
6
7 # It is part of the NewsStats package.
8 #
9 # Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
10 #
11 # It can be redistributed and/or modified under the same terms under 
12 # which Perl itself is published.
13
14 BEGIN {
15   our $VERSION = "0.01";
16   use File::Basename;
17   # we're in .../install, so our module is in ..
18   push(@INC, dirname($0).'/..');
19 }
20 use strict;
21
22 use NewsStats qw(:DEFAULT);
23
24 use Cwd;
25
26 use DBI;
27
28 ################################# Main program #################################
29
30 ### read commandline options
31 my %Options = &ReadOptions('');
32
33 ### change working directory to .. (as we're in .../install)
34 chdir dirname($0).'/..';
35
36 ### read configuration
37 print("Reading configuration.\n");
38 my %Conf = %{ReadConfig('newsstats.conf')};
39
40 ##### --------------------------------------------------------------------------
41 ##### Database table definitions
42 ##### --------------------------------------------------------------------------
43
44 my %DBCreate = ('DBTableRaw'  => <<RAW, 'DBTableGrps' => <<GRPS);
45 -- 
46 -- Table structure for table DBTableRaw
47 -- 
48
49 CREATE TABLE IF NOT EXISTS `$Conf{'DBTableRaw'}` (
50   `id` bigint(20) unsigned NOT NULL auto_increment,
51   `day` date NOT NULL,
52   `mid` varchar(250) character set ascii NOT NULL,
53   `date` datetime NOT NULL,
54   `timestamp` bigint(20) NOT NULL,
55   `token` varchar(80) character set ascii NOT NULL,
56   `size` bigint(20) NOT NULL,
57   `peer` varchar(250) NOT NULL,
58   `path` varchar(1000) NOT NULL,
59   `newsgroups` varchar(1000) NOT NULL,
60   `headers` longtext NOT NULL,
61   `disregard` tinyint(1) default '0',
62   PRIMARY KEY  (`id`),
63   KEY `day` (`day`),
64   KEY `mid` (`mid`),
65   KEY `peer` (`peer`)
66 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Raw data';
67 RAW
68 -- 
69 -- Table structure for table DBTableGrps
70 -- 
71
72 CREATE TABLE IF NOT EXISTS `$Conf{'DBTableGrps'}` (
73   `id` bigint(20) unsigned NOT NULL auto_increment,
74   `month` varchar(7) character set ascii NOT NULL,
75   `newsgroup` varchar(100) NOT NULL,
76   `postings` int(11) NOT NULL,
77   `revision` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
78   PRIMARY KEY  (`id`),
79   UNIQUE KEY `month_newsgroup` (`month`,`newsgroup`),
80   KEY `newsgroup` (`newsgroup`),
81   KEY `postings` (`postings`)
82 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Postings per newsgroup';
83 GRPS
84
85 ##### --------------------------- End of definitions ---------------------------
86
87 ### create database tables
88 print "-----\nStarting database table generation.\n";
89 # DB init
90 my $DBHandle = InitDB(\%Conf,1);
91
92 # read tables
93 my %TablesInDB = %{$DBHandle->table_info('%', '%', '%', 'TABLE')->fetchall_hashref('TABLE_NAME')};
94
95 # check for tables and create them, if they don't exist yet
96 foreach my $Table (keys %DBCreate) {
97   if (defined($TablesInDB{$Conf{$Table}})) {
98     printf("Database table %s.%s already exists, skipping ....\n",$Conf{'DBDatabase'},$Conf{$Table});
99     next;
100   };
101   my $DBQuery = $DBHandle->prepare($DBCreate{$Table});
102   $DBQuery->execute() or die sprintf("$MySelf: E: Can't create table %s in database %s: %s%\n",$Table,$Conf{'DBDatabase'},$DBI::errstr);
103   printf("Database table %s.%s created succesfully.\n",$Conf{'DBDatabase'},$Conf{$Table});
104 };
105
106 # close handle
107 $DBHandle->disconnect;
108 print "Database table generation done.\n";
109
110 ### output information on other necessary steps
111 my $Path = cwd();
112 print <<TODO;
113 -----
114 Things left to do:
115
116 1) Setup an INN feed to feedlog.pl
117
118    a) Edit your 'newsfeeds' file and insert something like
119
120           ## gather statistics for NewsStats
121           newsstats!\
122                   :!*,de.*\
123                   :Tc,WmtfbsPNH,Ac:$Path/feedlog.pl
124
125       Please
126
127       * check that you got the path to feedlog.pl right
128       * check that feedlog.pl can be executed by the news user
129       * adapt the pattern (here: 'de.*') to your needs
130
131    b) Check your 'newsfeeds' syntax:
132
133          # ctlinnd checkfile
134
135       and reload 'newsfeeds':
136
137          # ctlinnd reload newsfeeds 'Adding newsstats! feed'
138
139    c) Watch your 'news.notice' and 'errlog' files:
140
141          # tail -f /var/log/news/news.notice
142          ...
143          # tail -f /var/log/news/errlog
144
145 2) Watch your $Conf{'DBTableRaw'} table fill.
146
147 3) Read the documentation. ;)
148
149 Enjoy!
150
151 -thh <thh\@inter.net>
152 TODO
153
154 __END__
155
156 ################################ Documentation #################################
157
158 =head1 NAME
159
160 install - installation script
161
162 =head1 SYNOPSIS
163
164 B<install> [B<-Vh>]
165
166 =head1 REQUIREMENTS
167
168 See doc/README: Perl 5.8.x itself and the following modules from CPAN:
169
170 =over 2
171
172 =item -
173
174 Config::Auto
175
176 =item -
177
178 DBI
179
180 =back
181
182 =head1 DESCRIPTION
183
184 This script will create database tables as necessary and configured.
185
186 =head2 Configuration
187
188 F<install.pl> will read its configuration from F<newsstats.conf> via
189 Config::Auto.
190
191 See doc/INSTALL for an overview of possible configuration options.
192
193 =head1 OPTIONS
194
195 =over 3
196
197 =item B<-V> (version)
198
199 Print out version and copyright information on B<yapfaq> and exit.
200
201 =item B<-h> (help)
202
203 Print this man page and exit.
204
205 =back
206
207 =head1 FILES
208
209 =over 4
210
211 =item F<install.pl>
212
213 The script itself.
214
215 =item F<NewsStats.pm>
216
217 Library functions for the NewsStats package.
218
219 =item F<newsstats.conf>
220
221 Runtime configuration file for B<yapfaq>.
222
223 =back
224
225 =head1 BUGS
226
227 Please report any bugs or feature requests to the author or use the
228 bug tracker at L<http://bugs.th-h.de/>!
229
230 =head1 SEE ALSO
231
232 =over 2
233
234 =item -
235
236 doc/README
237
238 =item -
239
240 doc/INSTALL
241
242 =back
243
244 This script is part of the B<NewsStats> package.
245
246 =head1 AUTHOR
247
248 Thomas Hochstein <thh@inter.net>
249
250 =head1 COPYRIGHT AND LICENSE
251
252 Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
253
254 This program is free software; you may redistribute it and/or modify it
255 under the same terms as Perl itself.
256
257 =cut
This page took 0.014465 seconds and 2 git commands to generate.