import rt 3.4.6
[freeside.git] / rt / sbin / rt-test-dependencies.in
1 #!@PERL@
2 # BEGIN BPS TAGGED BLOCK {{{
3
4 # COPYRIGHT:
5 #  
6 # This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC 
7 #                                          <jesse@bestpractical.com>
8
9 # (Except where explicitly superseded by other copyright notices)
10
11
12 # LICENSE:
13
14 # This work is made available to you under the terms of Version 2 of
15 # the GNU General Public License. A copy of that license should have
16 # been provided with this software, but in any event can be snarfed
17 # from www.gnu.org.
18
19 # This work is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 # General Public License for more details.
23
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
28
29 # CONTRIBUTION SUBMISSION POLICY:
30
31 # (The following paragraph is not intended to limit the rights granted
32 # to you to modify and distribute this software under the terms of
33 # the GNU General Public License and is only of importance to you if
34 # you choose to contribute your changes and enhancements to the
35 # community by submitting them to Best Practical Solutions, LLC.)
36
37 # By intentionally submitting any modifications, corrections or
38 # derivatives to this work, or any other work intended for use with
39 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
40 # you are the copyright holder for those contributions and you grant
41 # Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
42 # royalty-free, perpetual, license to use, copy, create derivative
43 # works based on those contributions, and sublicense and distribute
44 # those contributions and any derivatives thereof.
45
46 # END BPS TAGGED BLOCK }}}
47 #
48 # This is just a basic script that checks to make sure that all
49 # the modules needed by RT before you can install it.
50 #
51
52 use strict;
53 no warnings qw(numeric redefine);
54 use Getopt::Long;
55 my %args;
56 my %deps;
57 GetOptions(
58     \%args,                               'v|verbose',
59     'install',                            'with-MYSQL',
60     'with-POSTGRESQL|with-pg|with-pgsql', 'with-SQLITE',
61     'with-ORACLE',                        'with-FASTCGI',
62     'with-SPEEDYCGI',                     'with-MODPERL1',
63     'with-MODPERL2',                      'with-DEV',
64     'download=s',
65     'repository=s'
66 );
67
68 unless (keys %args) {
69     help();
70     exit(0);
71 }
72
73 # Set up defaults
74 $args{'with-MASON'} = 1;
75 $args{'with-CORE'} = 1;
76 $args{'with-DEV'} =1; 
77 $args{'with-CLI'} =1; 
78 $args{'with-MAILGATE'} =1; 
79 {
80   my $section;
81   my %always_show_sections = (
82     perl => 1,
83     users => 1,
84   );
85
86   sub section {
87     my $s = shift;
88     $section = $s;
89     print "$s:\n";
90   }
91
92   my $any_missing = 0;
93   sub found {
94     my $msg = shift;
95     my $test = shift;
96     my $extra = shift;
97   
98     $any_missing = 1 unless $test;
99     if ($args{'v'} or not $test or $always_show_sections{$section}) {
100       print "\t$msg...";
101       print $test ? "found" : "MISSING";
102       print "\n";
103     }
104     
105     print "\t\t$extra\n" if defined $extra;
106   }
107
108   sub conclude {
109     if ($any_missing) {
110       print "\nSOMETHING WAS MISSING!\n";
111     } else {
112       print "\nEverything was found.\n";
113     }
114   }
115 }
116
117 sub help {
118
119     print <<'.';
120
121 By default, testdeps determine whether you have 
122 installed all the perl modules RT needs to run.
123
124         --install               Install missing modules
125
126 The following switches will tell the tool to check for specific dependencies
127
128         --with-mysql            Database interface for MySQL
129         --with-postgresql       Database interface for PostgreSQL 
130         --with-sqlite           Database interface and driver for SQLite (unsupported)
131         --with-oracle           Database interface for oracle (unsupported)
132
133         --with-fastcgi          Libraries needed to support the fastcgi handler
134         --with-speedycgi        Libraries needed to support the speedycgi handler
135         --with-modperl1         Libraries needed to support the modperl 1 handler
136         --with-modperl2         Libraries needed to support the modperl 2 handler
137
138         --with-dev              Tools needed for RT development
139
140 You can also specify -v or --verbose to list the status of all dependencies,
141 rather than just the missing ones.
142 .
143 }
144
145
146 sub _ {
147     map { /(\S+)\s*(\S*)/; $1 => ($2 ? $2 :'') } split ( /\n/, $_[0] );
148 }
149
150 $deps{'CORE'} = [ _( << '.') ];
151 Digest::base
152 Digest::MD5 2.27
153 DBI 1.37
154 Test::Inline
155 Class::ReturnValue 0.40
156 DBIx::SearchBuilder 1.35
157 Text::Template
158 File::Spec 0.8
159 HTML::Entities 
160 HTML::Scrubber 0.08
161 Net::Domain
162 Log::Dispatch 2.0
163 Locale::Maketext 1.06
164 Locale::Maketext::Lexicon 0.32
165 Locale::Maketext::Fuzzy
166 MIME::Entity 5.108
167 Mail::Mailer 1.57
168 Net::SMTP
169 Text::Wrapper 
170 Time::ParseDate
171 Time::HiRes 
172 File::Temp
173 Term::ReadKey
174 Text::Autoformat
175 Text::Quoted 1.3
176 Tree::Simple 1.04
177 Scalar::Util
178 Module::Versions::Report
179 Cache::Simple::TimedExpiry
180 XML::Simple
181 .
182
183 $deps{'MASON'} = [ _( << '.') ];
184 Params::Validate 0.02
185 Cache::Cache
186 Exception::Class 1.14
187 HTML::Mason 1.23
188 MLDBM
189 Errno
190 FreezeThaw
191 Digest::MD5 2.27
192 CGI::Cookie 1.20
193 Storable 2.08
194 Apache::Session 1.53
195 XML::RSS 1.05
196 HTTP::Server::Simple 0.07
197 HTTP::Server::Simple::Mason 0.09
198 Text::WikiFormat
199 .
200
201 $deps{'MAILGATE'} = [ _( << '.') ];
202 HTML::TreeBuilder
203 HTML::FormatText
204 Getopt::Long
205 LWP::UserAgent
206 .
207
208 $deps{'CLI'} = [ _( << '.') ];
209 Getopt::Long 2.24
210 .
211
212 $deps{'DEV'} = [ _( << '.') ];
213 Regexp::Common
214 Test::Inline 
215 Apache::Test
216 HTML::Form
217 HTML::TokeParser
218 WWW::Mechanize
219 Test::WWW::Mechanize
220 Module::Refresh 0.03
221 .
222
223 $deps{'FASTCGI'} = [ _( << '.') ];
224 CGI 2.92
225 FCGI
226 CGI::Fast 
227 .
228
229 $deps{'SPEEDYCGI'} = [ _( << '.') ];
230 CGI 2.92
231 CGI::SpeedyCGI
232 .
233
234
235 $deps{'MODPERL1'} = [ _( << '.') ];
236 CGI 2.92
237 Apache::Request
238 Apache::DBI 0.92
239 .
240
241 $deps{'MODPERL2'} = [ _( << '.') ];
242 CGI 2.92
243 Apache::DBI
244 HTML::Mason 1.31
245 .
246
247 $deps{'MYSQL'} = [ _( << '.') ];
248 DBD::mysql 2.1018
249 .
250 $deps{'ORACLE'} = [ _( << '.') ];
251 DBD::Oracle
252 .
253 $deps{'POSTGRESQL'} = [ _( << '.') ];
254 DBD::Pg 1.41
255 .
256
257 $deps{'SQLITE'} = [ _( << '.') ];
258 DBD::SQLite 1.00
259 .
260
261 if ($args{'download'}) {
262
263     download_mods();
264 }
265
266
267 check_perl_version();
268
269 check_users();
270
271
272 foreach my $type (keys %args) {
273     next unless ($type =~ /^with-(.*?)$/);
274     my $type = $1;
275     section("$type dependencies");
276     my @deps = (@{$deps{$type}});
277     while (@deps) {
278         my $module = shift @deps;
279         my $version = shift @deps;
280         my $ret = test_dep($module, $version);  
281
282         if ($args{'install'} && !$ret) {
283             resolve_dep($module);               
284         }
285     }
286 }
287
288 conclude();
289
290 sub test_dep {
291     my $module = shift;
292     my $version = shift;
293
294     eval "use $module $version ()";
295     if ($@) {
296         my $error = $@;
297         $error =~ s/\n(.*)$//s;
298         undef $error unless $error =~ /this is only/;
299         found("$module $version", 0, $error);
300
301         return undef;
302     } else {
303         found("$module $version", 1);
304         return 1;
305     }
306 }
307
308 sub resolve_dep {
309     my $module = shift;
310     system( qq[@PERL@ -MCPAN -e'install("$module")'] );
311 }
312
313 sub download_mods {
314     my %modules;
315     use CPAN;
316     
317     foreach my $key (keys %deps) {
318         my @deps = (@{$deps{$key}});
319         while (@deps) {
320             my $mod = shift @deps;
321             my $ver = shift @deps;
322             next if ($mod =~ /^(DBD-|Apache-Request)/);
323             $modules{$mod} = $ver;
324         }
325     }
326     my @mods = keys %modules;
327     CPAN::get();
328     my $moddir = $args{'download'};
329     foreach my $mod (@mods) {
330         $CPAN::Config->{'build_dir'} = $moddir;
331         CPAN::get($mod);
332     }
333
334     opendir(DIR, $moddir);
335     while ( my $dir = readdir(DIR)) {
336         print "Dir is $dir\n";
337         next if ( $dir =~ /^\.\.?$/);
338
339         # Skip things we've previously tagged
340         my $out = `svn ls $args{'repository'}/tags/$dir`;
341         next if ($out);
342
343         if ($dir =~ /^(.*)-(.*?)$/) {
344             `svn_load_dirs -no_user_input -t tags/$dir -v $args{'repository'} dists/$1 $moddir/$dir`;
345             `rm -rf $moddir/$dir`;
346
347         }
348
349     }
350     closedir(DIR);
351     exit;
352 }
353
354 sub check_perl_version {
355   section("perl");
356   eval {require 5.008003};
357   if ($@) {
358     found("5.8.3", 0, "RT is known to be non-functional on versions of perl older than 5.8.3. Please upgrade to 5.8.3 or newer.");
359     die;
360   } else {
361     found("5.8.3", 1);
362   }
363 }
364
365 sub check_users {
366   section("users");
367   found("rt group (@RTGROUP@)",      defined getgrnam("@RTGROUP@"));
368   found("bin owner (@BIN_OWNER@)",   defined getpwnam("@BIN_OWNER@"));
369   found("libs owner (@LIBS_OWNER@)", defined getpwnam("@LIBS_OWNER@"));
370   found("libs group (@LIBS_GROUP@)", defined getgrnam("@LIBS_GROUP@"));
371   found("web owner (@WEB_USER@)",    defined getpwnam("@WEB_USER@"));
372   found("web group (@WEB_GROUP@)",   defined getgrnam("@WEB_GROUP@"));
373 }
374
375
376
377 1;