19780544fSAndrew Rist#**************************************************************
29780544fSAndrew Rist#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
109780544fSAndrew Rist#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
129780544fSAndrew Rist#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
199780544fSAndrew Rist#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
229780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::control;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse Cwd;
27cdf0e10cSrcweiruse installer::converter;
28cdf0e10cSrcweiruse installer::exiter;
29cdf0e10cSrcweiruse installer::files;
30cdf0e10cSrcweiruse installer::globals;
31cdf0e10cSrcweiruse installer::pathanalyzer;
32cdf0e10cSrcweiruse installer::scriptitems;
33cdf0e10cSrcweiruse installer::systemactions;
34cdf0e10cSrcweir
35b274bc22SAndre Fischerour @ErrorMessages = undef;
36b274bc22SAndre Fischer
37cdf0e10cSrcweir#########################################################
38cdf0e10cSrcweir# Function that can be used for additional controls.
39cdf0e10cSrcweir# Search happens in $installer::globals::patharray.
40cdf0e10cSrcweir#########################################################
41cdf0e10cSrcweir
42cdf0e10cSrcweirsub check_needed_files_in_path
43cdf0e10cSrcweir{
44cdf0e10cSrcweir	my ( $filesref ) = @_;
45b274bc22SAndre Fischer
46b274bc22SAndre Fischer    my $error = 0;
47b274bc22SAndre Fischer	foreach my $onefile ( @{$filesref} )
48cdf0e10cSrcweir	{
49b274bc22SAndre Fischer		$installer::logger::Info->printf("...... searching %s ...\n", $onefile);
50cdf0e10cSrcweir
51cdf0e10cSrcweir		my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$onefile, $installer::globals::patharray , 0);
52cdf0e10cSrcweir
53cdf0e10cSrcweir		if ( $$fileref eq "" )
54cdf0e10cSrcweir		{
55cdf0e10cSrcweir			$error = 1;
56cdf0e10cSrcweir			installer::logger::print_error( "$onefile not found\n" );
57cdf0e10cSrcweir		}
58cdf0e10cSrcweir		else
59cdf0e10cSrcweir		{
60b274bc22SAndre Fischer			$installer::logger::Info->print( "\tFound: $$fileref\n" );
61cdf0e10cSrcweir		}
62cdf0e10cSrcweir	}
63cdf0e10cSrcweir
64cdf0e10cSrcweir	if ( $error )
65cdf0e10cSrcweir	{
66cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Could not find all needed files in path!", "check_needed_files_in_path");
67cdf0e10cSrcweir	}
68cdf0e10cSrcweir}
69cdf0e10cSrcweir
70cdf0e10cSrcweir#########################################################
71cdf0e10cSrcweir# Checking the local system
72cdf0e10cSrcweir# Checking existence of needed files in include path
73cdf0e10cSrcweir#########################################################
74cdf0e10cSrcweir
75cdf0e10cSrcweirsub check_system_path
76cdf0e10cSrcweir{
77cdf0e10cSrcweir	# The following files have to be found in the environment variable PATH
78cdf0e10cSrcweir	# All platforms: zip
79cdf0e10cSrcweir	# Windows only: "msiinfo.exe", "msidb.exe", "uuidgen.exe", "makecab.exe", "msitran.exe", "expand.exe" for msi database and packaging
80cdf0e10cSrcweir
81cdf0e10cSrcweir	my $onefile;
82cdf0e10cSrcweir	my $error = 0;
83cdf0e10cSrcweir	my $pathvariable = $ENV{'PATH'};
84cdf0e10cSrcweir	my $local_pathseparator = $installer::globals::pathseparator;
85cdf0e10cSrcweir
86cdf0e10cSrcweir	if( $^O =~ /cygwin/i )
87cdf0e10cSrcweir	{	# When using cygwin's perl the PATH variable is POSIX style and ...
88cdf0e10cSrcweir		$pathvariable = qx{cygpath -mp "$pathvariable"} ;
89cdf0e10cSrcweir		# has to be converted to DOS style for further use.
90cdf0e10cSrcweir		$local_pathseparator = ';';
91cdf0e10cSrcweir	}
92dfa12748SYuri Dario	if( $^O =~ /os2/i )
93dfa12748SYuri Dario	{
94dfa12748SYuri Dario		# has to be converted to DOS style for further use.
95dfa12748SYuri Dario		$local_pathseparator = ';';
96dfa12748SYuri Dario	}
97cdf0e10cSrcweir	my $patharrayref = installer::converter::convert_stringlist_into_array(\$pathvariable, $local_pathseparator);
98cdf0e10cSrcweir
99cdf0e10cSrcweir	$installer::globals::patharray = $patharrayref;
100cdf0e10cSrcweir
101cdf0e10cSrcweir	my @needed_files_in_path = ();
102cdf0e10cSrcweir
103cdf0e10cSrcweir	if (($installer::globals::iswin) && ($installer::globals::iswindowsbuild))
104cdf0e10cSrcweir	{
105cdf0e10cSrcweir		@needed_files_in_path = ("zip.exe", "msiinfo.exe", "msidb.exe", "uuidgen.exe", "makecab.exe", "msitran.exe", "expand.exe");
106cdf0e10cSrcweir	}
107dfa12748SYuri Dario	elsif ($installer::globals::iswin || $installer::globals::isos2)
108cdf0e10cSrcweir	{
109cdf0e10cSrcweir		@needed_files_in_path = ("zip.exe");
110cdf0e10cSrcweir	}
111cdf0e10cSrcweir	else
112cdf0e10cSrcweir	{
113cdf0e10cSrcweir		@needed_files_in_path = ("zip");
114cdf0e10cSrcweir	}
115cdf0e10cSrcweir
116cdf0e10cSrcweir	foreach $onefile ( @needed_files_in_path )
117cdf0e10cSrcweir	{
118b274bc22SAndre Fischer		$installer::logger::Info->printf("...... searching %s ...\n", $onefile);
119cdf0e10cSrcweir
120cdf0e10cSrcweir		my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$onefile, $patharrayref , 0);
121cdf0e10cSrcweir
122cdf0e10cSrcweir		if ( $$fileref eq "" )
123cdf0e10cSrcweir		{
124cdf0e10cSrcweir			$error = 1;
125cdf0e10cSrcweir			installer::logger::print_error( "$onefile not found\n" );
126cdf0e10cSrcweir		}
127cdf0e10cSrcweir		else
128cdf0e10cSrcweir		{
129b274bc22SAndre Fischer			$installer::logger::Info->print( "\tFound: $$fileref\n" );
130cdf0e10cSrcweir			# Saving the absolut path for msitran.exe. This is required for the determination of the checksum.
131cdf0e10cSrcweir			if ( $onefile eq "msitran.exe" ) { $installer::globals::msitranpath = $$fileref; }
132cdf0e10cSrcweir		}
133cdf0e10cSrcweir	}
134cdf0e10cSrcweir
135cdf0e10cSrcweir	if ( $error )
136cdf0e10cSrcweir	{
137cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Could not find all needed files in path!", "check_system_path");
138cdf0e10cSrcweir	}
139cdf0e10cSrcweir
140cdf0e10cSrcweir	# checking for epm, which has to be in the path or in the solver
141cdf0e10cSrcweir
142cdf0e10cSrcweir	if (( $installer::globals::call_epm ) && (!($installer::globals::iswindowsbuild)))
143cdf0e10cSrcweir	{
144cdf0e10cSrcweir		my $onefile = "epm";
145cdf0e10cSrcweir		my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$onefile, $patharrayref , 0);
146cdf0e10cSrcweir		if (!( $$fileref eq "" ))
147cdf0e10cSrcweir		{
148cdf0e10cSrcweir			$installer::globals::epm_in_path = 1;
149cdf0e10cSrcweir
150cdf0e10cSrcweir			if ( $$fileref =~ /^\s*\.\/epm\s*$/ )
151cdf0e10cSrcweir			{
152cdf0e10cSrcweir				my $currentdir = cwd();
153cdf0e10cSrcweir				$$fileref =~ s/\./$currentdir/;
154cdf0e10cSrcweir			}
155cdf0e10cSrcweir
156cdf0e10cSrcweir			$installer::globals::epm_path = $$fileref;
157cdf0e10cSrcweir		}
158cdf0e10cSrcweir	}
159cdf0e10cSrcweir
160cdf0e10cSrcweir	# checking, if upx can be found in path
161cdf0e10cSrcweir
162cdf0e10cSrcweir	if ( $installer::globals::iswindowsbuild ) { $installer::globals::upxfile = "upx.exe"; }
163cdf0e10cSrcweir	else { $installer::globals::upxfile = "upx"; }
164cdf0e10cSrcweir
165cdf0e10cSrcweir	my $upxfilename = $installer::globals::upxfile;
166cdf0e10cSrcweir	my $upxfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$upxfilename, $patharrayref , 0);
167cdf0e10cSrcweir
168cdf0e10cSrcweir	if (!( $$upxfileref eq "" ))
169cdf0e10cSrcweir	{
170cdf0e10cSrcweir		$installer::globals::upx_in_path = 1;
171cdf0e10cSrcweir		$installer::globals::upxfile = $$upxfileref;
172b274bc22SAndre Fischer		$installer::logger::Info->print( "\tFound: $$upxfileref\n" );
173cdf0e10cSrcweir	}
174cdf0e10cSrcweir
175cdf0e10cSrcweir}
176cdf0e10cSrcweir
177cdf0e10cSrcweir######################################################################
178cdf0e10cSrcweir# Determining the version of file makecab.exe
179cdf0e10cSrcweir######################################################################
180cdf0e10cSrcweir
181cdf0e10cSrcweirsub get_makecab_version
182cdf0e10cSrcweir{
183cdf0e10cSrcweir	my $makecabversion = -1;
184cdf0e10cSrcweir
185cdf0e10cSrcweir	my $systemcall = "makecab.exe |";
186cdf0e10cSrcweir	my @makecaboutput = ();
187cdf0e10cSrcweir
188cdf0e10cSrcweir	open (CAB, $systemcall);
189cdf0e10cSrcweir	while (<CAB>) { push(@makecaboutput, $_); }
190cdf0e10cSrcweir	close (CAB);
191cdf0e10cSrcweir
192cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
193cdf0e10cSrcweir
194cdf0e10cSrcweir	if ($returnvalue)
195cdf0e10cSrcweir	{
196b274bc22SAndre Fischer        $installer::logger::Global->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
197cdf0e10cSrcweir	}
198cdf0e10cSrcweir	else
199cdf0e10cSrcweir	{
200b274bc22SAndre Fischer        $installer::logger::Global->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
201cdf0e10cSrcweir
202cdf0e10cSrcweir		my $versionline = "";
203cdf0e10cSrcweir
204cdf0e10cSrcweir		for ( my $i = 0; $i <= $#makecaboutput; $i++ )
205cdf0e10cSrcweir		{
206cdf0e10cSrcweir			if ( $makecaboutput[$i] =~ /\bVersion\b/i )
207cdf0e10cSrcweir			{
208cdf0e10cSrcweir				$versionline = $makecaboutput[$i];
209cdf0e10cSrcweir				last;
210cdf0e10cSrcweir			}
211cdf0e10cSrcweir		}
212b274bc22SAndre Fischer
213b274bc22SAndre Fischer        $installer::logger::Global->printf("%s\n", $versionline);
214cdf0e10cSrcweir
215cdf0e10cSrcweir		if ( $versionline =~ /\bVersion\b\s+(\d+[\d\.]+\d+)\s+/ )
216cdf0e10cSrcweir		{
217cdf0e10cSrcweir			$makecabversion = $1;
218cdf0e10cSrcweir		}
219cdf0e10cSrcweir
220cdf0e10cSrcweir		# Only using the first number
221cdf0e10cSrcweir
222cdf0e10cSrcweir		if ( $makecabversion =~ /^\s*(\d+?)\D*/ )
223cdf0e10cSrcweir		{
224cdf0e10cSrcweir			$makecabversion = $1;
225cdf0e10cSrcweir		}
226b274bc22SAndre Fischer
227b274bc22SAndre Fischer        $installer::logger::Global->printf("Using version: %s\n", $makecabversion);
228cdf0e10cSrcweir	}
229cdf0e10cSrcweir
230cdf0e10cSrcweir	return $makecabversion;
231cdf0e10cSrcweir}
232cdf0e10cSrcweir
233cdf0e10cSrcweir######################################################################
234cdf0e10cSrcweir# Checking the version of file makecab.exe
235cdf0e10cSrcweir######################################################################
236cdf0e10cSrcweir
237cdf0e10cSrcweirsub check_makecab_version
238cdf0e10cSrcweir{
239cdf0e10cSrcweir	# checking version of makecab.exe
240cdf0e10cSrcweir	# Now it is guaranteed, that makecab.exe is in the path
241cdf0e10cSrcweir
242cdf0e10cSrcweir	my $do_check = 1;
243cdf0e10cSrcweir
244cdf0e10cSrcweir	my $makecabversion = get_makecab_version();
245cdf0e10cSrcweir
246b274bc22SAndre Fischer    $installer::logger::Global->printf("Tested version: %s\n", $installer::globals::controlledmakecabversion);
247cdf0e10cSrcweir
248cdf0e10cSrcweir	if ( $makecabversion < 0 ) { $do_check = 0; } # version could not be determined
249cdf0e10cSrcweir
250cdf0e10cSrcweir	if ( $do_check )
251cdf0e10cSrcweir	{
252cdf0e10cSrcweir		if ( $makecabversion < $installer::globals::controlledmakecabversion )
253cdf0e10cSrcweir		{
254cdf0e10cSrcweir			# warning for OOo, error for inhouse products
255cdf0e10cSrcweir			if ( $installer::globals::isopensourceproduct )
256cdf0e10cSrcweir			{
257cdf0e10cSrcweir				installer::logger::print_warning("Old version of makecab.exe. Found version: \"$makecabversion\", tested version: \"$installer::globals::controlledmakecabversion\"!\n");
258cdf0e10cSrcweir			}
259cdf0e10cSrcweir			else
260cdf0e10cSrcweir			{
261cdf0e10cSrcweir				installer::exiter::exit_program("makecab.exe too old. Found version: \"$makecabversion\", required version: \"$installer::globals::controlledmakecabversion\"!", "check_makecab_version");
262cdf0e10cSrcweir			}
263cdf0e10cSrcweir		}
264cdf0e10cSrcweir	}
265cdf0e10cSrcweir	else
266cdf0e10cSrcweir	{
267b274bc22SAndre Fischer        $installer::logger::Global->print("Warning: No version check of makecab.exe\n");
268cdf0e10cSrcweir	}
269cdf0e10cSrcweir}
270cdf0e10cSrcweir
271cdf0e10cSrcweir######################################################################
272cdf0e10cSrcweir# Reading the environment variables for the pathes in ziplist.
273cdf0e10cSrcweir# solarpath, solarenvpath, solarcommonpath, os, osdef, pmiscpath
274cdf0e10cSrcweir######################################################################
275cdf0e10cSrcweir
276cdf0e10cSrcweirsub check_system_environment
277cdf0e10cSrcweir{
278cdf0e10cSrcweir	my %variables = ();
279cdf0e10cSrcweir	my $key;
280cdf0e10cSrcweir	my $error = 0;
281cdf0e10cSrcweir
282cdf0e10cSrcweir	foreach $key ( @installer::globals::environmentvariables )
283cdf0e10cSrcweir	{
284cdf0e10cSrcweir		my $value = "";
285cdf0e10cSrcweir		if ( $ENV{$key} ) { $value = $ENV{$key}; }
286cdf0e10cSrcweir		$variables{$key} = $value;
287cdf0e10cSrcweir
288cdf0e10cSrcweir		if ( $value eq "" )
289cdf0e10cSrcweir		{
290cdf0e10cSrcweir			installer::logger::print_error( "$key not set in environment\n" );
291cdf0e10cSrcweir			$error = 1;
292cdf0e10cSrcweir		}
293cdf0e10cSrcweir	}
294cdf0e10cSrcweir
295cdf0e10cSrcweir	if ( $error )
296cdf0e10cSrcweir	{
297cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Environment variable not set!", "check_system_environment");
298cdf0e10cSrcweir	}
299cdf0e10cSrcweir
300cdf0e10cSrcweir	return \%variables;
301cdf0e10cSrcweir}
302cdf0e10cSrcweir
303cdf0e10cSrcweir
304b274bc22SAndre Fischersub prepare_error_processing ()
305cdf0e10cSrcweir{
306b274bc22SAndre Fischer    @ErrorMessages = ();
307b274bc22SAndre Fischer}
308cdf0e10cSrcweir
309b274bc22SAndre Fischer=item filter_log_error ($relative_time, $log_id, $process_id, $message)
310cdf0e10cSrcweir
311b274bc22SAndre Fischer    Process the given log message.  Returns $message unaltered.
312b274bc22SAndre Fischer
313b274bc22SAndre Fischer=cut
314b274bc22SAndre Fischersub filter_log_error ($$$$)
315b274bc22SAndre Fischer{
316b274bc22SAndre Fischer    my ($relative_time, $log_id, $process_id, $message) = @_;
317b274bc22SAndre Fischer
318b274bc22SAndre Fischer    if ($message =~ /\berror\b/i)
319b274bc22SAndre Fischer    {
320b274bc22SAndre Fischer        # Message contains the word "error".  Now we have to find out if it is relevant.
321b274bc22SAndre Fischer
322b274bc22SAndre Fischer        # Remove all filenames that contain the word "Error".
323b274bc22SAndre Fischer		my $work_string = $message;
324e50a3cc3SAndre Fischer		$work_string =~ s/Error\.(idt|mlf|ulf|idl|html|hpp|ipp)//g;
325cdf0e10cSrcweir
326b274bc22SAndre Fischer		if ($work_string =~ /\bError\b/i)
327cdf0e10cSrcweir		{
328b274bc22SAndre Fischer            # This really is an error message.
329b274bc22SAndre Fischer            push @ErrorMessages, {'relative_time' => $relative_time,
330b274bc22SAndre Fischer                                  'message' => $message};
331cdf0e10cSrcweir		}
332cdf0e10cSrcweir	}
333cdf0e10cSrcweir
334b274bc22SAndre Fischer    return $message;
335b274bc22SAndre Fischer}
336cdf0e10cSrcweir
337b274bc22SAndre Fischer
338b274bc22SAndre Fischer
339b274bc22SAndre Fischer
340b274bc22SAndre Fischersub printocessed_error_lines ()
341b274bc22SAndre Fischer{
342b274bc22SAndre Fischer    my $lines = [];
343b274bc22SAndre Fischer
344b274bc22SAndre Fischer    foreach my $line (@ErrorMessages)
345b274bc22SAndre Fischer    {
346b274bc22SAndre Fischer        push @$lines, sprintf("    %12.6f : %s", $line->{'relative_time'}, $line->{'message'});
347b274bc22SAndre Fischer    }
348b274bc22SAndre Fischer
349b274bc22SAndre Fischer    return $lines;
350b274bc22SAndre Fischer}
351b274bc22SAndre Fischer
352b274bc22SAndre Fischer
353b274bc22SAndre Fischer
354b274bc22SAndre Fischer
355b274bc22SAndre Fischer=item check_logfile()
356b274bc22SAndre Fischer
357b274bc22SAndre Fischer    Print all error messages (typically at the end) on the console.
358b274bc22SAndre Fischer
359b274bc22SAndre Fischer=cut
360b274bc22SAndre Fischersub check_logfile ()
361b274bc22SAndre Fischer{
362b274bc22SAndre Fischer	my ($logfile) = @_;
363b274bc22SAndre Fischer
364b274bc22SAndre Fischer	my @errors = ();
365b274bc22SAndre Fischer	my @output = ();
366b274bc22SAndre Fischer
367b274bc22SAndre Fischer	my $ignore_errors = ( ! $installer::globals::pro ) && ( $installer::globals::ignore_error_in_logfile );
368b274bc22SAndre Fischer	my $contains_errors = scalar @ErrorMessages > 0;
369b274bc22SAndre Fischer
370b274bc22SAndre Fischer    # Format errors
371b274bc22SAndre Fischer	if ($contains_errors)
372b274bc22SAndre Fischer    {
373b274bc22SAndre Fischer        push(@output, "\n");
374b274bc22SAndre Fischer        push(@output, "*********************************************************************\n");
375b274bc22SAndre Fischer        if ($ignore_errors)
376b274bc22SAndre Fischer        {
377b274bc22SAndre Fischer            push(@output, "The following errors in the log file were ignored:\n");
378b274bc22SAndre Fischer        }
379b274bc22SAndre Fischer        else
380b274bc22SAndre Fischer        {
381b274bc22SAndre Fischer            push(@output, "ERROR: The following errors occured in packaging process:\n");
382b274bc22SAndre Fischer        }
383b274bc22SAndre Fischer        push(@output, "\n");
384b274bc22SAndre Fischer
385b274bc22SAndre Fischer        foreach my $line (@ErrorMessages)
386b274bc22SAndre Fischer        {
387b274bc22SAndre Fischer            push @output, sprintf("    %12.6f : %s", $line->{'relative_time'}, $line->{'message'});
388b274bc22SAndre Fischer        }
389cdf0e10cSrcweir
390b274bc22SAndre Fischer		push(@output, "*********************************************************************\n");
391cdf0e10cSrcweir	}
392cdf0e10cSrcweir
393b274bc22SAndre Fischer    # Claim success if there where no errors or if errors are treated as warnings.
394b274bc22SAndre Fischer	if ( ! $contains_errors || $ignore_errors)
395b274bc22SAndre Fischer    {
396b274bc22SAndre Fischer		push(@output, "\n");
397b274bc22SAndre Fischer		push(@output, "***********************************************************\n");
398b274bc22SAndre Fischer		push(@output, "Successful packaging process!\n");
399b274bc22SAndre Fischer		push(@output, "***********************************************************\n");
400cdf0e10cSrcweir	}
401cdf0e10cSrcweir
402b274bc22SAndre Fischer	# Print the summary.
403cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Summary:");
404cdf0e10cSrcweir	my $force = 1; # print this message even in 'quiet' mode
405b274bc22SAndre Fischer	foreach my $line (@output)
406cdf0e10cSrcweir	{
407b274bc22SAndre Fischer		$installer::logger::Info->print($line, $force);
408cdf0e10cSrcweir	}
409b274bc22SAndre Fischer
410b274bc22SAndre Fischer    # Delete the accumulated error messages.  The @ErrorMessages will now contain
411b274bc22SAndre Fischer    # lines caused by printing those error messages.
412b274bc22SAndre Fischer    @ErrorMessages = ();
413b274bc22SAndre Fischer
414b274bc22SAndre Fischer    @installer::globals::errorlogfileinfo = @output;
415cdf0e10cSrcweir
416b274bc22SAndre Fischer	return $contains_error && ! $ignore_error;
417cdf0e10cSrcweir}
418cdf0e10cSrcweir
419cdf0e10cSrcweir#############################################################
420cdf0e10cSrcweir# Determining the ship installation directory
421cdf0e10cSrcweir#############################################################
422cdf0e10cSrcweir
423cdf0e10cSrcweirsub determine_ship_directory
424cdf0e10cSrcweir{
425cdf0e10cSrcweir	my ($languagesref) = @_;
426cdf0e10cSrcweir
427cdf0e10cSrcweir	if (!( $ENV{'SHIPDRIVE'} )) { installer::exiter::exit_program("ERROR: SHIPDRIVE must be set for updater!", "determine_ship_directory"); }
428cdf0e10cSrcweir
429cdf0e10cSrcweir	my $shipdrive = $ENV{'SHIPDRIVE'};
430cdf0e10cSrcweir
431*852d2129SAndre Fischer	my $languagestring = installer::languages::get_language_directory_name($$languagesref);
432cdf0e10cSrcweir
433cdf0e10cSrcweir	my $productstring = $installer::globals::product;
434cdf0e10cSrcweir	my $productsubdir = "";
435cdf0e10cSrcweir
436cdf0e10cSrcweir	if ( $productstring =~ /^\s*(.+?)\_\_(.+?)\s*$/ )
437cdf0e10cSrcweir	{
438cdf0e10cSrcweir		$productstring = $1;
439cdf0e10cSrcweir		$productsubdir = $2;
440cdf0e10cSrcweir	}
441cdf0e10cSrcweir
442cdf0e10cSrcweir	if ( $installer::globals::languagepack ) { $productstring = $productstring . "_languagepack"; }
443cdf0e10cSrcweir	if ( $installer::globals::patch ) { $productstring = $productstring . "_patch"; }
444cdf0e10cSrcweir
445cdf0e10cSrcweir	my $destdir = $shipdrive . $installer::globals::separator . $installer::globals::compiler .
446cdf0e10cSrcweir				$installer::globals::productextension . $installer::globals::separator .
447cdf0e10cSrcweir				$productstring . $installer::globals::separator;
448cdf0e10cSrcweir
449cdf0e10cSrcweir	if ( $productsubdir ) { $destdir = $destdir . $productsubdir . $installer::globals::separator; }
450cdf0e10cSrcweir
451cdf0e10cSrcweir	$destdir = $destdir . $installer::globals::installertypedir . $installer::globals::separator .
452cdf0e10cSrcweir				$installer::globals::build . "_" . $installer::globals::lastminor . "_" .
453cdf0e10cSrcweir				"native_inprogress-number_" . $languagestring . "\." . $installer::globals::buildid;
454cdf0e10cSrcweir
455b274bc22SAndre Fischer    $installer::logger::Global->print("\n");
456b274bc22SAndre Fischer    $installer::logger::Global->printf("Setting ship directory: %s\n", $destdir);
457cdf0e10cSrcweir
458cdf0e10cSrcweir	return $destdir;
459cdf0e10cSrcweir}
460cdf0e10cSrcweir
461cdf0e10cSrcweir#############################################################
462cdf0e10cSrcweir# Controlling if this is an official RE pack process
463cdf0e10cSrcweir#############################################################
464cdf0e10cSrcweir
465cdf0e10cSrcweirsub check_updatepack
466cdf0e10cSrcweir{
467cdf0e10cSrcweir	my $shipdrive = "";
468cdf0e10cSrcweir	my $filename = "";
469cdf0e10cSrcweir	my $infoline = "";
470cdf0e10cSrcweir
471cdf0e10cSrcweir	if ( $ENV{'UPDATER'} )	# the environment variable UPDATER has to be set
472cdf0e10cSrcweir	{
473b274bc22SAndre Fischer        $installer::logger::Global->print("\n");
474b274bc22SAndre Fischer        $installer::logger::Global->print("Environment variable UPDATER set\n");
475cdf0e10cSrcweir
476cdf0e10cSrcweir		if ( ! $ENV{'CWS_WORK_STAMP'} )	# the environment variable CWS_WORK_STAMP must not be set (set only in CWS)
477cdf0e10cSrcweir		{
478b274bc22SAndre Fischer            $installer::logger::Global->print("Environment variable CWS_WORK_STAMP not set\n");
479cdf0e10cSrcweir
480cdf0e10cSrcweir			if ( $ENV{'SHIPDRIVE'} )	# the environment variable SHIPDRIVE must be set
481cdf0e10cSrcweir			{
482cdf0e10cSrcweir				$shipdrive = $ENV{'SHIPDRIVE'};
483b274bc22SAndre Fischer                $installer::logger::Global->printf("Ship drive defined: %s\n", $shipdrive);
484cdf0e10cSrcweir
485cdf0e10cSrcweir				if ( -d $shipdrive )    # SHIPDRIVE must be a directory
486cdf0e10cSrcweir				{
487b274bc22SAndre Fischer                    $installer::logger::Global->print("Ship drive exists\n");
488cdf0e10cSrcweir
489cdf0e10cSrcweir					# try to write into $shipdrive
490cdf0e10cSrcweir
49101a01bd6SAndre Fischer					my $directory = $installer::globals::product . "_" . $installer::globals::compiler . "_" . $installer::globals::buildid . "_" . $installer::globals::languageproduct . "_test_$$";
492cdf0e10cSrcweir					$directory =~ s/\,/\_/g;	# for the list of languages
493cdf0e10cSrcweir					$directory =~ s/\-/\_/g;	# for en-US, pt-BR, ...
494cdf0e10cSrcweir					$directory = $shipdrive . $installer::globals::separator . $directory;
495cdf0e10cSrcweir
496b274bc22SAndre Fischer                    $installer::logger::Global->printf("Try to create directory: %s\n", $directory);
497cdf0e10cSrcweir
498cdf0e10cSrcweir					# saving this directory for later removal
499cdf0e10cSrcweir					$installer::globals::shiptestdirectory = $directory;
500cdf0e10cSrcweir
501cdf0e10cSrcweir					if ( installer::systemactions::try_to_create_directory($directory))
502cdf0e10cSrcweir					{
503b274bc22SAndre Fischer                        $installer::logger::Global->print("Write access on Ship drive\n");
504b274bc22SAndre Fischer                        $installer::logger::Global->print(
505b274bc22SAndre Fischer                            "Ship test directory %s was successfully created\n",
506b274bc22SAndre Fischer                            $installer::globals::shiptestdirectory);
507cdf0e10cSrcweir						my $systemcall = "rmdir $directory";
508cdf0e10cSrcweir						my $returnvalue = system($systemcall);
509cdf0e10cSrcweir
510cdf0e10cSrcweir						# 5th condition: No local build environment.
511cdf0e10cSrcweir						# In this case the content of SOLARENV starts with the content of SOL_TMP
512cdf0e10cSrcweir
513cdf0e10cSrcweir						my $solarenv = "";
514cdf0e10cSrcweir						my $sol_tmp;
515cdf0e10cSrcweir						if ( $ENV{'SOLARENV'} ) { $solarenv = $ENV{'SOLARENV'}; }
516cdf0e10cSrcweir
517b274bc22SAndre Fischer                        $installer::logger::Global->printf("Environment variable SOLARENV: %s\n", $solarenv);
518cdf0e10cSrcweir
519cdf0e10cSrcweir						if ( $ENV{'SOL_TMP'} )
520cdf0e10cSrcweir                        {
521cdf0e10cSrcweir                            $sol_tmp = $ENV{'SOL_TMP'};
522cdf0e10cSrcweir						    $infoline = "Environment variable SOL_TMP: $sol_tmp\n";
523cdf0e10cSrcweir                        } else {
524cdf0e10cSrcweir                            $infoline = "Environment variable SOL_TMP not set\n";
525cdf0e10cSrcweir                        }
526b274bc22SAndre Fischer                        $installer::logger::Global->print($infoline);
527cdf0e10cSrcweir
528cdf0e10cSrcweir						if ( defined $sol_tmp && ( $solarenv =~ /^\s*\Q$sol_tmp\E/ ))
529cdf0e10cSrcweir						{
530b274bc22SAndre Fischer                            $installer::logger::Global->print("Content of SOLARENV starts with the content of SOL_TMP\: Local environment -\> No Updatepack\n");
531cdf0e10cSrcweir						}
532cdf0e10cSrcweir						else
533cdf0e10cSrcweir						{
534b274bc22SAndre Fischer							$installer::logger::Global->print("Content of SOLARENV does not start with the content of SOL_TMP: No local environment\n");
535cdf0e10cSrcweir
536cdf0e10cSrcweir							$installer::globals::updatepack = 1;	# That's it
537cdf0e10cSrcweir						}
538cdf0e10cSrcweir
539cdf0e10cSrcweir						# Additional logging information for the temporary ship directory
540cdf0e10cSrcweir
541cdf0e10cSrcweir						if ( -d $installer::globals::shiptestdirectory )
542cdf0e10cSrcweir						{
543b274bc22SAndre Fischer                            $installer::logger::Global->printf(
544b274bc22SAndre Fischer                                "Ship test directory %s still exists. Trying removal later again.\n",
545b274bc22SAndre Fischer                                $installer::globals::shiptestdirectory);
546cdf0e10cSrcweir						}
547cdf0e10cSrcweir						else
548cdf0e10cSrcweir						{
549b274bc22SAndre Fischer                            $installer::logger::Global->printf(
550b274bc22SAndre Fischer                                "Ship test directory %s was successfully removed.\n",
551b274bc22SAndre Fischer                                $installer::globals::shiptestdirectory);
552cdf0e10cSrcweir						}
553cdf0e10cSrcweir					}
554cdf0e10cSrcweir					else
555cdf0e10cSrcweir					{
556b274bc22SAndre Fischer                        $installer::logger::Global->print("No write access on Ship drive\n");
557b274bc22SAndre Fischer                        $installer::logger::Global->printf("Failed to create directory \n", $directory);
558b274bc22SAndre Fischer						if ( defined $ENV{'BSCLIENT'} && ( uc $ENV{'BSCLIENT'} eq 'TRUE' ) )
559b274bc22SAndre Fischer                        {
560cdf0e10cSrcweir							installer::exiter::exit_program("ERROR: No write access to SHIPDRIVE allthough BSCLIENT is set.", "check_updatepack");
561cdf0e10cSrcweir						}
562cdf0e10cSrcweir					}
563cdf0e10cSrcweir				}
564cdf0e10cSrcweir				else
565cdf0e10cSrcweir				{
566b274bc22SAndre Fischer                    $installer::logger::Global->print("Ship drive not found: No updatepack\n");
567cdf0e10cSrcweir				}
568cdf0e10cSrcweir			}
569cdf0e10cSrcweir			else
570cdf0e10cSrcweir			{
571b274bc22SAndre Fischer                $installer::logger::Global->print("Environment variable SHIPDRIVE not set: No updatepack\n");
572cdf0e10cSrcweir			}
573cdf0e10cSrcweir		}
574cdf0e10cSrcweir		else
575cdf0e10cSrcweir		{
576b274bc22SAndre Fischer            $installer::logger::Global->print("Environment variable CWS_WORK_STAMP defined: No updatepack\n");
577cdf0e10cSrcweir		}
578cdf0e10cSrcweir	}
579cdf0e10cSrcweir
580b274bc22SAndre Fischer	if ( $installer::globals::updatepack )
581b274bc22SAndre Fischer    {
582b274bc22SAndre Fischer        $installer::logger::Global->print("Setting updatepack true\n");
583b274bc22SAndre Fischer        $installer::logger::Global->print("\n");
584b274bc22SAndre Fischer    }
585b274bc22SAndre Fischer	else
586b274bc22SAndre Fischer    {
587b274bc22SAndre Fischer        $installer::logger::Global->print("\n");
588b274bc22SAndre Fischer        $installer::logger::Global->print("No updatepack\n");
589b274bc22SAndre Fischer    }
590cdf0e10cSrcweir
591cdf0e10cSrcweir}
592cdf0e10cSrcweir
593cdf0e10cSrcweir#############################################################
594cdf0e10cSrcweir# Reading the Windows list file for language encodings
595cdf0e10cSrcweir#############################################################
596cdf0e10cSrcweir
597cdf0e10cSrcweirsub read_encodinglist
598cdf0e10cSrcweir{
599cdf0e10cSrcweir	my ($patharrayref) = @_;
600cdf0e10cSrcweir
601cdf0e10cSrcweir	my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$installer::globals::encodinglistname, $patharrayref , 0);
602cdf0e10cSrcweir
603cdf0e10cSrcweir	if ( $$fileref eq "" ) { installer::exiter::exit_program("ERROR: Did not find Windows encoding list $installer::globals::encodinglistname!", "read_encodinglist"); }
604cdf0e10cSrcweir
605b274bc22SAndre Fischer    $installer::logger::Global->printf("Found encoding file: %s\n", $$fileref);
606cdf0e10cSrcweir
607cdf0e10cSrcweir	my $encodinglist = installer::files::read_file($$fileref);
608cdf0e10cSrcweir
609cdf0e10cSrcweir	my %msiencoding = ();
610cdf0e10cSrcweir	my %msilanguage = ();
611cdf0e10cSrcweir
612cdf0e10cSrcweir	# Controlling the encoding list
613cdf0e10cSrcweir
614cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$encodinglist}; $i++ )
615cdf0e10cSrcweir	{
616cdf0e10cSrcweir		my $line = ${$encodinglist}[$i];
617cdf0e10cSrcweir
618cdf0e10cSrcweir		if ( $line =~ /^\s*\#/ ) { next; }	# this is a comment line
619cdf0e10cSrcweir
620cdf0e10cSrcweir		if ( $line =~ /^(.*?)(\#.*)$/ ) { $line = $1; }	# removing comments after "#"
621cdf0e10cSrcweir
622cdf0e10cSrcweir		if ( $line =~ /^\s*([\w-]+)\s*(\d+)\s*(\d+)\s*$/ )
623cdf0e10cSrcweir		{
624cdf0e10cSrcweir			my $onelanguage = $1;
625cdf0e10cSrcweir			my $codepage = $2;
626cdf0e10cSrcweir			my $windowslanguage = $3;
627cdf0e10cSrcweir
628cdf0e10cSrcweir			$msiencoding{$onelanguage} = $codepage;
629cdf0e10cSrcweir			$msilanguage{$onelanguage} = $windowslanguage;
630cdf0e10cSrcweir		}
631cdf0e10cSrcweir		else
632cdf0e10cSrcweir		{
633cdf0e10cSrcweir			installer::exiter::exit_program("ERROR: Wrong syntax in Windows encoding list $installer::globals::encodinglistname : en-US 1252 1033 !", "read_encodinglist");
634cdf0e10cSrcweir		}
635cdf0e10cSrcweir	}
636cdf0e10cSrcweir
637cdf0e10cSrcweir	$installer::globals::msiencoding = \%msiencoding;
638cdf0e10cSrcweir	$installer::globals::msilanguage = \%msilanguage;
639cdf0e10cSrcweir
640cdf0e10cSrcweir	# my $key;
641cdf0e10cSrcweir	# foreach $key (keys %{$installer::globals::msiencoding}) { print "A Key: $key : Value: $installer::globals::msiencoding->{$key}\n"; }
642cdf0e10cSrcweir	# foreach $key (keys %{$installer::globals::msilanguage}) { print "B Key: $key : Value: $installer::globals::msilanguage->{$key}\n"; }
643cdf0e10cSrcweir
644cdf0e10cSrcweir}
645cdf0e10cSrcweir
646cdf0e10cSrcweir#############################################################
647cdf0e10cSrcweir# Only for Windows and Linux (RPM)there is currently
648cdf0e10cSrcweir# a reliable mechanism to register extensions during
649cdf0e10cSrcweir# installation process. Therefore it is for all other
650cdf0e10cSrcweir# platforms forbidden to install oxt files into that
651cdf0e10cSrcweir# directory, in which they are searched for registration.
652cdf0e10cSrcweir#############################################################
653cdf0e10cSrcweir
654cdf0e10cSrcweirsub check_oxtfiles
655cdf0e10cSrcweir{
656cdf0e10cSrcweir	my ( $filesarray ) = @_;
657cdf0e10cSrcweir
658cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesarray}; $i++ )
659cdf0e10cSrcweir	{
660cdf0e10cSrcweir		my $onefile = ${$filesarray}[$i];
661cdf0e10cSrcweir
662cdf0e10cSrcweir		if (( $onefile->{'Name'} ) && ( $onefile->{'Dir'} ))
663cdf0e10cSrcweir		{
664cdf0e10cSrcweir			if (( $onefile->{'Name'} =~ /\.oxt\s*$/ ) && ( $onefile->{'Dir'} eq $installer::globals::extensioninstalldir ))
665cdf0e10cSrcweir			{
666cdf0e10cSrcweir				installer::exiter::exit_program("There is currently only for Linux (RPM) and Windows a reliable mechanism to register extensions during installation.\nPlease remove file \"$onefile->{'gid'}\" from your installation set!\nYou can use \"\#ifdef WNT\" and \"\#ifdef LINUX\" in scp.", "check_oxtfiles");
667cdf0e10cSrcweir			}
668cdf0e10cSrcweir		}
669cdf0e10cSrcweir	}
670cdf0e10cSrcweir}
671cdf0e10cSrcweir
672cdf0e10cSrcweir#############################################################
673cdf0e10cSrcweir# Check if Java is available to create xpd installer
674cdf0e10cSrcweir#############################################################
675cdf0e10cSrcweir
676cdf0e10cSrcweirsub check_java_for_xpd
677cdf0e10cSrcweir{
678cdf0e10cSrcweir	my ( $allvariables ) = @_;
679cdf0e10cSrcweir
680cdf0e10cSrcweir	if ( ! $installer::globals::solarjavaset ) { $allvariables->{'XPDINSTALLER'} = 0; }
681cdf0e10cSrcweir}
682cdf0e10cSrcweir
683cdf0e10cSrcweir####################################################################
684cdf0e10cSrcweir# Setting global variable "$installer::globals::addchildprojects"
685cdf0e10cSrcweir####################################################################
686cdf0e10cSrcweir
687cdf0e10cSrcweirsub set_addchildprojects
688cdf0e10cSrcweir{
689cdf0e10cSrcweir	my ($allvariables) = @_;
690cdf0e10cSrcweir
691cdf0e10cSrcweir	if (( $allvariables->{'JAVAPRODUCT'} ) ||
692cdf0e10cSrcweir		( $allvariables->{'ADAPRODUCT'} ) ||
693cdf0e10cSrcweir		( $allvariables->{'UREPRODUCT'} ) ||
694cdf0e10cSrcweir		( $allvariables->{'ADDREQUIREDPACKAGES'} )) { $installer::globals::addchildprojects = 1; }
695cdf0e10cSrcweir
696cdf0e10cSrcweir	if ( $installer::globals::patch )
697cdf0e10cSrcweir	{
698cdf0e10cSrcweir		$installer::globals::addchildprojects = 0;	# no child projects for patches
699cdf0e10cSrcweir	}
700cdf0e10cSrcweir
701b274bc22SAndre Fischer    $installer::logger::Global->printf(
702b274bc22SAndre Fischer        "Value of \$installer::globals::addchildprojects: %s\n",
703b274bc22SAndre Fischer        $installer::globals::addchildprojects);
704cdf0e10cSrcweir}
705cdf0e10cSrcweir
706cdf0e10cSrcweir####################################################################
707cdf0e10cSrcweir# Setting global variable "$installer::globals::addjavainstaller"
708cdf0e10cSrcweir####################################################################
709cdf0e10cSrcweir
710cdf0e10cSrcweirsub set_addjavainstaller
711cdf0e10cSrcweir{
712cdf0e10cSrcweir	my ($allvariables) = @_;
713cdf0e10cSrcweir
714cdf0e10cSrcweir	if ( $allvariables->{'JAVAINSTALLER'} ) { $installer::globals::addjavainstaller = 1; }
715cdf0e10cSrcweir
716cdf0e10cSrcweir	if ( $installer::globals::patch ) {	$installer::globals::addjavainstaller = 0; }
717cdf0e10cSrcweir	if ( $installer::globals::languagepack ) { $installer::globals::addjavainstaller = 0; }
718cdf0e10cSrcweir	if ( $allvariableshashref->{'XPDINSTALLER'} ) {	$installer::globals::addjavainstaller = 0; }
719cdf0e10cSrcweir
720b274bc22SAndre Fischer    $installer::logger::Global->printf(
721b274bc22SAndre Fischer        "Value of \$installer::globals::addjavainstaller: %s\n",
722b274bc22SAndre Fischer        $installer::globals::addjavainstaller);
723cdf0e10cSrcweir}
724cdf0e10cSrcweir
725cdf0e10cSrcweir#######################################################################
726cdf0e10cSrcweir# Setting global variable "$installer::globals::addsystemintegration"
727cdf0e10cSrcweir#######################################################################
728cdf0e10cSrcweir
729cdf0e10cSrcweirsub set_addsystemintegration
730cdf0e10cSrcweir{
731cdf0e10cSrcweir	my ($allvariables) = @_;
732cdf0e10cSrcweir
733cdf0e10cSrcweir	if ( $allvariables->{'ADDSYSTEMINTEGRATION'} ) { $installer::globals::addsystemintegration = 1; }
734cdf0e10cSrcweir
735cdf0e10cSrcweir	if ( $installer::globals::patch ) {	$installer::globals::addsystemintegration = 0; }
736cdf0e10cSrcweir	if ( $installer::globals::languagepack ) { $installer::globals::addsystemintegration = 0; }
737cdf0e10cSrcweir	if (( $installer::globals::packageformat eq "native" ) || ( $installer::globals::packageformat eq "portable" )) { $installer::globals::addsystemintegration = 0; }
738cdf0e10cSrcweir
739b274bc22SAndre Fischer    $installer::logger::Global->printf(
740b274bc22SAndre Fischer        "Value of \$installer::globals::addsystemintegration: %s\n",
741b274bc22SAndre Fischer        $installer::globals::addsystemintegration);
742cdf0e10cSrcweir}
743cdf0e10cSrcweir
744cdf0e10cSrcweir1;
745