comparison 2.4/install.pl @ 13:e3609c8714fb draft

Uploaded
author plus91-technologies-pvt-ltd
date Fri, 30 May 2014 03:37:55 -0400
parents
children
comparison
equal deleted inserted replaced
12:980fce54e60a 13:e3609c8714fb
1 #!/usr/bin/perl
2
3 =head1 NAME
4 install.pl
5
6 =head1 SYNOPSIS
7 USAGE: install.pl --prefix=/location/of/install/dir
8
9 =head1 OPTIONS
10
11 B<--prefix, -p>
12 Required. Prefix location where package will be installed.
13
14 B<--perl_exec, -e>
15 Optional. If perl exec is other than /usr/bin/perl please specify location of perl install
16
17 B<--help,-h>
18
19
20 =head1 DESCRIPTION
21 Install package
22
23 =head1 INPUT
24
25 =head1 OUTPUT
26
27
28 =head1 CONTACT
29 bjaysheel@gmail.com
30
31
32 ==head1 EXAMPLE
33 ./install.pl --prefix=/prefix
34
35 =cut
36
37 use strict;
38 use warnings;
39 use Cwd;
40 use Data::Dumper;
41 use Pod::Usage;
42 use Getopt::Long qw(:config no_ignore_case no_auto_abbrev pass_through);
43
44 my %options = ();
45 my $results = GetOptions (\%options,
46 'prefix|p=s',
47 'perl_exec|e=s',
48 'help|h') || pod2usage();
49
50 ## display documentation
51 if( $options{'help'} ){
52 pod2usage( {-exitval => 0, -verbose => 2, -output => \*STDERR} );
53 }
54
55 #############################################################################
56 #### make sure everything passed was peachy
57 &check_parameters(\%options);
58
59 #### print time now.
60 timestamp();
61
62 my $this = {};
63 my $progress = {};
64 my $cmd = "";
65
66 #### get current working dir
67 $this->{source} = getcwd();
68
69 $progress = getProgress();
70
71 #### make logs dir
72 $cmd = "mkdir -p $options{prefix}/logs";
73 execute_cmd($cmd);
74
75 #### installling libraries required for successfull run
76 install_libraries();
77
78 #### unpack binary dir containing all binary to be installed
79 #### which are required for successfull run
80 print STDERR "\n\nInstalling binaries...\n";
81
82 #### install each package in binary folder.
83 my @packages = qw(stringApprox levD);
84
85 foreach my $tool (@packages) {
86 if ((exists $progress->{$tool}) && ($progress->{$tool})){
87 print STDERR "\t$tool already installed. Skipping...\n";
88 } else {
89 print STDERR "\tInstalling $tool...\n";
90
91 #### unpack and install each tool
92 eval("install_${tool}()");
93 }
94 }
95
96 #### copy source code and update paths for perl and libs
97 install_source();
98
99 #### completion message
100 print "\n\n\tSoftSearch installation complete. Use following command to initiate a test run\n";
101 print "\n\tperl $options{prefix}/src/SoftSearch.pl -f {GENOME} -b {BAM_FILE}\n\n";
102
103 #### print time now
104 timestamp();
105
106 #############################################################################
107 sub check_parameters {
108 my $options = shift;
109
110 my @required = qw(prefix);
111
112 foreach my $key (@required) {
113 unless ($options{$key}) {
114 print STDERR "ARG: $key is required\n";
115 pod2usage({-exitval => 2, -message => "error message", -verbose => 1, -output => \*STDERR});
116 exit(-1);
117 }
118 }
119
120 $options{'perl_exec'} = "/usr/bin/perl" unless($options{'perl_exec'});
121 }
122
123 #############################################################################
124 sub getProgress {
125 my $hash = {};
126 my @sofar;
127
128 #### if file exists get progress so far.
129 if (-s "$options{prefix}/progress.txt") {
130 open(FHD, "<", "$options{prefix}/progress.txt") or die "Could not open file to read $options{prefix}/progress.txt";
131 while(<FHD>){
132 chomp $_;
133 push @sofar, $_;
134 }
135 close(FHD);
136
137 map { $hash->{$1} = $2 if( /([^=]+)\s*=\s*([^=]+)/ ) } @sofar;
138 }
139
140 #### return hash
141 return $hash;
142 }
143
144 #############################################################################
145 sub setProgress {
146 my $hash = shift;
147
148 open(OUT, ">", "$options{prefix}/progress.txt") or die "Could not open file to write $options{prefix}/progress.txt";
149
150 foreach my $key (keys %{$hash}){
151 print OUT $key."=".$hash->{$key}."\n";
152 }
153
154 close(OUT);
155 }
156
157 #############################################################################
158 sub install_libraries {
159 if ((exists $progress->{libraries}) && ($progress->{libraries})){
160 print STDERR "\tLibraries already installed. Skipping...\n";
161 return;
162 }
163
164 print STDERR "\n\nInstalling libraries...\n\n";
165 chdir($this->{source});
166
167 $cmd = "cp -r $this->{source}/library $options{prefix}/lib";
168 execute_cmd($cmd);
169
170 $progress->{libraries} = 1;
171 setProgress($progress);
172 }
173
174 #############################################################################
175 sub install_stringApprox {
176 #### check and install dir
177 my $dir = "$options{prefix}/lib";
178 my $cmd = "";
179
180 $cmd = "mkdir -p $dir";
181 execute_cmd($cmd);
182
183 $cmd = "tar -zxvf $this->{source}/binary/String-Approx-3.27.tar.gz -C $this->{source}/binary";
184 execute_cmd($cmd);
185
186 chdir("$this->{source}/binary/String-Approx-3.27");
187 $cmd = "perl Makefile.PL INSTALL_BASE=$options{prefix}";
188 $cmd .= " 1>$options{prefix}/logs/StringApprox.out";
189 $cmd .= " 2>$options{prefix}/logs/StringApprox.err";
190 execute_cmd($cmd);
191
192 $cmd = "make && make install";
193 $cmd .= " 1>>$options{prefix}/logs/StringApprox.out";
194 $cmd .= " 2>>$options{prefix}/logs/StringApprox.err";
195 execute_cmd($cmd);
196
197 $cmd = "make install";
198 $cmd .= " 1>>$options{prefix}/logs/StringApprox.out";
199 $cmd .= " 2>>$options{prefix}/logs/StringApprox.err";
200 execute_cmd($cmd);
201
202
203 chdir("$this->{source}/binary");
204 $cmd = "rm -rf $this->{source}/binary/String-Approx-3.27";
205 execute_cmd($cmd);
206
207 $progress->{stringApprox} = 1;
208 setProgress($progress);
209 }
210
211 #############################################################################
212 sub install_levD {
213 #### check and install dir
214 my $dir = "$options{prefix}/lib";
215 my $cmd = "";
216
217 $cmd = "mkdir -p $dir";
218 execute_cmd($cmd);
219
220 $cmd = "tar -zxvf $this->{source}/binary/Text-LevenshteinXS-0.03.tar.gz -C $this->{source}/binary";
221 execute_cmd($cmd);
222
223 chdir("$this->{source}/binary/Text-LevenshteinXS-0.03");
224 $cmd = "perl Makefile.PL INSTALL_BASE=$options{prefix}";
225 $cmd .= " 1>$options{prefix}/logs/levD.out";
226 $cmd .= " 2>$options{prefix}/logs/levD.err";
227 execute_cmd($cmd);
228
229 $cmd = "make";
230 $cmd .= " 1>>$options{prefix}/logs/levD.out";
231 $cmd .= " 2>>$options{prefix}/logs/levD.err";
232 execute_cmd($cmd);
233
234 $cmd .= "make install";
235 $cmd .= " 1>>$options{prefix}/logs/levD.out";
236 $cmd .= " 2>>$options{prefix}/logs/levD.err";
237 execute_cmd($cmd);
238
239 chdir("$this->{source}/binary");
240 $cmd = "rm -rf $this->{source}/binary/Text-LevenshteinXS-0.03";
241 execute_cmd($cmd);
242
243 $progress->{levD} = 1;
244 setProgress($progress);
245 }
246
247 #############################################################################
248 sub install_source {
249 if ((exists $progress->{source}) && ($progress->{source})){
250 print STDERR "\tSource already installed. Skipping...\n";
251 return;
252 }
253
254 print STDERR "\n\nInstalling source...\n\n";
255
256 #### create dir to store source code
257 $cmd = "mkdir -p $options{prefix}/src";
258 execute_cmd($cmd);
259
260 $cmd = "cp -r $this->{source}/script/* $options{prefix}/src/.";
261 execute_cmd($cmd);
262
263 #### make sure all scripts are executable
264 $cmd = "chmod -R +x $options{prefix}/src";
265 execute_cmd($cmd);
266
267 #### replace /usr/local/biotools/perl/5.10.0/bin/perl with perl_exec
268 $options{perl_exec} =~ s/\//\\\//g;
269 $cmd = "find $options{prefix}/src -name \"*.pl\" -print";
270 $cmd .= " -exec sed -i 's/#!\\/usr\\/local\\/biotools\\/perl\\/5.10.0\\/bin\\/perl/#!$options{perl_exec}/' {} \\;";
271 execute_cmd($cmd);
272
273 #### check if perl exec location is other than /usr/bin/perl
274 if ($options{perl_exec} !~ /^\/usr\/bin\/perl$/) {
275 $cmd = "find $options{prefix}/src -name \"*.pl\" -print";
276 $cmd .= " -exec sed -i 's/#!\\/usr\\/bin\\/perl/#!$options{perl_exec}/' {} \\;";
277 execute_cmd($cmd);
278 }
279
280 #### replace library references to local install
281 my $lib = "$options{prefix}/lib";
282 $lib =~ s/\//\\\//g;
283
284 $cmd = "find $options{prefix}/src -name \"*.pl\" -print";
285 $cmd .= " -exec sed -i 's/\\/data2\\/bsi\\/reference\\/softsearch\\/lib/$lib/' {} \\;";
286 execute_cmd($cmd);
287
288 $cmd = "find $options{prefix}/lib -name \"LevD.pm\" -print";
289 $cmd .= " -exec sed -i 's/\\/data2\\/bsi\\/reference\\/softsearch\\/lib/$lib/' {} \\;";
290 execute_cmd($cmd);
291
292 $progress->{source} = 1;
293 setProgress($progress);
294 }
295
296 #############################################################################
297 sub execute_cmd {
298 my $cmd = shift;
299
300 system($cmd);
301
302 #while (( $? >> 8 ) != 0 ){
303 # print STDERR "ERROR: Following command failed to execute. Exiting execution of workflow\n$cmd\n";
304 # exit(-1);
305 #}
306 }
307
308 #############################################################################
309 sub timestamp {
310 my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
311 my @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
312 my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
313 my $year = 1900 + $yearOffset;
314 my $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
315 print "Time now: " . $theTime."\n";
316 }