README: Fix spelling, small changes.
[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
f6d15ca7 31my %Options = &ReadOptions('u:');
2832c235
TH
32
33### change working directory to .. (as we're in .../install)
34chdir dirname($0).'/..';
f6d15ca7 35my $Path = cwd();
2832c235
TH
36
37### read configuration
38print("Reading configuration.\n");
39my %Conf = %{ReadConfig('newsstats.conf')};
40
41##### --------------------------------------------------------------------------
42##### Database table definitions
43##### --------------------------------------------------------------------------
44
45my %DBCreate = ('DBTableRaw' => <<RAW, 'DBTableGrps' => <<GRPS);
46--
47-- Table structure for table DBTableRaw
48--
49
50CREATE TABLE IF NOT EXISTS `$Conf{'DBTableRaw'}` (
51 `id` bigint(20) unsigned NOT NULL auto_increment,
52 `day` date NOT NULL,
53 `mid` varchar(250) character set ascii NOT NULL,
54 `date` datetime NOT NULL,
55 `timestamp` bigint(20) NOT NULL,
56 `token` varchar(80) character set ascii NOT NULL,
57 `size` bigint(20) NOT NULL,
58 `peer` varchar(250) NOT NULL,
59 `path` varchar(1000) NOT NULL,
60 `newsgroups` varchar(1000) NOT NULL,
61 `headers` longtext NOT NULL,
62 `disregard` tinyint(1) default '0',
63 PRIMARY KEY (`id`),
64 KEY `day` (`day`),
65 KEY `mid` (`mid`),
66 KEY `peer` (`peer`)
67) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Raw data';
68RAW
69--
70-- Table structure for table DBTableGrps
71--
72
73CREATE TABLE IF NOT EXISTS `$Conf{'DBTableGrps'}` (
74 `id` bigint(20) unsigned NOT NULL auto_increment,
75 `month` varchar(7) character set ascii NOT NULL,
76 `newsgroup` varchar(100) NOT NULL,
77 `postings` int(11) NOT NULL,
78 `revision` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
79 PRIMARY KEY (`id`),
80 UNIQUE KEY `month_newsgroup` (`month`,`newsgroup`),
81 KEY `newsgroup` (`newsgroup`),
82 KEY `postings` (`postings`)
83) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postings per newsgroup';
84GRPS
85
f6d15ca7
TH
86##### --------------------------------------------------------------------------
87##### Installation / upgrade instructions
88##### --------------------------------------------------------------------------
2832c235 89
f6d15ca7
TH
90my $Install = <<INSTALL;
91----------
2832c235
TH
92Things left to do:
93
941) Setup an INN feed to feedlog.pl
95
96 a) Edit your 'newsfeeds' file and insert something like
97
98 ## gather statistics for NewsStats
9c141b0c
TH
99 newsstats!\\
100 :!*,de.*\\
2832c235
TH
101 :Tc,WmtfbsPNH,Ac:$Path/feedlog.pl
102
103 Please
104
105 * check that you got the path to feedlog.pl right
106 * check that feedlog.pl can be executed by the news user
107 * adapt the pattern (here: 'de.*') to your needs
108
109 b) Check your 'newsfeeds' syntax:
110
111 # ctlinnd checkfile
112
113 and reload 'newsfeeds':
114
115 # ctlinnd reload newsfeeds 'Adding newsstats! feed'
116
117 c) Watch your 'news.notice' and 'errlog' files:
118
119 # tail -f /var/log/news/news.notice
120 ...
121 # tail -f /var/log/news/errlog
122
1232) Watch your $Conf{'DBTableRaw'} table fill.
124
1253) Read the documentation. ;)
126
127Enjoy!
128
129-thh <thh\@inter.net>
f6d15ca7
TH
130INSTALL
131
132my $Upgrade = <<UPGRADE;
133----------
134Your installation was upgraded from $Options{'u'} to $PackageVersion.
135
136Don't forget to restart your INN feed so that it can pick up the new version:
137
138 # ctlinnd begin 'newsstats!'
139
140(or whatever you called your feed).
141UPGRADE
142
143##### --------------------------------------------------------------------------
144##### Upgrading
145##### --------------------------------------------------------------------------
146my (%DBUpgrade,%Instructions);
147
148# 0.01 -> 0.02
149$DBUpgrade{'0.02'} = <<DB0point02;
150SELECT 1;
151DB0point02
152$Instructions{'0.02'} = <<IN0point02;
153Dummy Instructions.
154IN0point02
155
156##### --------------------------- End of definitions ---------------------------
157
158### DB init, read list of tables
159print "Reading database information.\n";
160my $DBHandle = InitDB(\%Conf,1);
161my %TablesInDB = %{$DBHandle->table_info('%', '%', '%', 'TABLE')->fetchall_hashref('TABLE_NAME')};
162
163if (!$Options{'u'}) {
164 ##### installation mode
165 print "----------\nStarting database table generation.\n";
166 # check for tables and create them, if they don't exist yet
167 foreach my $Table (keys %DBCreate) {
168 &CreateTable($Table);
169 };
170 print "Database table generation done.\n";
171
172 # Display install instructions
173 print $Install;
174} else {
175 ##### upgrade mode
176 print "----------\nStarting upgrade process.\n";
177 if ($Options{'u'} < $PackageVersion) {
178 # Database upgrades for each version
179 foreach my $UpVersion (sort keys %DBUpgrade) {
180 if ($UpVersion > $Options{'u'} and $UpVersion <= $PackageVersion) {
181 print "v$UpVersion: Executing database upgrade ...\n";
182 &DoMySQL($DBUpgrade{$UpVersion});
183 };
184 };
185 # Display upgrade instructions for each version
186 foreach my $UpVersion (sort keys %Instructions) {
187 if ($UpVersion > $Options{'u'} and $UpVersion <= $PackageVersion) {
188 print "v$UpVersion: Upgrade Instructions >>>>>\n";
189 my $Padding = ' ' x (length($UpVersion) + 3);
190 $Instructions{$UpVersion} =~ s/^/$Padding/;
191 print $Instructions{$UpVersion};
192 print "<" x (length($UpVersion) + 29) . "\n";
193 };
194 };
195 };
196 # Display upgrade instructions
197 print $Upgrade;
198};
199
200# close handle
201$DBHandle->disconnect;
202
203exit(0);
204
205################################# Subroutines ##################################
206
207sub CreateTable() {
208 my $Table = shift;
209 if (defined($TablesInDB{$Conf{$Table}})) {
210 printf("Database table %s.%s already exists, skipping ....\n",$Conf{'DBDatabase'},$Conf{$Table});
211 return;
212 };
213 my $DBQuery = $DBHandle->prepare($DBCreate{$Table});
214 $DBQuery->execute() or die sprintf("$MySelf: E: Can't create table %s in database %s: %s%\n",$Table,$Conf{'DBDatabase'},$DBI::errstr);
215 printf("Database table %s.%s created succesfully.\n",$Conf{'DBDatabase'},$Conf{$Table});
216 return;
217};
218
219sub DoMySQL() {
220 my $SQL = shift;
221 my $DBQuery = $DBHandle->prepare($SQL);
222 $DBQuery->execute() or warn sprintf("$MySelf: E: Database error: %s\n",$DBI::errstr);
223 return;
224};
225
2832c235
TH
226
227__END__
228
229################################ Documentation #################################
230
231=head1 NAME
232
233install - installation script
234
235=head1 SYNOPSIS
236
237B<install> [B<-Vh>]
238
239=head1 REQUIREMENTS
240
241See doc/README: Perl 5.8.x itself and the following modules from CPAN:
242
243=over 2
244
245=item -
246
247Config::Auto
248
249=item -
250
251DBI
252
253=back
254
255=head1 DESCRIPTION
256
257This script will create database tables as necessary and configured.
258
259=head2 Configuration
260
261F<install.pl> will read its configuration from F<newsstats.conf> via
262Config::Auto.
263
264See doc/INSTALL for an overview of possible configuration options.
265
266=head1 OPTIONS
267
268=over 3
269
270=item B<-V> (version)
271
272Print out version and copyright information on B<yapfaq> and exit.
273
274=item B<-h> (help)
275
276Print this man page and exit.
277
278=back
279
280=head1 FILES
281
282=over 4
283
284=item F<install.pl>
285
286The script itself.
287
288=item F<NewsStats.pm>
289
290Library functions for the NewsStats package.
291
292=item F<newsstats.conf>
293
294Runtime configuration file for B<yapfaq>.
295
296=back
297
298=head1 BUGS
299
300Please report any bugs or feature requests to the author or use the
301bug tracker at L<http://bugs.th-h.de/>!
302
303=head1 SEE ALSO
304
305=over 2
306
307=item -
308
309doc/README
310
311=item -
312
313doc/INSTALL
314
315=back
316
317This script is part of the B<NewsStats> package.
318
319=head1 AUTHOR
320
321Thomas Hochstein <thh@inter.net>
322
323=head1 COPYRIGHT AND LICENSE
324
325Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
326
327This program is free software; you may redistribute it and/or modify it
328under the same terms as Perl itself.
329
330=cut
This page took 0.0252 seconds and 4 git commands to generate.