import of rt 3.0.9
[freeside.git] / rt / sbin / rt-test-dependencies
1 #!/usr/bin/perl
2 # BEGIN LICENSE BLOCK
3
4 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
5
6 # (Except where explictly superceded by other copyright notices)
7
8 # This work is made available to you under the terms of Version 2 of
9 # the GNU General Public License. A copy of that license should have
10 # been provided with this software, but in any event can be snarfed
11 # from www.gnu.org.
12
13 # This work is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # General Public License for more details.
17
18 # Unless otherwise specified, all modifications, corrections or
19 # extensions to this work which alter its source code become the
20 # property of Best Practical Solutions, LLC when submitted for
21 # inclusion in the work.
22
23
24 # END LICENSE BLOCK
25
26 #
27 # This is just a basic script that checks to make sure that all
28 # the modules needed by RT before you can install it.
29 #
30
31 use strict;
32 no warnings qw(numeric redefine);
33 use Getopt::Long;
34 use CPAN;
35 my %args;
36 my %deps;
37 GetOptions(\%args,'install', 'with-MYSQL', 'with-POSTGRESQL|with-pg|with-pgsql', 'with-SQLITE', 'with-ORACLE', 'with-FASTCGI', 'with-SPEEDYCGI', 'with-MODPERL1', 'with-MODPERL2' ,'with-DEV');
38
39 if (!keys %args) {
40     help();
41     exit(0);
42 }
43 if ($args{'with-MODPERL2'}) {
44     warn_modperl2();
45 }
46
47 $args{'with-MASON'} = 1;
48 $args{'with-CORE'} = 1;
49 $args{'with-DEV'} =1; 
50 $args{'with-CLI'} =1; 
51 $args{'with-MAILGATE'} =1; 
52 if ($] < 5.007) {
53 $args{'with-I18N-COMPAT'} = 1;
54 }
55
56 sub warn_modperl2 {
57     print <<'.';
58         NOTE: mod_perl 2.0 isn't quite ready for prime_time just yet;
59         Best Practical Solutions strongly recommends that sites use
60         Apache 1.3 or FastCGI. If you MUST use mod_perl 2.0 (or 1.99),
61         please read the mailing list archives before asking for help.
62 .
63     sleep 5;
64 }
65
66
67 sub help {
68
69     print <<'.';
70
71 By default, testdeps determine whether you have 
72 installed all the perl modules RT needs to run.
73
74         --install               Install missing modules
75
76 The following switches will tell the tool to check for specific dependencies
77
78         --with-mysql            Database interface for MySQL
79         --with-postgresql       Database interface for PostgreSQL 
80         --with-sqlite           Database interface and driver for SQLite (unsupported)
81         --with-oracle           Database interface for oracle (unsupported)
82
83         --with-fastcgi          Libraries needed to support the fastcgi handler
84         --with-speedycgi        Libraries needed to support the speedycgi handler
85         --with-modperl1         Libraries needed to support the modperl 1 handler
86         --with-modperl2         Libraries needed to support the modperl 2 handler
87
88         --with-dev              Tools needed for RT development
89 .
90 }
91
92
93 sub _ {
94     map { /(\S+)\s*(\S*)/; $1 => ($2 ? $2 :'') } split ( /\n/, $_[0] );
95 }
96
97 $deps{'CORE'} = [ _( << '.') ];
98 Digest::MD5 2.27
99 DBI 1.37
100 Test::Inline
101 Class::ReturnValue 0.40
102 DBIx::SearchBuilder 0.97
103 Text::Template
104 File::Spec 0.8
105 HTML::Entities 
106 Net::Domain
107 Log::Dispatch 2.0
108 Locale::Maketext 1.06
109 Locale::Maketext::Lexicon 0.32
110 Locale::Maketext::Fuzzy
111 MIME::Entity 5.108
112 Mail::Mailer 1.57
113 Net::SMTP
114 Text::Wrapper 
115 Time::ParseDate
116 File::Temp
117 Term::ReadKey
118 Text::Autoformat
119 Text::Quoted 1.3
120 Scalar::Util
121 .
122
123 $deps{'MASON'} = [ _( << '.') ];
124 Params::Validate 0.02
125 Cache::Cache
126 Exception::Class
127 HTML::Mason 1.16
128 MLDBM
129 Errno
130 FreezeThaw
131 Digest::MD5 2.27
132 CGI::Cookie 1.20
133 Storable 2.08
134 Apache::Session 1.53
135 .
136
137 $deps{'MAILGATE'} = [ _( << '.') ];
138 HTML::TreeBuilder
139 HTML::FormatText
140 Getopt::Long
141 LWP::UserAgent
142 .
143
144 $deps{'CLI'} = [ _( << '.') ];
145 Getopt::Long 2.24
146 .
147
148 $deps{'DEV'} = [ _( << '.') ];
149 Regexp::Common
150 Time::HiRes 
151 Test::Inline 
152 WWW::Mechanize
153 .
154
155 $deps{'FASTCGI'} = [ _( << '.') ];
156 CGI 2.92
157 FCGI
158 CGI::Fast 
159 .
160
161 $deps{'SPEEDYCGI'} = [ _( << '.') ];
162 CGI 2.92
163 CGI::SpeedyCGI
164 .
165
166
167 $deps{'MODPERL1'} = [ _( << '.') ];
168 CGI 2.92
169 Apache::Request
170 Apache::DBI 0.92
171 .
172
173 $deps{'MODPERL2'} = [ _( << '.') ];
174 CGI 2.92
175 Apache::DBI
176 .
177
178 $deps{'I18N-COMPAT'} = [ _( << '.') ];
179 Text::Iconv
180 Encode::compat 0.04
181 .
182
183 $deps{'MYSQL'} = [ _( << '.') ];
184 DBD::mysql 2.1018
185 .
186 $deps{'ORACLE'} = [ _( << '.') ];
187 DBD::Oracle
188 .
189 $deps{'POSTGRESQL'} = [ _( << '.') ];
190 DBD::Pg
191 .
192
193 print "perl:\n";
194 print "\t5.8.0";
195 eval {require 5.008};
196 if ($@) {
197 print "...missing.\n";
198         eval {require 5.006001};
199         if ($@) {
200             print " RT is known to be non-functional on versions of perl older than 5.6.1. Please upgrade to 5.8.0 or newer";
201             die;
202         } else {
203             print " RT is not supported on perl 5.6.1\n";
204         }
205 } else {
206         print "...found\n";
207
208 }
209
210
211 foreach my $type (keys %args)  {
212 next unless ($type =~ /^with-(.*?)$/);
213 my $type = $1;
214 print "$type dependencies:\n";
215         my @deps = (@{$deps{$type}});
216         while (@deps) {
217                 my $module = shift @deps;
218                 my $version = shift @deps;
219 my $ret;
220         $ret =test_dep($module, $version);      
221
222 if ($args{'install'} && !$ret) {
223         resolve_dep($module);           
224 }
225 }
226 }
227 sub test_dep {
228         my $module = shift;
229         my $version = shift;
230
231         print "\t$module $version";
232         eval "use $module $version" ;
233         if ($@) {
234                 my $error = $@;
235                 $error =~ s/\n(.*)$//s;
236                 print "...MISSING\n";
237                         print "\t\t$error\n" if $error =~ /this is only/;
238
239                 return undef;
240         } else {
241                 print "...found\n";
242 return 1;
243         }
244 }
245
246 sub resolve_dep {
247         my $module = shift;
248         use CPAN;
249         CPAN::Shell->install($module);          
250         
251 }
252
253
254 sub print_help {
255     print << "EOF";
256
257 $0 FLAG DBTYPE
258
259
260 $0 is a tool for RT that will tell you if you've got all
261 the modules RT depends on properly installed.
262
263 Flags: (only one flag is valid for a given run)
264
265 -quiet will check to see if we've got everything we need
266         and will exit with a return code of (1) if we don't.
267
268 -warn will tell you what isn't properly installed
269
270 -fix will use CPANPLUS.pm or CPAN.pm to magically make everything better
271
272 DBTYPE is one of:
273         oracle, pg, mysql
274
275 EOF
276
277     exit(0);
278 }