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

Annotation of /FigCommon/bootstrap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.35 - (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 :     env_dir=`awk "\\$1 == \"$HOSTTYPE\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
532 :     export PATH=$env_dir/bin:${PATH}
533 :     END
534 :     }
535 :    
536 : olson 1.20 print $fh "alias rtpath='source \$RTDIST/releases/\$RTCURRENT/ReleaseTools/RTPath.sh'\n";
537 : olson 1.1 }
538 :    
539 :     sub write_csh_init
540 :     {
541 :     my($fh, $env) = @_;
542 :    
543 :     foreach my $item (@$env)
544 :     {
545 :     my($name, $value, $append) = @$item;
546 :    
547 :     if ($append)
548 :     {
549 :     #
550 :     # Write code to detect if the value is set, and act accordingly.
551 :     #
552 :    
553 :     print $fh <<END;
554 :     if (\$?$name) then
555 : olson 1.10 setenv $name $value:\${$name}
556 : olson 1.1 else
557 :     setenv $name $value
558 :     endif
559 :     END
560 :     }
561 :     else
562 :     {
563 :     print $fh "setenv $name \"$value\"\n";
564 :     }
565 :     }
566 :    
567 : olson 1.20 #
568 :     # Alias for RT stuff.
569 :     #
570 :     print $fh "alias rtpath 'source \$RTDIST/releases/\$RTCURRENT/ReleaseTools/RTPath.csh'\n";
571 : olson 1.1 }
572 :    
573 :     sub run_script
574 :     {
575 :     my($script) = @_;
576 :    
577 :    
578 :     unless (my $ret = do $script)
579 :     {
580 :     if ($@)
581 :     {
582 :     warn "Error parsing $script: $@\n";
583 :     }
584 :     elsif (!defined($ret))
585 :     {
586 :     warn "Couldn't do $script: $!\n";
587 :     }
588 :     else
589 :     {
590 :     warn "Counldn't run $script\n";
591 :     }
592 :     }
593 :    
594 :    
595 :     }
596 :    
597 :     sub configure_environment_specific
598 :     {
599 :     my $env_script = $ENV{FIGCONFIG_ENV_CONFIG};
600 :    
601 :     if (! -f $env_script)
602 :     {
603 :     warn "No environment-specific configuration file $env_script found, skipping\n";
604 :     return;
605 :     }
606 :    
607 :     run_script($env_script);
608 :     }
609 :    
610 :     #
611 :     # Create any directories that might be missing.
612 :     #
613 :    
614 :     sub setup_directories
615 :     {
616 :     my(@needed) = @_;
617 :    
618 :     for my $dir (@needed)
619 :     {
620 :     if (! -d $dir)
621 :     {
622 :     mkdir($dir) or warn "Could not create $dir: $!\n";
623 :     }
624 :     }
625 :     }
626 :    
627 :     sub setup_server_scripts
628 :     {
629 :     #
630 :     # Remove any start/stop servers scripts we might have, and write the stub
631 :     # start.
632 :     #
633 :    
634 :     unlink($start_servers);
635 :     unlink($stop_servers);
636 :    
637 :     open(F, ">$start_servers") or die "Cannot write $start_servers: $!";
638 :     print F "#!/bin/sh\n\n";
639 :     close(F);
640 :     chmod(0775, $start_servers);
641 :    
642 :     open(F, ">$stop_servers") or die "Cannot write $stop_servers: $!";
643 :     print F "#!/bin/sh\n\n";
644 :     close(F);
645 :     chmod(0775, $stop_servers);
646 :    
647 :     }
648 :    
649 : olson 1.31 sub write_run_perl
650 :     {
651 :     unlink($run_perl);
652 :     open(F, ">$run_perl") or die "Cannot write $run_perl: $!";
653 :    
654 :     print F "#!/bin/sh\n\n";
655 :    
656 :     print F ". $fig_disk/config/fig-user-env.sh\n\n";
657 :    
658 :     if ($env_config_type eq 'config_file')
659 :     {
660 :     print F <<'END';
661 : olson 1.34 env_dir=`awk "\\$1 == \"$HOSTNAME\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
662 :     if [ "$env_dir" = "" ] ; then
663 :     env_dir=`awk "\\$1 == \"$HOSTTYPE\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
664 :     fi
665 : olson 1.31 perl="$env_dir/bin/perl"
666 :     END
667 :     }
668 :     else
669 :     {
670 :     print F "perl=$env_dir/bin/perl\n";
671 :     }
672 :     print F 'exec $perl "$@"' . "\n";
673 :     close(F);
674 : olson 1.32 chmod(0775, $run_perl);
675 :     }
676 :    
677 :     sub write_run_python
678 :     {
679 :     unlink($run_python);
680 :     open(F, ">$run_python") or die "Cannot write $run_python: $!";
681 : olson 1.31
682 : olson 1.32 print F "#!/bin/sh\n\n";
683 :    
684 :     print F ". $fig_disk/config/fig-user-env.sh\n\n";
685 :    
686 :     if ($env_config_type eq 'config_file')
687 :     {
688 :     print F <<'END';
689 : olson 1.34 env_dir=`awk "\\$1 == \"$HOSTNAME\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
690 :     if [ "$env_dir" = "" ] ; then
691 :     env_dir=`awk "\\$1 == \"$HOSTTYPE\" { print \\$2 }" $FIG_ENV_CONFIG_FILE`
692 :     fi
693 : olson 1.32 python="$env_dir/bin/python"
694 :     END
695 :     }
696 :     else
697 :     {
698 :     print F "python=$env_dir/bin/python\n";
699 :     }
700 :     print F 'exec $python "$@"' . "\n";
701 :     close(F);
702 :     chmod(0775, $run_python);
703 : olson 1.31 }
704 :    
705 : olson 1.7 sub finalize_server_scripts
706 :     {
707 :     #
708 :     # After any environment-specific stuff, call start_services and stop_services.
709 :     #
710 :    
711 :     open(F, ">>$start_servers") or die "Cannot write $start_servers: $!";
712 :     print F "\n$fig_bin/start_services\n";
713 :     close(F);
714 :     chmod(0775, $start_servers);
715 :    
716 :     open(F, ">>$stop_servers") or die "Cannot write $stop_servers: $!";
717 :     print F "\n$fig_bin/stop_services\n";
718 :     close(F);
719 :     chmod(0775, $stop_servers);
720 :    
721 :     }
722 :    
723 : olson 1.1 sub write_config_pm
724 :     {
725 :     my($fh, $config) = @_;
726 :    
727 :     print $fh "package FIG_Config;\n\n";
728 :    
729 :     foreach my $item (@$config)
730 :     {
731 :     my($name, $value, $quote) = @$item;
732 :    
733 : olson 1.31 #
734 :     # special code for non-var=value items.
735 :     #
736 :     if (ref($name) eq 'HASH')
737 :     {
738 :     my $l = $name->{perl};
739 :     if ($l ne '')
740 :     {
741 :     print $fh "$l\n";
742 :     }
743 :     }
744 :     else
745 :     {
746 :     my $q = $quote ? '"' : '';
747 :     printf $fh "\$%-15s = $q$value$q;\n", $name;
748 :     }
749 : olson 1.1 }
750 :    
751 :     print $fh "\n1;\n";
752 :     }
753 :    
754 :     sub write_config_py
755 :     {
756 :     my($fh, $config) = @_;
757 :    
758 :     foreach my $item (@$config)
759 :     {
760 :     my($name, $value, $quote) = @$item;
761 :    
762 :     #
763 : olson 1.31 # special code for non-var=value items.
764 : olson 1.1 #
765 : olson 1.31 if (ref($name) eq 'HASH')
766 :     {
767 :     my $l = $name->{python};
768 :     if ($l ne '')
769 :     {
770 :     print $fh "$l\n";
771 :     }
772 :     }
773 :     else
774 :     {
775 :     #
776 :     # Ugh. "global" is a keyword in python.
777 :     #
778 :    
779 :     $name = "global_dir" if $name eq "global";
780 :    
781 :     my $q = $quote ? '"' : '';
782 :     printf $fh "%-15s = $q$value$q\n", $name;
783 :     }
784 : olson 1.1 }
785 :     }
786 :    
787 :     sub write_tool_hdr_perl
788 :     {
789 :     my($fh) = @_;
790 :    
791 :     my $perl = find_perl();
792 :    
793 :     print $fh "#!$perl\n";
794 :     print $fh "\n";
795 :    
796 :     if ($::perlenv_override)
797 :     {
798 :     #
799 :     # Write the tool header BEGIN block to reset the environment.
800 :     #
801 :    
802 :     print $fh "BEGIN {\n";
803 :     print $fh " \@INC = qw(\n";
804 :     for my $inc (@INC)
805 :     {
806 :     next if $inc eq '.';
807 :     print $fh "\t$inc\n";
808 :     }
809 : olson 1.2 print $fh ");\n";
810 : olson 1.1 print $fh "}\n";
811 :     }
812 :    
813 :     print $fh "use Data::Dumper;\n";
814 :     print $fh "use Carp;\n";
815 :    
816 : olson 1.2 #
817 :     # We generate a comment here that gets expanded by switch_to_release
818 :     # This is part of the effort in making the environment bootstrapping
819 :     # code independent of releases.
820 :     #
821 :    
822 :     #print $fh "use lib \"$release_lib\";\n";
823 :     #print $fh "use lib \"$release_lib/FigKernelPackages\";\n";
824 :    
825 :     print $fh "# Following block is expanded by switch_to_release to add use lib directives\n";
826 :     print $fh "# to point at the correct locations in the release directory.\n";
827 :     print $fh "#BEGIN switch_to_release generated code\n";
828 :     print $fh "#END switch_to_release generated code\n";
829 :     print $fh "\n";
830 :    
831 : olson 1.1 print $fh "use lib \"$fig_disk/config\";\n";
832 :    
833 :     print $fh "use FIG_Config;\n";
834 :     print $fh "\n";
835 : olson 1.11 print $fh "#### END tool_hdr ####\n\n"
836 : olson 1.1 }
837 :    
838 :     sub write_tool_hdr_python
839 :     {
840 :     my($fh) = @_;
841 :    
842 :     my $python = find_python();
843 :    
844 : olson 1.4 if ($OtherConfig->{python_require_poundbang_env})
845 :     {
846 :     print $fh "#!/usr/bin/env $python\n";
847 :     }
848 :     else
849 :     {
850 :     print $fh "#!$python\n";
851 :     }
852 : olson 1.1 print $fh "\n";
853 :    
854 : olson 1.11 print $fh "import sys, os\n";
855 : olson 1.2
856 :    
857 :     print $fh "sys.path.append('$OtherConfig->{python_site_path}')\n";
858 :    
859 : olson 1.11 #
860 :     # Append the perl path to the environment, for use later with CallPerl.
861 :     #
862 :    
863 : olson 1.23 my $perlpath = join(":", @INC, $release_lib, "$release_lib/FigKernelPackages", "$fig_disk/config");
864 : olson 1.11 print $fh <<END;
865 :     if os.getenv("PERL5LIB", "") != "":
866 :     _delim = ":"
867 :     else:
868 :     _delim = ""
869 :     os.environ["PERL5LIB"] = "$perlpath" + _delim + os.getenv("PERL5LIB", "")
870 :    
871 :     END
872 :    
873 : olson 1.2 print $fh "# Following block is expanded by switch_to_release to add use lib directives\n";
874 :     print $fh "# to point at the correct locations in the release directory.\n";
875 :     print $fh "#BEGIN switch_to_release generated code\n";
876 :     print $fh "#END switch_to_release generated code\n";
877 :     print $fh "\n";
878 :    
879 :     print $fh "sys.path.append('$fig_disk/config')\n";
880 :    
881 : olson 1.1 print $fh "import FIG_Config\n";
882 :     print $fh "\n";
883 : olson 1.11 print $fh "#### END tool_hdr_py ####\n\n"
884 : olson 1.1 }
885 :    
886 : olson 1.23 sub write_rtconfig
887 :     {
888 :     my($fh) = @_;
889 :    
890 :     my $python = find_python();
891 :     my $perl = find_perl();
892 :    
893 :     print $fh "RTPYTHON=$python\n";
894 :     print $fh "RTPERL=$perl\n";
895 :     print $fh "RTPYTHONPATH=$OtherConfig->{pythonpath}\n";
896 :    
897 : olson 1.25 my %seen;
898 :     my @perlpath;
899 : olson 1.32
900 :     my @dirs;
901 :     if ($env_config_type eq 'dir')
902 :     {
903 :     push(@dirs, @INC);
904 :     }
905 :     push(@dirs, "$fig_disk/config");
906 :     for (@dirs)
907 : olson 1.25 {
908 :     next if $seen{$_};
909 :     push(@perlpath, $_);
910 :     $seen{$_}++;
911 :     }
912 :     my $perlpath = join(":", @perlpath);
913 : olson 1.23
914 :     print $fh "RTPERL5LIB=$perlpath\n";
915 :    
916 :     print $fh "RTPYTHONIMPORTS=FIG_Config\n";
917 :     print $fh "RTPERLIMPORTS=FIG_Config\n";
918 : olson 1.25 print $fh "RTSETENV=BLASTMAT=$fig_disk/BLASTMAT\n";
919 :     print $fh "RTSETENV=FIG_HOME=$fig_disk\n";
920 : olson 1.27 print $fh "#RTLD_LDPATH=$OtherConfig->{ld_library_path}\n";
921 : olson 1.23 }
922 :    
923 : olson 1.1 setup_directories("$fig_disk/bin",
924 :     "$fig_disk/config");
925 :    
926 :     setup_server_scripts();
927 : olson 1.31 write_run_perl();
928 : olson 1.32 write_run_python();
929 : olson 1.1
930 :     find_python();
931 :    
932 :     compute_environment();
933 :     configure_std_fig_environment();
934 :     configure_python();
935 :     configure_environment_specific();
936 : olson 1.19 # configure_database();
937 : olson 1.7
938 :     finalize_server_scripts();
939 : olson 1.1
940 :     #
941 :     # Write the shell startup to the figdisk.
942 :     #
943 :     open(FH, ">$fig_disk/config/fig-user-env.sh") or die "Cannot write $fig_disk/config/fig-user-env.sh: $!";
944 :     write_bash_init(\*FH, $Env);
945 :     close(FH);
946 :    
947 :     open(FH, ">$fig_disk/config/fig-user-env.csh") or die "Cannot write $fig_disk/config/fig-user-env.csh: $!";
948 :     write_csh_init(\*FH, $Env);
949 :     close(FH);
950 :    
951 :     #
952 :     # Write the FIG_Config file.
953 :     #
954 :    
955 :     open(FH, ">$fig_disk/config/FIG_Config.pm") or die "Cannot write $fig_disk/config/FIG_Config.pm: $!";
956 :     write_config_pm(\*FH, $Config);
957 :     close(FH);
958 :    
959 :     open(FH, ">$fig_disk/config/FIG_Config.py") or die "Cannot write $fig_disk/config/FIG_Config.py: $!";
960 :     write_config_py(\*FH, $Config);
961 :     close(FH);
962 :    
963 :     #
964 :     # Write the tool headers
965 :     #
966 :    
967 : olson 1.2 open(FH, ">$fig_disk/config/base_tool_hdr") or die "Cannot write $fig_disk/config/tool_hdr: $!";
968 : olson 1.1 write_tool_hdr_perl(\*FH);
969 :     close(FH);
970 :    
971 : olson 1.2 open(FH, ">$fig_disk/config/base_tool_hdr_py") or die "Cannot write $fig_disk/config/tool_hdr_py: $!";
972 : olson 1.1 write_tool_hdr_python(\*FH);
973 :     close(FH);
974 :    
975 : olson 1.23 open(FH, ">$fig_disk/config/RTConfig") or die "Cannot write $fig_disk/config/RTConfig: $!";
976 :     write_rtconfig(\*FH);
977 :     close(FH);
978 :    
979 : olson 1.2 unshift(@INC, "$ENV{FIGCONFIG_RELEASE_DIR}");
980 :    
981 :     require FigCommon::SwitchRelease;
982 : olson 1.1
983 : olson 1.16 #
984 :     # We need to tweak the current path and PERL5LIB environment to get bootstrapping to
985 :     # work correctly.
986 :     #
987 :    
988 :     $ENV{PATH} = "$ENV{FIGCONFIG_ENVDIR}/bin:$ENV{PATH}";
989 :    
990 : olson 1.17 $ENV{PERL5LIB} = (map { $_->[1] } grep { $_->[0] eq "PERL5LIB"} @$Env)[0];
991 : olson 1.16
992 : 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