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

Annotation of /FigCommon/bootstrap.pl

Parent Directory Parent Directory | Revision Log Revision Log


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