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