[Bio] / FigCommon / bootstrap.pl Repository:
ViewVC logotype

Annotation of /FigCommon/bootstrap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.36 - (view) (download) (as text)

1 : olson 1.1 #
2 : olson 1.28 # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :    
18 :     #
19 : olson 1.1 # FIG bootstrap script.
20 :     #
21 :     # Control is passed here from the toplevel configure (or dists/releases/install depending
22 :     # on how far we've gotten in the process).
23 :     #
24 :     # The configure has set the following environment variables for our use:
25 :     #
26 :     # FIG_HOME Root of the FIGdisk tree we're setting up
27 : olson 1.31 # FIGCONFIG_ENV_TYPE Type of configuration environment - "config_file" for config file with host-type->directory
28 :     # mappings, or "dir" tranditional single-environment configuration.
29 : olson 1.1 # FIGCONFIG_ENV Name of the environment we're configuring for
30 : olson 1.31 # FIGCONFIG_ENV_CONFIG Location of enviroment configuration file.
31 : olson 1.1 # FIGCONFIG_ENV_DIR Directory in which the binary install tree for $FIGCONFIG_ENV lives
32 :     # FIGCONFIG_RELEASE Release number we're configuring
33 :     # FIGCONFIG_RELEASE_DIR Directory in which that release lives
34 :     #
35 :     # Important note: perl system libraries may not be available when this
36 :     # script is running, if the FIGCONFIG_ENV_DIR is different than it was
37 :     # when the binaries were created. Part of the task of this
38 :     # script is to recognize this case and configure the process
39 :     # environment correctly so that the post-install process as
40 :     # handled by the Makefiles can use perl properly, without concern for paths.
41 :     #
42 :    
43 :     #
44 :     # Look into the FIGCONFIG_ENV_DIR for the PREFIX that this
45 :     # environment was compiled on. If that directory is different
46 :     # than the one we're currently using, rewrite @INC accordingly.
47 :     #
48 :     # We put this into a BEGIN block so that we can later use "use"
49 :     # without worrying about paths.
50 :     #
51 :     # We also set the $perlenv_override to true if we've done this,
52 :     # so we can insert these fixes into the perl tool header.
53 :     #
54 :    
55 :     BEGIN {
56 :    
57 : olson 1.3 print "Here in the perl bootstrap. inc is:\n" . join("\n", @INC), "\n";
58 : olson 1.1
59 : parrello 1.29 my ($my_prefix, $prefix, $inc, @newInc);
60 : olson 1.1
61 :     $my_prefix = $ENV{FIGCONFIG_ENV_DIR};
62 :     open(P, "<$my_prefix/PREFIX");
63 :     $prefix = <P>;
64 :     chomp $prefix;
65 :    
66 :    
67 :     # print "Prefix is $prefix myprefix=$my_prefix\n";
68 :    
69 : olson 1.32 if ($prefix ne $my_prefix and $ENV{FIGCONFIG_ENV_CONFIG_TYPE} eq 'dir')
70 : olson 1.1 {
71 :     @newInc = ();
72 :     for $inc (@INC)
73 :     {
74 :     $inc =~ s,^$prefix,$my_prefix,;
75 :     push(@newInc, $inc);
76 :     }
77 :    
78 :     $::perlenv_override = 1;
79 : olson 1.3 @INC = @newInc;
80 : olson 1.1 }
81 :     }
82 :    
83 :    
84 :     use FileHandle;
85 :     use strict;
86 :    
87 :     #
88 :     # Environment definition
89 :     #
90 :     # This list contains triples
91 :     # ($name, $value, $appendFlag). $name is the name of the
92 :     # variable; $value is the value to set, and $appendFlag
93 :     # is nonzero if we need to append this value to an existing
94 :     # environment variable.
95 :     #
96 :    
97 :     our $Env = [];
98 :    
99 :     #
100 :     # FIG configuration information.
101 :     # This list contains tuples [$name, $value, $quote]
102 :     # which are to be set in the FIG_Config modules for
103 :     # both python and perl. $quote is 1 for things that need
104 :     # to be quoted, 0 otherwise.
105 :     #
106 :     our $Config = [];
107 :    
108 :     #
109 :     # Other key/value pairs of stuff we may need to pass
110 :     # to and from the environment-specific configuration modules.
111 :     #
112 :     # Known keys:
113 :     #
114 :     # pythonpath
115 :     #
116 :    
117 :     our $OtherConfig = {};
118 :    
119 :     #
120 :     # Cache values of the various places we may be installing things.
121 :     #
122 :    
123 :     our $fig_disk = $ENV{FIG_HOME};
124 : olson 1.31 our $env_config_type = $ENV{FIGCONFIG_ENV_CONFIG_TYPE};
125 :     our $env_config_file = $ENV{FIGCONFIG_ENV_CONFIG_FILE};
126 : olson 1.1 our $env_name = $ENV{FIGCONFIG_ENV};
127 : olson 1.7 our $env_dir = "$ENV{FIGCONFIG_ENV_DIR}";
128 : olson 1.1 our $env_bin = "$ENV{FIGCONFIG_ENV_DIR}/bin";
129 :     our $env_lib = "$ENV{FIGCONFIG_ENV_DIR}/lib";
130 : olson 1.2 #
131 :     # We are moving to use a symlink in dist/releases/current for these.
132 :     # This symlink is managed by switch_to_release.
133 :     #
134 :     #our $release_bin = "$ENV{FIGCONFIG_RELEASE_DIR}/bin/$ENV{FIGCONFIG_ENV}";
135 :     #our $release_lib = "$ENV{FIGCONFIG_RELEASE_DIR}/lib/$ENV{FIGCONFIG_ENV}";
136 :    
137 : olson 1.8 our $release_bin = "$fig_disk/dist/releases/current/$ENV{FIGCONFIG_ENV}/bin";
138 :     our $release_lib = "$fig_disk/dist/releases/current/$ENV{FIGCONFIG_ENV}/lib";
139 : olson 1.2
140 :     our $fig_bin = "$fig_disk/FIG/bin";
141 : olson 1.1
142 :     #
143 :     # Location of start/stop servers scripts.
144 :     #
145 :     our $start_servers = "$fig_disk/bin/start-servers";
146 :     our $stop_servers = "$fig_disk/bin/stop-servers";
147 : olson 1.31 our $run_perl = "$fig_disk/bin/run_perl";
148 : olson 1.32 our $run_python = "$fig_disk/bin/run_python";
149 : olson 1.1
150 :     sub configure_std_fig_environment
151 :     {
152 :     #
153 :     # Populate the Config with the usual stuff we need in FIG_Config.pm.
154 :     #
155 :    
156 :     my $fig = "$fig_disk/FIG";
157 :     my $data = "$fig/Data";
158 : olson 1.21 my $sproutData = "$fig/SproutData";
159 : olson 1.1
160 :     my $hostname = `hostname`;
161 :     chomp $hostname;
162 :    
163 :     push(@$Config, ["fig_disk", $fig_disk, 1]);
164 : olson 1.6 push(@$Config, ["blastmat", "$fig_disk/BLASTMAT", 1]);
165 : olson 1.1 push(@$Config, ["fig", $fig, 1]);
166 : olson 1.2 push(@$Config, ["bin", $fig_bin, 1]);
167 : olson 1.31 push(@$Config, ["env_config_type", $env_config_type, 1]);
168 :     if ($env_config_type eq 'config_file')
169 :     {
170 :     push(@$Config, ["env_config_file", $env_config_file, 1]);
171 :     push(@$Config, [{ perl => '&compute_env_values; ', python => '' }]);
172 :     }
173 :     else
174 :     {
175 :     push(@$Config, ["ext_bin", $env_bin, 1]);
176 :     push(@$Config, ["common_runtime", $env_dir, 1]);
177 :     }
178 : olson 1.18 push(@$Config, ["arch", $ENV{FIGCONFIG_ENV}, 1]);
179 : olson 1.22 push(@$Config, ["var", "$fig/var", 1]);
180 : olson 1.1 push(@$Config, ["data", $data, 1]);
181 :     push(@$Config, ["global", "$data/Global", 1]);
182 :     push(@$Config, ["organisms", "$data/Organisms", 1]);
183 :     push(@$Config, ["RC", "$fig_disk/FIG/ResolutionCenter", 1]);
184 :     push(@$Config, ["NR", "$fig_disk/FIG/NR", 1]);
185 :     push(@$Config, ["temp", "$fig_disk/FIG/Tmp", 1]);
186 : olson 1.21 push(@$Config, ["sproutData", $sproutData, 1]);
187 : olson 1.11
188 :     my $sandbox;
189 :     if ($ENV{FIGCONFIG_SANDBOX})
190 :     {
191 :     $sandbox = "/$ENV{FIGCONFIG_SANDBOX}";
192 :     }
193 :    
194 :     push(@$Config, ["temp_url", "http://$hostname$sandbox/FIG-Tmp", 1]);
195 :     push(@$Config, ["cgi_url", "http://$hostname$sandbox/FIG", 1]);
196 : golsen 1.9
197 :     #
198 :     # Add values for a relative base href of temp and CGI pages. The latter
199 :     # is used by HHTP.pm to write common page start. It would make the most
200 :     # sense to derive the above 2 values from these. -- GJO
201 :     #
202 :    
203 : olson 1.11 push(@$Config, ["temp_base", "$sandbox/FIG-Tmp/", 1]);
204 :     push(@$Config, ["cgi_base", "$sandbox/FIG/", 1]);
205 : olson 1.31
206 :     push(@$Config, [ { perl => <<'END' }]);
207 :     sub compute_env_values
208 :     {
209 :     return if defined($FIG_Config::hosttype);
210 : parrello 1.29
211 : olson 1.35 open(CF, "<$FIG_Config::env_config_file") or
212 :     die "Cannot open $FIG_Config::env_config_file: $!";
213 :    
214 :     my $hostinfo = `bash -c 'echo \$HOSTTYPE \$HOSTNAME'`;
215 :     if ($hostinfo !~ /^\s*(\S+)\s*(\S+)/)
216 : olson 1.31 {
217 :     die "Error retrieving hosttype; bash failed with rc=$?";
218 :     }
219 : olson 1.35 my $hosttype = $1;
220 :     my $hostname = $2;
221 :    
222 :     my %dat;
223 : olson 1.31 while (<CF>)
224 :     {
225 : olson 1.35 if (/^(\S+)\t(\S+)/)
226 : olson 1.31 {
227 : olson 1.35 $dat{$1} = $2;
228 : olson 1.31 }
229 :     }
230 : olson 1.35 close(CF);
231 :    
232 :     my $dir;
233 :     if ($dat{$hostname} ne '')
234 :     {
235 :     $dir = $dat{$hostname};
236 :     }
237 :     elsif ($dat{$hosttype} ne '')
238 :     {
239 :     $dir = $dat{$hosttype};
240 :     }
241 :     else
242 :     {
243 :     die "Could not find config mapping for hostname $hostname and hosttype $hosttype\n";
244 :     }
245 :     $FIG_Config::common_runtime = $dir;
246 :     $FIG_Config::ext_bin = "$dir/bin";
247 :     $FIG_Config::hosttype = $hosttype;
248 : olson 1.31 }
249 :     END
250 : olson 1.1 }
251 :    
252 :     sub compute_environment
253 :     {
254 :     #
255 :     # ReleaseTools configuration.
256 :     #
257 :    
258 :     push(@$Env, ["RTROOT", $ENV{FIG_HOME}, 0]);
259 :     push(@$Env, ["RTDIST", "\$RTROOT/dist", 0]);
260 : olson 1.23 push(@$Env, ["RTSITECONFIGDIR", "\$RTROOT/config", 0]);
261 : olson 1.1 push(@$Env, ["RTARCH", $ENV{FIGCONFIG_ENV}, 0]);
262 : olson 1.2 push(@$Env, ["RTCURRENT", "`cat \$RTROOT/CURRENT_RELEASE`", 0]);
263 : olson 1.1 push(@$Env, ["FIG_HOME", $ENV{FIG_HOME}, 0]);
264 :    
265 :     push(@$Env, ["BLASTMAT", "$ENV{FIG_HOME}/BLASTMAT", 0]);
266 :    
267 :     #
268 :     # Determine the path to use.
269 :     #
270 :     # This includes the path into the particular release we're configuring for,
271 :     # and to the environment's bin directory.
272 :     #
273 :    
274 :     my @path = ();
275 : olson 1.24 push(@path, $fig_bin);
276 : olson 1.31 if ($env_config_type eq 'dir')
277 :     {
278 :     push(@path, $env_bin);
279 :     }
280 : olson 1.1 push(@path, "$fig_disk/bin");
281 :    
282 :     push(@$Env, ["PATH", join(":", @path), 1]);
283 :    
284 : olson 1.26 #
285 :     # Compute LD_LIBRARY_PATH.
286 :     #
287 :     # Some packages, like mysql, place their shared libs in subdirectories
288 :     # of the libdir.
289 :     #
290 : olson 1.31 # We can only do this if we're configured with an env dir.
291 :     #
292 : olson 1.26
293 : olson 1.31 if ($env_config_type eq 'dir')
294 :     {
295 :     my @ld_path = ($env_lib);
296 :    
297 :     my $dh;
298 :     if (!opendir($dh, $env_lib))
299 :     {
300 :     warn "Could not opendir $env_lib: $!";
301 :     }
302 :    
303 :     while ($_ = readdir($dh))
304 :     {
305 :     next if /^\./;
306 :    
307 :     my $path = "$env_lib/$_";
308 :     next unless -d $path;
309 :    
310 :     #
311 :     # See if there are any .so's in here.
312 :     #
313 :    
314 :     my @solist = <$path/*.so*>;
315 :     if (@solist > 0)
316 :     {
317 :     push(@ld_path, $path);
318 :     }
319 :     }
320 :     closedir($dh);
321 :    
322 : olson 1.26 #
323 : olson 1.31 # And if perl is dynamically linked, we need to add the perl core directory
324 :     # to the path too.
325 : olson 1.26 #
326 : olson 1.31
327 :     my @coredir = <$env_lib/perl5/*/*/CORE>;
328 :     if (@coredir)
329 : olson 1.26 {
330 : olson 1.31 if ( -f "$coredir[0]/libperl.so" )
331 :     {
332 :     print "Found libperl in $coredir[0]\n";
333 :     push(@ld_path, $coredir[0]);
334 :     }
335 : olson 1.26 }
336 : olson 1.31
337 :     my $ld_path = join(":", @ld_path);
338 :     $OtherConfig->{ld_library_path} = $ld_path;
339 :    
340 :     push(@$Env, ["LD_LIBRARY_PATH", $ld_path, 1]);
341 : olson 1.26 }
342 :    
343 :     #
344 : olson 1.31 # If we're configuring with an env dir, we start with our @INC that we
345 :     # found. Otherwise we just append.
346 : olson 1.26 #
347 :    
348 : olson 1.31 my @perllib;
349 :     if ($env_config_type eq 'dir')
350 : olson 1.26 {
351 : olson 1.31 @perllib = grep({ $_ ne "." } @INC);
352 : olson 1.26 }
353 :    
354 : olson 1.31 push(@perllib,
355 :     $release_lib,
356 :     "$release_lib/FigKernelPackages",
357 :     "$release_lib/WebApplication",
358 :     "$release_lib/FortyEight",
359 :     "$release_lib/PPO",
360 :     "$fig_disk/config");
361 : olson 1.12
362 :     push(@$Env, ["PERL5LIB", join(":", @perllib), 1]);
363 : olson 1.1 }
364 :    
365 :     sub configure_python
366 :     {
367 :     #
368 :     # Determine the PYTHONPATH we're to use.
369 :     #
370 :     # Right now, we don't compute a replacement for the system path,
371 :     # but we're likely going to require that *if* python is
372 :     # distributed with the environment. We're currently not doing that.
373 :     #
374 :     # So we just need to point to any python packages in the release,
375 :     # and to packages that were installed in the environment dir.
376 :     #
377 :    
378 : olson 1.32 my $python = find_python(1);
379 : olson 1.1 print "Found python at $python\n";
380 :    
381 :     my $py_version = `$python -c 'import sys; print "%d.%d" % (sys.version_info[:2])'`;
382 :     chomp $py_version;
383 :     print "Python version $py_version\n";
384 :    
385 : olson 1.23 #
386 :     # Python figures this out for us.
387 :     #$OtherConfig->{python_site_path} = "$ENV{FIGCONFIG_ENV_DIR}/lib/python$py_version/site-packages";
388 : olson 1.2
389 : olson 1.1 my @path = ();
390 : olson 1.23 #push(@path, $OtherConfig->{python_site_path});
391 : olson 1.2 push(@path, "$release_lib");
392 : olson 1.1 push(@path, "$fig_disk/config");
393 :     push(@$Env, ["PYTHONPATH", join(":", @path), 1]);
394 :    
395 :     $OtherConfig->{pythonpath} = join(":", @path);
396 :     }
397 :    
398 :     sub find_in_path
399 :     {
400 : olson 1.5 my($file, @extra) = @_;
401 : olson 1.1 my(@path) = split(":", $ENV{PATH});
402 :    
403 : olson 1.5 for my $p (@path, @extra)
404 : olson 1.1 {
405 :     my $x = "$p/$file";
406 :     if (-x $x)
407 :     {
408 :     return $x;
409 :     }
410 :     }
411 :     return undef;
412 :     }
413 :    
414 :     #
415 :     # Find the name of the python executable we are to use.
416 :     #
417 :     sub find_python
418 :     {
419 : olson 1.32 my($to_exec) = @_;
420 : olson 1.1 my $python;
421 :    
422 : olson 1.32 if (!$to_exec and $env_config_type eq 'config_file')
423 :     {
424 :     return $run_python;
425 :     }
426 :    
427 : olson 1.1 #
428 :     # Special case for the mac.
429 :     #
430 : olson 1.11 # RDO 20040603 - don't do this any more; we want to pick up
431 :     # the python we ship.
432 :     #
433 : olson 1.1
434 : olson 1.11 if (0 && $ENV{FIGCONFIG_ENV} eq "mac")
435 : olson 1.1 {
436 : olson 1.7 #
437 :     # We'd like to use the MacPython that is installed
438 :     # as pythonw.
439 :     #
440 :     if ($python = find_in_path("pythonw", "/usr/local/bin"))
441 : olson 1.1 {
442 : olson 1.7 $OtherConfig->{python_require_poundbang_env} = 1;
443 : olson 1.1 return $python;
444 :     }
445 :    
446 :     #
447 : olson 1.7 # Otherwise, we can live with the regular python.
448 :     # Fall thru to the generic case.
449 : olson 1.1 #
450 : olson 1.7 }
451 :     #
452 :     # Non-mac, just look in the env dir or the path.
453 :     #
454 : olson 1.1
455 : olson 1.7 $python = "$ENV{FIGCONFIG_ENV_DIR}/bin/python";
456 :     if (-x $python)
457 :     {
458 : olson 1.13 #
459 :     # The mac doesn't seem to like the long #! lines, so we'll use poundbang env.
460 :     #
461 : olson 1.15 if ($ENV{FIGCONFIG_ENV} =~ /^mac/)
462 : olson 1.13 {
463 :     $OtherConfig->{python_require_poundbang_env} = 1;
464 :     }
465 : olson 1.7 return $python;
466 : olson 1.1 }
467 :    
468 : olson 1.7 return find_in_path("python");
469 : olson 1.1 }
470 :    
471 :     #
472 :     # Find the name of the perl executable we are to use.
473 :     #
474 :     sub find_perl
475 :     {
476 :     my $perl;
477 :    
478 : olson 1.31 if ($env_config_type eq 'config_file')
479 :     {
480 :     return $run_perl;
481 :     }
482 :    
483 : olson 1.1 $perl = "$ENV{FIGCONFIG_ENV_DIR}/bin/perl";
484 :     if (-x $perl)
485 :     {
486 :     return $perl;
487 :     }
488 :    
489 :     warn "We did not find a perl executable in the SEED distribution; some modules may not be found\n";
490 :     return find_in_path("perl");
491 :     }
492 :    
493 :     sub write_bash_init
494 :     {
495 :     my($fh, $env) = @_;
496 :    
497 :     foreach my $item (@$env)
498 :     {
499 :     my($name, $value, $append) = @$item;
500 :    
501 :     if ($append)
502 :     {
503 :     #
504 :     # Write code to detect if the value is set, and act accordingly.
505 :     #
506 :    
507 :     print $fh <<END;
508 :     DELIM=
509 :     if [ -n "\$$name" ] ; then
510 :     DELIM=:
511 :     fi
512 : olson 1.10 $name=$value\${DELIM}\${$name}
513 : olson 1.1 export $name
514 :     END
515 :     }
516 :     else
517 :     {
518 :     print $fh "$name=\"$value\"\n";
519 :     print $fh "export $name\n";
520 :     }
521 :     }
522 : olson 1.31
523 :     #
524 :     # If we're configuring from a config file, add the code to set up the PATH with the
525 :     # right ext_bin.
526 :     #
527 :     if ($env_config_type eq 'config_file')
528 :     {
529 :     print $fh "export FIG_ENV_CONFIG_FILE='$env_config_file'\n";
530 :     print $fh <<'END';
531 : olson 1.36 env_dir=`awk "\\$1 == \"$HOSTNAME\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
532 :     if [ "$env_dir" = "" ] ; then
533 :     env_dir=`awk "\\$1 == \"$HOSTTYPE\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
534 :     fi
535 : olson 1.31 export PATH=$env_dir/bin:${PATH}
536 :     END
537 :     }
538 :    
539 : olson 1.20 print $fh "alias rtpath='source \$RTDIST/releases/\$RTCURRENT/ReleaseTools/RTPath.sh'\n";
540 : olson 1.1 }
541 :    
542 :     sub write_csh_init
543 :     {
544 :     my($fh, $env) = @_;
545 :    
546 :     foreach my $item (@$env)
547 :     {
548 :     my($name, $value, $append) = @$item;
549 :    
550 :     if ($append)
551 :     {
552 :     #
553 :     # Write code to detect if the value is set, and act accordingly.
554 :     #
555 :    
556 :     print $fh <<END;
557 :     if (\$?$name) then
558 : olson 1.10 setenv $name $value:\${$name}
559 : olson 1.1 else
560 :     setenv $name $value
561 :     endif
562 :     END
563 :     }
564 :     else
565 :     {
566 :     print $fh "setenv $name \"$value\"\n";
567 :     }
568 :     }
569 :    
570 : olson 1.20 #
571 :     # Alias for RT stuff.
572 :     #
573 :     print $fh "alias rtpath 'source \$RTDIST/releases/\$RTCURRENT/ReleaseTools/RTPath.csh'\n";
574 : olson 1.1 }
575 :    
576 :     sub run_script
577 :     {
578 :     my($script) = @_;
579 :    
580 :    
581 :     unless (my $ret = do $script)
582 :     {
583 :     if ($@)
584 :     {
585 :     warn "Error parsing $script: $@\n";
586 :     }
587 :     elsif (!defined($ret))
588 :     {
589 :     warn "Couldn't do $script: $!\n";
590 :     }
591 :     else
592 :     {
593 :     warn "Counldn't run $script\n";
594 :     }
595 :     }
596 :    
597 :    
598 :     }
599 :    
600 :     sub configure_environment_specific
601 :     {
602 :     my $env_script = $ENV{FIGCONFIG_ENV_CONFIG};
603 :    
604 :     if (! -f $env_script)
605 :     {
606 :     warn "No environment-specific configuration file $env_script found, skipping\n";
607 :     return;
608 :     }
609 :    
610 :     run_script($env_script);
611 :     }
612 :    
613 :     #
614 :     # Create any directories that might be missing.
615 :     #
616 :    
617 :     sub setup_directories
618 :     {
619 :     my(@needed) = @_;
620 :    
621 :     for my $dir (@needed)
622 :     {
623 :     if (! -d $dir)
624 :     {
625 :     mkdir($dir) or warn "Could not create $dir: $!\n";
626 :     }
627 :     }
628 :     }
629 :    
630 :     sub setup_server_scripts
631 :     {
632 :     #
633 :     # Remove any start/stop servers scripts we might have, and write the stub
634 :     # start.
635 :     #
636 :    
637 :     unlink($start_servers);
638 :     unlink($stop_servers);
639 :    
640 :     open(F, ">$start_servers") or die "Cannot write $start_servers: $!";
641 :     print F "#!/bin/sh\n\n";
642 :     close(F);
643 :     chmod(0775, $start_servers);
644 :    
645 :     open(F, ">$stop_servers") or die "Cannot write $stop_servers: $!";
646 :     print F "#!/bin/sh\n\n";
647 :     close(F);
648 :     chmod(0775, $stop_servers);
649 :    
650 :     }
651 :    
652 : olson 1.31 sub write_run_perl
653 :     {
654 :     unlink($run_perl);
655 :     open(F, ">$run_perl") or die "Cannot write $run_perl: $!";
656 :    
657 :     print F "#!/bin/sh\n\n";
658 :    
659 :     print F ". $fig_disk/config/fig-user-env.sh\n\n";
660 :    
661 :     if ($env_config_type eq 'config_file')
662 :     {
663 :     print F <<'END';
664 : olson 1.34 env_dir=`awk "\\$1 == \"$HOSTNAME\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
665 :     if [ "$env_dir" = "" ] ; then
666 :     env_dir=`awk "\\$1 == \"$HOSTTYPE\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
667 :     fi
668 : olson 1.31 perl="$env_dir/bin/perl"
669 :     END
670 :     }
671 :     else
672 :     {
673 :     print F "perl=$env_dir/bin/perl\n";
674 :     }
675 :     print F 'exec $perl "$@"' . "\n";
676 :     close(F);
677 : olson 1.32 chmod(0775, $run_perl);
678 :     }
679 :    
680 :     sub write_run_python
681 :     {
682 :     unlink($run_python);
683 :     open(F, ">$run_python") or die "Cannot write $run_python: $!";
684 : olson 1.31
685 : olson 1.32 print F "#!/bin/sh\n\n";
686 :    
687 :     print F ". $fig_disk/config/fig-user-env.sh\n\n";
688 :    
689 :     if ($env_config_type eq 'config_file')
690 :     {
691 :     print F <<'END';
692 : olson 1.34 env_dir=`awk "\\$1 == \"$HOSTNAME\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
693 :     if [ "$env_dir" = "" ] ; then
694 :     env_dir=`awk "\\$1 == \"$HOSTTYPE\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
695 :     fi
696 : olson 1.32 python="$env_dir/bin/python"
697 :     END
698 :     }
699 :     else
700 :     {
701 :     print F "python=$env_dir/bin/python\n";
702 :     }
703 :     print F 'exec $python "$@"' . "\n";
704 :     close(F);
705 :     chmod(0775, $run_python);
706 : olson 1.31 }
707 :    
708 : olson 1.7 sub finalize_server_scripts
709 :     {
710 :     #
711 :     # After any environment-specific stuff, call start_services and stop_services.
712 :     #
713 :    
714 :     open(F, ">>$start_servers") or die "Cannot write $start_servers: $!";
715 :     print F "\n$fig_bin/start_services\n";
716 :     close(F);
717 :     chmod(0775, $start_servers);
718 :    
719 :     open(F, ">>$stop_servers") or die "Cannot write $stop_servers: $!";
720 :     print F "\n$fig_bin/stop_services\n";
721 :     close(F);
722 :     chmod(0775, $stop_servers);
723 :    
724 :     }
725 :    
726 : olson 1.1 sub write_config_pm
727 :     {
728 :     my($fh, $config) = @_;
729 :    
730 :     print $fh "package FIG_Config;\n\n";
731 :    
732 :     foreach my $item (@$config)
733 :     {
734 :     my($name, $value, $quote) = @$item;
735 :    
736 : olson 1.31 #
737 :     # special code for non-var=value items.
738 :     #
739 :     if (ref($name) eq 'HASH')
740 :     {
741 :     my $l = $name->{perl};
742 :     if ($l ne '')
743 :     {
744 :     print $fh "$l\n";
745 :     }
746 :     }
747 :     else
748 :     {
749 :     my $q = $quote ? '"' : '';
750 :     printf $fh "\$%-15s = $q$value$q;\n", $name;
751 :     }
752 : olson 1.1 }
753 :    
754 :     print $fh "\n1;\n";
755 :     }
756 :    
757 :     sub write_config_py
758 :     {
759 :     my($fh, $config) = @_;
760 :    
761 :     foreach my $item (@$config)
762 :     {
763 :     my($name, $value, $quote) = @$item;
764 :    
765 :     #
766 : olson 1.31 # special code for non-var=value items.
767 : olson 1.1 #
768 : olson 1.31 if (ref($name) eq 'HASH')
769 :     {
770 :     my $l = $name->{python};
771 :     if ($l ne '')
772 :     {
773 :     print $fh "$l\n";
774 :     }
775 :     }
776 :     else
777 :     {
778 :     #
779 :     # Ugh. "global" is a keyword in python.
780 :     #
781 :    
782 :     $name = "global_dir" if $name eq "global";
783 :    
784 :     my $q = $quote ? '"' : '';
785 :     printf $fh "%-15s = $q$value$q\n", $name;
786 :     }
787 : olson 1.1 }
788 :     }
789 :    
790 :     sub write_tool_hdr_perl
791 :     {
792 :     my($fh) = @_;
793 :    
794 :     my $perl = find_perl();
795 :    
796 :     print $fh "#!$perl\n";
797 :     print $fh "\n";
798 :    
799 :     if ($::perlenv_override)
800 :     {
801 :     #
802 :     # Write the tool header BEGIN block to reset the environment.
803 :     #
804 :    
805 :     print $fh "BEGIN {\n";
806 :     print $fh " \@INC = qw(\n";
807 :     for my $inc (@INC)
808 :     {
809 :     next if $inc eq '.';
810 :     print $fh "\t$inc\n";
811 :     }
812 : olson 1.2 print $fh ");\n";
813 : olson 1.1 print $fh "}\n";
814 :     }
815 :    
816 :     print $fh "use Data::Dumper;\n";
817 :     print $fh "use Carp;\n";
818 :    
819 : olson 1.2 #
820 :     # We generate a comment here that gets expanded by switch_to_release
821 :     # This is part of the effort in making the environment bootstrapping
822 :     # code independent of releases.
823 :     #
824 :    
825 :     #print $fh "use lib \"$release_lib\";\n";
826 :     #print $fh "use lib \"$release_lib/FigKernelPackages\";\n";
827 :    
828 :     print $fh "# Following block is expanded by switch_to_release to add use lib directives\n";
829 :     print $fh "# to point at the correct locations in the release directory.\n";
830 :     print $fh "#BEGIN switch_to_release generated code\n";
831 :     print $fh "#END switch_to_release generated code\n";
832 :     print $fh "\n";
833 :    
834 : olson 1.1 print $fh "use lib \"$fig_disk/config\";\n";
835 :    
836 :     print $fh "use FIG_Config;\n";
837 :     print $fh "\n";
838 : olson 1.11 print $fh "#### END tool_hdr ####\n\n"
839 : olson 1.1 }
840 :    
841 :     sub write_tool_hdr_python
842 :     {
843 :     my($fh) = @_;
844 :    
845 :     my $python = find_python();
846 :    
847 : olson 1.4 if ($OtherConfig->{python_require_poundbang_env})
848 :     {
849 :     print $fh "#!/usr/bin/env $python\n";
850 :     }
851 :     else
852 :     {
853 :     print $fh "#!$python\n";
854 :     }
855 : olson 1.1 print $fh "\n";
856 :    
857 : olson 1.11 print $fh "import sys, os\n";
858 : olson 1.2
859 :    
860 :     print $fh "sys.path.append('$OtherConfig->{python_site_path}')\n";
861 :    
862 : olson 1.11 #
863 :     # Append the perl path to the environment, for use later with CallPerl.
864 :     #
865 :    
866 : olson 1.23 my $perlpath = join(":", @INC, $release_lib, "$release_lib/FigKernelPackages", "$fig_disk/config");
867 : olson 1.11 print $fh <<END;
868 :     if os.getenv("PERL5LIB", "") != "":
869 :     _delim = ":"
870 :     else:
871 :     _delim = ""
872 :     os.environ["PERL5LIB"] = "$perlpath" + _delim + os.getenv("PERL5LIB", "")
873 :    
874 :     END
875 :    
876 : olson 1.2 print $fh "# Following block is expanded by switch_to_release to add use lib directives\n";
877 :     print $fh "# to point at the correct locations in the release directory.\n";
878 :     print $fh "#BEGIN switch_to_release generated code\n";
879 :     print $fh "#END switch_to_release generated code\n";
880 :     print $fh "\n";
881 :    
882 :     print $fh "sys.path.append('$fig_disk/config')\n";
883 :    
884 : olson 1.1 print $fh "import FIG_Config\n";
885 :     print $fh "\n";
886 : olson 1.11 print $fh "#### END tool_hdr_py ####\n\n"
887 : olson 1.1 }
888 :    
889 : olson 1.23 sub write_rtconfig
890 :     {
891 :     my($fh) = @_;
892 :    
893 :     my $python = find_python();
894 :     my $perl = find_perl();
895 :    
896 :     print $fh "RTPYTHON=$python\n";
897 :     print $fh "RTPERL=$perl\n";
898 :     print $fh "RTPYTHONPATH=$OtherConfig->{pythonpath}\n";
899 :    
900 : olson 1.25 my %seen;
901 :     my @perlpath;
902 : olson 1.32
903 :     my @dirs;
904 :     if ($env_config_type eq 'dir')
905 :     {
906 :     push(@dirs, @INC);
907 :     }
908 :     push(@dirs, "$fig_disk/config");
909 :     for (@dirs)
910 : olson 1.25 {
911 :     next if $seen{$_};
912 :     push(@perlpath, $_);
913 :     $seen{$_}++;
914 :     }
915 :     my $perlpath = join(":", @perlpath);
916 : olson 1.23
917 :     print $fh "RTPERL5LIB=$perlpath\n";
918 :    
919 :     print $fh "RTPYTHONIMPORTS=FIG_Config\n";
920 :     print $fh "RTPERLIMPORTS=FIG_Config\n";
921 : olson 1.25 print $fh "RTSETENV=BLASTMAT=$fig_disk/BLASTMAT\n";
922 :     print $fh "RTSETENV=FIG_HOME=$fig_disk\n";
923 : olson 1.27 print $fh "#RTLD_LDPATH=$OtherConfig->{ld_library_path}\n";
924 : olson 1.23 }
925 :    
926 : olson 1.1 setup_directories("$fig_disk/bin",
927 :     "$fig_disk/config");
928 :    
929 :     setup_server_scripts();
930 : olson 1.31 write_run_perl();
931 : olson 1.32 write_run_python();
932 : olson 1.1
933 :     find_python();
934 :    
935 :     compute_environment();
936 :     configure_std_fig_environment();
937 :     configure_python();
938 :     configure_environment_specific();
939 : olson 1.19 # configure_database();
940 : olson 1.7
941 :     finalize_server_scripts();
942 : olson 1.1
943 :     #
944 :     # Write the shell startup to the figdisk.
945 :     #
946 :     open(FH, ">$fig_disk/config/fig-user-env.sh") or die "Cannot write $fig_disk/config/fig-user-env.sh: $!";
947 :     write_bash_init(\*FH, $Env);
948 :     close(FH);
949 :    
950 :     open(FH, ">$fig_disk/config/fig-user-env.csh") or die "Cannot write $fig_disk/config/fig-user-env.csh: $!";
951 :     write_csh_init(\*FH, $Env);
952 :     close(FH);
953 :    
954 :     #
955 :     # Write the FIG_Config file.
956 :     #
957 :    
958 :     open(FH, ">$fig_disk/config/FIG_Config.pm") or die "Cannot write $fig_disk/config/FIG_Config.pm: $!";
959 :     write_config_pm(\*FH, $Config);
960 :     close(FH);
961 :    
962 :     open(FH, ">$fig_disk/config/FIG_Config.py") or die "Cannot write $fig_disk/config/FIG_Config.py: $!";
963 :     write_config_py(\*FH, $Config);
964 :     close(FH);
965 :    
966 :     #
967 :     # Write the tool headers
968 :     #
969 :    
970 : olson 1.2 open(FH, ">$fig_disk/config/base_tool_hdr") or die "Cannot write $fig_disk/config/tool_hdr: $!";
971 : olson 1.1 write_tool_hdr_perl(\*FH);
972 :     close(FH);
973 :    
974 : olson 1.2 open(FH, ">$fig_disk/config/base_tool_hdr_py") or die "Cannot write $fig_disk/config/tool_hdr_py: $!";
975 : olson 1.1 write_tool_hdr_python(\*FH);
976 :     close(FH);
977 :    
978 : olson 1.23 open(FH, ">$fig_disk/config/RTConfig") or die "Cannot write $fig_disk/config/RTConfig: $!";
979 :     write_rtconfig(\*FH);
980 :     close(FH);
981 :    
982 : olson 1.2 unshift(@INC, "$ENV{FIGCONFIG_RELEASE_DIR}");
983 :    
984 :     require FigCommon::SwitchRelease;
985 : olson 1.1
986 : olson 1.16 #
987 :     # We need to tweak the current path and PERL5LIB environment to get bootstrapping to
988 :     # work correctly.
989 :     #
990 :    
991 :     $ENV{PATH} = "$ENV{FIGCONFIG_ENVDIR}/bin:$ENV{PATH}";
992 :    
993 : olson 1.17 $ENV{PERL5LIB} = (map { $_->[1] } grep { $_->[0] eq "PERL5LIB"} @$Env)[0];
994 : olson 1.16
995 : olson 1.2 &FigCommon::SwitchRelease::switch_to_release($fig_disk, $ENV{FIGCONFIG_ENV}, $ENV{FIGCONFIG_RELEASE});

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3