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