import rt 3.2.2
[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-2004 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 use CPAN;
56 my %args;
57 my %deps;
58 GetOptions(\%args, 'v|verbose', 'install', 'with-MYSQL', 'with-POSTGRESQL|with-pg|with-pgsql', 'with-SQLITE', 'with-ORACLE', 'with-FASTCGI', 'with-SPEEDYCGI', 'with-MODPERL1', 'with-MODPERL2' ,'with-DEV', 'download=s');
59
60 if (!keys %args) {
61     help();
62     exit(0);
63 }
64 if ($args{'with-MODPERL2'}) {
65     warn_modperl2();
66 }
67
68 $args{'with-MASON'} = 1;
69 $args{'with-CORE'} = 1;
70 $args{'with-DEV'} =1; 
71 $args{'with-CLI'} =1; 
72 $args{'with-MAILGATE'} =1; 
73
74 sub warn_modperl2 {
75     print <<'.';
76         NOTE: mod_perl 2.0 isn't quite ready for prime_time just yet;
77         Best Practical Solutions strongly recommends that sites use
78         Apache 1.3 or FastCGI. If you MUST use mod_perl 2.0 (or 1.99),
79         please read the mailing list archives before asking for help.
80 .
81     sleep 5;
82 }
83
84
85 sub help {
86
87     print <<'.';
88
89 By default, testdeps determine whether you have 
90 installed all the perl modules RT needs to run.
91
92         --install               Install missing modules
93
94 The following switches will tell the tool to check for specific dependencies
95
96         --with-mysql            Database interface for MySQL
97         --with-postgresql       Database interface for PostgreSQL 
98         --with-sqlite           Database interface and driver for SQLite (unsupported)
99         --with-oracle           Database interface for oracle (unsupported)
100
101         --with-fastcgi          Libraries needed to support the fastcgi handler
102         --with-speedycgi        Libraries needed to support the speedycgi handler
103         --with-modperl1         Libraries needed to support the modperl 1 handler
104         --with-modperl2         Libraries needed to support the modperl 2 handler
105
106         --with-dev              Tools needed for RT development
107
108 You can also specify -v or --verbose to list the status of all dependencies,
109 rather than just the missing ones.
110 .
111 }
112
113
114 sub _ {
115     map { /(\S+)\s*(\S*)/; $1 => ($2 ? $2 :'') } split ( /\n/, $_[0] );
116 }
117
118 $deps{'CORE'} = [ _( << '.') ];
119 Digest::base
120 Digest::MD5 2.27
121 DBI 1.37
122 Test::Inline
123 Class::ReturnValue 0.40
124 DBIx::SearchBuilder 1.01
125 Text::Template
126 File::Spec 0.8
127 HTML::Entities 
128 HTML::Scrubber 0.08
129 Net::Domain
130 Log::Dispatch 2.0
131 Locale::Maketext 1.06
132 Locale::Maketext::Lexicon 0.32
133 Locale::Maketext::Fuzzy
134 MIME::Entity 5.108
135 Mail::Mailer 1.57
136 Net::SMTP
137 Text::Wrapper 
138 Time::ParseDate
139 File::Temp
140 Term::ReadKey
141 Text::Autoformat
142 Text::Quoted 1.3
143 Tree::Simple 1.04
144 Scalar::Util
145 Module::Versions::Report
146 .
147
148 $deps{'MASON'} = [ _( << '.') ];
149 Params::Validate 0.02
150 Cache::Cache
151 Exception::Class 1.14
152 HTML::Mason 1.23
153 MLDBM
154 Errno
155 FreezeThaw
156 Digest::MD5 2.27
157 CGI::Cookie 1.20
158 Storable 2.08
159 Apache::Session 1.53
160 XML::RSS
161 .
162
163 $deps{'MAILGATE'} = [ _( << '.') ];
164 HTML::TreeBuilder
165 HTML::FormatText
166 Getopt::Long
167 LWP::UserAgent
168 .
169
170 $deps{'CLI'} = [ _( << '.') ];
171 Getopt::Long 2.24
172 .
173
174 $deps{'DEV'} = [ _( << '.') ];
175 Regexp::Common
176 Time::HiRes 
177 Test::Inline 
178 Apache::Test
179 HTML::Form
180 HTML::TokeParser
181 WWW::Mechanize
182 .
183
184 $deps{'FASTCGI'} = [ _( << '.') ];
185 CGI 2.92
186 FCGI
187 CGI::Fast 
188 .
189
190 $deps{'SPEEDYCGI'} = [ _( << '.') ];
191 CGI 2.92
192 CGI::SpeedyCGI
193 .
194
195
196 $deps{'MODPERL1'} = [ _( << '.') ];
197 CGI 2.92
198 Apache::Request
199 Apache::DBI 0.92
200 .
201
202 $deps{'MODPERL2'} = [ _( << '.') ];
203 CGI 2.92
204 Apache::DBI
205 .
206
207 $deps{'MYSQL'} = [ _( << '.') ];
208 DBD::mysql 2.1018
209 .
210 $deps{'ORACLE'} = [ _( << '.') ];
211 DBD::Oracle
212 .
213 $deps{'POSTGRESQL'} = [ _( << '.') ];
214 DBD::Pg
215 .
216
217 $deps{'SQLITE'} = [ _( << '.') ];
218 DBD::SQLite
219 .
220
221 if ($args{'download'}) {
222
223     my %modules;
224
225     foreach my $key (keys %deps) {
226         my @deps = (@{$deps{$key}});
227         while (@deps) {
228             my $mod = shift @deps;
229             my $ver = shift @deps;
230             next if ($mod =~ /^(DBD-|Apache-Request)/);
231             $modules{$mod} = $ver;
232         }
233     }
234     my @mods = keys %modules;
235     CPAN::get();
236     my $moddir = $args{'download'};
237     foreach my $mod (@mods) {
238         $CPAN::Config->{'build_dir'} = $moddir;
239         CPAN::get($mod);
240     }
241
242     opendir(DIR, $moddir);
243     while ( my $dir = readdir(DIR)) {
244         print "Dir is $dir\n";
245         next if ( $dir =~ /^\.\.?$/);
246
247         if ($dir =~ /^(.*)-(.*?)$/) {
248             print "$1  --  $2\n";
249             `svn_load_dirs.pl file:///Users/jesse/mod-repo $1 $moddir/$dir`;
250             `rm -rf $moddir/$dir`;
251
252         }
253
254     }
255     closedir(DIR);
256     exit;
257 }
258
259
260 print "perl:\n";
261 print "\t5.8.3";
262 eval {require 5.008003};
263 if ($@) {
264     print "...MISSING.\n";
265     eval {require 5.008000};
266     if ($@) {
267         print "\nRT is known to be non-functional on versions of perl older than 5.8.3.\nPlease upgrade to 5.8.3 or newer\n\n";
268         die;
269     } 
270
271     eval {require 5.008003};
272     if ($@) {
273         print "\nRT is known to be non-functional on versions of perl older than 5.8.3.\nPlease upgrade to 5.8.3 or newer\n\n";
274     }
275 } else {
276     print "...found\n" if $args{'v'};
277 }
278
279 print "users:\n";
280 print "\trt group (@RTGROUP@)...",      (defined getgrnam("@RTGROUP@")    ? "found" : "MISSING"), "\n";
281 print "\tbin owner (@BIN_OWNER@)...",   (defined getpwnam("@BIN_OWNER@")  ? "found" : "MISSING"), "\n";
282 print "\tlibs owner (@LIBS_OWNER@)...", (defined getpwnam("@LIBS_OWNER@") ? "found" : "MISSING"), "\n";
283 print "\tlibs group (@LIBS_GROUP@)...", (defined getgrnam("@LIBS_GROUP@") ? "found" : "MISSING"), "\n";
284 print "\tweb owner (@WEB_USER@)...",    (defined getpwnam("@WEB_USER@")   ? "found" : "MISSING"), "\n";
285 print "\tweb group (@WEB_GROUP@)...",   (defined getgrnam("@WEB_GROUP@")  ? "found" : "MISSING"), "\n";
286
287 foreach my $type (keys %args) {
288     next unless ($type =~ /^with-(.*?)$/);
289     my $type = $1;
290     print "$type dependencies:\n";
291     my @deps = (@{$deps{$type}});
292     while (@deps) {
293         my $module = shift @deps;
294         my $version = shift @deps;
295         my $ret = test_dep($module, $version);  
296
297         if ($args{'install'} && !$ret) {
298             resolve_dep($module);               
299         }
300     }
301 }
302
303 sub test_dep {
304     my $module = shift;
305     my $version = shift;
306
307     eval "use $module $version ()";
308     if ($@) {
309         my $error = $@;
310         $error =~ s/\n(.*)$//s;
311         print "\t$module $version";
312         print "...MISSING\n";
313         print "\t\t$error\n" if $error =~ /this is only/;
314
315         return undef;
316     } else {
317         print "\t$module $version...found\n" if $args{'v'};
318         return 1;
319     }
320 }
321
322 sub resolve_dep {
323     my $module = shift;
324     use CPAN;
325     CPAN::Shell->install($module);              
326 }
327
328
329 sub print_help {
330     print << "EOF";
331
332 $0 FLAG DBTYPE
333
334
335 $0 is a tool for RT that will tell you if you've got all
336 the modules RT depends on properly installed.
337
338 Flags: (only one flag is valid for a given run)
339
340 -quiet will check to see if we've got everything we need
341         and will exit with a return code of (1) if we don't.
342
343 -warn will tell you what isn't properly installed
344
345 -fix will use CPANPLUS.pm or CPAN.pm to magically make everything better
346
347 DBTYPE is one of:
348         oracle, pg, mysql
349
350 EOF
351
352     exit(0);
353 }