Introduce end-of-line normalization and add .gitattributes.
[usenet/newsstats.git] / install / install.pl
CommitLineData
2832c235
TH
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
14BEGIN {
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}
20use strict;
21
22use NewsStats qw(:DEFAULT);
23
24use Cwd;
25
26use DBI;
27
28################################# Main program #################################
29
30### read commandline options
31my %Options = &ReadOptions('');
32
33### change working directory to .. (as we're in .../install)
34chdir dirname($0).'/..';
35
36### read configuration
37print("Reading configuration.\n");
38my %Conf = %{ReadConfig('newsstats.conf')};
39
40##### --------------------------------------------------------------------------
41##### Database table definitions
42##### --------------------------------------------------------------------------
43
44my %DBCreate = ('DBTableRaw' => <<RAW, 'DBTableGrps' => <<GRPS);
45--
46-- Table structure for table DBTableRaw
47--
48
49CREATE 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';
67RAW
68--
69-- Table structure for table DBTableGrps
70--
71
72CREATE 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';
83GRPS
84
85##### --------------------------- End of definitions ---------------------------
86
87### create database tables
88print "-----\nStarting database table generation.\n";
89# DB init
90my $DBHandle = InitDB(\%Conf,1);
91
92# read tables
93my %TablesInDB = %{$DBHandle->table_info('%', '%', '%', 'TABLE')->fetchall_hashref('TABLE_NAME')};
94
95# check for tables and create them, if they don't exist yet
96foreach 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;
108print "Database table generation done.\n";
109
110### output information on other necessary steps
111my $Path = cwd();
112print <<TODO;
113-----
114Things left to do:
115
1161) 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
1452) Watch your $Conf{'DBTableRaw'} table fill.
146
1473) Read the documentation. ;)
148
149Enjoy!
150
151-thh <thh\@inter.net>
152TODO
153
154__END__
155
156################################ Documentation #################################
157
158=head1 NAME
159
160install - installation script
161
162=head1 SYNOPSIS
163
164B<install> [B<-Vh>]
165
166=head1 REQUIREMENTS
167
168See doc/README: Perl 5.8.x itself and the following modules from CPAN:
169
170=over 2
171
172=item -
173
174Config::Auto
175
176=item -
177
178DBI
179
180=back
181
182=head1 DESCRIPTION
183
184This script will create database tables as necessary and configured.
185
186=head2 Configuration
187
188F<install.pl> will read its configuration from F<newsstats.conf> via
189Config::Auto.
190
191See doc/INSTALL for an overview of possible configuration options.
192
193=head1 OPTIONS
194
195=over 3
196
197=item B<-V> (version)
198
199Print out version and copyright information on B<yapfaq> and exit.
200
201=item B<-h> (help)
202
203Print this man page and exit.
204
205=back
206
207=head1 FILES
208
209=over 4
210
211=item F<install.pl>
212
213The script itself.
214
215=item F<NewsStats.pm>
216
217Library functions for the NewsStats package.
218
219=item F<newsstats.conf>
220
221Runtime configuration file for B<yapfaq>.
222
223=back
224
225=head1 BUGS
226
227Please report any bugs or feature requests to the author or use the
228bug tracker at L<http://bugs.th-h.de/>!
229
230=head1 SEE ALSO
231
232=over 2
233
234=item -
235
236doc/README
237
238=item -
239
240doc/INSTALL
241
242=back
243
244This script is part of the B<NewsStats> package.
245
246=head1 AUTHOR
247
248Thomas Hochstein <thh@inter.net>
249
250=head1 COPYRIGHT AND LICENSE
251
252Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
253
254This program is free software; you may redistribute it and/or modify it
255under the same terms as Perl itself.
256
257=cut
This page took 0.021796 seconds and 4 git commands to generate.