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