1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#*************************************************************************
27
28package installer::epmfile;
29
30use Cwd;
31use installer::converter;
32use installer::existence;
33use installer::exiter;
34use installer::files;
35use installer::globals;
36use installer::logger;
37use installer::packagelist;
38use installer::pathanalyzer;
39use installer::remover;
40use installer::scriptitems;
41use installer::systemactions;
42use installer::worker;
43use POSIX;
44
45############################################################################
46# Reading the package map to find Solaris package names for
47# the corresponding abbreviations
48############################################################################
49
50sub read_packagemap
51{
52	my ($allvariables, $includepatharrayref, $languagesarrayref) = @_;
53
54	my $packagemapname = "";
55	if ( $allvariables->{'PACKAGEMAP'} ) { $packagemapname = $allvariables->{'PACKAGEMAP'}; }
56	if ( $packagemapname eq "" ) { installer::exiter::exit_program("ERROR: Property PACKAGEMAP must be defined!", "read_packagemap"); }
57
58	my $infoline = "\n\nCollected abbreviations and package names:\n";
59	push(@installer::globals::logfileinfo, $infoline);
60
61	# Can be a comma separated list. All files have to be found in include pathes
62	my $allpackagemapnames = installer::converter::convert_stringlist_into_hash(\$packagemapname, ",");
63	foreach my $onepackagemapname ( keys %{$allpackagemapnames} )
64	{
65		my $packagemapref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$onepackagemapname, $includepatharrayref, 0);
66
67		if ( $$packagemapref eq "" ) { installer::exiter::exit_program("ERROR: Could not find package map file \"$onepackagemapname\" (propery PACKAGEMAP)!", "read_packagemap"); }
68
69		my $packagemapcontent = installer::files::read_file($$packagemapref);
70
71		for ( my $i = 0; $i <= $#{$packagemapcontent}; $i++ )
72		{
73			my $line = ${$packagemapcontent}[$i];
74
75			if ( $line =~ /^\s*\#/ ) { next; }  # comment line
76			if ( $line =~ /^\s*$/ ) { next; }  # empty line
77
78			if ( $line =~ /^\s*(.*?)\t(.*?)\s*$/ )
79			{
80				my $abbreviation = $1;
81				my $packagename = $2;
82				installer::packagelist::resolve_packagevariables(\$abbreviation, $allvariables, 0);
83				installer::packagelist::resolve_packagevariables(\$packagename, $allvariables, 0);
84
85				# Special handling for language strings %LANGUAGESTRING
86
87				if (( $abbreviation =~ /\%LANGUAGESTRING/ ) || ( $packagename =~ /\%LANGUAGESTRING/ ))
88				{
89					foreach my $onelang ( @{$languagesarrayref} )
90					{
91                        my $local_abbreviation = $abbreviation;
92                        my $local_packagename = $packagename;
93						$local_abbreviation =~ s/\%LANGUAGESTRING/$onelang/g;
94						$local_packagename =~ s/\%LANGUAGESTRING/$onelang/g;
95
96                        # Logging all abbreviations and packagenames
97                        $infoline = "$onelang : $local_abbreviation : $local_packagename\n";
98                        push(@installer::globals::logfileinfo, $infoline);
99
100						if ( exists($installer::globals::dependfilenames{$local_abbreviation}) )
101						{
102							installer::exiter::exit_program("ERROR: Packagename for  Solaris package $local_abbreviation already defined ($installer::globals::dependfilenames{$local_abbreviation})!", "read_packagemap");
103						}
104						else
105						{
106							$installer::globals::dependfilenames{$local_abbreviation} = $local_packagename;
107						}
108					}
109				}
110				else
111				{
112                    # Logging all abbreviations and packagenames
113                    $infoline = "$abbreviation : $packagename\n";
114                    push(@installer::globals::logfileinfo, $infoline);
115
116					if ( exists($installer::globals::dependfilenames{$abbreviation}) )
117					{
118						installer::exiter::exit_program("ERROR: Packagename for  Solaris package $abbreviation already defined ($installer::globals::dependfilenames{$abbreviation})!", "read_packagemap");
119					}
120					else
121					{
122						$installer::globals::dependfilenames{$abbreviation} = $packagename;
123					}
124				}
125			}
126			else
127			{
128				my $errorline = $i + 1;
129				installer::exiter::exit_program("ERROR: Wrong syntax in file \"$onepackagemapname\" (line $errorline)!", "read_packagemap");
130			}
131		}
132	}
133
134	$infoline = "\n\n";
135	push(@installer::globals::logfileinfo, $infoline);
136
137}
138
139############################################################################
140# The header file contains the strings for the epm header in all languages
141############################################################################
142
143sub get_string_from_headerfile
144{
145	my ($searchstring, $language, $fileref) = @_;
146
147	my $returnstring  = "";
148	my $onestring  = "";
149	my $englishstring  = "";
150	my $foundblock = 0;
151	my $foundstring = 0;
152	my $foundenglishstring = 0;
153	my $englishidentifier = "01";
154
155	$searchstring = "[" . $searchstring . "]";
156
157	for ( my $i = 0; $i <= $#{$fileref}; $i++ )
158	{
159		my $line = ${$fileref}[$i];
160
161		if ( $line =~ /^\s*\Q$searchstring\E\s*$/ )
162		{
163			$foundblock = 1;
164			my $counter = $i + 1;
165
166			$line = ${$fileref}[$counter];
167
168			# Beginning of the next block oder Dateiende
169
170			while ((!($line =~ /^\s*\[\s*\w+\s*\]\s*$/ )) && ( $counter <= $#{$fileref} ))
171			{
172				if ( $line =~ /^\s*\Q$language\E\s+\=\s*\"(.*)\"\s*$/ )
173				{
174					$onestring = $1;
175					$foundstring = 1;
176					last;
177				}
178
179				if ( $line =~ /^\s*\Q$englishidentifier\E\s+\=\s*\"(.*)\"\s*$/ )
180				{
181					$englishstring = $1;
182					$foundenglishstring = 1;
183				}
184
185				$counter++;
186				$line = ${$fileref}[$counter];
187			}
188		}
189	}
190
191	if ( $foundstring )
192	{
193		$returnstring = $onestring;
194	}
195	else
196	{
197		if ( $foundenglishstring )
198		{
199			$returnstring = $englishstring;
200		}
201		else
202		{
203			installer::exiter::exit_program("ERROR: No string found for $searchstring in epm header file (-h)", "get_string_from_headerfile");
204		}
205	}
206
207	return \$returnstring;
208}
209
210##########################################################
211# Filling the epm file with directories, files and links
212##########################################################
213
214sub put_directories_into_epmfile
215{
216	my ($directoriesarrayref, $epmfileref, $allvariables, $packagerootpath) = @_;
217	my $group = "bin";
218
219	if ( $installer::globals::islinuxbuild )
220	{
221		$group = "root";
222	}
223
224	for ( my $i = 0; $i <= $#{$directoriesarrayref}; $i++ )
225	{
226		my $onedir = ${$directoriesarrayref}[$i];
227		my $dir = "";
228
229		if ( $onedir->{'Dir'} ) { $dir = $onedir->{'Dir'}; }
230
231		# if (!($dir =~ /\bPREDEFINED_/ ))
232		if ((!($dir =~ /\bPREDEFINED_/ )) || ( $dir =~ /\bPREDEFINED_PROGDIR\b/ ))
233		{
234			my $hostname = $onedir->{'HostName'};
235
236			# not including simple directory "/opt"
237			# if (( $allvariables->{'SETSTATICPATH'} ) && ( $hostname eq $packagerootpath )) { next; }
238
239			my $line = "d 755 root $group $hostname -\n";
240
241			push(@{$epmfileref}, $line)
242		}
243	}
244}
245
246sub put_files_into_epmfile
247{
248	my ($filesinproductarrayref, $epmfileref) = @_;
249
250	for ( my $i = 0; $i <= $#{$filesinproductarrayref}; $i++ )
251	{
252		my $onefile = ${$filesinproductarrayref}[$i];
253
254		my $unixrights = $onefile->{'UnixRights'};
255		my $destination = $onefile->{'destination'};
256		my $sourcepath = $onefile->{'sourcepath'};
257
258		my $filetype = "f";
259		my $styles = "";
260		if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
261		if ( $styles =~ /\bCONFIGFILE\b/ ) { $filetype = "c"; }
262
263		my $group = "bin";
264		if ( $installer::globals::islinuxbuild ) { $group = "root"; }
265		if (( $installer::globals::issolarisbuild ) && ( $onefile->{'SolarisGroup'} )) { $group = $onefile->{'SolarisGroup'}; }
266
267		my $line = "$filetype $unixrights root $group $destination $sourcepath\n";
268
269		push(@{$epmfileref}, $line);
270	}
271}
272
273sub put_links_into_epmfile
274{
275	my ($linksinproductarrayref, $epmfileref) = @_;
276	my $group = "bin";
277
278	if ( $installer::globals::islinuxbuild )
279	{
280		$group = "root";
281	}
282
283
284	for ( my $i = 0; $i <= $#{$linksinproductarrayref}; $i++ )
285	{
286		my $onelink = ${$linksinproductarrayref}[$i];
287		my $destination = $onelink->{'destination'};
288		my $destinationfile = $onelink->{'destinationfile'};
289
290		my $line = "l 000 root $group $destination $destinationfile\n";
291
292		push(@{$epmfileref}, $line)
293	}
294}
295
296sub put_unixlinks_into_epmfile
297{
298	my ($unixlinksinproductarrayref, $epmfileref) = @_;
299	my $group = "bin";
300
301	if ( $installer::globals::islinuxbuild ) { $group = "root";	}
302
303	for ( my $i = 0; $i <= $#{$unixlinksinproductarrayref}; $i++ )
304	{
305		my $onelink = ${$unixlinksinproductarrayref}[$i];
306		my $destination = $onelink->{'destination'};
307		my $target = $onelink->{'Target'};
308
309		my $line = "l 000 root $group $destination $target\n";
310
311		push(@{$epmfileref}, $line)
312	}
313}
314
315###############################################
316# Creating epm header file
317###############################################
318
319sub create_epm_header
320{
321	my ($variableshashref, $filesinproduct, $languagesref, $onepackage) = @_;
322
323	my @epmheader = ();
324
325	my ($licensefilename, $readmefilename);
326
327	my $foundlicensefile = 0;
328	my $foundreadmefile = 0;
329
330	my $line = "";
331	my $infoline = "";
332
333	# %product OpenOffice.org Software
334	# %version 2.0
335	# %description A really great software
336	# %copyright 1999-2003 by OOo
337	# %vendor OpenOffice.org
338	# %license /test/replace/01/LICENSE01
339	# %readme /test/replace/01/README01
340	# %requires foo
341	# %provides bar
342
343	# The first language in the languages array determines the language of license and readme file
344
345	my $searchlanguage = ${$languagesref}[0];
346
347	# using the description for the %product line in the epm list file
348
349	my $productnamestring = $onepackage->{'description'};
350	installer::packagelist::resolve_packagevariables(\$productnamestring, $variableshashref, 0);
351	if ( $variableshashref->{'PRODUCTEXTENSION'} ) { $productnamestring = $productnamestring . " " . $variableshashref->{'PRODUCTEXTENSION'}; }
352
353	$line = "%product" . " " . $productnamestring . "\n";
354	push(@epmheader, $line);
355
356	# Determining the release version
357	# This release version has to be listed in the line %version : %version versionnumber releasenumber
358
359	# if ( $variableshashref->{'PACKAGEVERSION'} ) { $installer::globals::packageversion = $variableshashref->{'PACKAGEVERSION'}; }
360	if ( ! $onepackage->{'packageversion'} ) { installer::exiter::exit_program("ERROR: No packageversion defined for package: $onepackage->{'module'}!", "create_epm_header"); }
361	$installer::globals::packageversion = $onepackage->{'packageversion'};
362	installer::packagelist::resolve_packagevariables(\$installer::globals::packageversion, $variableshashref, 0);
363	if ( $variableshashref->{'PACKAGEREVISION'} ) { $installer::globals::packagerevision = $variableshashref->{'PACKAGEREVISION'}; }
364
365	$line = "%version" . " " . $installer::globals::packageversion . "\n";
366	push(@epmheader, $line);
367
368	$line = "%release" . " " . $installer::globals::packagerevision . "\n";
369	if ( $installer::globals::islinuxrpmbuild ) { $line = "%release" . " " . $installer::globals::buildid . "\n"; }
370	push(@epmheader, $line);
371
372	# Description, Copyright and Vendor are multilingual and are defined in
373	# the string file for the header file ($headerfileref)
374
375	my $descriptionstring = $onepackage->{'description'};
376	installer::packagelist::resolve_packagevariables(\$descriptionstring, $variableshashref, 0);
377	$line = "%description" . " " . $descriptionstring . "\n";
378	push(@epmheader, $line);
379
380	my $copyrightstring = $onepackage->{'copyright'};
381	installer::packagelist::resolve_packagevariables(\$copyrightstring, $variableshashref, 0);
382	$line = "%copyright" . " " . $copyrightstring . "\n";
383	push(@epmheader, $line);
384
385	my $vendorstring = $onepackage->{'vendor'};
386	installer::packagelist::resolve_packagevariables(\$vendorstring, $variableshashref, 0);
387	$line = "%vendor" . " " . $vendorstring . "\n";
388	push(@epmheader, $line);
389
390	# License and Readme file can be included automatically from the file list
391
392	if ( $installer::globals::iswindowsbuild )
393	{
394		$licensefilename = "license.txt";
395		$readmefilename = "readme.txt";
396	}
397	else
398	{
399		$licensefilename = "LICENSE";
400		$readmefilename = "README";
401	}
402
403	if (( $installer::globals::languagepack )	# in language packs the files LICENSE and README are removed, because they are not language specific
404		|| ( $variableshashref->{'NO_README_IN_ROOTDIR'} ))
405	{
406		if ( $installer::globals::iswindowsbuild )
407		{
408			$licensefilename = "license_$searchlanguage.txt";
409			$readmefilename = "readme_$searchlanguage.txt";
410		}
411		else
412		{
413			$licensefilename = "LICENSE_$searchlanguage";
414			$readmefilename = "README_$searchlanguage";
415		}
416	}
417
418	my $license_in_package_defined = 0;
419
420	if ( $installer::globals::issolarisbuild )
421	{
422		if ( $onepackage->{'solariscopyright'} )
423		{
424			$licensefilename = $onepackage->{'solariscopyright'};
425			$license_in_package_defined = 1;
426		}
427	}
428
429	# Process for Linux packages, in which only a very basic license file is
430	# included into the package.
431
432	if ( $installer::globals::islinuxbuild )
433	{
434		if ( $variableshashref->{'COPYRIGHT_INTO_LINUXPACKAGE'} )
435		{
436			$licensefilename = "linuxcopyrightfile";
437			$license_in_package_defined = 1;
438		}
439	}
440	# searching for and readme file
441
442	for ( my $i = 0; $i <= $#{$filesinproduct}; $i++ )
443	{
444		my $onefile = ${$filesinproduct}[$i];
445		my $filename = $onefile->{'Name'};
446		if ( $filename eq $readmefilename )
447		{
448			$foundreadmefile = 1;
449			$line = "%readme" . " " . $onefile->{'sourcepath'} . "\n";
450			push(@epmheader, $line);
451			last;
452		}
453	}
454
455	# searching for and license file
456
457	if ( $license_in_package_defined )
458	{
459		my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, "" , 0);
460
461		if ( $$fileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find license file $licensefilename (A)!", "create_epm_header"); }
462
463		# Special handling to add the content of the file "license_en-US" to the solaris copyrightfile. But not for all products
464
465		if (( $installer::globals::issolarispkgbuild ) && ( ! $variableshashref->{'NO_LICENSE_INTO_COPYRIGHT'} ))
466		{
467			if ( ! $installer::globals::englishlicenseset ) { installer::worker::set_english_license() }
468
469			# The location for the new file
470			my $languagestring = "";
471			for ( my $i = 0; $i <= $#{$languagesref}; $i++ ) { $languagestring = $languagestring . "_" . ${$languagesref}[$i]; }
472			$languagestring =~ s/^\s*_//;
473
474			my $copyrightdir = installer::systemactions::create_directories("copyright", \$languagestring);
475
476			my $copyrightfile = installer::files::read_file($$fileref);
477
478			# Adding license content to copyright file
479			push(@{$copyrightfile}, "\n");
480			for ( my $i = 0; $i <= $#{$installer::globals::englishlicense}; $i++ ) { push(@{$copyrightfile}, ${$installer::globals::englishlicense}[$i]); }
481
482			# New destination for $$fileref
483			$$fileref = $copyrightdir . $installer::globals::separator . "solariscopyrightfile_" . $onepackage->{'module'};
484			if ( -f $$fileref ) { unlink $$fileref; }
485			installer::files::save_file($$fileref, $copyrightfile);
486		}
487
488		$infoline = "Using license file: \"$$fileref\"!\n";
489		push(@installer::globals::logfileinfo, $infoline);
490
491		$foundlicensefile = 1;
492		$line = "%license" . " " . $$fileref . "\n";
493		push(@epmheader, $line);
494	}
495	else
496	{
497		for ( my $i = 0; $i <= $#{$filesinproduct}; $i++ )
498		{
499			my $onefile = ${$filesinproduct}[$i];
500			my $filename = $onefile->{'Name'};
501
502			if ( $filename eq $licensefilename )
503			{
504				$foundlicensefile = 1;
505				$line = "%license" . " " . $onefile->{'sourcepath'} . "\n";
506				push(@epmheader, $line);
507				last;
508			}
509		}
510	}
511
512	if (!($foundlicensefile))
513	{
514		installer::exiter::exit_program("ERROR: Could not find license file $licensefilename (B)", "create_epm_header");
515	}
516
517	if (!($foundreadmefile))
518	{
519		installer::exiter::exit_program("ERROR: Could not find readme file $readmefilename (C)", "create_epm_header");
520	}
521
522	# including %replaces
523
524	my $replaces = "";
525
526	if (( $installer::globals::issolarispkgbuild ) && ( ! $installer::globals::patch ))
527	{
528		$replaces = "solarisreplaces";	 # the name in the packagelist
529	}
530	elsif (( $installer::globals::islinuxbuild ) && ( ! $installer::globals::patch ))
531	{
532		$replaces = "linuxreplaces";	# the name in the packagelist
533	}
534
535	if (( $replaces ) && ( ! $installer::globals::patch ))
536	{
537		if ( $onepackage->{$replaces} )
538		{
539			my $replacesstring = $onepackage->{$replaces};
540
541			my $allreplaces = installer::converter::convert_stringlist_into_array(\$replacesstring, ",");
542
543			for ( my $i = 0; $i <= $#{$allreplaces}; $i++ )
544			{
545				my $onereplaces = ${$allreplaces}[$i];
546				$onereplaces =~ s/\s*$//;
547				installer::packagelist::resolve_packagevariables(\$onereplaces, $variableshashref, 1);
548				if ( $installer::globals::linuxlinkrpmprocess ) { $onereplaces = $onereplaces . "u"; }
549				$line = "%replaces" . " " . $onereplaces . "\n";
550				push(@epmheader, $line);
551
552				# Force the openofficeorg packages to get removed,
553				# see http://www.debian.org/doc/debian-policy/ch-relationships.html
554				# 7.5.2 Replacing whole packages, forcing their removal
555
556				if ( $installer::globals::debian )
557				{
558					$line = "%incompat" . " " . $onereplaces . "\n";
559					push(@epmheader, $line);
560				}
561			}
562
563			if ( $installer::globals::debian && $variableshashref->{'UNIXPRODUCTNAME'} eq 'openoffice.org' )
564			{
565				$line = "%provides" . " openoffice.org-unbundled\n";
566				push(@epmheader, $line);
567				$line = "%incompat" . " openoffice.org-bundled\n";
568				push(@epmheader, $line);
569			}
570		}
571	}
572
573	# including the directives for %requires and %provides
574
575	my $provides = "";
576	my $requires = "";
577
578	if ( $installer::globals::issolarispkgbuild )
579	{
580		$provides = "solarisprovides";	 # the name in the packagelist
581		$requires = "solarisrequires";	 # the name in the packagelist
582	}
583	elsif ( $installer::globals::isfreebsdpkgbuild )
584	{
585		$provides = "freebsdprovides";	 # the name in the packagelist
586		$requires = "freebsdrequires";	 # the name in the packagelist
587	}
588	elsif (( $installer::globals::islinuxrpmbuild ) &&
589			( $installer::globals::patch ) &&
590			( exists($onepackage->{'linuxpatchrequires'}) ))
591	{
592		$provides = "provides";	 # the name in the packagelist
593		$requires = "linuxpatchrequires";	 # the name in the packagelist
594	}
595	else
596	{
597		$provides = "provides";	 		# the name in the packagelist
598		$requires = "requires";	 		# the name in the packagelist
599	}
600
601	# if ( $installer::globals::patch )
602	# {
603	#	$onepackage->{$provides} = "";
604		my $isdict = 0;
605		if ( $onepackage->{'packagename'} =~ /-dict-/ ) { $isdict = 1;  }
606
607	#	$onepackage->{$requires} = "";
608	# }
609
610	if ( $onepackage->{$provides} )
611	{
612		my $providesstring = $onepackage->{$provides};
613
614		my $allprovides = installer::converter::convert_stringlist_into_array(\$providesstring, ",");
615
616		for ( my $i = 0; $i <= $#{$allprovides}; $i++ )
617		{
618			my $oneprovides = ${$allprovides}[$i];
619			$oneprovides =~ s/\s*$//;
620			installer::packagelist::resolve_packagevariables(\$oneprovides, $variableshashref, 1);
621			if ( $installer::globals::linuxlinkrpmprocess ) { $oneprovides = $oneprovides . "u"; }
622			$line = "%provides" . " " . $oneprovides . "\n";
623			push(@epmheader, $line);
624		}
625	}
626
627	if ( $onepackage->{$requires} )
628	{
629		my $requiresstring = $onepackage->{$requires};
630
631		if ( $installer::globals::add_required_package ) { $requiresstring = $requiresstring . "," . $installer::globals::add_required_package; }
632
633		# The requires string can contain the separator "," in the names (descriptions) of the packages
634		# (that are required for Solaris depend files). Therefore "," inside such a description has to
635		# masked with a backslash.
636		# This masked separator need to be found and replaced, before the stringlist is converted into an array.
637		# This replacement has to be turned back after the array is created.
638
639		my $replacementstring = "COMMAREPLACEMENT";
640		$requiresstring = installer::converter::replace_masked_separator($requiresstring, ",", "$replacementstring");
641
642		my $allrequires = installer::converter::convert_stringlist_into_array(\$requiresstring, ",");
643
644		installer::converter::resolve_masked_separator($allrequires, ",", $replacementstring);
645
646		for ( my $i = 0; $i <= $#{$allrequires}; $i++ )
647		{
648			my $onerequires = ${$allrequires}[$i];
649			$onerequires =~ s/\s*$//;
650			installer::packagelist::resolve_packagevariables2(\$onerequires, $variableshashref, 0, $isdict);
651
652			# Special handling for Solaris. In depend files, the names of the packages are required, not
653			# only the abbreviation. Therefore there is a special syntax for names in packagelist:
654			# solarisrequires = "SUNWcar (Name="Package name of SUNWcar"),SUNWkvm (Name="Package name of SUNWcar"), ...
655			# if ( $installer::globals::issolarispkgbuild )
656			# {
657			#	if ( $onerequires =~ /^\s*(.*?)\s+\(\s*Name\s*=\s*\"(.*?)\"\s*\)\s*$/ )
658			#	{
659			#		$onerequires = $1;
660			#		$packagename = $2;
661			#		$installer::globals::dependfilenames{$onerequires} = $packagename;
662			#	}
663			# }
664
665			$line = "%requires" . " " . $onerequires . "\n";
666			push(@epmheader, $line);
667		}
668	}
669	else
670	{
671		if ( $installer::globals::add_required_package )
672		{
673			my $requiresstring = $installer::globals::add_required_package;
674
675			my $replacementstring = "COMMAREPLACEMENT";
676			$requiresstring = installer::converter::replace_masked_separator($requiresstring, ",", "$replacementstring");
677			my $allrequires = installer::converter::convert_stringlist_into_array(\$requiresstring, ",");
678			installer::converter::resolve_masked_separator($allrequires, ",", $replacementstring);
679
680			for ( my $i = 0; $i <= $#{$allrequires}; $i++ )
681			{
682				my $onerequires = ${$allrequires}[$i];
683				$onerequires =~ s/\s*$//;
684				installer::packagelist::resolve_packagevariables(\$onerequires, $variableshashref, 0);
685
686				# Special handling for Solaris. In depend files, the names of the packages are required, not
687				# only the abbreviation. Therefore there is a special syntax for names in packagelist:
688				# solarisrequires = "SUNWcar (Name="Package name of SUNWcar"),SUNWkvm (Name="Package name of SUNWcar"), ...
689				# if ( $installer::globals::issolarispkgbuild )
690				# {
691				#	if ( $onerequires =~ /^\s*(.*?)\s+\(\s*Name\s*=\s*\"(.*?)\"\s*\)\s*$/ )
692				#	{
693				#		$onerequires = $1;
694				#		$packagename = $2;
695				#		$installer::globals::dependfilenames{$onerequires} = $packagename;
696				#	}
697				# }
698
699				$line = "%requires" . " " . $onerequires . "\n";
700				push(@epmheader, $line);
701			}
702		}
703	}
704
705	return \@epmheader;
706}
707
708#######################################
709# Adding header to epm file
710#######################################
711
712sub adding_header_to_epm_file
713{
714	my ($epmfileref, $epmheaderref) = @_;
715
716	for ( my $i = 0; $i <= $#{$epmheaderref}; $i++ )
717	{
718		push( @{$epmfileref}, ${$epmheaderref}[$i] );
719	}
720
721	push( @{$epmfileref}, "\n\n" );
722}
723
724#####################################################
725# Replace one in shell scripts ( ${VARIABLENAME} )
726#####################################################
727
728sub replace_variable_in_shellscripts
729{
730	my ($scriptref, $variable, $searchstring) = @_;
731
732	for ( my $i = 0; $i <= $#{$scriptref}; $i++ )
733	{
734		${$scriptref}[$i] =~ s/\$\{$searchstring\}/$variable/g;
735	}
736}
737
738###################################################
739# Replace one in shell scripts ( %VARIABLENAME )
740###################################################
741
742sub replace_percent_variable_in_shellscripts
743{
744	my ($scriptref, $variable, $searchstring) = @_;
745
746	for ( my $i = 0; $i <= $#{$scriptref}; $i++ )
747	{
748		${$scriptref}[$i] =~ s/\%$searchstring/$variable/g;
749	}
750}
751
752################################################
753# Replacing many variables in shell scripts
754################################################
755
756sub replace_many_variables_in_shellscripts
757{
758	my ($scriptref, $variableshashref) = @_;
759
760	my $key;
761
762	foreach $key (keys %{$variableshashref})
763	{
764		my $value = $variableshashref->{$key};
765		# $value = lc($value); 	# lowercase !
766		# if ( $installer::globals::issolarisbuild) { $value =~ s/\.org/org/g; }	# openofficeorg instead of openoffice.org
767		replace_variable_in_shellscripts($scriptref, $value, $key);
768	}
769}
770
771#######################################
772# Adding shell scripts to epm file
773#######################################
774
775sub adding_shellscripts_to_epm_file
776{
777	my ($epmfileref, $shellscriptsfilename, $localrootpath, $allvariableshashref, $filesinpackage) = @_;
778
779	# $installer::globals::shellscriptsfilename
780
781	push( @{$epmfileref}, "\n\n" );
782
783	my $shellscriptsfileref = installer::files::read_file($shellscriptsfilename);
784
785	replace_variable_in_shellscripts($shellscriptsfileref, $localrootpath, "rootpath");
786
787	replace_many_variables_in_shellscripts($shellscriptsfileref, $allvariableshashref);
788
789	for ( my $i = 0; $i <= $#{$shellscriptsfileref}; $i++ )
790	{
791		push( @{$epmfileref}, ${$shellscriptsfileref}[$i] );
792	}
793
794	push( @{$epmfileref}, "\n" );
795}
796
797#################################################
798# Determining the epm on the system
799#################################################
800
801sub find_epm_on_system
802{
803	my ($includepatharrayref) = @_;
804
805	installer::logger::include_header_into_logfile("Check epm on system");
806
807	my $epmname = "epm";
808
809	# epm should be defined through the configure script but we need to
810	# check for it to be defined because of the Sun environment.
811	# Check the environment variable first and if it is not defined,
812	# or if it is but the location is not executable, search further.
813	# It has to be found in the solver or it has to be in the path
814	# (saved in $installer::globals::epm_in_path) or we get the specified
815	# one through the environment (i.e. when --with-epm=... is specified)
816
817	if ($ENV{'EPM'})
818	{
819		if (($ENV{'EPM'} ne "") && (-x "$ENV{'EPM'}"))
820		{
821			$epmname = $ENV{'EPM'};
822		}
823		elsif ( ($ENV{'EPM'} eq "no") || ($ENV{'EPM'} eq "internal") )
824		{
825			$epmname = "epm";
826			my $epmref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$epmname, $includepatharrayref, 0);
827			if ($$epmref eq "") { installer::exiter::exit_program("ERROR: Could not find program $epmname (EPM set to \"internal\" or \"no\")!", "find_epm_on_system"); }
828			$epmname = $$epmref;
829		}
830		else
831		{
832			installer::exiter::exit_program("Environment variable EPM set (\"$ENV{'EPM'}\"), but file does not exist or is not executable!", "find_epm_on_system");
833		}
834	}
835	else
836	{
837		my $epmfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$epmname, $includepatharrayref, 0);
838
839		if (($$epmfileref eq "") && (!($installer::globals::epm_in_path))) { installer::exiter::exit_program("ERROR: Could not find program $epmname!", "find_epm_on_system"); }
840		if (($$epmfileref eq "") && ($installer::globals::epm_in_path)) { $epmname = $installer::globals::epm_path; }
841		if (!($$epmfileref eq "")) { $epmname = $$epmfileref; }
842	}
843
844	my $infoline = "Using epmfile: $epmname\n";
845	push( @installer::globals::logfileinfo, $infoline);
846
847	return $epmname;
848}
849
850#################################################
851# Determining the epm patch state
852# saved in $installer::globals::is_special_epm
853#################################################
854
855sub set_patch_state
856{
857	my ($epmexecutable) = @_;
858
859	my $infoline = "";
860
861	my $systemcall = "$epmexecutable |";
862	open (EPMPATCH, "$systemcall");
863
864	while (<EPMPATCH>)
865	{
866		chop;
867		if ( $_ =~ /Patched for OpenOffice.org/ ) { $installer::globals::is_special_epm = 1; }
868	}
869
870	close (EPMPATCH);
871
872	if ( $installer::globals::is_special_epm )
873	{
874		$infoline = "\nPatch state: This is a patched version of epm!\n\n";
875		push( @installer::globals::logfileinfo, $infoline);
876	}
877	else
878	{
879		$infoline = "\nPatch state: This is an unpatched version of epm!\n\n";
880		push( @installer::globals::logfileinfo, $infoline);
881	}
882
883	if ( ( $installer::globals::is_special_epm ) && (($installer::globals::islinuxrpmbuild) || ($installer::globals::issolarispkgbuild)) )
884	{
885		# Special postprocess handling only for Linux RPM and Solaris packages
886		$installer::globals::postprocess_specialepm = 1;
887		$installer::globals::postprocess_standardepm = 0;
888	}
889	else
890	{
891		$installer::globals::postprocess_specialepm = 0;
892		$installer::globals::postprocess_standardepm = 1;
893	}
894}
895
896#################################################
897# LD_PRELOAD string for Debian packages
898#################################################
899
900sub get_ld_preload_string
901{
902	my ($includepatharrayref) = @_;
903
904	my $getuidlibraryname = "getuid.so";
905
906	my $getuidlibraryref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$getuidlibraryname, $includepatharrayref, 0);
907	if ($$getuidlibraryref eq "") { installer::exiter::exit_program("ERROR: Could not find $getuidlibraryname!", "get_ld_preload_string"); }
908
909	my $ldpreloadstring = "LD_PRELOAD=" . $$getuidlibraryref;
910
911	return $ldpreloadstring;
912}
913
914#################################################
915# Calling epm to create the installation sets
916#################################################
917
918sub call_epm
919{
920	my ($epmname, $epmlistfilename, $packagename, $includepatharrayref) = @_;
921
922	installer::logger::include_header_into_logfile("epm call for $packagename");
923
924	my $packageformat = $installer::globals::packageformat;
925
926	my $localpackagename = $packagename;
927	# Debian allows only lowercase letters in package name
928	if ( $installer::globals::debian ) { $localpackagename = lc($localpackagename); }
929
930	my $outdirstring = "";
931	if ( $installer::globals::epmoutpath ne "" ) { $outdirstring = " --output-dir $installer::globals::epmoutpath"; }
932
933	# Debian package build needs a LD_PRELOAD for correct rights
934
935	my $ldpreloadstring = "";
936
937	if ( $installer::globals::debian ) { $ldpreloadstring = get_ld_preload_string($includepatharrayref) . " "; }
938
939	my $extraflags = "";
940        if ($ENV{'EPM_FLAGS'}) { $extraflags = $ENV{'EPM_FLAGS'}; }
941
942	my $systemcall = $ldpreloadstring . $epmname . " -f " . $packageformat . " " . $extraflags . " " . $localpackagename . " " . $epmlistfilename . $outdirstring . " -v " . " 2\>\&1 |";
943
944	installer::logger::print_message( "... $systemcall ...\n" );
945
946	my $maxepmcalls = 3;
947
948	for ( my $i = 1; $i <= $maxepmcalls; $i++ )
949	{
950		my @epmoutput = ();
951
952		open (EPM, "$systemcall");
953		while (<EPM>) {push(@epmoutput, $_); }
954		close (EPM);
955
956		my $returnvalue = $?;	# $? contains the return value of the systemcall
957
958		my $infoline = "Systemcall  (Try $i): $systemcall\n";
959		push( @installer::globals::logfileinfo, $infoline);
960
961		for ( my $j = 0; $j <= $#epmoutput; $j++ )
962		{
963			if ( $i < $maxepmcalls ) { $epmoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; }
964			push( @installer::globals::logfileinfo, "$epmoutput[$j]");
965		}
966
967		if ($returnvalue)
968		{
969			$infoline = "Try $i : Could not execute \"$systemcall\"!\n";
970			push( @installer::globals::logfileinfo, $infoline);
971			if ( $i == $maxepmcalls ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "call_epm"); }
972		}
973		else
974		{
975			installer::logger::print_message( "Success (Try $i): \"$systemcall\"\n" );
976			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
977			push( @installer::globals::logfileinfo, $infoline);
978			last;
979		}
980	}
981}
982
983#####################################################################
984# Adding the new line for relocatables into pkginfo file (Solaris)
985# or spec file (Linux) created by epm
986#####################################################################
987
988sub add_one_line_into_file
989{
990	my ($file, $insertline, $filename) = @_;
991
992	if ( $installer::globals::issolarispkgbuild )
993	{
994		push(@{$file}, $insertline);		# simply adding at the end of pkginfo file
995	}
996
997	if ( $installer::globals::islinuxrpmbuild )
998	{
999		# Adding behind the line beginning with: Group:
1000
1001		my $inserted_line = 0;
1002
1003		for ( my $i = 0; $i <= $#{$file}; $i++ )
1004		{
1005			if ( ${$file}[$i] =~ /^\s*Group\:\s*/ )
1006			{
1007				splice(@{$file},$i+1,0,$insertline);
1008				$inserted_line = 1;
1009				last;
1010			}
1011		}
1012
1013		if (! $inserted_line) { installer::exiter::exit_program("ERROR: Did not find string \"Group:\" in file: $filename", "add_one_line_into_file"); }
1014	}
1015
1016	$insertline =~ s/\s*$//;	# removing line end for correct logging
1017	my $infoline = "Success: Added line $insertline into file $filename!\n";
1018	push( @installer::globals::logfileinfo, $infoline);
1019}
1020
1021#####################################################################
1022# Setting the revision VERSION=1.9,REV=66  .
1023# Also adding the new line: "AutoReqProv: no"
1024#####################################################################
1025
1026sub set_revision_in_pkginfo
1027{
1028	my ($file, $filename, $variables, $packagename) = @_;
1029
1030	my $revisionstring = "\,REV\=" . $installer::globals::packagerevision;
1031
1032	# Adding also a time string to the revision. Syntax: VERSION=8.0.0,REV=66.2005.01.24
1033
1034	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
1035
1036	$mday = $mday;
1037	$mon = $mon + 1;
1038	$year = $year + 1900;
1039
1040	if ( $mday < 10 ) { $mday = "0" . $mday; }
1041	if ( $mon < 10 ) { $mon = "0" . $mon; }
1042	$datestring = $year . "." . $mon . "." . $mday;
1043	$revisionstring = $revisionstring . "." . $datestring;
1044
1045	for ( my $i = 0; $i <= $#{$file}; $i++ )
1046	{
1047		if ( ${$file}[$i] =~ /^\s*(VERSION\=.*?)\s*$/ )
1048		{
1049			my $oldstring = $1;
1050			my $newstring = $oldstring . $revisionstring;	# also adding the date string
1051			${$file}[$i] =~ s/$oldstring/$newstring/;
1052			my $infoline = "Info: Changed in $filename file: \"$oldstring\" to \"$newstring\"!\n";
1053			push( @installer::globals::logfileinfo, $infoline);
1054			last;
1055		}
1056	}
1057
1058	# For Update and Patch reasons, this string can also be kept constant
1059
1060	my $pkgversion = "SOLSPARCPKGVERSION";
1061	if ( $installer::globals::issolarisx86build ) { $pkgversion = "SOLIAPKGVERSION"; }
1062
1063	if (( $variables->{$pkgversion} ) && ( $variables->{$pkgversion} ne "" ))
1064	{
1065		if ( $variables->{$pkgversion} ne "FINALVERSION" )
1066		{
1067			# In OOo 3.x timeframe, this string is no longer unique for all packages, because of the three layer.
1068			# In the string: "3.0.0,REV=9.2008.09.30" only the part "REV=9.2008.09.30" can be unique for all packages
1069			# and therefore be set as $pkgversion.
1070			# The first part "3.0.0" has to be derived from the
1071
1072			my $version = $installer::globals::packageversion;
1073			if ( $version =~ /^\s*(\d+)\.(\d+)\.(\d+)\s*$/ )
1074			{
1075				my $major = $1;
1076				my $minor = $2;
1077				my $micro = $3;
1078
1079				my $finalmajor = $major;
1080				my $finalminor = $minor;
1081				my $finalmicro = 0;
1082
1083				# if (( $packagename =~ /-ure\s*$/ ) && ( $finalmajor == 1 )) { $finalminor = 4; }
1084
1085				$version = "$finalmajor.$finalminor.$finalmicro";
1086			}
1087
1088			my $datestring = $variables->{$pkgversion};
1089
1090			# Allowing some packages to have another date of creation.
1091			# They can be defined in product definition using a key like "SOLSPARCPKGVERSION_$packagename"
1092
1093			my $additionalkey = $pkgversion . "_" . $packagename;
1094			if (( $variables->{$additionalkey} ) && ( $variables->{$additionalkey} ne "" )) { $datestring = $variables->{$additionalkey}; }
1095
1096			my $versionstring = "$version,$datestring";
1097
1098			for ( my $i = 0; $i <= $#{$file}; $i++ )
1099			{
1100				if ( ${$file}[$i] =~ /^\s*(VERSION\=).*?\s*$/ )
1101				{
1102					my $start = $1;
1103					my $newstring = $start . $versionstring . "\n";	# setting the complete new string
1104					my $oldstring = ${$file}[$i];
1105					${$file}[$i] = $newstring;
1106					$oldstring =~ s/\s*$//;
1107					$newstring =~ s/\s*$//;
1108					my $infoline = "Info: Changed in $filename file: \"$oldstring\" to \"$newstring\"!\n";
1109					push( @installer::globals::logfileinfo, $infoline);
1110					last;
1111				}
1112			}
1113		}
1114	}
1115}
1116
1117########################################################
1118# Setting Patch information for Respin versions
1119# into pkginfo file. This prevents Respin versions
1120# from patching.
1121########################################################
1122
1123sub set_patchlist_in_pkginfo_for_respin
1124{
1125	my ($changefile, $filename, $allvariables, $packagename) = @_;
1126
1127	my $patchlistname = "SOLSPARCPATCHLISTFORRESPIN";
1128	if ( $installer::globals::issolarisx86build ) { $patchlistname = "SOLIAPATCHLISTFORRESPIN"; }
1129
1130	if ( $allvariables->{$patchlistname} )
1131	{
1132		# patchlist separator is a blank
1133		my $allpatchesstring = $allvariables->{$patchlistname};
1134		my @usedpatches = ();
1135
1136		# Analyzing the patchlist
1137		# Syntax: 120186-10 126411-01(+core-01) -> use 126411-01 only for core-01
1138		# Syntax: 120186-10 126411-01(-core-01) -> use 126411-01 for all packages except for core-01
1139		my $allpatches = installer::converter::convert_whitespace_stringlist_into_array(\$allpatchesstring);
1140
1141		for ( my $i = 0; $i <= $#{$allpatches}; $i++ )
1142		{
1143			my $patchdefinition = ${$allpatches}[$i];
1144
1145			my $patchid = "";
1146			my $symbol = "";
1147			my $constraint = "";
1148			my $isusedpatch = 0;
1149
1150			if ( $patchdefinition =~ /^\s*(.+)\(([+-])(.+)\)\s*$/ )
1151			{
1152				$patchid = $1;
1153				$symbol = $2;
1154				$constraint = $3;
1155			}
1156			elsif (( $patchdefinition =~ /\(/ ) || ( $patchdefinition =~ /\)/ ))	# small syntax check
1157			{
1158				# if there is a bracket in the $patchdefinition, but it does not
1159				# match the if-condition, this is an erroneous definition.
1160				installer::exiter::exit_program("ERROR: Unknown patch string: $patchdefinition", "set_patchlist_in_pkginfo_for_respin");
1161			}
1162			else
1163			{
1164				$patchid = $patchdefinition;
1165				$isusedpatch = 1; # patches without constraint are always included
1166			}
1167
1168			if ( $symbol ne "" )
1169			{
1170				if ( $symbol eq "+" )
1171				{
1172					if ( $packagename =~ /^.*\Q$constraint\E\s*$/ ) { $isusedpatch = 1; }
1173				}
1174
1175				if ( $symbol eq "-" )
1176				{
1177					if ( ! ( $packagename =~ /^.*\Q$constraint\E\s*$/ )) { $isusedpatch = 1; }
1178				}
1179			}
1180
1181			if ( $isusedpatch ) { push(@usedpatches, $patchid); }
1182		}
1183
1184		if ( $#usedpatches > -1 )
1185		{
1186			my $patchstring = installer::converter::convert_array_to_space_separated_string(\@usedpatches);
1187
1188			my $newline = "PATCHLIST=" . $patchstring . "\n";
1189			add_one_line_into_file($changefile, $newline, $filename);
1190
1191			# Adding patch info for each used patch in the patchlist
1192
1193			for ( my $i = 0; $i <= $#usedpatches; $i++ )
1194			{
1195				my $patchid = $usedpatches[$i];
1196				my $key = "PATCH_INFO_" . $patchid;
1197				$key =~ s/\s*$//;
1198
1199				if ( ! $allvariables->{$key} ) { installer::exiter::exit_program("ERROR: No Patch info available in zip list file for $key", "set_patchlist_in_pkginfo"); }
1200				my $value = set_timestamp_in_patchinfo($allvariables->{$key});
1201				$newline = $key . "=" . $value . "\n";
1202
1203				add_one_line_into_file($changefile, $newline, $filename);
1204			}
1205		}
1206	}
1207}
1208
1209########################################################
1210# Solaris requires, that the time of patch installation
1211# must not be empty.
1212# Format: Mon Mar 24 11:20:56 PDT 2008
1213# Log file: Tue Apr 29 23:26:19 2008 (04:31 min.)
1214# Replace string: ${TIMESTAMP}
1215########################################################
1216
1217sub set_timestamp_in_patchinfo
1218{
1219	my ($value) = @_;
1220
1221	my $currenttime = localtime();
1222
1223	if ( $currenttime =~ /^\s*(.+?)(\d\d\d\d)\s*$/ )
1224	{
1225		my $start = $1;
1226		my $year = $2;
1227		$currenttime = $start . "CET " . $year;
1228	}
1229
1230	$value =~ s/\$\{TIMESTAMP\}/$currenttime/;
1231
1232	return $value;
1233}
1234
1235########################################################
1236# Setting MAXINST=1000 into the pkginfo file.
1237########################################################
1238
1239sub set_maxinst_in_pkginfo
1240{
1241	my ($changefile, $filename) = @_;
1242
1243	my $newline = "MAXINST\=1000\n";
1244
1245	add_one_line_into_file($changefile, $newline, $filename);
1246}
1247
1248#############################################################
1249# Setting several Solaris variables into the pkginfo file.
1250#############################################################
1251
1252sub set_solaris_parameter_in_pkginfo
1253{
1254	my ($changefile, $filename, $allvariables) = @_;
1255
1256	my $newline = "";
1257
1258	# SUNW_PRODNAME
1259	# SUNW_PRODVERS
1260	# SUNW_PKGVERS
1261	# Not: SUNW_PKGTYPE
1262	# HOTLINE
1263	# EMAIL
1264
1265	my $productname = $allvariables->{'PRODUCTNAME'};
1266	$newline = "SUNW_PRODNAME=$productname\n";
1267	add_one_line_into_file($changefile, $newline, $filename);
1268
1269	my $productversion = "";
1270	if ( $allvariables->{'PRODUCTVERSION'} )
1271	{
1272		$productversion = $allvariables->{'PRODUCTVERSION'};
1273		if ( $allvariables->{'PRODUCTEXTENSION'} ) { $productversion = $productversion . "/" . $allvariables->{'PRODUCTEXTENSION'}; }
1274	}
1275	$newline = "SUNW_PRODVERS=$productversion\n";
1276	add_one_line_into_file($changefile, $newline, $filename);
1277
1278	$newline = "SUNW_PKGVERS=1\.0\n";
1279	add_one_line_into_file($changefile, $newline, $filename);
1280
1281	if ( $allvariables->{'SUNW_PKGTYPE'} )
1282	{
1283		$newline = "SUNW_PKGTYPE=$allvariables->{'SUNW_PKGTYPE'}\n";
1284		add_one_line_into_file($changefile, $newline, $filename);
1285	}
1286    else
1287    {
1288        $newline = "SUNW_PKGTYPE=\n";
1289        add_one_line_into_file($changefile, $newline, $filename);
1290    }
1291
1292	$newline = "HOTLINE=Please contact your local service provider\n";
1293	add_one_line_into_file($changefile, $newline, $filename);
1294
1295	$newline = "EMAIL=\n";
1296	add_one_line_into_file($changefile, $newline, $filename);
1297
1298}
1299
1300#####################################################################
1301# epm uses as archtecture for Solaris x86 "i86pc". This has to be
1302# changed to "i386".
1303#####################################################################
1304
1305sub fix_architecture_setting
1306{
1307	my ($changefile) = @_;
1308
1309	for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1310	{
1311		if ( ${$changefile}[$i] =~ /^\s*ARCH=i86pc\s*$/ )
1312		{
1313			${$changefile}[$i] =~ s/i86pc/i386/;
1314			last;
1315		}
1316
1317	}
1318}
1319
1320#####################################################################
1321# Adding a new line for topdir into specfile, removing old
1322# topdir if set.
1323#####################################################################
1324
1325sub set_topdir_in_specfile
1326{
1327	my ($changefile, $filename, $newepmdir) = @_;
1328
1329	# $newepmdir =~ s/^\s*\.//;	# removing leading "."
1330	$newepmdir = cwd() . $installer::globals::separator . $newepmdir; # only absolute path allowed
1331
1332	# removing "%define _topdir", if existing
1333
1334	for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1335	{
1336		if ( ${$changefile}[$i] =~ /^\s*\%define _topdir\s+/ )
1337		{
1338			my $removeline = ${$changefile}[$i];
1339			$removeline =~ s/\s*$//;
1340			splice(@{$changefile},$i,1);
1341			my $infoline = "Info: Removed line \"$removeline\" from file $filename!\n";
1342			push( @installer::globals::logfileinfo, $infoline);
1343			last;
1344		}
1345	}
1346
1347	# Adding "topdir" behind the line beginning with: Group:
1348
1349	my $inserted_line = 0;
1350
1351	my $topdirline = "\%define _topdir $newepmdir\n";
1352
1353	for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1354	{
1355		if ( ${$changefile}[$i] =~ /^\s*Group\:\s*/ )
1356		{
1357			splice(@{$changefile},$i+1,0,$topdirline);
1358			$inserted_line = 1;
1359			$topdirline =~ s/\s*$//;
1360			my $infoline = "Success: Added line $topdirline into file $filename!\n";
1361			push( @installer::globals::logfileinfo, $infoline);
1362		}
1363	}
1364
1365	if (! $inserted_line) { installer::exiter::exit_program("ERROR: Did not find string \"Group:\" in file: $filename", "set_topdir_in_specfile"); }
1366
1367}
1368
1369#####################################################################
1370# Setting the packager in the spec file
1371# Syntax: Packager: abc@def
1372#####################################################################
1373
1374sub set_packager_in_specfile
1375{
1376	my ($changefile) = @_;
1377
1378	my $packager = $installer::globals::longmanufacturer;
1379
1380	for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1381	{
1382		if ( ${$changefile}[$i] =~ /^\s*Packager\s*:\s*(.+?)\s*$/ )
1383		{
1384			my $oldstring = $1;
1385			${$changefile}[$i] =~ s/\Q$oldstring\E/$packager/;
1386			my $infoline = "Info: Changed Packager in spec file from $oldstring to $packager!\n";
1387			push( @installer::globals::logfileinfo, $infoline);
1388			last;
1389		}
1390	}
1391}
1392
1393#####################################################################
1394# Setting the requirements in the spec file (i81494)
1395# Syntax: PreReq: "requirements" (only for shared extensions)
1396#####################################################################
1397
1398sub set_prereq_in_specfile
1399{
1400	my ($changefile) = @_;
1401
1402	my $prereq = "PreReq:";
1403
1404	for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1405	{
1406		if ( ${$changefile}[$i] =~ /^\s*Requires:\s*(.+?)\s*$/ )
1407		{
1408			my $oldstring = ${$changefile}[$i];
1409			${$changefile}[$i] =~ s/Requires:/$prereq/;
1410			my $infoline = "Info: Changed requirements in spec file from $oldstring to ${$changefile}[$i]!\n";
1411			push( @installer::globals::logfileinfo, $infoline);
1412		}
1413	}
1414}
1415
1416#####################################################################
1417# Setting the Auto[Req]Prov line and __find_requires
1418#####################################################################
1419
1420sub set_autoprovreq_in_specfile
1421{
1422    my ($changefile, $findrequires, $bindir) = @_;
1423
1424	my $autoreqprovline;
1425
1426    if ( $findrequires )
1427    {
1428        $autoreqprovline = "AutoProv\: no\n%define __find_requires $bindir/$findrequires\n";
1429    }
1430    else
1431    {
1432        $autoreqprovline = "AutoReqProv\: no\n";
1433    }
1434
1435    $autoreqprovline .= "%define _binary_filedigest_algorithm 1\n%define _binary_payload w9.gzdio\n";
1436
1437	for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1438	{
1439        # Adding "autoreqprov" behind the line beginning with: Group:
1440		if ( ${$changefile}[$i] =~ /^\s*Group\:\s*/ )
1441		{
1442			splice(@{$changefile},$i+1,0,$autoreqprovline);
1443			$autoreqprovline =~ s/\s*$//;
1444            $infoline = "Success: Added line $autoreqprovline into spec file!\n";
1445			push( @installer::globals::logfileinfo, $infoline);
1446
1447			last;
1448        }
1449    }
1450}
1451
1452#####################################################################
1453# Replacing Copyright with License in the spec file
1454# Syntax: License: LGPL, SISSL
1455#####################################################################
1456
1457sub set_license_in_specfile
1458{
1459	my ($changefile, $variableshashref) = @_;
1460
1461	my $license = $variableshashref->{'LICENSENAME'};
1462
1463	for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1464	{
1465		if ( ${$changefile}[$i] =~ /^\s*Copyright\s*:\s*(.+?)\s*$/ )
1466		{
1467			${$changefile}[$i] = "License: $license\n";
1468			my $infoline = "Info: Replaced Copyright with License: $license !\n";
1469			push( @installer::globals::logfileinfo, $infoline);
1470			last;
1471		}
1472	}
1473}
1474
1475#########################################################
1476# Building relocatable Solaris packages means:
1477# 1. Add "BASEDIR=/opt" into pkginfo
1478# 2. Remove "/opt/" from all objects in prototype file
1479# For step2 this function exists
1480# Sample: d none /opt/openofficeorg20/help 0755 root other
1481# -> d none openofficeorg20/help 0755 root other
1482#########################################################
1483
1484sub make_prototypefile_relocatable
1485{
1486	my ($prototypefile, $relocatablepath) = @_;
1487
1488	for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1489	{
1490		if ( ${$prototypefile}[$i] =~ /^\s*\w\s+\w+\s+\/\w+/ )	# this is an object line
1491		{
1492			${$prototypefile}[$i] =~ s/$relocatablepath//;	# Important: $relocatablepath has a "/" at the end. Example "/opt/"
1493		}
1494	}
1495
1496	# If the $relocatablepath is "/opt/openoffice20/" the line "d none /opt/openoffice20" was not changed.
1497	# This line has to be removed now
1498
1499	if ( $relocatablepath ne "/" ) { $relocatablepath =~ s/\/\s*$//; }		# removing the ending slash
1500
1501	for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1502	{
1503		if ( ${$prototypefile}[$i] =~ /^\s*d\s+\w+\s+\Q$relocatablepath\E/ )
1504		{
1505			my $line = ${$prototypefile}[$i];
1506			splice(@{$prototypefile},$i,1);	# removing the line
1507			$line =~ s/\s*$//;
1508			my $infoline = "Info: Removed line \"$line\" from prototype file!\n";
1509			push( @installer::globals::logfileinfo, $infoline);
1510			last;
1511		}
1512	}
1513
1514	# Making "\$" to "$" in prototype file. "\$" was created by epm.
1515
1516	for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1517	{
1518		if ( ${$prototypefile}[$i] =~ /\\\$/ )
1519		{
1520			${$prototypefile}[$i] =~ s/\\\$/\$/g;
1521			my $infoline2 = "Info: Changed line in prototype file: ${$prototypefile}[$i] !\n";
1522			push( @installer::globals::logfileinfo, $infoline2);
1523		}
1524	}
1525}
1526
1527
1528#########################################################################
1529# In scp the flag VOLATEFILE can be used. This shall lead to style "v"
1530# in Solaris prototype file. This is not supported by epm and has
1531# therefore to be included in prototypefile, not in epm list file.
1532#########################################################################
1533
1534sub set_volatilefile_into_prototypefile
1535{
1536	my ($prototypefile, $filesref) = @_;
1537
1538	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1539	{
1540		my $onefile = ${$filesref}[$i];
1541
1542		my $styles = "";
1543		if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
1544
1545		if ( $styles =~ /\bVOLATILEFILE\b/ )
1546		{
1547			my $sourcepath = $onefile->{'sourcepath'};
1548
1549			for ( my $j = 0; $j <= $#{$prototypefile}; $j++ )
1550			{
1551				if (( ${$prototypefile}[$j] =~ /^\s*f\s+none\s+/ ) && ( ${$prototypefile}[$j] =~ /\=\Q$sourcepath\E\s+/ ))
1552				{
1553					my $oldline = ${$prototypefile}[$j];
1554					${$prototypefile}[$j] =~ s/^\s*f/v/;
1555					my $newline = ${$prototypefile}[$j];
1556					$oldline =~ s/\s*$//;
1557					$newline =~ s/\s*$//;
1558					my $infoline = "Volatile file: Changing content from \"$oldline\" to \"$newline\" .\n";
1559					push(@installer::globals::logfileinfo, $infoline);
1560					last;
1561				}
1562			}
1563		}
1564	}
1565}
1566
1567#########################################################################
1568# Replacing the variables in the Solaris patch shell scripts.
1569# Taking care, that multiple slashes are not always removed.
1570#########################################################################
1571
1572sub replace_variables_in_shellscripts_for_patch
1573{
1574	my ($scriptfile, $scriptfilename, $oldstring, $newstring) = @_;
1575
1576	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
1577	{
1578		if ( ${$scriptfile}[$i] =~ /\Q$oldstring\E/ )
1579		{
1580			my $oldline = ${$scriptfile}[$i];
1581			if (( $oldstring eq "PRODUCTDIRECTORYNAME" ) && ( $newstring eq "" )) { $oldstring = $oldstring . "/"; }
1582			${$scriptfile}[$i] =~ s/\Q$oldstring\E/$newstring/g;
1583			my $infoline = "Info: Substituting in $scriptfilename $oldstring by $newstring\n";
1584			push(@installer::globals::logfileinfo, $infoline);
1585		}
1586	}
1587}
1588
1589#########################################################################
1590# Replacing the variables in the shell scripts or in the epm list file
1591# Linux: spec file
1592# Solaris: preinstall, postinstall, preremove, postremove
1593# If epm is used in the original version (not relocatable)
1594# the variables have to be exchanged in the list file,
1595# created for epm.
1596#########################################################################
1597
1598sub replace_variables_in_shellscripts
1599{
1600	my ($scriptfile, $scriptfilename, $oldstring, $newstring) = @_;
1601
1602	my $debug = 0;
1603	if ( $oldstring eq "PRODUCTDIRECTORYNAME" ) { $debug = 1; }
1604
1605	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
1606	{
1607		if ( ${$scriptfile}[$i] =~ /\Q$oldstring\E/ )
1608		{
1609			my $oldline = ${$scriptfile}[$i];
1610			${$scriptfile}[$i] =~ s/\Q$oldstring\E/$newstring/g;
1611			${$scriptfile}[$i] =~ s/\/\//\//g;	# replacing "//" by "/" , if path $newstring is empty!
1612			my $infoline = "Info: Substituting in $scriptfilename $oldstring by $newstring\n";
1613			push(@installer::globals::logfileinfo, $infoline);
1614			if ( $debug )
1615			{
1616				$infoline = "Old Line: $oldline";
1617				push(@installer::globals::logfileinfo, $infoline);
1618				$infoline = "New Line: ${$scriptfile}[$i]";
1619				push(@installer::globals::logfileinfo, $infoline);
1620			}
1621		}
1622	}
1623}
1624
1625############################################################
1626# Determinig the directory created by epm, in which the
1627# RPMS or Solaris packages are created.
1628############################################################
1629
1630sub determine_installdir_ooo
1631{
1632	# A simple "ls" command returns the directory name
1633
1634	my $dirname = "";
1635
1636	my $systemcall = "ls |";
1637	open (LS, "$systemcall");
1638	$dirname = <LS>;
1639	close (LS);
1640
1641	$dirname =~ s/\s*$//;
1642
1643	my $infoline = "Info: Directory created by epm: $dirname\n";
1644	push(@installer::globals::logfileinfo, $infoline);
1645
1646	return $dirname;
1647}
1648
1649############################################################
1650# Setting the tab content into the file container
1651############################################################
1652
1653sub set_tab_into_datafile
1654{
1655	my ($changefile, $filesref) = @_;
1656
1657	my @newclasses = ();
1658	my $newclassesstring = "";
1659
1660	if ( $installer::globals::issolarispkgbuild )
1661	{
1662		for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1663		{
1664			my $onefile = ${$filesref}[$i];
1665
1666			if ( $onefile->{'SolarisClass'} )
1667			{
1668				my $sourcepath = $onefile->{'sourcepath'};
1669
1670				for ( my $j = 0; $j <= $#{$changefile}; $j++ )
1671				{
1672					if (( ${$changefile}[$j] =~ /^\s*f\s+none\s+/ ) && ( ${$changefile}[$j] =~ /\=\Q$sourcepath\E\s+/ ))
1673					{
1674						my $oldline = ${$changefile}[$j];
1675						${$changefile}[$j] =~ s/f\s+none/e $onefile->{'SolarisClass'}/;
1676						my $newline = ${$changefile}[$j];
1677						$oldline =~ s/\s*$//;
1678						$newline =~ s/\s*$//;
1679
1680						my $infoline = "TAB: Changing content from \"$oldline\" to \"$newline\" .\n";
1681						push(@installer::globals::logfileinfo, $infoline);
1682
1683						# collecting all new classes
1684						if (! installer::existence::exists_in_array($onefile->{'SolarisClass'}, \@newclasses))
1685						{
1686							push(@newclasses, $onefile->{'SolarisClass'});
1687						}
1688
1689						last;
1690					}
1691				}
1692			}
1693		}
1694
1695		$newclassesstring = installer::converter::convert_array_to_space_separated_string(\@newclasses);
1696	}
1697
1698	if ( $installer::globals::islinuxrpmbuild )
1699	{
1700		for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1701		{
1702			my $onefile = ${$filesref}[$i];
1703
1704			if ( $onefile->{'SpecFileContent'} )
1705			{
1706				my $destination = $onefile->{'destination'};
1707
1708				for ( my $j = 0; $j <= $#{$changefile}; $j++ )
1709				{
1710					if ( ${$changefile}[$j] =~ /^\s*(\%attr\(.*\))\s+(\".*?\Q$destination\E\"\s*)$/ )
1711					{
1712						my $begin = $1;
1713						my $end = $2;
1714
1715						my $oldline = ${$changefile}[$j];
1716						${$changefile}[$j] = $begin . " " . $onefile->{'SpecFileContent'} . " " . $end;
1717						my $newline = ${$changefile}[$j];
1718
1719						$oldline =~ s/\s*$//;
1720						$newline =~ s/\s*$//;
1721
1722						my $infoline = "TAB: Changing content from \"$oldline\" to \"$newline\" .\n";
1723						push(@installer::globals::logfileinfo, $infoline);
1724
1725						last;
1726					}
1727				}
1728			}
1729		}
1730	}
1731
1732	return $newclassesstring;
1733}
1734
1735############################################################
1736# Including additional classes into the pkginfo file
1737############################################################
1738
1739sub include_classes_into_pkginfo
1740{
1741	my ($changefile, $classesstring) = @_;
1742
1743	for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1744	{
1745		if ( ${$changefile}[$i] =~ /^\s*CLASSES\=none/ )
1746		{
1747			${$changefile}[$i] =~ s/\s*$//;
1748			my $oldline = ${$changefile}[$i];
1749			${$changefile}[$i] = ${$changefile}[$i] . " " . $classesstring . "\n";
1750			my $newline = ${$changefile}[$i];
1751			$newline =~ s/\s*$//;
1752
1753			my $infoline = "pkginfo file: Changing content from \"$oldline\" to \"$newline\" .\n";
1754			push(@installer::globals::logfileinfo, $infoline);
1755		}
1756	}
1757}
1758
1759##########################################################################################
1760# Checking, if an extension is included into the package (Linux).
1761# All extension files have to be installed into directory
1762# share/extension/install
1763# %attr(0444,root,root) "/opt/staroffice8/share/extension/install/SunSearchToolbar.oxt"
1764##########################################################################################
1765
1766sub is_extension_package
1767{
1768	my ($specfile) = @_;
1769
1770	my $is_extension_package = 0;
1771
1772	for ( my $i = 0; $i <= $#{$specfile}; $i++ )
1773	{
1774		my $line = ${$specfile}[$i];
1775		if ( $line =~ /share\/extension\/install\/.*?\.oxt\"\s*$/ )
1776		{
1777			$is_extension_package = 1;
1778			last;
1779		}
1780	}
1781
1782	return $is_extension_package;
1783}
1784
1785######################################################################
1786# Checking, if an extension is included into the package (Solaris).
1787# All extension files have to be installed into directory
1788# share/extension/install
1789######################################################################
1790
1791sub contains_extension_dir
1792{
1793	my ($prototypefile) = @_;
1794
1795	my $contains_extension_dir = 0;
1796
1797	# d none opt/openoffice.org3/share/extensions/
1798
1799	for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1800	{
1801		my $line = ${$prototypefile}[$i];
1802		if ( $line =~ /^\s*d\s+none\s.*\/share\/extensions\// )
1803		{
1804			$contains_extension_dir = 1;
1805			last;
1806		}
1807	}
1808
1809	return $contains_extension_dir;
1810}
1811
1812############################################################
1813# A Solaris patch contains 7 specific scripts
1814############################################################
1815
1816sub add_scripts_into_prototypefile
1817{
1818	my ($prototypefile, $prototypefilename, $languagestringref, $staticpath) = @_;
1819
1820	# The files are stored in the directory $installer::globals::patchincludepath
1821	# The file names are available via @installer::globals::solarispatchscripts
1822
1823	my $path = $installer::globals::patchincludepath;
1824	$path =~ s/\/\s*$//;
1825	$path = $path . $installer::globals::separator;
1826
1827	my @newlines = ();
1828	my $is_extension_package = contains_extension_dir($prototypefile);
1829
1830	if ( $is_extension_package )
1831	{
1832		for ( my $i = 0; $i <= $#installer::globals::solarispatchscriptsforextensions; $i++ )
1833		{
1834			my $sourcefilename = $path . $installer::globals::solarispatchscriptsforextensions[$i];
1835			my $destfile = $installer::globals::solarispatchscriptsforextensions[$i];
1836
1837			# If the sourcepath has "_extension" in its name, this has to be removed
1838			$destfile =~ s/_extensions\s*$//;  # hard coded renaming of script name
1839
1840			# Creating unique directory name with $prototypefilename
1841			my $extensiondir = installer::systemactions::create_directories("extensionscripts", $languagestringref);
1842
1843			if ( $prototypefilename =~ /\/(\S*?)\s*$/ ) { $prototypefilename = $1; }
1844			$prototypefilename =~ s/\./_/g;
1845			my $destdir = $extensiondir . $installer::globals::separator . $prototypefilename;
1846			if ( ! -d $destdir ) { installer::systemactions::create_directory($destdir); }
1847			my $destpath = $destdir . $installer::globals::separator . $destfile;
1848			if ( -f $destpath ) { unlink($destpath); }
1849
1850			# Reading file
1851			my $scriptfile = installer::files::read_file($sourcefilename);
1852
1853			# Replacing variables
1854			my $oldstring = "PRODUCTDIRECTORYNAME";
1855			replace_variables_in_shellscripts_for_patch($scriptfile, $destpath, $oldstring, $staticpath);
1856
1857			# Saving file
1858			installer::files::save_file($destpath, $scriptfile);
1859
1860			# Writing file destination into prototype file
1861			my $line = "i $destfile=" . $destpath . "\n";
1862			push(@newlines, $line);
1863		}
1864	}
1865	else
1866	{
1867		for ( my $i = 0; $i <= $#installer::globals::solarispatchscripts; $i++ )
1868		{
1869			my $line = "i $installer::globals::solarispatchscripts[$i]=" . $path . $installer::globals::solarispatchscripts[$i] . "\n";
1870			push(@newlines, $line);
1871		}
1872	}
1873
1874	# Including the new lines after the last line starting with "i"
1875
1876	for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1877	{
1878		if ( ${$prototypefile}[$i] =~ /^\s*i\s+copyright/ )
1879		{
1880			splice(@{$prototypefile}, $i, 1);	# ignoring old copyright text, using patch standard
1881			next;
1882		}
1883		if ( ${$prototypefile}[$i] =~ /^\s*i\s+/ ) { next; }
1884		splice(@{$prototypefile}, $i, 0, @newlines);
1885		last;
1886	}
1887}
1888
1889############################################################
1890# Adding patch infos in pkginfo file
1891############################################################
1892
1893sub include_patchinfos_into_pkginfo
1894{
1895	my ( $changefile, $filename, $variableshashref ) = @_;
1896
1897	# SUNW_PATCHID=101998-10
1898	# SUNW_OBSOLETES=114999-01 113999-01
1899	# SUNW_PKGTYPE=usr
1900	# SUNW_PKGVERS=1.0
1901	# SUNW_REQUIRES=126411-01
1902
1903	my $patchidname = "SOLSPARCPATCHID";
1904	if ( $installer::globals::issolarisx86build ) { $patchidname = "SOLIAPATCHID"; }
1905
1906	if ( ! $variableshashref->{$patchidname} ) { installer::exiter::exit_program("ERROR: Variable $patchidname not defined in zip list file!", "include_patchinfos_into_pkginfo"); }
1907
1908	my $newline = "SUNW_PATCHID=" . $variableshashref->{$patchidname} . "\n";
1909	add_one_line_into_file($changefile, $newline, $filename);
1910
1911	my $patchobsoletesname = "SOLSPARCPATCHOBSOLETES";
1912	if ( $installer::globals::issolarisx86build ) { $patchobsoletesname = "SOLIAPATCHOBSOLETES"; }
1913
1914	my $obsoletes = "";
1915	if ( $variableshashref->{$patchobsoletesname} ) { $obsoletes = $variableshashref->{$patchobsoletesname}; }
1916	$newline = "SUNW_OBSOLETES=" . $obsoletes . "\n";
1917	add_one_line_into_file($changefile, $newline, $filename);
1918
1919	my $patchrequiresname = "SOLSPARCPATCHREQUIRES";
1920	if ( $installer::globals::issolarisx86build ) { $patchrequiresname = "SOLIAPATCHREQUIRES"; }
1921
1922	if ( $variableshashref->{$patchrequiresname} )
1923	{
1924		my $requires = $variableshashref->{$patchrequiresname};
1925		$newline = "SUNW_REQUIRES=" . $requires . "\n";
1926		add_one_line_into_file($changefile, $newline, $filename);
1927	}
1928	$newline = "SUNW_PATCH_PROPERTIES=\n";
1929	add_one_line_into_file($changefile, $newline, $filename);
1930	# $newline = "SUNW_PKGTYPE=usr\n";
1931	# add_one_line_into_file($changefile, $newline, $filename);
1932
1933	# $newline = "SUNW_PKGVERS=1.0\n";
1934	# add_one_line_into_file($changefile, $newline, $filename);
1935}
1936
1937############################################################
1938# Setting the correct Solaris locales
1939############################################################
1940
1941sub get_solaris_language_for_langpack
1942{
1943	my ( $onelanguage ) = @_;
1944
1945	my $sollanguage = $onelanguage;
1946	$sollanguage =~ s/\-/\_/;
1947
1948	if ( $sollanguage eq "de" ) { $sollanguage = "de"; }
1949	elsif ( $sollanguage eq "en_US" ) { $sollanguage = "en_AU,en_CA,en_GB,en_IE,en_MT,en_NZ,en_US,en_US.UTF-8"; }
1950	elsif ( $sollanguage eq "es" ) { $sollanguage = "es"; }
1951	elsif ( $sollanguage eq "fr" ) { $sollanguage = "fr"; }
1952	elsif ( $sollanguage eq "hu" ) { $sollanguage = "hu_HU"; }
1953	elsif ( $sollanguage eq "it" ) { $sollanguage = "it"; }
1954	elsif ( $sollanguage eq "nl" ) { $sollanguage = "nl_BE,nl_NL"; }
1955	elsif ( $sollanguage eq "pl" ) { $sollanguage = "pl_PL"; }
1956	elsif ( $sollanguage eq "sv" ) { $sollanguage = "sv"; }
1957	elsif ( $sollanguage eq "pt" ) { $sollanguage = "pt_PT"; }
1958	elsif ( $sollanguage eq "pt_BR" ) { $sollanguage = "pt_BR"; }
1959	elsif ( $sollanguage eq "ru" ) { $sollanguage = "ru_RU"; }
1960	elsif ( $sollanguage eq "ja" ) { $sollanguage = "ja,ja_JP,ja_JP.PCK,ja_JP.UTF-8"; }
1961	elsif ( $sollanguage eq "ko" ) { $sollanguage = "ko,ko.UTF-8"; }
1962	elsif ( $sollanguage eq "zh_CN" ) { $sollanguage = "zh,zh.GBK,zh_CN.GB18030,zh.UTF-8"; }
1963	elsif ( $sollanguage eq "zh_TW" ) { $sollanguage = "zh_TW,zh_TW.BIG5,zh_TW.UTF-8,zh_HK.BIG5HK,zh_HK.UTF-8"; }
1964
1965	return $sollanguage;
1966}
1967
1968############################################################
1969# Adding language infos in pkginfo file
1970############################################################
1971
1972sub include_languageinfos_into_pkginfo
1973{
1974	my ( $changefile, $filename, $languagestringref, $onepackage, $variableshashref ) = @_;
1975
1976	# SUNWPKG_LIST=core01
1977	# SUNW_LOC=de
1978
1979	my $locallang = $onepackage->{'language'};
1980	my $solarislanguage = get_solaris_language_for_langpack($locallang);
1981
1982	my $newline = "SUNW_LOC=" . $solarislanguage . "\n";
1983	add_one_line_into_file($changefile, $newline, $filename);
1984
1985	# SUNW_PKGLIST is required, if SUNW_LOC is defined.
1986	if ( $onepackage->{'pkg_list_entry'} )
1987	{
1988		my $packagelistentry = $onepackage->{'pkg_list_entry'};
1989		installer::packagelist::resolve_packagevariables(\$packagelistentry, $variableshashref, 1);
1990		$newline = "SUNW_PKGLIST=" . $packagelistentry . "\n";
1991		add_one_line_into_file($changefile, $newline, $filename);
1992	}
1993	else
1994	{
1995		# Using default package ooobasis30-core01.
1996		my $packagelistentry = "%BASISPACKAGEPREFIX%WITHOUTDOTOOOBASEVERSION-core01";
1997		installer::packagelist::resolve_packagevariables(\$packagelistentry, $variableshashref, 1);
1998		$newline = "SUNW_PKGLIST=" . $packagelistentry . "\n";
1999		add_one_line_into_file($changefile, $newline, $filename);
2000	}
2001}
2002
2003############################################################
2004# Collecting all files included in patch in
2005# @installer::globals::patchfilecollector
2006############################################################
2007
2008sub collect_patch_files
2009{
2010	my ($file, $packagename, $prefix) = @_;
2011
2012	# $file is the spec file or the prototypefile
2013
2014	$prefix = $prefix . "/";
2015	my $packagenamestring = "Package " . $packagename . " \:\n";
2016	push(@installer::globals::patchfilecollector, $packagenamestring);
2017
2018	for ( my $i = 0; $i <= $#{$file}; $i++ )
2019	{
2020		my $line = ${$file}[$i];
2021
2022		if ( $installer::globals::islinuxrpmbuild )
2023		{
2024			# %attr(0444,root,root) "/opt/openofficeorg20/program/about.bmp"
2025
2026			if ( $line =~ /^\s*\%attr\(.*\)\s*\"(.*?)\"\s*$/ )
2027			{
2028				my $filename = $1 . "\n";
2029				$filename =~ s/^\s*\Q$prefix\E//;
2030				push(@installer::globals::patchfilecollector, $filename);
2031			}
2032		}
2033
2034		if ( $installer::globals::issolarispkgbuild )
2035		{
2036			# f none program/msomrl.rdb=/ab/SRC680/unxsols4.pro/bin/msomrl.rdb 0444 root bin
2037
2038			if ( $line =~ /^\s*f\s+\w+\s+(.*?)\=/ )
2039			{
2040				my $filename = $1 . "\n";
2041				push(@installer::globals::patchfilecollector, $filename);
2042			}
2043		}
2044	}
2045
2046	push(@installer::globals::patchfilecollector, "\n");
2047
2048}
2049
2050############################################################
2051# Including package names into the depend files.
2052# The package names have to be included into
2053# packagelist. They are already saved in
2054# %installer::globals::dependfilenames.
2055############################################################
2056
2057sub put_packagenames_into_dependfile
2058{
2059	my ( $file ) = @_;
2060
2061	for ( my $i = 0; $i <= $#{$file}; $i++ )
2062	{
2063		my $line = ${$file}[$i];
2064		if ( $line =~ /^\s*\w\s+(.*?)\s*$/ )
2065		{
2066			my $abbreviation = $1;
2067
2068            if ( $abbreviation =~ /\%/ ) { installer::exiter::exit_program("ERROR: Could not resolve all properties in Solaris package abbreviation \"$abbreviation\"!", "read_packagemap"); }
2069
2070			if ( exists($installer::globals::dependfilenames{$abbreviation}) )
2071			{
2072                my $packagename = $installer::globals::dependfilenames{$abbreviation};
2073                if ( $packagename =~ /\%/ ) { installer::exiter::exit_program("ERROR: Could not resolve all properties in Solaris package name \"$packagename\"!", "read_packagemap"); }
2074
2075				$line =~ s/\s*$//;
2076				${$file}[$i] = $line . "\t" . $packagename . "\n";
2077			}
2078			else
2079			{
2080				installer::exiter::exit_program("ERROR: Missing packagename for Solaris package \"$abbreviation\"!", "put_packagenames_into_dependfile");
2081			}
2082		}
2083	}
2084}
2085
2086############################################################
2087# Including the relocatable directory into
2088# spec file and pkginfo file
2089# Linux: set topdir in specfile
2090# Solaris: remove $relocatablepath (/opt/)
2091# for all objects in prototype file
2092# and changing "topdir" for Linux
2093############################################################
2094
2095sub prepare_packages
2096{
2097	my ($loggingdir, $packagename, $staticpath, $relocatablepath, $onepackage, $variableshashref, $filesref, $languagestringref) = @_;
2098
2099	my $filename = "";
2100	my $newline = "";
2101	my $newepmdir = $installer::globals::epmoutpath . $installer::globals::separator;
2102
2103	my $localrelocatablepath = $relocatablepath;
2104	if ( $localrelocatablepath ne "/" ) { $localrelocatablepath =~ s/\/\s*$//; }
2105
2106	if ( $installer::globals::issolarispkgbuild )
2107	{
2108		$filename = $packagename . ".pkginfo";
2109		$newline = "BASEDIR\=" . $localrelocatablepath . "\n";
2110	}
2111
2112	if ( $installer::globals::islinuxrpmbuild )
2113	{
2114		# if ( $localrelocatablepath =~ /^\s*$/ ) { $localrelocatablepath = "/"; }; # at least the "/"
2115		$filename =  $packagename . ".spec";
2116		$newline = "Prefix\:\ " . $localrelocatablepath . "\n";
2117	}
2118
2119	my $completefilename = $newepmdir . $filename;
2120
2121	if ( ! -f $completefilename) { installer::exiter::exit_program("ERROR: Did not find file: $completefilename", "prepare_packages"); }
2122	my $changefile = installer::files::read_file($completefilename);
2123	if ( $newline ne "" )
2124	{
2125		add_one_line_into_file($changefile, $newline, $filename);
2126		installer::files::save_file($completefilename, $changefile);
2127	}
2128
2129	# my $newepmdir = $completefilename;
2130	# installer::pathanalyzer::get_path_from_fullqualifiedname(\$newepmdir);
2131
2132	# adding new "topdir" and removing old "topdir" in specfile
2133
2134	if ( $installer::globals::islinuxrpmbuild )
2135	{
2136		set_topdir_in_specfile($changefile, $filename, $newepmdir);
2137		set_autoprovreq_in_specfile($changefile, $onepackage->{'findrequires'}, "$installer::globals::unpackpath" . "/bin");
2138		set_packager_in_specfile($changefile);
2139		if ( is_extension_package($changefile) ) { set_prereq_in_specfile($changefile); }
2140		set_license_in_specfile($changefile, $variableshashref);
2141		set_tab_into_datafile($changefile, $filesref);
2142		# check_requirements_in_specfile($changefile);
2143		installer::files::save_file($completefilename, $changefile);
2144		if ( $installer::globals::patch ) { collect_patch_files($changefile, $packagename, $localrelocatablepath); }
2145	}
2146
2147	# removing the relocatable path in prototype file
2148
2149	if ( $installer::globals::issolarispkgbuild )
2150	{
2151		set_revision_in_pkginfo($changefile, $filename, $variableshashref, $packagename);
2152		set_maxinst_in_pkginfo($changefile, $filename);
2153		set_solaris_parameter_in_pkginfo($changefile, $filename, $variableshashref);
2154		if ( $installer::globals::issolarisx86build ) { fix_architecture_setting($changefile); }
2155		if ( ! $installer::globals::patch ) { set_patchlist_in_pkginfo_for_respin($changefile, $filename, $variableshashref, $packagename); }
2156		if ( $installer::globals::patch ) { include_patchinfos_into_pkginfo($changefile, $filename, $variableshashref); }
2157		if (( $onepackage->{'language'} ) && ( $onepackage->{'language'} ne "" ) && ( $onepackage->{'language'} ne "en-US" )) { include_languageinfos_into_pkginfo($changefile, $filename, $languagestringref, $onepackage, $variableshashref); }
2158		installer::files::save_file($completefilename, $changefile);
2159
2160		my $prototypefilename = $packagename . ".prototype";
2161		$prototypefilename = $newepmdir . $prototypefilename;
2162		if (! -f $prototypefilename) { installer::exiter::exit_program("ERROR: Did not find prototype file: $prototypefilename", "prepare_packages"); }
2163
2164		my $prototypefile = installer::files::read_file($prototypefilename);
2165		make_prototypefile_relocatable($prototypefile, $relocatablepath);
2166		set_volatilefile_into_prototypefile($prototypefile, $filesref);
2167		my $classesstring = set_tab_into_datafile($prototypefile, $filesref);
2168		if ($classesstring)
2169		{
2170			include_classes_into_pkginfo($changefile, $classesstring);
2171			installer::files::save_file($completefilename, $changefile);
2172		}
2173
2174		if ( $installer::globals::patch ) { add_scripts_into_prototypefile($prototypefile, $prototypefilename, $languagestringref, $staticpath); }
2175
2176		installer::files::save_file($prototypefilename, $prototypefile);
2177		if ( $installer::globals::patch ) { collect_patch_files($prototypefile, $packagename, ""); }
2178
2179		# Adding package names into depend files for Solaris (not supported by epm)
2180		my $dependfilename = $packagename . ".depend";
2181		$dependfilename = $newepmdir . $dependfilename;
2182		if ( -f $dependfilename)
2183		{
2184			my $dependfile = installer::files::read_file($dependfilename);
2185			put_packagenames_into_dependfile($dependfile);
2186			installer::files::save_file($dependfilename, $dependfile);
2187		}
2188	}
2189
2190	return $newepmdir;
2191}
2192
2193############################################################
2194# Linux requirement for perl is changed by epm from
2195# /usr/bin/perl to perl .
2196# Requires: perl
2197############################################################
2198
2199sub check_requirements_in_specfile
2200{
2201	my ( $specfile ) = @_;
2202
2203	for ( my $i = 0; $i <= $#{$specfile}; $i++ )
2204	{
2205		if (( ${$specfile}[$i] =~ /^\s*Requires/ ) && ( ${$specfile}[$i] =~ /\bperl\b/ ) && ( ! (  ${$specfile}[$i] =~ /\/usr\/bin\/perl\b/ )))
2206		{
2207			my $oldline = ${$specfile}[$i];
2208			${$specfile}[$i] =~ s/perl/\/usr\/bin\/perl/;
2209			my $newline = ${$specfile}[$i];
2210
2211			$oldline =~ s/\s*$//;
2212			$newline =~ s/\s*$//;
2213			my $infoline = "Spec File: Changing content from \"$oldline\" to \"$newline\".\n";
2214			push(@installer::globals::logfileinfo, $infoline);
2215		}
2216	}
2217}
2218
2219###############################################################################
2220# Replacement of PRODUCTINSTALLLOCATION and PRODUCTDIRECTORYNAME in the
2221# epm list file.
2222# The complete rootpath is stored in $installer::globals::rootpath
2223# or for each package in $onepackage->{'destpath'}
2224# The static rootpath is stored in $staticpath
2225# The relocatable path is stored in $relocatablepath
2226# PRODUCTINSTALLLOCATION is the relocatable part ("/opt") and
2227# PRODUCTDIRECTORYNAME the static path ("openofficeorg20").
2228# In standard epm process:
2229# No usage of package specific variables like $BASEDIR, because
2230# 1. These variables would be replaced in epm process
2231# 2. epm version 3.7 does not support relocatable packages
2232###############################################################################
2233
2234sub resolve_path_in_epm_list_before_packaging
2235{
2236	my ($listfile, $listfilename, $variable, $path) = @_;
2237
2238	installer::logger::include_header_into_logfile("Replacing variables in epm list file:");
2239
2240	$path =~ s/\/\s*$//;
2241	replace_variables_in_shellscripts($listfile, $listfilename, $variable, $path);
2242
2243}
2244
2245#################################################################
2246# Determining the rpm version. Beginning with rpm version 4.0
2247# the tool to create RPMs is "rpmbuild" and no longer "rpm"
2248#################################################################
2249
2250sub determine_rpm_version
2251{
2252	my $rpmversion = 0;
2253	my $rpmout = "";
2254	my $systemcall = "";
2255
2256	# my $systemcall = "rpm --version |";
2257	# "rpm --version" has problems since LD_LIBRARY_PATH was removed. Therefore the content of $RPM has to be called.
2258	# "rpm --version" and "rpmbuild --version" have the same output. Therefore $RPM can be used. Its value
2259	# is saved in $installer::globals::rpm
2260
2261	if ( $installer::globals::rpm ne "" )
2262	{
2263		$systemcall = "$installer::globals::rpm --version |";
2264	}
2265	else
2266	{
2267		$systemcall = "rpm --version |";
2268	}
2269
2270	open (RPM, "$systemcall");
2271	$rpmout = <RPM>;
2272	close (RPM);
2273
2274	if ( $rpmout ne "" )
2275	{
2276		$rpmout =~ s/\s*$//g;
2277
2278		my $infoline = "Systemcall: $systemcall\n";
2279		push( @installer::globals::logfileinfo, $infoline);
2280
2281		if ( $rpmout eq "" ) { $infoline = "ERROR: Could not find file \"rpm\" !\n"; }
2282		else { $infoline = "Success: rpm version: $rpmout\n"; }
2283
2284		push( @installer::globals::logfileinfo, $infoline);
2285
2286		if ( $rpmout =~ /(\d+)\.(\d+)\.(\d+)/ ) { $rpmversion = $1; }
2287		elsif ( $rpmout =~ /(\d+)\.(\d+)/ ) { $rpmversion = $1; }
2288		elsif ( $rpmout =~ /(\d+)/ ) { $rpmversion = $1; }
2289		else { installer::exiter::exit_program("ERROR: Unknown format: $rpmout ! Expected: \"a.b.c\", or \"a.b\", or \"a\"", "determine_rpm_version"); }
2290	}
2291
2292	return $rpmversion;
2293}
2294
2295####################################################
2296# Writing some info about rpm into the log file
2297####################################################
2298
2299sub log_rpm_info
2300{
2301	my $systemcall = "";
2302	my $infoline = "";
2303
2304	$infoline = "\nLogging rpmrc content using --showrc\n\n";
2305	push( @installer::globals::logfileinfo, $infoline);
2306
2307	if ( $installer::globals::rpm ne "" )
2308	{
2309		$systemcall = "$installer::globals::rpm --showrc |";
2310	}
2311	else
2312	{
2313		$systemcall = "rpm --showrc |";
2314	}
2315
2316	my @fullrpmout = ();
2317
2318	open (RPM, "$systemcall");
2319	while (<RPM>) {push(@fullrpmout, $_); }
2320	close (RPM);
2321
2322	if ( $#fullrpmout > -1 )
2323	{
2324		for ( my $i = 0; $i <= $#fullrpmout; $i++ )
2325		{
2326			my $rpmout = $fullrpmout[$i];
2327			$rpmout =~ s/\s*$//g;
2328
2329			$infoline = "$rpmout\n";
2330			$infoline =~ s/error/e_r_r_o_r/gi;  # avoiding log problems
2331			push( @installer::globals::logfileinfo, $infoline);
2332		}
2333	}
2334	else
2335	{
2336		$infoline = "Problem in systemcall: $systemcall : No return value\n";
2337		push( @installer::globals::logfileinfo, $infoline);
2338	}
2339
2340	$infoline = "End of logging rpmrc\n\n";
2341	push( @installer::globals::logfileinfo, $infoline);
2342}
2343
2344#################################################
2345# Systemcall to start the packaging process
2346#################################################
2347
2348sub create_packages_without_epm
2349{
2350	my ($epmdir, $packagename, $includepatharrayref, $allvariables, $languagestringref) = @_;
2351
2352	# Solaris: pkgmk -o -f solaris-2.8-sparc/SUNWso8m34.prototype -d solaris-2.8-sparc
2353	# Solaris: pkgtrans solaris-2.8-sparc SUNWso8m34.pkg SUNWso8m34
2354	# Solaris: tar -cf - SUNWso8m34 | gzip > SUNWso8m34.tar.gz
2355
2356	if ( $installer::globals::issolarispkgbuild )
2357	{
2358		my $prototypefile = $epmdir . $packagename . ".prototype";
2359		if (! -f $prototypefile) { installer::exiter::exit_program("ERROR: Did not find file: $prototypefile", "create_packages_without_epm"); }
2360
2361		my $destinationdir = $prototypefile;
2362		installer::pathanalyzer::get_path_from_fullqualifiedname(\$destinationdir);
2363		$destinationdir =~ s/\/\s*$//;	# removing ending slashes
2364
2365		# my $systemcall = "pkgmk -o -f $prototypefile -d $destinationdir \> /dev/null 2\>\&1";
2366		my $systemcall = "pkgmk -l 1073741824 -o -f $prototypefile -d $destinationdir 2\>\&1 |";
2367		installer::logger::print_message( "... $systemcall ...\n" );
2368
2369		my $maxpkgmkcalls = 3;
2370
2371		for ( my $i = 1; $i <= $maxpkgmkcalls; $i++ )
2372		{
2373			my @pkgmkoutput = ();
2374
2375			open (PKGMK, "$systemcall");
2376			while (<PKGMK>) {push(@pkgmkoutput, $_); }
2377			close (PKGMK);
2378
2379			my $returnvalue = $?;	# $? contains the return value of the systemcall
2380
2381			my $infoline = "Systemcall (Try $i): $systemcall\n";
2382			push( @installer::globals::logfileinfo, $infoline);
2383
2384			for ( my $j = 0; $j <= $#pkgmkoutput; $j++ )
2385			{
2386				if ( $i < $maxpkgmkcalls ) { $pkgmkoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; }
2387				push( @installer::globals::logfileinfo, "$pkgmkoutput[$j]");
2388			}
2389
2390			if ($returnvalue)
2391			{
2392				$infoline = "Try $i : Could not execute \"$systemcall\"!\n";
2393				push( @installer::globals::logfileinfo, $infoline);
2394				if ( $i == $maxpkgmkcalls ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "create_packages_without_epm"); }
2395			}
2396			else
2397			{
2398				installer::logger::print_message( "Success (Try $i): \"$systemcall\"\n" );
2399				$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2400				push( @installer::globals::logfileinfo, $infoline);
2401				last;
2402			}
2403		}
2404
2405		# It might be necessary to save uncompressed Solaris packages
2406
2407		if ( $allvariables->{'JDSBUILD'} )
2408		{
2409			if ( ! $installer::globals::jds_language_controlled )
2410			{
2411				my $correct_language = installer::worker::check_jds_language($allvariables, $languagestringref);
2412				$installer::globals::correct_jds_language = $correct_language;
2413				$installer::globals::jds_language_controlled = 1;
2414			}
2415
2416			if ( $installer::globals::correct_jds_language )
2417			{
2418				if ( $installer::globals::saved_packages_path eq "" )
2419				{
2420					$packagestempdir = installer::systemactions::create_directories("jds", $languagestringref);
2421					$installer::globals::saved_packages_path = $packagestempdir;
2422					push(@installer::globals::jdsremovedirs, $packagestempdir);
2423				}
2424
2425				$systemcall = "cd $destinationdir; cp -p -R $packagename $installer::globals::saved_packages_path;";
2426			 	make_systemcall($systemcall);
2427				installer::logger::print_message( "... $systemcall ...\n" );
2428
2429				# Setting unix rights to "775" for all created directories inside the package,
2430				# that is saved in temp directory
2431
2432				$systemcall = "cd $packagestempdir; find $packagename -type d -exec chmod 775 \{\} \\\;";
2433				installer::logger::print_message( "... $systemcall ...\n" );
2434
2435				$returnvalue = system($systemcall);
2436
2437				$infoline = "Systemcall: $systemcall\n";
2438				push( @installer::globals::logfileinfo, $infoline);
2439
2440				if ($returnvalue)
2441				{
2442					$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2443					push( @installer::globals::logfileinfo, $infoline);
2444				}
2445				else
2446				{
2447					$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2448					push( @installer::globals::logfileinfo, $infoline);
2449				}
2450			}
2451		}
2452
2453		# compressing packages
2454
2455		if ( ! $installer::globals::solarisdontcompress )
2456		{
2457			my $faspac = "faspac-so.sh";
2458
2459			my $compressorref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$faspac, $includepatharrayref, 0);
2460			if ($$compressorref ne "")
2461			{
2462				# Saving original pkginfo, to set time stamp later
2463				my $pkginfoorig = "$destinationdir/$packagename/pkginfo";
2464				my $pkginfotmp = "$destinationdir/$packagename" . ".pkginfo.tmp";
2465				$systemcall = "cp -p $pkginfoorig $pkginfotmp";
2466			 	make_systemcall($systemcall);
2467
2468				$faspac = $$compressorref;
2469				$infoline = "Found compressor: $faspac\n";
2470				push( @installer::globals::logfileinfo, $infoline);
2471
2472				installer::logger::print_message( "... $faspac ...\n" );
2473				installer::logger::include_timestamp_into_logfile("Starting $faspac");
2474
2475			 	$systemcall = "/bin/sh $faspac -a -q -d $destinationdir $packagename";	 # $faspac has to be the absolute path!
2476			 	make_systemcall($systemcall);
2477
2478			 	# Setting time stamp for pkginfo, because faspac-so.sh changed the pkginfo file,
2479			 	# updated the size and checksum, but not the time stamp.
2480			 	$systemcall = "touch -r $pkginfotmp $pkginfoorig";
2481			 	make_systemcall($systemcall);
2482				if ( -f $pkginfotmp ) { unlink($pkginfotmp); }
2483
2484				installer::logger::include_timestamp_into_logfile("End of $faspac");
2485			}
2486			else
2487			{
2488				$infoline = "Not found: $faspac\n";
2489				push( @installer::globals::logfileinfo, $infoline);
2490			}
2491		}
2492
2493		# Setting unix rights to "775" for all created directories inside the package
2494
2495		$systemcall = "cd $destinationdir; find $packagename -type d -exec chmod 775 \{\} \\\;";
2496		installer::logger::print_message( "... $systemcall ...\n" );
2497
2498		$returnvalue = system($systemcall);
2499
2500		$infoline = "Systemcall: $systemcall\n";
2501		push( @installer::globals::logfileinfo, $infoline);
2502
2503		if ($returnvalue)
2504		{
2505			$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2506			push( @installer::globals::logfileinfo, $infoline);
2507		}
2508		else
2509		{
2510			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2511			push( @installer::globals::logfileinfo, $infoline);
2512		}
2513
2514		######################
2515		# making pkg files
2516		######################
2517
2518		# my $streamname = $packagename . ".pkg";
2519		# $systemcall = "pkgtrans $destinationdir $streamname $packagename";
2520		# print "... $systemcall ...\n";
2521
2522		# $returnvalue = system($systemcall);
2523
2524		# $infoline = "Systemcall: $systemcall\n";
2525		# push( @installer::globals::logfileinfo, $infoline);
2526
2527		# if ($returnvalue)
2528		# {
2529		# 	$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2530		# 	push( @installer::globals::logfileinfo, $infoline);
2531		# }
2532		# else
2533		# {
2534		# 	$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2535		# 	push( @installer::globals::logfileinfo, $infoline);
2536		# }
2537
2538		#########################
2539		# making tar.gz files
2540		#########################
2541
2542		# my $targzname = $packagename . ".tar.gz";
2543		# $systemcall = "cd $destinationdir; tar -cf - $packagename | gzip > $targzname";
2544		# print "... $systemcall ...\n";
2545
2546		# $returnvalue = system($systemcall);
2547
2548		# $infoline = "Systemcall: $systemcall\n";
2549		# push( @installer::globals::logfileinfo, $infoline);
2550
2551		# if ($returnvalue)
2552		# {
2553		#	$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2554		#	push( @installer::globals::logfileinfo, $infoline);
2555		# }
2556		# else
2557		# {
2558		#	$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2559		#	push( @installer::globals::logfileinfo, $infoline);
2560		# }
2561	}
2562
2563	# Linux: rpm -bb so8m35.spec	( -> dependency check abklemmen? )
2564
2565	if ( $installer::globals::islinuxrpmbuild )
2566	{
2567		my $specfilename = $epmdir . $packagename . ".spec";
2568		if (! -f $specfilename) { installer::exiter::exit_program("ERROR: Did not find file: $specfilename", "create_packages_without_epm"); }
2569
2570		# my $rpmcommand = "rpm";
2571		my $rpmcommand = $installer::globals::rpm;
2572		my $rpmversion = determine_rpm_version();
2573
2574		# if ( $rpmversion >= 4 ) { $rpmcommand = "rpmbuild"; }
2575
2576		# saving globally for later usage
2577		$installer::globals::rpmcommand = $rpmcommand;
2578		$installer::globals::rpmquerycommand = "rpm";
2579
2580		my $target = "";
2581		if ( $installer::globals::compiler =~ /unxlngi/) { $target = "i586"; }
2582		elsif ( $installer::globals::compiler =~ /unxlng/) {$target = (POSIX::uname())[4]; }
2583
2584		# rpm 4.6 ignores buildroot tag in spec file
2585
2586		my $buildrootstring = "";
2587
2588		if ( $rpmversion >= 4 )
2589		{
2590			my $dir = getcwd;
2591			my $buildroot = $dir . "/" . $epmdir . "buildroot/";
2592			$buildrootstring = "--buildroot=$buildroot";
2593			mkdir($buildroot = $dir . "/" . $epmdir . "BUILD/");
2594		}
2595
2596		if ( ! $installer::globals::rpminfologged )
2597		{
2598			log_rpm_info();
2599			$installer::globals::rpminfologged = 1;
2600		}
2601
2602		my $systemcall = "$rpmcommand -bb --define \"_unpackaged_files_terminate_build  0\" $specfilename --target $target $buildrootstring 2\>\&1 |";
2603
2604		installer::logger::print_message( "... $systemcall ...\n" );
2605
2606		my $maxrpmcalls = 3;
2607		my $rpm_failed = 0;
2608
2609		for ( my $i = 1; $i <= $maxrpmcalls; $i++ )
2610		{
2611			my @rpmoutput = ();
2612
2613			open (RPM, "$systemcall");
2614			while (<RPM>) {push(@rpmoutput, $_); }
2615			close (RPM);
2616
2617			my $returnvalue = $?;	# $? contains the return value of the systemcall
2618
2619			my $infoline = "Systemcall (Try $i): $systemcall\n";
2620			push( @installer::globals::logfileinfo, $infoline);
2621
2622			for ( my $j = 0; $j <= $#rpmoutput; $j++ )
2623			{
2624				# if ( $i < $maxrpmcalls ) { $rpmoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; }
2625				$rpmoutput[$j] =~ s/\bERROR\b/PROBLEM/ig;
2626				push( @installer::globals::logfileinfo, "$rpmoutput[$j]");
2627			}
2628
2629			if ($returnvalue)
2630			{
2631				$infoline = "Try $i : Could not execute \"$systemcall\"!\n";
2632				push( @installer::globals::logfileinfo, $infoline);
2633				$rpm_failed = 1;
2634			}
2635			else
2636			{
2637				installer::logger::print_message( "Success (Try $i): \"$systemcall\"\n" );
2638				$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2639				push( @installer::globals::logfileinfo, $infoline);
2640				$rpm_failed = 0;
2641				last;
2642			}
2643		}
2644
2645		if ( $rpm_failed )
2646		{
2647			# Because of the problems with LD_LIBARY_PATH, a direct call of local "rpm" or "rpmbuild" might be successful
2648			my $rpmprog = "";
2649			if ( -f "/usr/bin/rpmbuild" ) { $rpmprog = "/usr/bin/rpmbuild"; }
2650			elsif ( -f "/usr/bin/rpm" ) { $rpmprog = "/usr/bin/rpm"; }
2651
2652			if ( $rpmprog ne "" )
2653			{
2654				installer::logger::print_message( "... $rpmprog ...\n" );
2655
2656				my $helpersystemcall = "$rpmprog -bb $specfilename --target $target $buildrootstring 2\>\&1 |";
2657
2658				my @helperrpmoutput = ();
2659
2660				open (RPM, "$helpersystemcall");
2661				while (<RPM>) {push(@helperrpmoutput, $_); }
2662				close (RPM);
2663
2664				my $helperreturnvalue = $?;	# $? contains the return value of the systemcall
2665
2666				$infoline = "\nLast try: Using $rpmprog directly (problem with LD_LIBARY_PATH)\n";
2667				push( @installer::globals::logfileinfo, $infoline);
2668
2669				$infoline = "\nSystemcall: $helpersystemcall\n";
2670				push( @installer::globals::logfileinfo, $infoline);
2671
2672				for ( my $j = 0; $j <= $#helperrpmoutput; $j++ ) { push( @installer::globals::logfileinfo, "$helperrpmoutput[$j]"); }
2673
2674				if ($helperreturnvalue)
2675				{
2676					$infoline = "Could not execute \"$helpersystemcall\"!\n";
2677					push( @installer::globals::logfileinfo, $infoline);
2678				}
2679				else
2680				{
2681					installer::logger::print_message( "Success: \"$helpersystemcall\"\n" );
2682					$infoline = "Success: Executed \"$helpersystemcall\" successfully!\n";
2683					push( @installer::globals::logfileinfo, $infoline);
2684					$rpm_failed = 0;
2685				}
2686			}
2687
2688			# Now it is really time to exit this packaging process, if the error still occurs
2689			if ( $rpm_failed ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "create_packages_without_epm"); }
2690		}
2691	}
2692}
2693
2694#################################################
2695# Removing all temporary files created by epm
2696#################################################
2697
2698sub remove_temporary_epm_files
2699{
2700	my ($epmdir, $loggingdir, $packagename) = @_;
2701
2702	# saving the files into the loggingdir
2703
2704	if ( $installer::globals::issolarispkgbuild )
2705	{
2706		my @extensions = ();
2707		push(@extensions, ".pkginfo");
2708		push(@extensions, ".prototype");
2709		push(@extensions, ".postinstall");
2710		push(@extensions, ".postremove");
2711		push(@extensions, ".preinstall");
2712		push(@extensions, ".preremove");
2713		push(@extensions, ".depend");
2714
2715		for ( my $i = 0; $i <= $#extensions; $i++ )
2716		{
2717			my $removefile = $epmdir . $packagename . $extensions[$i];
2718			my $destfile = $loggingdir . $packagename . $extensions[$i] . ".log";
2719
2720			if (! -f $removefile) { next; }
2721
2722			my $systemcall = "mv -f $removefile $destfile";
2723			system($systemcall);	 # ignoring the return value
2724			$infoline = "Systemcall: $systemcall\n";
2725			push( @installer::globals::logfileinfo, $infoline);
2726		}
2727
2728		# removing the package
2729
2730#		my $removedir = $epmdir . $packagename;
2731#
2732#		my $systemcall = "rm -rf $removedir";
2733#
2734#		print "... $systemcall ...\n";
2735#
2736#		my $returnvalue = system($systemcall);
2737#
2738#		my $infoline = "Systemcall: $systemcall\n";
2739#		push( @installer::globals::logfileinfo, $infoline);
2740#
2741#		if ($returnvalue)
2742#		{
2743#			$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2744#			push( @installer::globals::logfileinfo, $infoline);
2745#		}
2746#		else
2747#		{
2748#			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2749#			push( @installer::globals::logfileinfo, $infoline);
2750#		}
2751	}
2752
2753	if ( $installer::globals::islinuxrpmbuild )
2754	{
2755		my $removefile = $epmdir . $packagename . ".spec";
2756		my $destfile = $loggingdir . $packagename . ".spec.log";
2757
2758		 # if (! -f $removefile) { next; }
2759
2760		my $systemcall = "mv -f $removefile $destfile";
2761		system($systemcall);	 # ignoring the return value
2762		$infoline = "Systemcall: $systemcall\n";
2763		push( @installer::globals::logfileinfo, $infoline);
2764
2765		# removing the directory "buildroot"
2766
2767		my $removedir = $epmdir . "buildroot";
2768
2769		$systemcall = "rm -rf $removedir";
2770
2771		installer::logger::print_message( "... $systemcall ...\n" );
2772
2773		my $returnvalue = system($systemcall);
2774
2775		$removedir = $epmdir . "BUILD";
2776
2777		$systemcall = "rm -rf $removedir";
2778
2779		installer::logger::print_message( "... $systemcall ...\n" );
2780
2781		$returnvalue = system($systemcall);
2782
2783
2784		my $infoline = "Systemcall: $systemcall\n";
2785		push( @installer::globals::logfileinfo, $infoline);
2786
2787		if ($returnvalue)
2788		{
2789			$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2790			push( @installer::globals::logfileinfo, $infoline);
2791		}
2792		else
2793		{
2794			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2795			push( @installer::globals::logfileinfo, $infoline);
2796		}
2797	}
2798}
2799
2800######################################################
2801# Making the systemcall
2802######################################################
2803
2804sub make_systemcall
2805{
2806	my ($systemcall) = @_;
2807
2808	my $returnvalue = system($systemcall);
2809
2810	my $infoline = "Systemcall: $systemcall\n";
2811	push( @installer::globals::logfileinfo, $infoline);
2812
2813	if ($returnvalue)
2814	{
2815		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2816		push( @installer::globals::logfileinfo, $infoline);
2817	}
2818	else
2819	{
2820		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2821		push( @installer::globals::logfileinfo, $infoline);
2822	}
2823}
2824
2825###########################################################
2826# Creating a better directory structure in the solver.
2827###########################################################
2828
2829sub create_new_directory_structure
2830{
2831	my ($newepmdir) = @_;
2832
2833	my $newdir = $installer::globals::epmoutpath;
2834
2835	if ( $installer::globals::islinuxrpmbuild )
2836	{
2837		my $rpmdir;
2838                my $machine = "";
2839		if ( $installer::globals::compiler =~ /unxlngi/) {
2840                    $rpmdir = "$installer::globals::epmoutpath/RPMS/i586";
2841                }
2842		elsif ( $installer::globals::compiler =~ /unxlng/) {
2843                    $machine = (POSIX::uname())[4];
2844                    $rpmdir = "$installer::globals::epmoutpath/RPMS/$machine";
2845                }
2846                else { installer::exiter::exit_program("ERROR: rpmdir undefined !", "create_new_directory_structure"); }
2847
2848		my $systemcall = "mv $rpmdir/* $newdir";	# moving the rpms into the directory "RPMS"
2849
2850		my $returnvalue = system($systemcall);
2851
2852		my $infoline = "Systemcall: $systemcall\n";
2853		push( @installer::globals::logfileinfo, $infoline);
2854
2855		if ($returnvalue)
2856		{
2857			$infoline = "ERROR: Could not move content of \"$rpmdir\" to \"$newdir\"!\n";
2858			push( @installer::globals::logfileinfo, $infoline);
2859		}
2860		else
2861		{
2862			$infoline = "Success: Moved content of \"$rpmdir\" to \"$newdir\"!\n";
2863			push( @installer::globals::logfileinfo, $infoline);
2864		}
2865
2866		# and removing the empty directory
2867
2868		if ( $machine ne "" )
2869		{
2870			installer::systemactions::remove_empty_directory("$installer::globals::epmoutpath/RPMS/$machine");
2871		}
2872		installer::systemactions::remove_empty_directory("$installer::globals::epmoutpath/RPMS/x86_64");
2873		installer::systemactions::remove_empty_directory("$installer::globals::epmoutpath/RPMS/i586");
2874		installer::systemactions::remove_empty_directory("$installer::globals::epmoutpath/RPMS/i386");
2875		installer::systemactions::remove_empty_directory("$installer::globals::epmoutpath/RPMS");
2876
2877	}
2878
2879	# Setting unix rights to "775" for $newdir ("RPMS" or "packages")
2880
2881	my $localcall = "chmod 775 $newdir \>\/dev\/null 2\>\&1";
2882	my $callreturnvalue = system($localcall);
2883
2884	my $callinfoline = "Systemcall: $localcall\n";
2885	push( @installer::globals::logfileinfo, $callinfoline);
2886
2887	if ($callreturnvalue)
2888	{
2889		$callinfoline = "ERROR: Could not execute \"$localcall\"!\n";
2890		push( @installer::globals::logfileinfo, $callinfoline);
2891	}
2892	else
2893	{
2894		$callinfoline = "Success: Executed \"$localcall\" successfully!\n";
2895		push( @installer::globals::logfileinfo, $callinfoline);
2896	}
2897}
2898
2899######################################################
2900# Collect modules with product specific styles.
2901######################################################
2902
2903sub collect_modules_with_style
2904{
2905	my ($style, $modulesarrayref) = @_;
2906
2907	my @allmodules = ();
2908
2909	for ( my $i = 0; $i <= $#{$modulesarrayref}; $i++ )
2910	{
2911		my $onemodule = ${$modulesarrayref}[$i];
2912		my $styles = "";
2913		if ( $onemodule->{'Styles'} ) { $styles = $onemodule->{'Styles'}; }
2914		if ( $styles =~ /\b\Q$style\E\b/ )
2915		{
2916			push(@allmodules, $onemodule);
2917		}
2918	}
2919
2920	return \@allmodules;
2921}
2922
2923######################################################
2924# Remove modules without packagecontent.
2925######################################################
2926
2927sub remove_modules_without_package
2928{
2929	my ($allmodules) = @_;
2930
2931	my @allmodules = ();
2932
2933	for ( my $i = 0; $i <= $#{$allmodules}; $i++ )
2934	{
2935		my $onemodule = ${$allmodules}[$i];
2936		my $packagename = "";
2937		if ( $onemodule->{'PackageName'} ) { $packagename = $onemodule->{'PackageName'}; }
2938		if ( $packagename ne "" )
2939		{
2940			push(@allmodules, $onemodule);
2941		}
2942	}
2943
2944	return \@allmodules;
2945}
2946
2947######################################################
2948# Unpacking tar.gz file and setting new packagename.
2949######################################################
2950
2951sub unpack_tar_gz_file
2952{
2953	my ($packagename, $destdir) = @_;
2954
2955	my $newpackagename = "";
2956
2957	if ( $packagename =~ /\.tar\.gz\s*$/ )
2958	{
2959		# Collecting all packages in directory "packages"
2960		my $oldcontent = installer::systemactions::read_directory($destdir);
2961
2962		# unpacking gunzip
2963		my $systemcall = "cd $destdir; cat $packagename | gunzip | tar -xf -";
2964		make_systemcall($systemcall);
2965
2966		# deleting the tar.gz files
2967		$systemcall = "cd $destdir; rm -f $packagename";
2968		make_systemcall($systemcall);
2969
2970		# Finding new content -> that is the package name
2971		my ($newcontent, $allcontent ) = installer::systemactions::find_new_content_in_directory($destdir, $oldcontent);
2972		$newpackagename = ${$newcontent}[0];
2973		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$newpackagename);
2974	}
2975
2976	if ( $newpackagename ne "" ) { $packagename = $newpackagename; }
2977
2978	return $packagename;
2979}
2980
2981######################################################
2982# Copying files of child projects.
2983######################################################
2984
2985sub copy_childproject_files
2986{
2987	my ($allmodules, $sopackpath, $destdir, $modulesarrayref, $allvariables, $subdir, $includepatharrayref, $use_sopackpath) = @_;
2988
2989	for ( my $i = 0; $i <= $#{$allmodules}; $i++ )
2990	{
2991		my $localdestdir = $destdir;
2992		my $onemodule = ${$allmodules}[$i];
2993		my $packagename = $onemodule->{'PackageName'};
2994		my $sourcefile = "";
2995		if ( $use_sopackpath )
2996		{
2997			$sourcefile = $sopackpath . $installer::globals::separator . $installer::globals::compiler . $installer::globals::separator . $subdir . $installer::globals::separator . $packagename;
2998		}
2999		else
3000		{
3001			my $sourcepathref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$packagename, $includepatharrayref, 1);
3002			$sourcefile = $$sourcepathref;
3003		}
3004
3005		if ( ! -f $sourcefile ) { installer::exiter::exit_program("ERROR: File not found: $sourcefile ($packagename) !", "copy_childproject_files"); }
3006		if ( $onemodule->{'Subdir'} )
3007		{
3008			$localdestdir = $localdestdir . $installer::globals::separator . $onemodule->{'Subdir'};
3009			if ( ! -d $localdestdir ) { installer::systemactions::create_directory($localdestdir); }
3010		}
3011		installer::systemactions::copy_one_file($sourcefile, $localdestdir);
3012		# Solaris: unpacking tar.gz files and setting new packagename
3013		if ( $installer::globals::issolarispkgbuild ) { $packagename = unpack_tar_gz_file($packagename, $localdestdir); }
3014
3015		if (( $installer::globals::isxpdplatform ) && ( $allvariables->{'XPDINSTALLER'} ))
3016		{
3017			installer::xpdinstaller::create_xpd_file_for_childproject($onemodule, $localdestdir, $packagename, $allvariableshashref, $modulesarrayref);
3018		}
3019	}
3020
3021}
3022
3023######################################################
3024# Copying files for system integration.
3025######################################################
3026
3027sub copy_and_unpack_tar_gz_files
3028{
3029	my ($sourcefile, $destdir) = @_;
3030
3031	my $systemcall = "cd $destdir; cat $sourcefile | gunzip | tar -xf -";
3032	make_systemcall($systemcall);
3033}
3034
3035######################################################
3036# Including child packages into the
3037# installation set.
3038######################################################
3039
3040sub put_childprojects_into_installset
3041{
3042	my ($newdir, $allvariables, $modulesarrayref, $includepatharrayref) = @_;
3043
3044	my $infoline = "";
3045
3046	my $sopackpath = "";
3047	if ( $ENV{'SO_PACK'} ) { $sopackpath  = $ENV{'SO_PACK'}; }
3048	else { installer::exiter::exit_program("ERROR: Environment variable SO_PACK not set!", "put_childprojects_into_installset"); }
3049
3050	my $destdir = "$newdir";
3051
3052	# adding Java
3053
3054	my $sourcefile = "";
3055
3056	# Finding the modules defined in scp (with flag JAVAMODULE, ADAMODULE, ...)
3057	# Getting name of package from scp-Module
3058	# Copy file into installation set
3059	# Create xpd file and put it into xpd directory
3060	# xpd file has to be created completely from module and package itself (-> no packagelist!)
3061
3062	if ( $allvariables->{'JAVAPRODUCT'} )
3063	{
3064		# Collect all modules with flag "JAVAMODULE"
3065		my $allmodules = collect_modules_with_style("JAVAMODULE", $modulesarrayref);
3066		$allmodules = remove_modules_without_package($allmodules);
3067		copy_childproject_files($allmodules, $sopackpath, $destdir, $modulesarrayref, $allvariables, "jre", $includepatharrayref, 1);
3068	}
3069
3070	# Adding additional required packages (freetype).
3071	# This package names are stored in global array @installer::globals::requiredpackages
3072
3073	if ( $allvariables->{'ADDREQUIREDPACKAGES'} )
3074	{
3075		# Collect all modules with flag "REQUIREDPACKAGEMODULE"
3076		my $allmodules = collect_modules_with_style("REQUIREDPACKAGEMODULE", $modulesarrayref);
3077		$allmodules = remove_modules_without_package($allmodules);
3078		copy_childproject_files($allmodules, $sopackpath, $destdir, $modulesarrayref, $allvariables, "requiredpackages", $includepatharrayref, 1);
3079	}
3080
3081	# Collect all modules with flag "USERLANDMODULE"
3082	my $alluserlandmodules = collect_modules_with_style("USERLANDMODULE", $modulesarrayref);
3083	$alluserlandmodules = remove_modules_without_package($alluserlandmodules);
3084	copy_childproject_files($alluserlandmodules, $sopackpath, $destdir, $modulesarrayref, $allvariables, "", $includepatharrayref, 0);
3085
3086}
3087
3088######################################################
3089# Checking whether the new content is a directory and
3090# not a package. If it is a directory, the complete
3091# content of the directory has to be added to the
3092# array newcontent.
3093######################################################
3094
3095sub control_subdirectories
3096{
3097	my ($content, $subdir) = @_;
3098
3099	my @newcontent = ();
3100
3101	for ( my $i = 0; $i <= $#{$content}; $i++ )
3102	{
3103		if ( -d ${$content}[$i] )
3104		{
3105			$subdir = ${$content}[$i];
3106			installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$subdir);
3107			my $allpackages = installer::systemactions::read_directory(${$content}[$i]);
3108			for ( my $j = 0; $j <= $#{$allpackages}; $j++ )
3109			{
3110				# Currently only Linux rpm is supported, debian packages cannot be installed via xpd installer
3111				if (( $installer::globals::islinuxbuild ) && ( ! ( ${$allpackages}[$j] =~ /\.rpm\s*$/ ))) { next; }
3112				push(@newcontent, ${$allpackages}[$j]);
3113			}
3114		}
3115		else
3116		{
3117			push(@newcontent, ${$content}[$i]);
3118		}
3119	}
3120
3121	return (\@newcontent, $subdir);
3122}
3123
3124######################################################
3125# Including the system integration files into the
3126# installation sets.
3127######################################################
3128
3129sub put_systemintegration_into_installset
3130{
3131	my ($newdir, $includepatharrayref, $allvariables, $modulesarrayref) = @_;
3132
3133	my $destdir = $newdir;
3134
3135	# adding System integration files
3136
3137	my $sourcefile = "";
3138
3139	# Finding the modules defined in scp (with flag SYSTEMMODULE)
3140	# Getting name of package from scp-Module
3141	# Search package in list off all include files
3142	# Copy file into installation set and unpack it (always tar.gz)
3143	# Create xpd file and put it into xpd directory
3144	# tar.gz can contain a different number of packages -> automatically create hidden sub modules
3145	# xpd file has to be created completely from module and package itself (-> no packagelist!)
3146
3147	# Collect all modules with flag "SYSTEMMODULE"
3148	my $allmodules = collect_modules_with_style("SYSTEMMODULE", $modulesarrayref);
3149	$allmodules = remove_modules_without_package($allmodules);
3150
3151	for ( my $i = 0; $i <= $#{$allmodules}; $i++ )
3152	{
3153		my $onemodule = ${$allmodules}[$i];
3154		my $packagetarfilename = $onemodule->{'PackageName'};
3155
3156		my $infoline = "Including into installation set: $packagetarfilename\n";
3157		push( @installer::globals::logfileinfo, $infoline);
3158
3159		my $sourcepathref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$packagetarfilename, $includepatharrayref, 1);
3160		if ( $$sourcepathref eq "" ) { installer::exiter::exit_program("ERROR: Source path not found for $packagetarfilename!", "copy_systemintegration_files"); }
3161
3162		# Collecting all packages in directory "packages" or "RPMS"
3163		my $oldcontent = installer::systemactions::read_directory($destdir);
3164
3165		copy_and_unpack_tar_gz_files($$sourcepathref, $destdir);
3166
3167		# Finding new content -> that is the package name
3168		my ($newcontent, $allcontent ) = installer::systemactions::find_new_content_in_directory($destdir, $oldcontent);
3169
3170		# special handling, if new content is a directory
3171		my $subdir = "";
3172		if ( ! $installer::globals::issolarispkgbuild ) { ($newcontent, $subdir) = control_subdirectories($newcontent); }
3173
3174		# Adding license content into Solaris packages
3175		if (( $installer::globals::issolarispkgbuild ) && ( $installer::globals::englishlicenseset ) && ( ! $variableshashref->{'NO_LICENSE_INTO_COPYRIGHT'} )) { installer::worker::add_license_into_systemintegrationpackages($destdir, $newcontent); }
3176
3177		if (( $installer::globals::isxpdplatform ) && ( $allvariables->{'XPDINSTALLER'} ))
3178		{
3179			installer::xpdinstaller::create_xpd_file_for_systemintegration($onemodule, $newcontent, $modulesarrayref, $subdir);
3180		}
3181	}
3182}
3183
3184######################################################
3185# Analyzing the Unix installation path.
3186# From the installation path /opt/openofficeorg20
3187# is the part /opt relocatable and the part
3188# openofficeorg20 static.
3189######################################################
3190
3191sub analyze_rootpath
3192{
3193	my ($rootpath, $staticpathref, $relocatablepathref, $allvariables) = @_;
3194
3195	$rootpath =~ s/\/\s*$//;	# removing ending slash
3196
3197	##############################################################
3198	# Version 1: "/opt" is variable and "openofficeorg20" fixed
3199	##############################################################
3200
3201	# my $staticpath = $rootpath;
3202	# installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$staticpath);
3203	# $$staticpathref = $staticpath;				# will be "openofficeorg20"
3204
3205	# my $relocatablepath = $rootpath;
3206	# installer::pathanalyzer::get_path_from_fullqualifiedname(\$relocatablepath);
3207	# $$relocatablepathref = $relocatablepath;		# will be "/opt/"
3208
3209	##############################################################
3210	# Version 2: "/opt/openofficeorg20" is variable and "" fixed
3211	##############################################################
3212
3213	# if ( $$relocatablepathref eq "" )	# relocatablepath is not defined in package list
3214	# {
3215	#	$$staticpathref = "";	# will be ""
3216	#	$$relocatablepathref = $rootpath . "\/"; # relocatable path must end with "/", will be "/opt/openofficeorg20/"
3217	#	# setting the static path to the hostname of the directory with style OFFICEDIRECTORY
3218	#	if ( $allvariables->{'SETSTATICPATH'} ) { $$staticpathref = $installer::globals::officedirhostname; }
3219	#
3220	# }
3221	# else	# relocatablepath is defined in package list
3222	# {
3223	#	$$relocatablepathref =~ s/\/\s*$//;			# removing ending slash
3224	#	$$relocatablepathref = $$relocatablepathref . "\/";	# relocatable path must end with "/"
3225	#	my $staticpath = $rootpath;
3226	#	$staticpath =~ s/\Q$$relocatablepathref\E//;
3227	#	$staticpath =~ s/\/\s*$//;
3228	#	$$staticpathref = $staticpath;
3229	# }
3230
3231	##############################################################
3232	# Version 3: "/" is variable and "/opt/openofficeorg20" fixed
3233	##############################################################
3234
3235	$$relocatablepathref = "/";
3236	# Static path has to contain the office directory name. This is replaced in shellscripts.
3237	$$staticpathref = $rootpath . $installer::globals::separator . $installer::globals::officedirhostname;
3238	# For RPM version 3.x it is required, that Prefix is not "/" in spec file. In this case --relocate will not work,
3239	# because RPM 3.x says, that the package is not relocatable. Therefore we have to use Prefix=/opt and for
3240	# all usages of --relocate this path has to be on both sides of the "=": --relocate /opt=<myselectdir>/opt .
3241	if ( $installer::globals::islinuxrpmbuild )
3242	{
3243		$$relocatablepathref = $rootpath . "\/"; # relocatable path must end with "/", will be "/opt/"
3244		$$staticpathref = $installer::globals::officedirhostname; # to be used as replacement in shell scripts
3245	}
3246
3247	if ( $installer::globals::islinuxdebbuild )
3248	{
3249		$$relocatablepathref = "";
3250		# $$staticpathref is already "/opt/openoffice.org3", no additional $rootpath required.
3251		# $$staticpathref = $rootpath . $installer::globals::separator . $$staticpathref;  # no relocatibility for Debian
3252	}
3253
3254}
3255
3256######################################################
3257# Including license and readme into
3258# Unix installation sets.
3259######################################################
3260
3261sub put_installsetfiles_into_installset
3262{
3263	my ($destdir) = @_;
3264
3265	# All files for the installation set are saved in the global
3266	# array @installer::globals::installsetfiles
3267
3268	for ( my $i = 0; $i <= $#installer::globals::installsetfiles; $i++ )
3269	{
3270		my $onefile = $installer::globals::installsetfiles[$i];
3271		my $sourcefile = $onefile->{'sourcepath'};
3272		my $destfile = "";
3273		if ( $installer::globals::addjavainstaller ) { $destfile = $onefile->{'Name'}; }
3274		else { $destfile = $destdir . $installer::globals::separator . $onefile->{'Name'}; }
3275		installer::systemactions::copy_one_file($sourcefile, $destfile);
3276
3277		my $infoline = "Adding to installation set \"$destfile\" from source \"$sourcefile\".\n";
3278		push( @installer::globals::logfileinfo, $infoline);
3279	}
3280}
3281
3282######################################################
3283# Replacing one variable in patchinfo file
3284######################################################
3285
3286sub replace_one_variable_in_file
3287{
3288	my ( $file, $placeholder, $value ) = @_;
3289
3290	for ( my $i = 0; $i <= $#{$file}; $i++ )
3291	{
3292		${$file}[$i] =~ s/$placeholder/$value/g;
3293	}
3294}
3295
3296######################################################
3297# Setting variables in the patchinfo file
3298######################################################
3299
3300sub set_patchinfo
3301{
3302	my ( $patchinfofile, $patchid, $allvariables ) = @_;
3303
3304	# Setting: PATCHIDPLACEHOLDER and ARCHITECTUREPLACEHOLDER and PATCHCORRECTSPLACEHOLDER
3305
3306	replace_one_variable_in_file($patchinfofile, "PATCHIDPLACEHOLDER", $patchid);
3307
3308	my $architecture = "";
3309	if ( $installer::globals::issolarissparcbuild ) { $architecture = "sparc"; }
3310	if ( $installer::globals::issolarisx86build ) { $architecture = "i386"; }
3311
3312	replace_one_variable_in_file($patchinfofile, "ARCHITECTUREPLACEHOLDER", $architecture);
3313
3314	if ( ! $allvariables->{'SOLARISPATCHCORRECTS'} ) { installer::exiter::exit_program("ERROR: No setting for PATCH_CORRECTS in zip list file!", "set_patchinfo"); }
3315	my $patchcorrects = $allvariables->{'SOLARISPATCHCORRECTS'};
3316
3317	replace_one_variable_in_file($patchinfofile, "PATCHCORRECTSPLACEHOLDER", $patchcorrects);
3318
3319	# Setting also PATCH_REQUIRES in patch info file, if entry in zip list file exists
3320	my $requiresstring = "";
3321	if ( $installer::globals::issolarissparcbuild ) { $requiresstring = "SOLSPARCPATCHREQUIRES"; }
3322	if ( $installer::globals::issolarisx86build ) { $requiresstring = "SOLIAPATCHREQUIRES"; }
3323
3324	if ( $allvariables->{$requiresstring} )
3325	{
3326		my $newline = "PATCH_REQUIRES=\"" . $allvariables->{$requiresstring} . "\"" . "\n";
3327		push(@{$patchinfofile}, $newline);
3328	}
3329}
3330
3331######################################################
3332# Finalizing patch: Renaming directory and
3333# including additional patch files.
3334######################################################
3335
3336sub finalize_patch
3337{
3338	my ( $newepmdir, $allvariables ) = @_;
3339
3340	my $patchidname = "SOLSPARCPATCHID";
3341	if ( $installer::globals::issolarisx86build ) { $patchidname = "SOLIAPATCHID"; }
3342
3343	if ( ! $allvariables->{$patchidname} ) { installer::exiter::exit_program("ERROR: Variable $patchidname not defined in zip list file!", "finalize_patch"); }
3344	my $patchid = $allvariables->{$patchidname};
3345	installer::systemactions::rename_directory($newepmdir, $patchid);
3346
3347	# Copying all typical patch files into the patch directory
3348	# All patch file names are stored in @installer::globals::solarispatchfiles
3349	# Location of the file is $installer::globals::patchincludepath
3350
3351	my $sourcepath = $installer::globals::patchincludepath;
3352	$sourcepath =~ s/\/\s*$//;
3353
3354	for ( my $i = 0; $i <= $#installer::globals::solarispatchfiles; $i++ )
3355	{
3356		my $sourcefile = $sourcepath . $installer::globals::separator . $installer::globals::solarispatchfiles[$i];
3357		my $destfile = $patchid . $installer::globals::separator . $installer::globals::solarispatchfiles[$i];
3358		installer::systemactions::copy_one_file($sourcefile, $destfile);
3359	}
3360
3361	# And editing the patchinfo file
3362
3363	my $patchinfofilename = $patchid . $installer::globals::separator . "patchinfo";
3364	my $patchinfofile = installer::files::read_file($patchinfofilename);
3365	set_patchinfo($patchinfofile, $patchid, $allvariables);
3366	installer::files::save_file($patchinfofilename, $patchinfofile);
3367}
3368
3369######################################################
3370# Finalizing Linux patch: Renaming directory and
3371# including additional patch files.
3372######################################################
3373
3374sub finalize_linux_patch
3375{
3376	my ( $newepmdir, $allvariables, $includepatharrayref ) = @_;
3377
3378	# Copying the setup into the patch directory
3379	# and including the list of RPMs into it
3380
3381	print "... creating patch setup ...\n";
3382
3383	installer::logger::include_header_into_logfile("Creating Linux patch setup:");
3384
3385	# find and read setup script template
3386
3387	my $scriptfilename = "linuxpatchscript.sh";
3388	my $scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$scriptfilename, $includepatharrayref, 0);
3389	if ($$scriptref eq "") { installer::exiter::exit_program("ERROR: Could not find patch script template $scriptfilename!", "finalize_linux_patch"); }
3390	my $scriptfile = installer::files::read_file($$scriptref);
3391
3392	my $infoline = "Found  script file $scriptfilename: $$scriptref \n";
3393	push( @installer::globals::logfileinfo, $infoline);
3394
3395	# Collecting all RPMs in the patch directory
3396
3397	my $fileextension = "rpm";
3398	my $rpmfiles = installer::systemactions::find_file_with_file_extension($fileextension, $newepmdir);
3399	if ( ! ( $#{$rpmfiles} > -1 )) { installer::exiter::exit_program("ERROR: Could not find rpm in directory $newepmdir!", "finalize_linux_patch"); }
3400	for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$rpmfiles}[$i]); }
3401
3402#	my $installline = "";
3403#
3404#	for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ )
3405#	{
3406#		$installline = $installline . "  rpm --prefix \$PRODUCTINSTALLLOCATION -U $newepmdir/${$rpmfiles}[$i]\n";
3407#	}
3408#
3409#	$installline =~ s/\s*$//;
3410#
3411#	for ( my $j = 0; $j <= $#{$scriptfile}; $j++ )
3412#	{
3413#		${$scriptfile}[$j] =~ s/INSTALLLINES/$installline/;
3414#	}
3415
3416	# Searching packagename containing -core01
3417	my $found_package = 0;
3418	my $searchpackagename = "";
3419	for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ )
3420	{
3421		if ( ${$rpmfiles}[$i] =~ /-core01-/ )
3422		{
3423			$searchpackagename = ${$rpmfiles}[$i];
3424			$found_package = 1;
3425			if ( $searchpackagename =~ /^\s*(.*?-core01)-.*/ ) { $searchpackagename = $1; }
3426			last;
3427		}
3428	}
3429
3430	if ( ! $found_package ) { installer::exiter::exit_program("ERROR: No package containing \"-core01\" found in directory \"$newepmdir\"", "finalize_linux_patch"); }
3431
3432	# Replacing the searchpackagename
3433	for ( my $j = 0; $j <= $#{$scriptfile}; $j++ ) { ${$scriptfile}[$j] =~ s/SEARCHPACKAGENAMEPLACEHOLDER/$searchpackagename/; }
3434
3435	# Setting the PRODUCTDIRECTORYNAME to $installer::globals::officedirhostname
3436	for ( my $j = 0; $j <= $#{$scriptfile}; $j++ ) { ${$scriptfile}[$j] =~ s/PRODUCTDIRECTORYNAME/$installer::globals::officedirhostname/; }
3437
3438	# Replacing the productname
3439	my $productname = $allvariables->{'PRODUCTNAME'};
3440	$productname = lc($productname);
3441	$productname =~ s/ /_/g;	# abc office -> abc_office
3442#	$productname =~ s/\.//g;	# openoffice.org -> openofficeorg
3443
3444	$infoline = "Adding productname $productname into Linux patch script\n";
3445	push( @installer::globals::logfileinfo, $infoline);
3446
3447	for ( my $j = 0; $j <= $#{$scriptfile}; $j++ ) { ${$scriptfile}[$j] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/; }
3448
3449	# Saving the file
3450
3451	my $newscriptfilename = "setup"; # $newepmdir . $installer::globals::separator . "setup";
3452	installer::files::save_file($newscriptfilename, $scriptfile);
3453
3454	$infoline = "Saved Linux patch setup $newscriptfilename \n";
3455	push( @installer::globals::logfileinfo, $infoline);
3456
3457	# Setting unix rights 755
3458	my $localcall = "chmod 775 $newscriptfilename \>\/dev\/null 2\>\&1";
3459	system($localcall);
3460}
3461
34621;
3463