summaryrefslogtreecommitdiffstats
path: root/ldap/cm/newinst/setup.pl
blob: cee72f6fbe7a11d597e11b504c893668aeeb20b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!./tools/perl
# --- BEGIN COPYRIGHT BLOCK ---
# Copyright (C) 2005 Red Hat, Inc.
# All rights reserved.
# --- END COPYRIGHT BLOCK ---
#
# This program will package a downloaded JRE into a nsjre.zip
# file suitable for a DS install.

use lib './lib';
use FileHandle;

autoflush STDERR 1;
autoflush STDOUT 1;

delete $ENV{LD_LIBRARY_PATH};

# Set required JRE version
if ($^O eq "hpux") {
    $jdkVersion = "HP's 32-bit HP-UX";
    $reqVersion = "1.4.2.04";
    delete $ENV{SHLIB_PATH};
} elsif ($^O eq "MSWin32") {
    $jdkVersion = "Sun's 32-bit MS Windows";
    $reqVersion = "1.4.2_05";
} elsif ($^O eq "linux") {
    $jdkVersion = "Sun's 32-bit Linux";
    $reqVersion = "1.4.2_05";
} elsif ($^O eq "solaris") {
    $jdkVersion = "Sun's 32-bit Solaris";
    $reqVersion = "1.4.2_05";
} else {
    print("Unsupported operating system: $^O!\n");
    exit;
}

# Check if base/nsjre.zip or base/jre.z already exists
unless (-e "./base/nsjre.zip" || -e "./base/jre.z") {
    # Check if NSJRE environment variable is set
    if ($ENV{NSJRE}) {
        chomp ($jrepath = $ENV{NSJRE});
        print ("Using NSJRE environment variable: $jrepath\n");
    } else {
        print ("In order to run setup, you need to have version");
        print (" $reqVersion of\n");
        print ("$jdkVersion Java runtime environment on your system.\n\n");
        print ("Enter the path to the unpackaged JRE: ");
        chomp ($jrepath = <STDIN>);
    }

    VerifyJRE();
    CreatePackage();
    CleanUp();
}

# Kick off setup
exec("./dssetup @ARGV");

sub VerifyJRE {
    print ("\nVerifying JRE...");
    unless (-e "$jrepath" && -r "$jrepath") { die ("\nError: Can't access JRE: $!\n"); }
    unless (-e "$jrepath/bin" && -r "$jrepath/bin") { die ("\nError: Can't access $jrepath/bin: $!\n"); }
    unless (-e "$jrepath/bin" && -r "$jrepath/lib") { die ("\nError: Can't access $jrepath/lib: $!\n"); }
    unless (-e "$jrepath/bin/java" || -e "$jrepath/bin/java.exe") { die ("\nError: Invalid JRE found: $!\n"); }

    my $jreVersion = `\"$jrepath/bin/java\" -version 2>&1`;
    $jreVersion =~ /".*"/;
    $foundVersion = $&;
    print (" Found JRE $foundVersion\n");
    unless ($foundVersion =~ $reqVersion) {
        print ("\nWarning: This product was certified with JRE version \"$reqVersion\".  You have version $foundVersion.\n");
        print ("The product may not behave correctly if you use this JRE.\n");
        print ("Would you like to continue anyway [yes/no]? ");
        chomp ($answer = <STDIN>);
        unless ($answer eq "yes") { exit; } 
    }
}

sub CreatePackage {
    print ("Creating JRE package...");

    # Create packaging area
    mkdir ("bin", 0755) || die ("Error: Can't create ./bin: $!\n");
    mkdir ("bin/base", 0755) || die ("Error: Can't create ./bin/base: $!\n");
    mkdir ("bin/base/jre", 0755) || die ("Error: Can't create ./bin/base/jre: $!\n");

    # Copy bin and lib from JRE into packaging area, then create zip archive
    if ($^O eq "MSWin32") {
        system ("xcopy /E /I /Q \"$jrepath/bin\" \"bin/base/jre/bin\"") == 0 ||
            die ("\nError: Can't copy JRE: $!\n");
        system ("xcopy /E /I /Q \"$jrepath/lib\" \"bin/base/jre/lib\"") == 0 ||
            die ("\nError: Can't copy JRE: $!\n");
        system ("./tools/zip -q -r ./base/jre.z ./bin") == 0 ||
            die ("\nError: Can't create JRE archive: $!\n");
    } else {
        system ("cp -R $jrepath/bin ./bin/base/jre") == 0 ||
            die ("\nError: Can't copy JRE: $!\n");
        system ("cp -R $jrepath/lib ./bin/base/jre") == 0 ||
            die ("\nError: Can't copy JRE: $!\n");

        # On HP-UX, we need to move some libraries in the JRE package
        if ($^O eq "hpux") {
            system ("cp -f ./bin/base/jre/lib/PA_RISC/native_threads/libhpi.sl ./bin/base/jre/lib/PA_RISC/libhpi.sl") == 0 ||
                die ("\nError: Can't create JRE archive: $!\n");
            system ("cp -f ./bin/base/jre/lib/PA_RISC2.0/native_threads/libhpi.sl ./bin/base/jre/lib/PA_RISC2.0/libhpi.sl") == 0 ||
                die ("\nError: Can't create JRE archive: $!\n");
            system ("cp -f ./bin/base/jre/lib/PA_RISC2.0W/native_threads/libhpi.sl ./bin/base/jre/lib/PA_RISC2.0W/libhpi.sl") == 0 ||
                die ("\nError: Can't create JRE archive: $!\n");
        }

        system ("./tools/zip -q -r ./base/nsjre.zip ./bin") == 0 ||
            die ("\nError: Can't create JRE archive: $!\n");
    }

    print (" Done\n");
}

sub CleanUp {
    print ("Cleaning up...");

    # Remove packaging area
    RemoveFiles ("./bin");
    rmdir ("./bin") || die ("Error: can't remove ./bin: $!\n");

    print (" Done\n");
}

sub RemoveFiles {
    my $dir = shift;
    opendir (DIR, $dir) || die ("Error: Can't open $dir: $!");
    my @entries = map { "$dir/$_" } grep { !/^\.$|^\.\.$/ } readdir DIR;
    closedir DIR;
    for (@entries) {
	if (-l $_) {
            unlink || die ("Error: Can't remove $_: $!\n");
	} elsif (-d $_) {
            RemoveFiles($_);
            rmdir($_) || die ("Error: Can't remove $_: $!\n");
        } else {
            unlink || die ("Error: Can't remove $_: $!\n");
        }
    }
}