signup with agent selection
[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 $args{'with-MASON'} = 1;
44 $args{'with-CORE'} = 1;
45 $args{'with-DEV'} =1; 
46 $args{'with-CLI'} =1; 
47 $args{'with-MAILGATE'} =1; 
48 if ($] < 5.007) {
49 $args{'with-I18N-COMPAT'} = 1;
50 }
51
52
53 sub help {
54
55 print <<'.'
56
57 By default, testdeps determine whether you have 
58 installed all the perl modules RT needs to run.
59
60         --install               Install missing modules
61
62 The following switches will tell the tool to check for specific dependencies
63
64         --with-mysql            Database interface for MySQL
65         --with-postgresql       Database interface for PostgreSQL 
66         --with-sqlite           Database interface and driver for SQLite (unsupported)
67         --with-oracle           Database interface for oracle (unsupported)
68
69         --with-fastcgi          Libraries needed to support the fastcgi handler
70         --with-speedycgi        Libraries needed to support the speedycgi handler
71         --with-modperl1         Libraries needed to support the modperl 1 handler
72         --with-modperl2         Libraries needed to support the modperl 2 handler
73
74         --with-dev              Tools needed for RT development
75 .
76 }
77
78
79 sub _ {
80     map { /(\S+)\s*(\S*)/; $1 => ($2 ? $2 :'') } split ( /\n/, $_[0] );
81 }
82
83 $deps{'CORE'} = [ _( << '.') ];
84 Digest::MD5
85 DBI 1.18
86 Test::Inline
87 Class::ReturnValue 0.40
88 DBIx::SearchBuilder 0.86
89 Text::Template
90 File::Spec 0.8
91 HTML::Entities 
92 Net::Domain
93 Log::Dispatch 2.0
94 Locale::Maketext 1.04
95 Locale::Maketext::Lexicon 0.25
96 Locale::Maketext::Fuzzy
97 MIME::Entity 5.108
98 Mail::Mailer 1.57
99 Net::SMTP
100 Text::Wrapper 
101 Time::ParseDate
102 File::Temp
103 Term::ReadKey
104 Text::Autoformat
105 Text::Quoted
106 .
107
108 $deps{'MASON'} = [ _( << '.') ];
109 Params::Validate 0.02
110 Cache::Cache
111 Exception::Class
112 HTML::Mason 1.16
113 MLDBM
114 Errno
115 FreezeThaw
116 Digest::MD5
117 CGI::Cookie 1.20
118 Storable
119 Apache::Session 1.53
120 .
121
122 $deps{'MAILGATE'} = [ _( << '.') ];
123 HTML::TreeBuilder
124 HTML::FormatText
125 Getopt::Long
126 LWP::UserAgent
127 .
128
129 $deps{'CLI'} = [ _( << '.') ];
130 Getopt::Long 2.24
131 .
132
133 $deps{'DEV'} = [ _( << '.') ];
134 Regexp::Common
135 Time::HiRes 
136 Test::Inline 
137 WWW::Mechanize
138 .
139
140 $deps{'FASTCGI'} = [ _( << '.') ];
141 CGI
142 FCGI
143 CGI::Fast 
144 .
145
146 $deps{'SPEEDYCGI'} = [ _( << '.') ];
147 CGI
148 CGI::SpeedyCGI
149 .
150
151
152 $deps{'MODPERL1'} = [ _( << '.') ];
153 CGI
154 Apache::Request
155 Apache::DBI
156 .
157
158 $deps{'MODPERL2'} = [ _( << '.') ];
159 CGI 2.89
160 Apache::DBI
161 .
162
163 $deps{'I18N-COMPAT'} = [ _( << '.') ];
164 Text::Iconv
165 Encode::compat 0.04
166 .
167
168 $deps{'MYSQL'} = [ _( << '.') ];
169 DBD::mysql 2.1018
170 .
171 $deps{'ORACLE'} = [ _( << '.') ];
172 DBD::Oracle
173 .
174 $deps{'POSTGRESQL'} = [ _( << '.') ];
175 DBD::Pg
176 .
177
178
179 foreach my $type (keys %args)  {
180 next unless ($type =~ /^with-(.*?)$/);
181 my $type = $1;
182 print "$type dependencies:\n";
183         my @deps = (@{$deps{$type}});
184         while (@deps) {
185                 my $module = shift @deps;
186                 my $version = shift @deps;
187 my $ret;
188         $ret =test_dep($module, $version);      
189
190 if ($args{'install'} && !$ret) {
191         resolve_dep($module);           
192 }
193 }
194 }
195 sub test_dep {
196         my $module = shift;
197         my $version = shift;
198
199           print "\t$module $version";
200         eval "use $module $version" ;
201         if ($@) {
202         my $error = $@;
203         $error =~ s/\n(.*)$//s;
204         print "...MISSING\n";
205                 print "\t\t$error\n" if $error =~ /this is only/;
206
207         return undef;
208         } else {
209         print "...found\n";
210 return 1;
211         }
212 }
213
214 sub resolve_dep {
215         my $module = shift;
216         use CPAN;
217         CPAN::Shell->install($module);          
218         
219 }
220
221
222 sub print_help {
223     print << "EOF";
224
225 $0 FLAG DBTYPE
226
227
228 $0 is a tool for RT that will tell you if you've got all
229 the modules RT depends on properly installed.
230
231 Flags: (only one flag is valid for a given run)
232
233 -quiet will check to see if we've got everything we need
234         and will exit with a return code of (1) if we don't.
235
236 -warn will tell you what isn't properly installed
237
238 -fix will use CPANPLUS.pm or CPAN.pm to magically make everything better
239
240 DBTYPE is one of:
241         oracle, pg, mysql
242
243 EOF
244
245     exit(0);
246 }