5 # This script will create database tables as necessary.
7 # It is part of the NewsStats package.
9 # Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
11 # It can be redistributed and/or modified under the same terms under
12 # which Perl itself is published.
15 our $VERSION = "0.01";
17 # we're in .../install, so our module is in ..
18 push(@INC, dirname($0).'/..');
22 use NewsStats qw(:DEFAULT);
28 ################################# Main program #################################
30 ### read commandline options
31 my %Options = &ReadOptions('');
33 ### change working directory to .. (as we're in .../install)
34 chdir dirname($0).'/..';
36 ### read configuration
37 print("Reading configuration.\n");
38 my %Conf = %{ReadConfig('newsstats.conf')};
40 ##### --------------------------------------------------------------------------
41 ##### Database table definitions
42 ##### --------------------------------------------------------------------------
44 my %DBCreate = ('DBTableRaw' => <<RAW, 'DBTableGrps' => <<GRPS);
46 -- Table structure for table DBTableRaw
49 CREATE TABLE IF NOT EXISTS `$Conf{'DBTableRaw'}` (
50 `id` bigint(20) unsigned NOT NULL auto_increment,
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',
66 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Raw data';
69 -- Table structure for table DBTableGrps
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,
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';
85 ##### --------------------------- End of definitions ---------------------------
87 ### create database tables
88 print "-----\nStarting database table generation.\n";
90 my $DBHandle = InitDB(\%Conf,1);
93 my %TablesInDB = %{$DBHandle->table_info('%', '%', '%', 'TABLE')->fetchall_hashref('TABLE_NAME')};
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});
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});
107 $DBHandle->disconnect;
108 print "Database table generation done.\n";
110 ### output information on other necessary steps
116 1) Setup an INN feed to feedlog.pl
118 a) Edit your 'newsfeeds' file and insert something like
120 ## gather statistics for NewsStats
123 :Tc,WmtfbsPNH,Ac:$Path/feedlog.pl
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
131 b) Check your 'newsfeeds' syntax:
135 and reload 'newsfeeds':
137 # ctlinnd reload newsfeeds 'Adding newsstats! feed'
139 c) Watch your 'news.notice' and 'errlog' files:
141 # tail -f /var/log/news/news.notice
143 # tail -f /var/log/news/errlog
145 2) Watch your $Conf{'DBTableRaw'} table fill.
147 3) Read the documentation. ;)
151 -thh <thh\@inter.net>
156 ################################ Documentation #################################
160 install - installation script
168 See doc/README: Perl 5.8.x itself and the following modules from CPAN:
184 This script will create database tables as necessary and configured.
188 F<install.pl> will read its configuration from F<newsstats.conf> via
191 See doc/INSTALL for an overview of possible configuration options.
197 =item B<-V> (version)
199 Print out version and copyright information on B<yapfaq> and exit.
203 Print this man page and exit.
215 =item F<NewsStats.pm>
217 Library functions for the NewsStats package.
219 =item F<newsstats.conf>
221 Runtime configuration file for B<yapfaq>.
227 Please report any bugs or feature requests to the author or use the
228 bug tracker at L<http://bugs.th-h.de/>!
244 This script is part of the B<NewsStats> package.
248 Thomas Hochstein <thh@inter.net>
250 =head1 COPYRIGHT AND LICENSE
252 Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
254 This program is free software; you may redistribute it and/or modify it
255 under the same terms as Perl itself.