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

Annotation of /FigCommon/bootstrap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.31 - (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 :     if ($prefix ne $my_prefix)
70 :     {
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.1
149 :     sub configure_std_fig_environment
150 :     {
151 :     #
152 :     # Populate the Config with the usual stuff we need in FIG_Config.pm.
153 :     #
154 :    
155 :     my $fig = "$fig_disk/FIG";
156 :     my $data = "$fig/Data";
157 : olson 1.21 my $sproutData = "$fig/SproutData";
158 : olson 1.1
159 :     my $hostname = `hostname`;
160 :     chomp $hostname;
161 :    
162 :     push(@$Config, ["fig_disk", $fig_disk, 1]);
163 : olson 1.6 push(@$Config, ["blastmat", "$fig_disk/BLASTMAT", 1]);
164 : olson 1.1 push(@$Config, ["fig", $fig, 1]);
165 : olson 1.2 push(@$Config, ["bin", $fig_bin, 1]);
166 : olson 1.31 push(@$Config, ["env_config_type", $env_config_type, 1]);
167 :     if ($env_config_type eq 'config_file')
168 :     {
169 :     push(@$Config, ["env_config_file", $env_config_file, 1]);
170 :     push(@$Config, [{ perl => '&compute_env_values; ', python => '' }]);
171 :     }
172 :     else
173 :     {
174 :     push(@$Config, ["ext_bin", $env_bin, 1]);
175 :     push(@$Config, ["common_runtime", $env_dir, 1]);
176 :     }
177 : olson 1.18 push(@$Config, ["arch", $ENV{FIGCONFIG_ENV}, 1]);
178 : olson 1.22 push(@$Config, ["var", "$fig/var", 1]);
179 : olson 1.1 push(@$Config, ["data", $data, 1]);
180 :     push(@$Config, ["global", "$data/Global", 1]);
181 :     push(@$Config, ["organisms", "$data/Organisms", 1]);
182 :     push(@$Config, ["RC", "$fig_disk/FIG/ResolutionCenter", 1]);
183 :     push(@$Config, ["NR", "$fig_disk/FIG/NR", 1]);
184 :     push(@$Config, ["temp", "$fig_disk/FIG/Tmp", 1]);
185 : olson 1.21 push(@$Config, ["sproutData", $sproutData, 1]);
186 : olson 1.11
187 :     my $sandbox;
188 :     if ($ENV{FIGCONFIG_SANDBOX})
189 :     {
190 :     $sandbox = "/$ENV{FIGCONFIG_SANDBOX}";
191 :     }
192 :    
193 :     push(@$Config, ["temp_url", "http://$hostname$sandbox/FIG-Tmp", 1]);
194 :     push(@$Config, ["cgi_url", "http://$hostname$sandbox/FIG", 1]);
195 : golsen 1.9
196 :     #
197 :     # Add values for a relative base href of temp and CGI pages. The latter
198 :     # is used by HHTP.pm to write common page start. It would make the most
199 :     # sense to derive the above 2 values from these. -- GJO
200 :     #
201 :    
202 : olson 1.11 push(@$Config, ["temp_base", "$sandbox/FIG-Tmp/", 1]);
203 :     push(@$Config, ["cgi_base", "$sandbox/FIG/", 1]);
204 : olson 1.31
205 :     push(@$Config, [ { perl => <<'END' }]);
206 :     sub compute_env_values
207 :     {
208 :     return if defined($FIG_Config::hosttype);
209 : parrello 1.29
210 : olson 1.31 my $hosttype = `bash -c 'echo \$HOSTTYPE'`;
211 :     if ($hosttype eq '')
212 :     {
213 :     die "Error retrieving hosttype; bash failed with rc=$?";
214 :     }
215 :     chomp $hosttype;
216 :     open(CF, "<$FIG_Config::env_config_file") or
217 :     die "Cannot open $FIG_Config::env_config_file: $!";
218 :     my $found;
219 :     while (<CF>)
220 :     {
221 :     if (/^$hosttype\t(\S+)/)
222 :     {
223 :     $found++;
224 :     $FIG_Config::common_runtime = $1;
225 :     $FIG_Config::env_bin = "$1/bin";
226 :     $FIG_Config::hosttype = $hosttype;
227 :     $found++;
228 :     last;
229 :     }
230 :     }
231 :     $found or die "Could not find binary directory for hosttype $hosttype in $FIG_Config::env_config_file";
232 :     }
233 :     END
234 : olson 1.1 }
235 :    
236 :     sub compute_environment
237 :     {
238 :     #
239 :     # ReleaseTools configuration.
240 :     #
241 :    
242 :     push(@$Env, ["RTROOT", $ENV{FIG_HOME}, 0]);
243 :     push(@$Env, ["RTDIST", "\$RTROOT/dist", 0]);
244 : olson 1.23 push(@$Env, ["RTSITECONFIGDIR", "\$RTROOT/config", 0]);
245 : olson 1.1 push(@$Env, ["RTARCH", $ENV{FIGCONFIG_ENV}, 0]);
246 : olson 1.2 push(@$Env, ["RTCURRENT", "`cat \$RTROOT/CURRENT_RELEASE`", 0]);
247 : olson 1.1 push(@$Env, ["FIG_HOME", $ENV{FIG_HOME}, 0]);
248 :    
249 :     push(@$Env, ["BLASTMAT", "$ENV{FIG_HOME}/BLASTMAT", 0]);
250 :    
251 :     #
252 :     # Determine the path to use.
253 :     #
254 :     # This includes the path into the particular release we're configuring for,
255 :     # and to the environment's bin directory.
256 :     #
257 :    
258 :     my @path = ();
259 : olson 1.24 push(@path, $fig_bin);
260 : olson 1.31 if ($env_config_type eq 'dir')
261 :     {
262 :     push(@path, $env_bin);
263 :     }
264 : olson 1.1 push(@path, "$fig_disk/bin");
265 :    
266 :     push(@$Env, ["PATH", join(":", @path), 1]);
267 :    
268 : olson 1.26 #
269 :     # Compute LD_LIBRARY_PATH.
270 :     #
271 :     # Some packages, like mysql, place their shared libs in subdirectories
272 :     # of the libdir.
273 :     #
274 : olson 1.31 # We can only do this if we're configured with an env dir.
275 :     #
276 : olson 1.26
277 : olson 1.31 if ($env_config_type eq 'dir')
278 :     {
279 :     my @ld_path = ($env_lib);
280 :    
281 :     my $dh;
282 :     if (!opendir($dh, $env_lib))
283 :     {
284 :     warn "Could not opendir $env_lib: $!";
285 :     }
286 :    
287 :     while ($_ = readdir($dh))
288 :     {
289 :     next if /^\./;
290 :    
291 :     my $path = "$env_lib/$_";
292 :     next unless -d $path;
293 :    
294 :     #
295 :     # See if there are any .so's in here.
296 :     #
297 :    
298 :     my @solist = <$path/*.so*>;
299 :     if (@solist > 0)
300 :     {
301 :     push(@ld_path, $path);
302 :     }
303 :     }
304 :     closedir($dh);
305 :    
306 : olson 1.26 #
307 : olson 1.31 # And if perl is dynamically linked, we need to add the perl core directory
308 :     # to the path too.
309 : olson 1.26 #
310 : olson 1.31
311 :     my @coredir = <$env_lib/perl5/*/*/CORE>;
312 :     if (@coredir)
313 : olson 1.26 {
314 : olson 1.31 if ( -f "$coredir[0]/libperl.so" )
315 :     {
316 :     print "Found libperl in $coredir[0]\n";
317 :     push(@ld_path, $coredir[0]);
318 :     }
319 : olson 1.26 }
320 : olson 1.31
321 :     my $ld_path = join(":", @ld_path);
322 :     $OtherConfig->{ld_library_path} = $ld_path;
323 :    
324 :     push(@$Env, ["LD_LIBRARY_PATH", $ld_path, 1]);
325 : olson 1.26 }
326 :    
327 :     #
328 : olson 1.31 # If we're configuring with an env dir, we start with our @INC that we
329 :     # found. Otherwise we just append.
330 : olson 1.26 #
331 :    
332 : olson 1.31 my @perllib;
333 :     if ($env_config_type eq 'dir')
334 : olson 1.26 {
335 : olson 1.31 @perllib = grep({ $_ ne "." } @INC);
336 : olson 1.26 }
337 :    
338 : olson 1.31 push(@perllib,
339 :     $release_lib,
340 :     "$release_lib/FigKernelPackages",
341 :     "$release_lib/WebApplication",
342 :     "$release_lib/FortyEight",
343 :     "$release_lib/PPO",
344 :     "$fig_disk/config");
345 : olson 1.12
346 :     push(@$Env, ["PERL5LIB", join(":", @perllib), 1]);
347 : olson 1.1 }
348 :    
349 :     sub configure_python
350 :     {
351 :     #
352 :     # Determine the PYTHONPATH we're to use.
353 :     #
354 :     # Right now, we don't compute a replacement for the system path,
355 :     # but we're likely going to require that *if* python is
356 :     # distributed with the environment. We're currently not doing that.
357 :     #
358 :     # So we just need to point to any python packages in the release,
359 :     # and to packages that were installed in the environment dir.
360 :     #
361 :    
362 :     my $python = find_python();
363 :     print "Found python at $python\n";
364 :    
365 :     my $py_version = `$python -c 'import sys; print "%d.%d" % (sys.version_info[:2])'`;
366 :     chomp $py_version;
367 :     print "Python version $py_version\n";
368 :    
369 : olson 1.23 #
370 :     # Python figures this out for us.
371 :     #$OtherConfig->{python_site_path} = "$ENV{FIGCONFIG_ENV_DIR}/lib/python$py_version/site-packages";
372 : olson 1.2
373 : olson 1.1 my @path = ();
374 : olson 1.23 #push(@path, $OtherConfig->{python_site_path});
375 : olson 1.2 push(@path, "$release_lib");
376 : olson 1.1 push(@path, "$fig_disk/config");
377 :     push(@$Env, ["PYTHONPATH", join(":", @path), 1]);
378 :    
379 :     $OtherConfig->{pythonpath} = join(":", @path);
380 :     }
381 :    
382 :     sub find_in_path
383 :     {
384 : olson 1.5 my($file, @extra) = @_;
385 : olson 1.1 my(@path) = split(":", $ENV{PATH});
386 :    
387 : olson 1.5 for my $p (@path, @extra)
388 : olson 1.1 {
389 :     my $x = "$p/$file";
390 :     if (-x $x)
391 :     {
392 :     return $x;
393 :     }
394 :     }
395 :     return undef;
396 :     }
397 :    
398 :     #
399 :     # Find the name of the python executable we are to use.
400 :     #
401 :     sub find_python
402 :     {
403 :     my $python;
404 :    
405 :     #
406 :     # Special case for the mac.
407 :     #
408 : olson 1.11 # RDO 20040603 - don't do this any more; we want to pick up
409 :     # the python we ship.
410 :     #
411 : olson 1.1
412 : olson 1.11 if (0 && $ENV{FIGCONFIG_ENV} eq "mac")
413 : olson 1.1 {
414 : olson 1.7 #
415 :     # We'd like to use the MacPython that is installed
416 :     # as pythonw.
417 :     #
418 :     if ($python = find_in_path("pythonw", "/usr/local/bin"))
419 : olson 1.1 {
420 : olson 1.7 $OtherConfig->{python_require_poundbang_env} = 1;
421 : olson 1.1 return $python;
422 :     }
423 :    
424 :     #
425 : olson 1.7 # Otherwise, we can live with the regular python.
426 :     # Fall thru to the generic case.
427 : olson 1.1 #
428 : olson 1.7 }
429 :     #
430 :     # Non-mac, just look in the env dir or the path.
431 :     #
432 : olson 1.1
433 : olson 1.7 $python = "$ENV{FIGCONFIG_ENV_DIR}/bin/python";
434 :     if (-x $python)
435 :     {
436 : olson 1.13 #
437 :     # The mac doesn't seem to like the long #! lines, so we'll use poundbang env.
438 :     #
439 : olson 1.15 if ($ENV{FIGCONFIG_ENV} =~ /^mac/)
440 : olson 1.13 {
441 :     $OtherConfig->{python_require_poundbang_env} = 1;
442 :     }
443 : olson 1.7 return $python;
444 : olson 1.1 }
445 :    
446 : olson 1.7 return find_in_path("python");
447 : olson 1.1 }
448 :    
449 :     #
450 :     # Find the name of the perl executable we are to use.
451 :     #
452 :     sub find_perl
453 :     {
454 :     my $perl;
455 :    
456 : olson 1.31 if ($env_config_type eq 'config_file')
457 :     {
458 :     return $run_perl;
459 :     }
460 :    
461 : olson 1.1 $perl = "$ENV{FIGCONFIG_ENV_DIR}/bin/perl";
462 :     if (-x $perl)
463 :     {
464 :     return $perl;
465 :     }
466 :    
467 :     warn "We did not find a perl executable in the SEED distribution; some modules may not be found\n";
468 :     return find_in_path("perl");
469 :     }
470 :    
471 :     sub write_bash_init
472 :     {
473 :     my($fh, $env) = @_;
474 :    
475 :     foreach my $item (@$env)
476 :     {
477 :     my($name, $value, $append) = @$item;
478 :    
479 :     if ($append)
480 :     {
481 :     #
482 :     # Write code to detect if the value is set, and act accordingly.
483 :     #
484 :    
485 :     print $fh <<END;
486 :     DELIM=
487 :     if [ -n "\$$name" ] ; then
488 :     DELIM=:
489 :     fi
490 : olson 1.10 $name=$value\${DELIM}\${$name}
491 : olson 1.1 export $name
492 :     END
493 :     }
494 :     else
495 :     {
496 :     print $fh "$name=\"$value\"\n";
497 :     print $fh "export $name\n";
498 :     }
499 :     }
500 : olson 1.31
501 :     #
502 :     # If we're configuring from a config file, add the code to set up the PATH with the
503 :     # right ext_bin.
504 :     #
505 :     if ($env_config_type eq 'config_file')
506 :     {
507 :     print $fh "export FIG_ENV_CONFIG_FILE='$env_config_file'\n";
508 :     print $fh <<'END';
509 :     env_dir=`awk "\\$1 == \"$HOSTTYPE\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
510 :     export PATH=$env_dir/bin:${PATH}
511 :     END
512 :     }
513 :    
514 : olson 1.20 print $fh "alias rtpath='source \$RTDIST/releases/\$RTCURRENT/ReleaseTools/RTPath.sh'\n";
515 : olson 1.1 }
516 :    
517 :     sub write_csh_init
518 :     {
519 :     my($fh, $env) = @_;
520 :    
521 :     foreach my $item (@$env)
522 :     {
523 :     my($name, $value, $append) = @$item;
524 :    
525 :     if ($append)
526 :     {
527 :     #
528 :     # Write code to detect if the value is set, and act accordingly.
529 :     #
530 :    
531 :     print $fh <<END;
532 :     if (\$?$name) then
533 : olson 1.10 setenv $name $value:\${$name}
534 : olson 1.1 else
535 :     setenv $name $value
536 :     endif
537 :     END
538 :     }
539 :     else
540 :     {
541 :     print $fh "setenv $name \"$value\"\n";
542 :     }
543 :     }
544 :    
545 : olson 1.20 #
546 :     # Alias for RT stuff.
547 :     #
548 :     print $fh "alias rtpath 'source \$RTDIST/releases/\$RTCURRENT/ReleaseTools/RTPath.csh'\n";
549 : olson 1.1 }
550 :    
551 :     sub run_script
552 :     {
553 :     my($script) = @_;
554 :    
555 :    
556 :     unless (my $ret = do $script)
557 :     {
558 :     if ($@)
559 :     {
560 :     warn "Error parsing $script: $@\n";
561 :     }
562 :     elsif (!defined($ret))
563 :     {
564 :     warn "Couldn't do $script: $!\n";
565 :     }
566 :     else
567 :     {
568 :     warn "Counldn't run $script\n";
569 :     }
570 :     }
571 :    
572 :    
573 :     }
574 :    
575 :     sub configure_environment_specific
576 :     {
577 :     my $env_script = $ENV{FIGCONFIG_ENV_CONFIG};
578 :    
579 :     if (! -f $env_script)
580 :     {
581 :     warn "No environment-specific configuration file $env_script found, skipping\n";
582 :     return;
583 :     }
584 :    
585 :     run_script($env_script);
586 :     }
587 :    
588 :     #
589 :     # Create any directories that might be missing.
590 :     #
591 :    
592 :     sub setup_directories
593 :     {
594 :     my(@needed) = @_;
595 :    
596 :     for my $dir (@needed)
597 :     {
598 :     if (! -d $dir)
599 :     {
600 :     mkdir($dir) or warn "Could not create $dir: $!\n";
601 :     }
602 :     }
603 :     }
604 :    
605 :     sub setup_server_scripts
606 :     {
607 :     #
608 :     # Remove any start/stop servers scripts we might have, and write the stub
609 :     # start.
610 :     #
611 :    
612 :     unlink($start_servers);
613 :     unlink($stop_servers);
614 :    
615 :     open(F, ">$start_servers") or die "Cannot write $start_servers: $!";
616 :     print F "#!/bin/sh\n\n";
617 :     close(F);
618 :     chmod(0775, $start_servers);
619 :    
620 :     open(F, ">$stop_servers") or die "Cannot write $stop_servers: $!";
621 :     print F "#!/bin/sh\n\n";
622 :     close(F);
623 :     chmod(0775, $stop_servers);
624 :    
625 :     }
626 :    
627 : olson 1.31 sub write_run_perl
628 :     {
629 :     unlink($run_perl);
630 :     open(F, ">$run_perl") or die "Cannot write $run_perl: $!";
631 :    
632 :     print F "#!/bin/sh\n\n";
633 :    
634 :     print F ". $fig_disk/config/fig-user-env.sh\n\n";
635 :    
636 :     if ($env_config_type eq 'config_file')
637 :     {
638 :     print F <<'END';
639 :     env_dir=`awk "\\$1 == \"$HOSTTYPE\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
640 :     perl="$env_dir/bin/perl"
641 :     END
642 :     }
643 :     else
644 :     {
645 :     print F "perl=$env_dir/bin/perl\n";
646 :     }
647 :     print F 'exec $perl "$@"' . "\n";
648 :     close(F);
649 :    
650 :     }
651 :    
652 : olson 1.7 sub finalize_server_scripts
653 :     {
654 :     #
655 :     # After any environment-specific stuff, call start_services and stop_services.
656 :     #
657 :    
658 :     open(F, ">>$start_servers") or die "Cannot write $start_servers: $!";
659 :     print F "\n$fig_bin/start_services\n";
660 :     close(F);
661 :     chmod(0775, $start_servers);
662 :    
663 :     open(F, ">>$stop_servers") or die "Cannot write $stop_servers: $!";
664 :     print F "\n$fig_bin/stop_services\n";
665 :     close(F);
666 :     chmod(0775, $stop_servers);
667 :    
668 :     }
669 :    
670 : olson 1.1 sub write_config_pm
671 :     {
672 :     my($fh, $config) = @_;
673 :    
674 :     print $fh "package FIG_Config;\n\n";
675 :    
676 :     foreach my $item (@$config)
677 :     {
678 :     my($name, $value, $quote) = @$item;
679 :    
680 : olson 1.31 #
681 :     # special code for non-var=value items.
682 :     #
683 :     if (ref($name) eq 'HASH')
684 :     {
685 :     my $l = $name->{perl};
686 :     if ($l ne '')
687 :     {
688 :     print $fh "$l\n";
689 :     }
690 :     }
691 :     else
692 :     {
693 :     my $q = $quote ? '"' : '';
694 :     printf $fh "\$%-15s = $q$value$q;\n", $name;
695 :     }
696 : olson 1.1 }
697 :    
698 :     print $fh "\n1;\n";
699 :     }
700 :    
701 :     sub write_config_py
702 :     {
703 :     my($fh, $config) = @_;
704 :    
705 :     foreach my $item (@$config)
706 :     {
707 :     my($name, $value, $quote) = @$item;
708 :    
709 :     #
710 : olson 1.31 # special code for non-var=value items.
711 : olson 1.1 #
712 : olson 1.31 if (ref($name) eq 'HASH')
713 :     {
714 :     my $l = $name->{python};
715 :     if ($l ne '')
716 :     {
717 :     print $fh "$l\n";
718 :     }
719 :     }
720 :     else
721 :     {
722 :     #
723 :     # Ugh. "global" is a keyword in python.
724 :     #
725 :    
726 :     $name = "global_dir" if $name eq "global";
727 :    
728 :     my $q = $quote ? '"' : '';
729 :     printf $fh "%-15s = $q$value$q\n", $name;
730 :     }
731 : olson 1.1 }
732 :     }
733 :    
734 :     sub write_tool_hdr_perl
735 :     {
736 :     my($fh) = @_;
737 :    
738 :     my $perl = find_perl();
739 :    
740 :     print $fh "#!$perl\n";
741 :     print $fh "\n";
742 :    
743 :     if ($::perlenv_override)
744 :     {
745 :     #
746 :     # Write the tool header BEGIN block to reset the environment.
747 :     #
748 :    
749 :     print $fh "BEGIN {\n";
750 :     print $fh " \@INC = qw(\n";
751 :     for my $inc (@INC)
752 :     {
753 :     next if $inc eq '.';
754 :     print $fh "\t$inc\n";
755 :     }
756 : olson 1.2 print $fh ");\n";
757 : olson 1.1 print $fh "}\n";
758 :     }
759 :    
760 :     print $fh "use Data::Dumper;\n";
761 :     print $fh "use Carp;\n";
762 :    
763 : olson 1.2 #
764 :     # We generate a comment here that gets expanded by switch_to_release
765 :     # This is part of the effort in making the environment bootstrapping
766 :     # code independent of releases.
767 :     #
768 :    
769 :     #print $fh "use lib \"$release_lib\";\n";
770 :     #print $fh "use lib \"$release_lib/FigKernelPackages\";\n";
771 :    
772 :     print $fh "# Following block is expanded by switch_to_release to add use lib directives\n";
773 :     print $fh "# to point at the correct locations in the release directory.\n";
774 :     print $fh "#BEGIN switch_to_release generated code\n";
775 :     print $fh "#END switch_to_release generated code\n";
776 :     print $fh "\n";
777 :    
778 : olson 1.1 print $fh "use lib \"$fig_disk/config\";\n";
779 :    
780 :     print $fh "use FIG_Config;\n";
781 :     print $fh "\n";
782 : olson 1.11 print $fh "#### END tool_hdr ####\n\n"
783 : olson 1.1 }
784 :    
785 :     sub write_tool_hdr_python
786 :     {
787 :     my($fh) = @_;
788 :    
789 :     my $python = find_python();
790 :    
791 : olson 1.4 if ($OtherConfig->{python_require_poundbang_env})
792 :     {
793 :     print $fh "#!/usr/bin/env $python\n";
794 :     }
795 :     else
796 :     {
797 :     print $fh "#!$python\n";
798 :     }
799 : olson 1.1 print $fh "\n";
800 :    
801 : olson 1.11 print $fh "import sys, os\n";
802 : olson 1.2
803 :    
804 :     print $fh "sys.path.append('$OtherConfig->{python_site_path}')\n";
805 :    
806 : olson 1.11 #
807 :     # Append the perl path to the environment, for use later with CallPerl.
808 :     #
809 :    
810 : olson 1.23 my $perlpath = join(":", @INC, $release_lib, "$release_lib/FigKernelPackages", "$fig_disk/config");
811 : olson 1.11 print $fh <<END;
812 :     if os.getenv("PERL5LIB", "") != "":
813 :     _delim = ":"
814 :     else:
815 :     _delim = ""
816 :     os.environ["PERL5LIB"] = "$perlpath" + _delim + os.getenv("PERL5LIB", "")
817 :    
818 :     END
819 :    
820 : olson 1.2 print $fh "# Following block is expanded by switch_to_release to add use lib directives\n";
821 :     print $fh "# to point at the correct locations in the release directory.\n";
822 :     print $fh "#BEGIN switch_to_release generated code\n";
823 :     print $fh "#END switch_to_release generated code\n";
824 :     print $fh "\n";
825 :    
826 :     print $fh "sys.path.append('$fig_disk/config')\n";
827 :    
828 : olson 1.1 print $fh "import FIG_Config\n";
829 :     print $fh "\n";
830 : olson 1.11 print $fh "#### END tool_hdr_py ####\n\n"
831 : olson 1.1 }
832 :    
833 : olson 1.23 sub write_rtconfig
834 :     {
835 :     my($fh) = @_;
836 :    
837 :     my $python = find_python();
838 :     my $perl = find_perl();
839 :    
840 :     print $fh "RTPYTHON=$python\n";
841 :     print $fh "RTPERL=$perl\n";
842 :     print $fh "RTPYTHONPATH=$OtherConfig->{pythonpath}\n";
843 :    
844 : olson 1.25 my %seen;
845 :     my @perlpath;
846 :     for (@INC, "$fig_disk/config")
847 :     {
848 :     next if $seen{$_};
849 :     push(@perlpath, $_);
850 :     $seen{$_}++;
851 :     }
852 :     my $perlpath = join(":", @perlpath);
853 : olson 1.23
854 :     print $fh "RTPERL5LIB=$perlpath\n";
855 :    
856 :     print $fh "RTPYTHONIMPORTS=FIG_Config\n";
857 :     print $fh "RTPERLIMPORTS=FIG_Config\n";
858 : olson 1.25 print $fh "RTSETENV=BLASTMAT=$fig_disk/BLASTMAT\n";
859 :     print $fh "RTSETENV=FIG_HOME=$fig_disk\n";
860 : olson 1.27 print $fh "#RTLD_LDPATH=$OtherConfig->{ld_library_path}\n";
861 : olson 1.23 }
862 :    
863 : olson 1.1 setup_directories("$fig_disk/bin",
864 :     "$fig_disk/config");
865 :    
866 :     setup_server_scripts();
867 : olson 1.31 write_run_perl();
868 : olson 1.1
869 :     find_python();
870 :    
871 :     compute_environment();
872 :     configure_std_fig_environment();
873 :     configure_python();
874 :     configure_environment_specific();
875 : olson 1.19 # configure_database();
876 : olson 1.7
877 :     finalize_server_scripts();
878 : olson 1.1
879 :     #
880 :     # Write the shell startup to the figdisk.
881 :     #
882 :     open(FH, ">$fig_disk/config/fig-user-env.sh") or die "Cannot write $fig_disk/config/fig-user-env.sh: $!";
883 :     write_bash_init(\*FH, $Env);
884 :     close(FH);
885 :    
886 :     open(FH, ">$fig_disk/config/fig-user-env.csh") or die "Cannot write $fig_disk/config/fig-user-env.csh: $!";
887 :     write_csh_init(\*FH, $Env);
888 :     close(FH);
889 :    
890 :     #
891 :     # Write the FIG_Config file.
892 :     #
893 :    
894 :     open(FH, ">$fig_disk/config/FIG_Config.pm") or die "Cannot write $fig_disk/config/FIG_Config.pm: $!";
895 :     write_config_pm(\*FH, $Config);
896 :     close(FH);
897 :    
898 :     open(FH, ">$fig_disk/config/FIG_Config.py") or die "Cannot write $fig_disk/config/FIG_Config.py: $!";
899 :     write_config_py(\*FH, $Config);
900 :     close(FH);
901 :    
902 :     #
903 :     # Write the tool headers
904 :     #
905 :    
906 : olson 1.2 open(FH, ">$fig_disk/config/base_tool_hdr") or die "Cannot write $fig_disk/config/tool_hdr: $!";
907 : olson 1.1 write_tool_hdr_perl(\*FH);
908 :     close(FH);
909 :    
910 : olson 1.2 open(FH, ">$fig_disk/config/base_tool_hdr_py") or die "Cannot write $fig_disk/config/tool_hdr_py: $!";
911 : olson 1.1 write_tool_hdr_python(\*FH);
912 :     close(FH);
913 :    
914 : olson 1.23 open(FH, ">$fig_disk/config/RTConfig") or die "Cannot write $fig_disk/config/RTConfig: $!";
915 :     write_rtconfig(\*FH);
916 :     close(FH);
917 :    
918 : olson 1.2 unshift(@INC, "$ENV{FIGCONFIG_RELEASE_DIR}");
919 :    
920 :     require FigCommon::SwitchRelease;
921 : olson 1.1
922 : olson 1.16 #
923 :     # We need to tweak the current path and PERL5LIB environment to get bootstrapping to
924 :     # work correctly.
925 :     #
926 :    
927 :     $ENV{PATH} = "$ENV{FIGCONFIG_ENVDIR}/bin:$ENV{PATH}";
928 :    
929 : olson 1.17 $ENV{PERL5LIB} = (map { $_->[1] } grep { $_->[0] eq "PERL5LIB"} @$Env)[0];
930 : olson 1.16
931 : 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