package INSTALL::bean; use INSTALL::common; use INSTALL::os; use INSTALL::global; use INSTALL::query; use INSTALL::substitute; use INSTALL::parameter; use strict; no strict 'subs'; ########## Define Globals my $pParameters = \%INSTALL::parameter::variables; my $pGlobals = \%INSTALL::global::variables; my $pOS = \%INSTALL::os::Details; #------------------------------------------------------------------------------ # Detect the jre version in the specified directory. If no version can be # detected, undef will be returned. #------------------------------------------------------------------------------ sub detect_version { (@_ == 1) || die "Invalid number of arguments."; my $jre_path = shift @_; INSTALL::common::libpath_append($pGlobals->{lib_dir}); # This is to account for any dependence on libstdc++-1-x.so.x in the JVM. # We handle this elsewhere (in caspi2.pl) for the rest of the installation # but it needs to be added to the library path so that future executions # of the JVM will succeed. if (-x "$jre_path/bin/java") { my @java_output; # On linux with jre 131, java -version has annoying tendency # not to work the first time... so try three times, if necessary # note 1: this happens regardless of version of perl. # note 2: this does not happen with jre 122. foreach (1..3) { @java_output = split(/\n/,`$jre_path/bin/java -version 2>&1`); foreach(@java_output) { if (/java version "(\d+\.\d+(\.\d+)?)"/) { return($1); } elsif (/java version "(\d+\.\d+(\.\d+)?)(_\d+)?"/) { return($1); } # this is how it is stored for HP-UX. This can also be a default # action for other platforms elsif (/java version "(\d+\.\d+(\.\d+)?)(?:.*)"/) { return($1); } # Try to support older JRE versions as well. elsif (/jre version "(?:.*)\.(\d+\.\d+)?(.*)"/) { return($1); } } } } return(undef); } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # External functions #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub setup { (@_ == 1) || die "Invalid number of arguments."; my $pBeanHash = shift @_; my %jre_map = ( DEFAULT => ["1.3.x", "1.4.x"], AIX => ["1.2.x"], SUNOS => ["1.2.x"], 'HP-UX' => ["1.3.x", "1.4.x"], LINUX => ["1.2.x"] ); my @platform_supported_jres = (@{$jre_map{uc($pOS->{os})}},@{$jre_map{DEFAULT}}); sub confirm_existence { ($#_ == 0) || die "Invalid number of arguments."; my ($dir) = @_; if ($dir eq "none") { report(""); my $answer = INSTALL::query::user ("Would you like to cancel this configuration","terminal_mark=?","y","default=n"); report(""); if ($answer eq "y") { return(1); } else { # Cause a requery. return(undef); } } elsif (not -d $dir) { report("Invalid: The specified dir or file does not exist."); report(""); } return(-d $dir); } my $JRE_DefaultPath = undef ; my %JRE_DefaultPaths = ( DEFAULT => [ "/usr/local/jdk" ], LINUX => [ "/usr/java" ], SUNOS => [ "/usr/java" ], AIX => [ "/usr/jdk_base", "/usr/java130", "/usr/java131" ], 'HP-UX' => [ "/opt/java1.3" ], ); (exists $JRE_DefaultPaths{uc($pOS->{os})}) ? map { $JRE_DefaultPath = $_ if (-d "$_") } @{$JRE_DefaultPaths{uc($pOS->{os})}} : map { $JRE_DefaultPath = $_ } ${$JRE_DefaultPaths{DEFAULT}} [ 0 ] ; unless ($JRE_DefaultPath) { $JRE_DefaultPath = (exists $JRE_DefaultPaths{uc($pOS->{os})}) ? ${JRE_DefaultPaths{uc($pOS->{os})}} [ 0 ] : ${JRE_DefaultPaths{DEFAULT}} [ 0 ] ; } my $bundled_jre_path = undef ; # Detect if this product ships with a JRE. $bundled_jre_path = undef ; local *BEAN_DIR; if (opendir(BEAN_DIR,$pGlobals->{bean_dir})) { foreach my $file (readdir(BEAN_DIR)) { if ($file =~ /^jre[0-9]/) { $bundled_jre_path = "$pGlobals->{bean_dir}/$file"; last; } } closedir(BEAN_DIR); } SETUP_AGAIN: if ($bundled_jre_path) { $pBeanHash->{bean::jre_path} = $bundled_jre_path; } my $manual_setup_required = undef; my $disable_bean = undef; my $isVisible = (boolean_value($pParameters->{bundle_install}) || interactive); my $inInstaller = ($0 =~ /caspi2\.pl/); if (-d $pBeanHash->{bean::jre_path}) { if ($isVisible) { my $valid_jres = join(", ",@platform_supported_jres); my $bundled_jre_version = detect_version($pBeanHash->{bean::jre_path}); my $option = INSTALL::query::user_menu ( "Sun Chili!Soft ASP - Configuring Java Support", "The Sun Chili!Beans component allows you to directly access Java objects and ". "classes from inside your ASP scripts. For this functionality to be provided, ". "a Java runtime environment (JRE) must be installed. Sun Chili!Soft ASP ". "includes JRE $bundled_jre_version. While other JREs are supported, the use ". "of JRE $bundled_jre_version is strongly recommended. Choose option 1 ". "to use the bundled JRE.", "Which JRE would you like to use", "terminal_mark=?", ($inInstaller ? "default=" : "")."Use the bundled JRE $bundled_jre_version.", "Specify the path to an existing JRE.", "Disable Java support.", ($inInstaller ? () : "default=Keep your current settings.") ); if ($option == 2) { $manual_setup_required = 1; } elsif ($option == 3) { $disable_bean = 1; } elsif ($option == 4) { return(-1); } } } elsif ($isVisible) { my $valid_jres = join(", ",@platform_supported_jres); my $option = INSTALL::query::user_menu ( "Sun Chili!Soft ASP - Configuring Java Support", "The Chili!Beans component allows users to directly access Java objects and ". "classes from inside their ASP scripts. However, for this functionality to ". "be provided, a Java Runtime Environment (JRE) needs to be installed.", "Which JRE would you like to use", "terminal_mark=?", "Specify the path to an existing JRE.", "Disable Java support.", ($inInstaller ? () : "default=Keep your current settings.") ); if ($option == 1) { $manual_setup_required = 1; } elsif ($option == 2) { $disable_bean = 1; } else { return(-1); } } if ($isVisible) { if ($disable_bean) { my $confirm = INSTALL::query::user ("\nAre you sure you want to disable Java support", "terminal_mark=?", "y", "default=n"); if ($confirm eq 'y') { return(undef); } else { goto SETUP_AGAIN; } } if ($manual_setup_required) { my $jre_path = INSTALL::query::user_function ( "\nEnter the path to your JRE (type none to return to previous menu)\n", *confirm_existence, "terminal_mark=:", "default=$JRE_DefaultPath", "invalid_choice="); if ($jre_path eq "none") { goto SETUP_AGAIN; } $pBeanHash->{bean::jre_path} = $jre_path; } } else { # Non interactive. if (exists $pParameters->{jre_path}) { $pBeanHash->{bean::jre_path} = $pParameters->{jre_path}; } if ((not exists $pParameters->{jre_enabled}) || boolean_value($pParameters->{jre_enabled})) { # Only enable the bean if the user chose to enable it, or enabling it / # disabling it was not specified. unless (-d $pBeanHash->{bean::jre_path}) { # Non-interactive doesn't get the bean, unless its specifies the location # of a JRE, or a JRE is shipped with the product. return(note("No JRE could be found to install Java support for.")); } } else { return(note("No JRE will be installed to by user request.")); } } ## Now we will have validate the path. if ( -d "$pBeanHash->{bean::jre_path}/jre") { $pBeanHash->{bean::jre_path} = "$pBeanHash->{bean::jre_path}/jre"; } # Now detect the Java versions. if (!(-x "$pBeanHash->{bean::jre_path}/bin/java")) { error("Unable to locate java binary in JRE path $pBeanHash->{bean::jre_path}.", "Confirm that the 'java' binary is located in:", " $pBeanHash->{bean::jre_path}/bin"); goto SETUP_ERROR; } $pBeanHash->{bean::jre_version} = detect_version($pBeanHash->{bean::jre_path}); if (not exists $pBeanHash->{bean::jre_version}) { error("Unable to retrieve version information from java binary:", " $pBeanHash->{bean::jre_path}/bin/java"); goto SETUP_ERROR; } else { my $found_match; my @supported_jre_patterns = @platform_supported_jres; @supported_jre_patterns = map { s/\.x/(\.[0-9]\+)\?/g; $_ } @supported_jre_patterns; if (not grep { $pBeanHash->{bean::jre_version} =~ /^$_$/; } @supported_jre_patterns) { error("Unsupported JRE version detected ($pBeanHash->{bean::jre_version})."); goto SETUP_ERROR; } } my @lib_dirs = () ; if ($pOS->{os} =~ /HP-UX/) { my $ld_preload_supported=`(strings '/lib/dld.sl' | fgrep LD_PRELOAD) 2>/dev/null` ; unless ($ld_preload_supported) { error ("Chili!Beans uses the LD_PRELOAD feature of the dynamic loader.", "Setup has detected that currently you do NOT have this support", "with your loader. This feature is available when you install the ", "latest ld/dld patch. Please refer to Sun Chili!Soft documentation", "for more information on this.", ) ; if ($isVisible) { report("Press Enter to continue ..."); ; } return (undef); #$pBeanHash->{bean::jvm_type} = "classic" ; } $pBeanHash->{bean::jvm_type} = "hotspot" ; push @lib_dirs, map("$pBeanHash->{bean::jre_path}/$_", ( "lib/$pBeanHash->{bean::arch}/server", "lib/$pBeanHash->{bean::arch}/hotspot", ) ); push @lib_dirs, map("$pBeanHash->{bean::jre_path}/$_", ( "lib", "lib/$pBeanHash->{bean::arch}", "lib/$pBeanHash->{bean::arch}/classic", "lib/$pBeanHash->{bean::arch}/native_threads", "lib/$pBeanHash->{bean::arch}/green_threads", ) ); } else { push @lib_dirs, map("$pBeanHash->{bean::jre_path}/$_", ( "lib", "lib/$pBeanHash->{bean::arch}", "lib/$pBeanHash->{bean::arch}/native_threads", "lib/$pBeanHash->{bean::arch}/green_threads", "lib/$pBeanHash->{bean::arch}/server", "lib/$pBeanHash->{bean::arch}/classic", "lib/$pBeanHash->{bean::arch}/client", ) ); } # Will be defined, only for 1.2.x on non-Solaris. $pBeanHash->{bean::hpi_libpath} = undef; my @lib_prefixes = ("java","jvm") ; if ($pOS->{os} !~ /SunOS/i) { # HPI is the Host Porting Interface (which is used on non-Solaris JVMs). push @lib_prefixes,"hpi"; } # Initialize all variables yet to be set to undef. foreach my $lib_prefix (@lib_prefixes) { $pBeanHash->{"bean::${lib_prefix}_libpath"} = $pBeanHash->{"bean::${lib_prefix}_library"} = undef; } foreach my $lib_dir (@lib_dirs) { foreach my $lib_prefix (@lib_prefixes) { if (not defined $pBeanHash->{"bean::${lib_prefix}_libpath"}) { foreach my $libext (@{$pOS->{shlib_extensions}}) { if (-f "$lib_dir/lib${lib_prefix}.$libext") { $pBeanHash->{"bean::${lib_prefix}_libpath"} = $lib_dir; $pBeanHash->{"bean::${lib_prefix}_library"} = "$lib_dir/lib${lib_prefix}.$libext"; } } } } } # for some reason, Big blue chose to ship its jvm libraries in innovative # locations. my $locateJVM_Library = undef ; foreach my $lib_prefix (@lib_prefixes) { if ((-f "$pBeanHash->{'bean::${lib_prefix}_libpath'}") && (-f "$pBeanHash->{'bean::${lib_prefix}_library'}")) { $locateJVM_Library = 1 ; last ; } } unless ($locateJVM_Library) { my @lib_dirs = () ; push @lib_dirs,"$pBeanHash->{bean::jre_path}/bin" ; push @lib_dirs, map("$pBeanHash->{bean::jre_path}/bin/$_", ( "server", "native_threads", "classic", "client", "green_threads", "$pBeanHash->{bean::arch}/server", "$pBeanHash->{bean::arch}/native_threads", "$pBeanHash->{bean::arch}/classic", "$pBeanHash->{bean::arch}/client", "$pBeanHash->{bean::arch}/green_threads", ) ); foreach my $lib_dir (@lib_dirs) { foreach my $lib_prefix (@lib_prefixes) { foreach my $libext (@{$pOS->{shlib_extensions}}) { if (-f "$lib_dir/lib${lib_prefix}.$libext") { $pBeanHash->{"bean::${lib_prefix}_libpath"} = $lib_dir; $pBeanHash->{"bean::${lib_prefix}_library"} = "$lib_dir/lib${lib_prefix}.$libext"; } } } } } # screwed up hack for HP support. if ($pOS->{os} =~ /HP-UX/ && $pBeanHash->{"bean::jvm_library"}) { $pBeanHash->{"bean::java_library"} = $pBeanHash->{"bean::jvm_library"}; } my %required_libs = ( "1.1.[0-9]+" => ["java"], "1.[23].[0-9]+" => [@lib_prefixes] ); # Confirm that the required libraries for this version of the jre are found. my $pRequired_libs; foreach(keys %required_libs) { if ($pBeanHash->{bean::jre_version} =~ /$_/) { $pRequired_libs = $required_libs{$_} ; last; } } foreach my $lib_prefix (@{$pRequired_libs}) { if (not $pBeanHash->{"bean::${lib_prefix}_libpath"}) { note("Unable to locate $lib_prefix library."); goto SETUP_ERROR; } } if (boolean_value($pParameters->{bundle_install}) || interactive) { my $message; if ($pBeanHash->{bean::jre_path} eq $bundled_jre_path) { $message = "\nAre you sure you want to install the bundled JRE $pBeanHash->{bean::jre_version}" } else { $message = "\nAre you sure you want to install to the JRE $pBeanHash->{bean::jre_version} located in\n". "$pBeanHash->{bean::jre_path}"; } my $confirm = INSTALL::query::user ($message, "terminal_mark=?", "default=y", "n"); if ($confirm eq 'n') { goto SETUP_AGAIN; } } $pBeanHash->{bean::support}="yes"; return(1); SETUP_ERROR: # Only visible (ie. interactive or bundle) installs should be allowed to # respond to an error. Non-visible installs should merely return their # error message and be on their merry way. if ($isVisible) { print STDERR ("Press Enter to input another path.\n"); ; $pBeanHash->{jre_path} = " # Set to the JRE root directory."; goto SETUP_AGAIN; } else { return(wantarray ? () : undef); } } sub configure { my %bean_hash; if ($pOS->{os} =~ /AIX/) { $bean_hash{bean::arch} = "aix"; } elsif ($pOS->{os} =~ /HP-UX/i) { # we need to detect whether this machine is a 32bit or 64 bit # machine, accordingly we can set the arch to PA_RISC to either default # or hotspot. $bean_hash{bean::arch} = "PA_RISC"; } elsif ($pOS->{os} =~ /Linux/i) { if ($pOS->{hardware} =~ /ia32/i) { $bean_hash{bean::arch} = "i386"; } else { die "Unhandled version of linux hardware."; } } else { $bean_hash{bean::arch} = $pOS->{hardware}; } my $setup_result = INSTALL::bean::setup(\%bean_hash); unless($setup_result) { # Unless the setup was successful, change the settings to descriptions # of what their intended values should be (for manual editing purposes). %bean_hash = ( bean::support => "no", bean::jvm_type => "hotspot", bean::arch => $bean_hash{bean::arch}, bean::jre_version => " # Set to the JRE version being used.", bean::jre_path => " # Set to the JRE root directory.", bean::java_libpath => " # Set to the directory containing your java library.", bean::jvm_libpath => " # Set to the directory containing your jvm library.", bean::hpi_libpath => " # Set to the directory containing your hpi library (if one exists).", bean::java_library => " # Set to the full path of your java library (e.g. <>/libjava.so).", bean::jvm_library => " # Set to the full path of your jvm library (e.g. <>/libjvm.sl)." ); } if ($setup_result >= 0) { # Unless the setup result was negative, which indicates that the user # chose to leave their settings unchanged, we should perform # substitution on the template file. foreach (keys %bean_hash) { $pGlobals->{$_} = $bean_hash{$_}; } INSTALL::substitute::template("javasetup.sh",$pGlobals->{asphome}); if ((exists $pParameters->{jre_enabled}) && (not boolean_value($pParameters->{jre_enabled}))) { # Failures when jre_enabled=false is set are ignored, due to the # fact that the setup function itself errors out, we need to alter # the functions path to accomodate this peculiar behavior. return(1); } } if ($setup_result > 0) { summary_log("Chili!Beans enabled: yes", " JRE version: $bean_hash{bean::jre_version}", " JRE path: $bean_hash{bean::jre_path}"); } elsif ($setup_result == 0) { summary_log("Chili!Bean enabled: no"); } return($setup_result); } 1;