installer.pl untested

filter: Statementstmt 0.0% 0 / 141 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 17 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 218 CC 14 SCAR 39.8
CC
14
Cov
0%
test_wsrf_lite
90.0
install_wsrf_lite
42.0
REAPER
2.0
CRAP 53.6
1 #! /usr/bin/perl -w
2  
3 # Installer script for WSRF::Lite. This script is designed to work
4 # with the OMII (http://www.omii.ac.uk/) installation system which
5 # uses ant. The build.xml file invokes this script with the required
6 # command line option.
7  
8 use CPAN;
9 use CPAN::Config;
10 use Cwd;
11 use Getopt::Std;
12 #use strict;
13 $|++;
14  
15  
16 # We fork processes, eg client scripts, need to reap what we sow.
17 # REAPER kills of stray children.
18 sub REAPER {
19 local $!;
20 waitpid(-1,0);
21 $SIG{CHLD} = \&REAPER; # still loathe sysV
22 }
23  
24  
25 $VERSION = 0.3;
26  
27 our ($opt_h,$opt_t,$opt_i,$opt_v);
28  
29 my $usage = <<EOF;
30 This is the installer script for the OMII distribution of WSRF::Lite. It must
31 be run from the WSRF::Lite distribution directory.
32  
33 -i install WSRF::Lite.
34  
35 -t test WSRF::Lite installation, will start a WSRF::Lite Container and check
36 that it is functioning correctly.
37  
38 -v check whether the Perl environment is correct.
39  
40 -h prints this message.
41  
42 EOF
43  
44  
45 if ( ! @ARGV )
46 {
47 print $usage;
48 exit 0;
49 }
50  
51  
52  
53 #The set of modules that need to be installed by
54 #WSRF::Lite
55 my @CriticalModules = qw(URI LWP SOAP::Lite XML::DOM DateTime
56 DateTime::Format::Epoch DateTime::Format::W3CDTF
57 Storable IO::Socket HTTP::Status HTTP::Daemon HTTP::Request
58 HTTP::Response);
59  
60 my @NonCriticalModules = qw(Digest::SHA1 HTTP::Daemon::SSL
61 Crypt::OpenSSL::X509 XML::CanonicalizeXML
62 Crypt::OpenSSL::RSA );
63  
64 my @modules = ( @CriticalModules, @NonCriticalModules );
65  
66  
67 getopts("hitv");
68  
69 # print help message and exit
70 if($opt_h) {
71 print $usage;
72 exit 0;
73 }
74  
75  
76 # install WSRF::Lite and exit
77 if($opt_i) {
78 print "Installing WSRF::Lite...\n";
79 eval { #trap exceptions and make sure to clean up
80 install_wsrf_lite();
81 };
82 if ($@) {
83 print "$@";
84 local $SIG{HUP} = 'IGNORE';
85 kill (HUP, -$$);
86 exit -1;
87 }
88 }
89  
90 # test installation of WSRF::Lite
91 if($opt_t) {
92 print "Testing WSRF::Lite installation...\n";
93 eval { #trap exceptions and make sure to clean up
94 test_wsrf_lite();
95 };
96 if ($@) {
97 print "$@";
98 local $SIG{HUP} = 'IGNORE';
99 kill (HUP, -$$);
100 exit -1;
101 }
102 }
103  
104 # check the Perl environment
105 if($opt_v) {
106 print "Validating the Perl environment...\n";
107 my @MissingNonCriticalModules = ();
108 my @MissingCriticalModules = ();
109 my $noncrit = 0;
110 foreach my $module ( @NonCriticalModules )
111 {
112 eval "require $module";
113 if( $@ ) #could not load module
114 {
115 $noncrit = 1;
116 push @MissingNonCriticalModules, $module;
117 print " Non Critical module $module missing.\n";
118 }
119 }
120  
121 my $fail = 0;
122 foreach my $module ( @CriticalModules )
123 {
124 eval "require $module";
125 if( $@ ) #could not load module
126 {
127 $fail = 1;
128 push @MissingCriticalModules, $module;
129 print " Fail: Critical module $module missing\n";
130 }
131 }
132  
133 #check for versions
134 if ( defined($SOAP::Lite::VERSION) && ( $SOAP::Lite::VERSION lt 0.67 ) )
135 {
136 print " Fail: SOAP::Lite version is $SOAP::Lite::VERSION, version 0.67 or higher is required\n";
137 $fail = 1;
138 }
139  
140 print "WSRF::Lite can be installed on this system but will have limited functionality due to missing modules.\n" if ( !$fail && $noncrit);
141  
142 die "Perl environment will not support WSRF::Lite\n"
143 if $fail;
144 }
145  
146  
147  
148 #Come to the end of the script kill everything.
149 {
150 local $SIG{HUP} = 'IGNORE';
151 kill (HUP, -$$);
152 }
153  
154  
155 exit;
156  
157  
158 sub test_wsrf_lite {
159  
160 #Check if WSRF_MODULES environmental variable is set
161 if ( !defined($ENV{WSRF_MODULES}) )
162 {
163 print "Environmental variable WSRF_MODULES not set.\n";
164 my $dir = getcwd;
165 $ENV{WSRF_MODULES} = $dir."/modules";
166 print 'Setting $ENV{WSRF_MODULES} to '.$dir."/modules\n";
167 }
168  
169 #check if the directories have been created
170 my @dirs = qw( /tmp/wsrf /tmp/wsrf/data);
171 foreach my $dir (@dirs)
172 {
173 print "Checking for directory $dir...";
174 if ( ! -d $dir)
175 {
176 print "No, doesn't exist.\nCreating $dir...";
177 return "Could not make $dir\n" unless mkdir($dir);
178 print "Done\n";
179 }
180 else
181 {
182 print "OK\n";
183 }
184 print "Checking if $dir has correct permissions...";
185 if ( ! -w $dir || ! -r $dir )
186 {
187 print "No\n";
188 exit;
189 }
190 else
191 {
192 print "Yes\n";
193 }
194 }
195
196 #need to start Container...
197 opendir(DIR, ".") or die "Could not open directory \".\" $!\n";
198 my @files = readdir DIR;
199 closedir DIR;
200
201 die "Could not find ./Container.pl\n"
202 unless grep (/^Container.pl$/, @files);
203  
204 #fork and exec the Container
205 if (my $pid = fork) #parent
206 {
207 print "Parent $$ Forked\n";
208 sleep 1;
209 #Check if the Container is still runing.
210 die "Container process $pid does not seem to be running, check \"./output\""
211 if not kill(0,$pid);
212  
213 print "Changing directory to ./test\n";
214 chdir "./test" or return "Could not change directory to ./test";
215 print "Running ./client_test.pl\n";
216 my @args = qw(./client_test.pl);
217 system(@args) == 0
218 or die "system @args failed: $?";
219 }
220 elsif (defined($pid) ) #child
221 {
222 print "Child $$ starting Container.pl, output sent to ./output\n";
223 exec "./Container.pl -d > ./output 2>&1 "
224 or die "Couldn't execute ./Container.pl -d > ./output 2>&1";
225 }
226 else
227 {
228 die "Fork failed\n";
229 }
230  
231 return;
232 }
233  
234  
235  
236 sub install_wsrf_lite {
237  
238 my $message = <<EOF;
239 To install WSRF::Lite you need CPAN configured for this account - for more
240 information on configuring CPAN see CPAN_help in the WSRF::Lite distribution
241 directory. You can use Cntrl-C to exit the script.
242 EOF
243  
244 #remember where the cwd is
245 my $cwd = getcwd;
246  
247 #Print the set of CPAN mirrors that this installation
248 #has been configured to use
249 my @urllist = @{$CPAN::Config->{'urllist'}};
250  
251 print "CPAN has been configured to use the following mirrors...\n";
252 foreach my $url ( @urllist )
253 {
254 print " ".$url."\n";
255 }
256  
257 print "Installing Crypt::OpenSSL::RSA version 0.18\n";
258 $obj = CPAN::Shell->expandany("IROBERTS/Crypt-OpenSSL-RSA-0.18.tar.gz");
259  
260 if ( $obj->uptodate() )
261 {
262 print " Crypt::OpenSSL::RSA is up to date\n";
263 }
264 else
265 {
266 $obj->install;
267 }
268  
269 foreach my $mod ( @modules )
270 {
271 print "Installing $mod...\n";
272 $obj = CPAN::Shell->expand('Module',$mod);
273 $obj->install;
274 }
275  
276  
277 unless (my $return = do './Makefile.PL')
278 {
279 die "Couldn't parse Makefile.PL: $@" if $@;
280 die "Couldn't do Makefile.PL: $!" unless defined $return;
281 die "Couldn't run Makefile.PL" unless $return;
282 }
283  
284 #find out which make we should use...
285  
286 my $make = $CPAN::Config->{'make'};
287 print $make."\n";
288  
289 print "Running make...\n";
290 print `$make`;
291 print "Running make test...\n";
292 print `$make test`;
293 print "Running make install...\n";
294 print `$make install`;
295  
296 chdir($cwd);
297 return;
298 }