setup.pl 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!./tools/perl
  2. # --- BEGIN COPYRIGHT BLOCK ---
  3. # This Program is free software; you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation; version 2 of the License.
  6. #
  7. # This Program is distributed in the hope that it will be useful, but WITHOUT
  8. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License along with
  12. # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  13. # Place, Suite 330, Boston, MA 02111-1307 USA.
  14. #
  15. # In addition, as a special exception, Red Hat, Inc. gives You the additional
  16. # right to link the code of this Program with code not covered under the GNU
  17. # General Public License ("Non-GPL Code") and to distribute linked combinations
  18. # including the two, subject to the limitations in this paragraph. Non-GPL Code
  19. # permitted under this exception must only link to the code of this Program
  20. # through those well defined interfaces identified in the file named EXCEPTION
  21. # found in the source code files (the "Approved Interfaces"). The files of
  22. # Non-GPL Code may instantiate templates or use macros or inline functions from
  23. # the Approved Interfaces without causing the resulting work to be covered by
  24. # the GNU General Public License. Only Red Hat, Inc. may make changes or
  25. # additions to the list of Approved Interfaces. You must obey the GNU General
  26. # Public License in all respects for all of the Program code and other code used
  27. # in conjunction with the Program except the Non-GPL Code covered by this
  28. # exception. If you modify this file, you may extend this exception to your
  29. # version of the file, but you are not obligated to do so. If you do not wish to
  30. # provide this exception without modification, you must delete this exception
  31. # statement from your version and license this file solely under the GPL without
  32. # exception.
  33. #
  34. #
  35. # Copyright (C) 2005 Red Hat, Inc.
  36. # All rights reserved.
  37. # --- END COPYRIGHT BLOCK ---
  38. #
  39. # This program will package a downloaded JRE into a nsjre.zip
  40. # file suitable for a DS install.
  41. use lib './lib';
  42. use FileHandle;
  43. autoflush STDERR 1;
  44. autoflush STDOUT 1;
  45. delete $ENV{LD_LIBRARY_PATH};
  46. # Set required JRE version
  47. if ($^O eq "hpux") {
  48. $jdkVersion = "HP's 32-bit HP-UX";
  49. $reqVersion = "1.4.2.07";
  50. delete $ENV{SHLIB_PATH};
  51. } elsif ($^O eq "MSWin32") {
  52. $jdkVersion = "Sun's 32-bit MS Windows";
  53. $reqVersion = "1.4.2_05";
  54. } elsif ($^O eq "linux") {
  55. $jdkVersion = "Sun's 32-bit Linux";
  56. $reqVersion = "1.4.2_05";
  57. } elsif ($^O eq "solaris") {
  58. $jdkVersion = "Sun's 32-bit Solaris";
  59. $reqVersion = "1.4.2_05";
  60. } else {
  61. print("Unsupported operating system: $^O!\n");
  62. exit;
  63. }
  64. # Check if base/nsjre.zip or base/jre.z already exists
  65. unless (-e "./base/nsjre.zip" || -e "./base/jre.z") {
  66. # Check if NSJRE environment variable is set
  67. if ($ENV{NSJRE}) {
  68. chomp ($jrepath = $ENV{NSJRE});
  69. print ("Using NSJRE environment variable: $jrepath\n");
  70. } else {
  71. print ("In order to run setup, you need to have version");
  72. print (" $reqVersion of\n");
  73. print ("$jdkVersion Java runtime environment on your system.\n\n");
  74. print ("Enter the path to the unpackaged JRE: ");
  75. chomp ($jrepath = <STDIN>);
  76. }
  77. VerifyJRE();
  78. CreatePackage();
  79. CleanUp();
  80. }
  81. # Kick off setup
  82. exec("./dssetup @ARGV");
  83. sub VerifyJRE {
  84. print ("\nVerifying JRE...");
  85. unless (-e "$jrepath" && -r "$jrepath") { die ("\nError: Can't access JRE: $!\n"); }
  86. unless (-e "$jrepath/bin" && -r "$jrepath/bin") { die ("\nError: Can't access $jrepath/bin: $!\n"); }
  87. unless (-e "$jrepath/bin" && -r "$jrepath/lib") { die ("\nError: Can't access $jrepath/lib: $!\n"); }
  88. unless (-e "$jrepath/bin/java" || -e "$jrepath/bin/java.exe") { die ("\nError: Invalid JRE found: $!\n"); }
  89. my $jreVersion = `\"$jrepath/bin/java\" -version 2>&1`;
  90. $jreVersion =~ /".*"/;
  91. $foundVersion = $&;
  92. print (" Found JRE $foundVersion\n");
  93. unless ($foundVersion =~ $reqVersion) {
  94. print ("\nWarning: This product was certified with JRE version \"$reqVersion\". You have version $foundVersion.\n");
  95. print ("The product may not behave correctly if you use this JRE.\n");
  96. print ("Would you like to continue anyway [yes/no]? ");
  97. chomp ($answer = <STDIN>);
  98. unless ($answer eq "yes") { exit; }
  99. }
  100. }
  101. sub CreatePackage {
  102. print ("Creating JRE package...");
  103. # Create packaging area
  104. mkdir ("bin", 0755) || die ("Error: Can't create ./bin: $!\n");
  105. mkdir ("bin/base", 0755) || die ("Error: Can't create ./bin/base: $!\n");
  106. mkdir ("bin/base/jre", 0755) || die ("Error: Can't create ./bin/base/jre: $!\n");
  107. # Copy bin and lib from JRE into packaging area, then create zip archive
  108. if ($^O eq "MSWin32") {
  109. system ("xcopy /E /I /Q \"$jrepath/bin\" \"bin/base/jre/bin\"") == 0 ||
  110. die ("\nError: Can't copy JRE: $!\n");
  111. system ("xcopy /E /I /Q \"$jrepath/lib\" \"bin/base/jre/lib\"") == 0 ||
  112. die ("\nError: Can't copy JRE: $!\n");
  113. system ("./tools/zip -q -r ./base/jre.z ./bin") == 0 ||
  114. die ("\nError: Can't create JRE archive: $!\n");
  115. } else {
  116. system ("cp -R $jrepath/bin ./bin/base/jre") == 0 ||
  117. die ("\nError: Can't copy JRE: $!\n");
  118. system ("cp -R $jrepath/lib ./bin/base/jre") == 0 ||
  119. die ("\nError: Can't copy JRE: $!\n");
  120. # On HP-UX, we need to move some libraries in the JRE package
  121. if ($^O eq "hpux") {
  122. system ("cp -f ./bin/base/jre/lib/PA_RISC/native_threads/libhpi.sl ./bin/base/jre/lib/PA_RISC/libhpi.sl") == 0 ||
  123. die ("\nError: Can't create JRE archive: $!\n");
  124. system ("cp -f ./bin/base/jre/lib/PA_RISC2.0/native_threads/libhpi.sl ./bin/base/jre/lib/PA_RISC2.0/libhpi.sl") == 0 ||
  125. die ("\nError: Can't create JRE archive: $!\n");
  126. system ("cp -f ./bin/base/jre/lib/PA_RISC2.0W/native_threads/libhpi.sl ./bin/base/jre/lib/PA_RISC2.0W/libhpi.sl") == 0 ||
  127. die ("\nError: Can't create JRE archive: $!\n");
  128. }
  129. system ("./tools/zip -q -r ./base/nsjre.zip ./bin") == 0 ||
  130. die ("\nError: Can't create JRE archive: $!\n");
  131. }
  132. print (" Done\n");
  133. }
  134. sub CleanUp {
  135. print ("Cleaning up...");
  136. # Remove packaging area
  137. RemoveFiles ("./bin");
  138. rmdir ("./bin") || die ("Error: can't remove ./bin: $!\n");
  139. print (" Done\n");
  140. }
  141. sub RemoveFiles {
  142. my $dir = shift;
  143. opendir (DIR, $dir) || die ("Error: Can't open $dir: $!");
  144. my @entries = map { "$dir/$_" } grep { !/^\.$|^\.\.$/ } readdir DIR;
  145. closedir DIR;
  146. for (@entries) {
  147. if (-l $_) {
  148. unlink || die ("Error: Can't remove $_: $!\n");
  149. } elsif (-d $_) {
  150. RemoveFiles($_);
  151. rmdir($_) || die ("Error: Can't remove $_: $!\n");
  152. } else {
  153. unlink || die ("Error: Can't remove $_: $!\n");
  154. }
  155. }
  156. }