tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / solenv / bin / modules / installer / epmfile.pm
blob0b2caf1fff37cde6ce27c5a95f7fdfa6da846c41
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer::epmfile;
21 use strict;
22 use warnings;
24 use Cwd qw();
25 use installer::converter;
26 use installer::exiter;
27 use installer::files;
28 use installer::globals;
29 use installer::logger;
30 use installer::packagelist;
31 use installer::pathanalyzer;
32 use installer::remover;
33 use installer::scpzipfiles;
34 use installer::scriptitems;
35 use installer::systemactions;
36 use POSIX;
38 # please Debian packaging, fdo#53341
39 sub debian_rewrite($)
41 my $dep = shift;
42 if ( $installer::globals::debian ) {
43 $dep =~ s/_/-/g; # Debian allows no underline in package name
44 $dep = lc ($dep);
46 return $dep;
49 ############################################################################
50 # Reading the package map to find Solaris package names for
51 # the corresponding abbreviations
52 ############################################################################
54 sub read_packagemap
56 my ($allvariables, $includepatharrayref, $languagesarrayref) = @_;
58 my $packagemapname = "";
59 if ( $allvariables->{'PACKAGEMAP'} ) { $packagemapname = $allvariables->{'PACKAGEMAP'}; }
60 if ( $packagemapname eq "" ) { installer::exiter::exit_program("ERROR: Property PACKAGEMAP must be defined!", "read_packagemap"); }
62 my $infoline = "\n\nCollected abbreviations and package names:\n";
63 push(@installer::globals::logfileinfo, $infoline);
65 # Can be a comma separated list. All files have to be found in include paths
66 my $allpackagemapnames = installer::converter::convert_stringlist_into_hash(\$packagemapname, ",");
67 foreach my $onepackagemapname ( keys %{$allpackagemapnames} )
69 my $packagemapref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$onepackagemapname, $includepatharrayref, 0);
71 if ( $$packagemapref eq "" ) { installer::exiter::exit_program("ERROR: Could not find package map file \"$onepackagemapname\" (property PACKAGEMAP)!", "read_packagemap"); }
73 my $packagemapcontent = installer::files::read_file($$packagemapref);
75 for ( my $i = 0; $i <= $#{$packagemapcontent}; $i++ )
77 my $line = ${$packagemapcontent}[$i];
79 if ( $line =~ /^\s*\#/ ) { next; } # comment line
80 if ( $line =~ /^\s*$/ ) { next; } # empty line
82 if ( $line =~ /^\s*(.*?)\t(.*?)\s*$/ )
84 my $abbreviation = $1;
85 my $packagename = $2;
86 installer::packagelist::resolve_packagevariables(\$abbreviation, $allvariables, 0);
87 installer::packagelist::resolve_packagevariables(\$packagename, $allvariables, 0);
89 # Special handling for language strings %LANGUAGESTRING
91 if (( $abbreviation =~ /\%LANGUAGESTRING/ ) || ( $packagename =~ /\%LANGUAGESTRING/ ))
93 foreach my $onelang ( @{$languagesarrayref} )
95 my $local_abbreviation = $abbreviation;
96 my $local_packagename = $packagename;
97 $local_abbreviation =~ s/\%LANGUAGESTRING/$onelang/g;
98 $local_packagename =~ s/\%LANGUAGESTRING/$onelang/g;
100 # Logging all abbreviations and packagenames
101 $infoline = "$onelang : $local_abbreviation : $local_packagename\n";
102 push(@installer::globals::logfileinfo, $infoline);
104 if ( exists($installer::globals::dependfilenames{$local_abbreviation}) )
106 installer::exiter::exit_program("ERROR: Packagename for Solaris package $local_abbreviation already defined ($installer::globals::dependfilenames{$local_abbreviation})!", "read_packagemap");
108 else
110 $installer::globals::dependfilenames{$local_abbreviation} = $local_packagename;
114 else
116 # Logging all abbreviations and packagenames
117 $infoline = "$abbreviation : $packagename\n";
118 push(@installer::globals::logfileinfo, $infoline);
120 if ( exists($installer::globals::dependfilenames{$abbreviation}) )
122 installer::exiter::exit_program("ERROR: Packagename for Solaris package $abbreviation already defined ($installer::globals::dependfilenames{$abbreviation})!", "read_packagemap");
124 else
126 $installer::globals::dependfilenames{$abbreviation} = $packagename;
130 else
132 my $errorline = $i + 1;
133 installer::exiter::exit_program("ERROR: Wrong syntax in file \"$onepackagemapname\" (line $errorline)!", "read_packagemap");
138 $infoline = "\n\n";
139 push(@installer::globals::logfileinfo, $infoline);
143 ##########################################################
144 # Filling the epm file with directories, files and links
145 ##########################################################
147 sub put_directories_into_epmfile
149 my ($directoriesarrayref, $epmfileref, $allvariables, $packagerootpath) = @_;
150 my $group = "bin";
152 if ( $installer::globals::islinuxbuild )
154 $group = "root";
157 for ( my $i = 0; $i <= $#{$directoriesarrayref}; $i++ )
159 my $onedir = ${$directoriesarrayref}[$i];
160 my $dir = "";
162 if ( $onedir->{'Dir'} ) { $dir = $onedir->{'Dir'}; }
164 if ((!($dir =~ /\bPREDEFINED_/ )) || ( $dir =~ /\bPREDEFINED_PROGDIR\b/ ))
166 my $hostname = $onedir->{'HostName'};
168 my $line = "d 755 root $group $hostname -\n";
170 push(@{$epmfileref}, $line)
175 sub put_files_into_epmfile
177 my ($filesinproductarrayref, $epmfileref) = @_;
179 for ( my $i = 0; $i <= $#{$filesinproductarrayref}; $i++ )
181 my $onefile = ${$filesinproductarrayref}[$i];
183 my $unixrights = $onefile->{'UnixRights'};
184 my $destination = $onefile->{'destination'};
185 my $sourcepath = $onefile->{'sourcepath'};
187 my $filetype = "f";
188 my $styles = "";
189 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
190 if ( $styles =~ /\bCONFIGFILE\b/ ) { $filetype = "c"; }
192 my $group = "bin";
193 if ( $installer::globals::islinuxbuild ) { $group = "root"; }
194 if (( $installer::globals::issolarisbuild ) && ( $onefile->{'SolarisGroup'} )) { $group = $onefile->{'SolarisGroup'}; }
196 my $line = "$filetype $unixrights root $group $destination $sourcepath\n";
198 push(@{$epmfileref}, $line);
202 sub put_links_into_epmfile
204 my ($linksinproductarrayref, $epmfileref) = @_;
205 my $group = "bin";
207 if ( $installer::globals::islinuxbuild )
209 $group = "root";
213 for ( my $i = 0; $i <= $#{$linksinproductarrayref}; $i++ )
215 my $onelink = ${$linksinproductarrayref}[$i];
216 my $destination = $onelink->{'destination'};
217 my $destinationfile = $onelink->{'destinationfile'};
219 my $line = "l 000 root $group $destination $destinationfile\n";
221 push(@{$epmfileref}, $line)
225 sub put_unixlinks_into_epmfile
227 my ($unixlinksinproductarrayref, $epmfileref) = @_;
228 my $group = "bin";
230 if ( $installer::globals::islinuxbuild ) { $group = "root"; }
232 for ( my $i = 0; $i <= $#{$unixlinksinproductarrayref}; $i++ )
234 my $onelink = ${$unixlinksinproductarrayref}[$i];
235 my $destination = $onelink->{'destination'};
236 my $target = $onelink->{'Target'};
238 my $line = "l 000 root $group $destination $target\n";
240 push(@{$epmfileref}, $line)
244 ###############################################
245 # Creating epm header file
246 ###############################################
248 sub create_epm_header
250 my ($variableshashref, $filesinproduct, $languagesref, $onepackage) = @_;
252 my @epmheader = ();
254 my ($licensefilename, $readmefilename, $readmefilenameen);
256 my $foundlicensefile = 0;
257 my $foundreadmefile = 0;
259 my $line = "";
260 my $infoline = "";
262 # %product LibreOffice Software
263 # %version 2.0
264 # %description A really great software
265 # %copyright 1999-2003 by OOo
266 # %vendor LibreOffice
267 # %license /test/replace/01/LICENSE01
268 # %readme /test/replace/01/README01
269 # %requires foo
270 # %provides bar
271 # %replaces bar
272 # %incompat bar
274 # The first language in the languages array determines the language of license and readme file
276 my $searchlanguage = ${$languagesref}[0];
278 # using the description for the %product line in the epm list file
280 my $productnamestring = $onepackage->{'description'};
281 installer::packagelist::resolve_packagevariables(\$productnamestring, $variableshashref, 0);
282 if ( $variableshashref->{'PRODUCTEXTENSION'} ) { $productnamestring = $productnamestring . $variableshashref->{'PRODUCTEXTENSION'}; }
284 $line = "%product" . " " . $productnamestring . "\n";
285 push(@epmheader, $line);
287 # Determining the release version
288 # This release version has to be listed in the line %version : %version versionnumber releasenumber
290 if ( ! $onepackage->{'packageversion'} ) { installer::exiter::exit_program("ERROR: No packageversion defined for package: $onepackage->{'module'}!", "create_epm_header"); }
291 $installer::globals::packageversion = $onepackage->{'packageversion'};
292 installer::packagelist::resolve_packagevariables(\$installer::globals::packageversion, $variableshashref, 0);
293 if ( $variableshashref->{'PACKAGEREVISION'} ) { $installer::globals::packagerevision = $variableshashref->{'PACKAGEREVISION'}; }
295 $line = "%version" . " " . $installer::globals::packageversion . "\n";
296 push(@epmheader, $line);
298 $line = "%release" . " " . $installer::globals::packagerevision . "\n";
299 if ( $installer::globals::isrpmbuild ) { $line = "%release" . " " . $installer::globals::buildid . "\n"; }
300 push(@epmheader, $line);
302 # Description, Copyright and Vendor are multilingual and are defined in
303 # the string file for the header file ($headerfileref)
305 my $descriptionstring = $onepackage->{'description'};
306 installer::packagelist::resolve_packagevariables(\$descriptionstring, $variableshashref, 0);
307 $line = "%description" . " " . $descriptionstring . "\n";
308 push(@epmheader, $line);
310 my $copyrightstring = $onepackage->{'copyright'};
311 installer::packagelist::resolve_packagevariables(\$copyrightstring, $variableshashref, 0);
312 $line = "%copyright" . " " . $copyrightstring . "\n";
313 push(@epmheader, $line);
315 my $vendorstring = $onepackage->{'vendor'};
316 installer::packagelist::resolve_packagevariables(\$vendorstring, $variableshashref, 0);
317 $line = "%vendor" . " " . $vendorstring . "\n";
318 push(@epmheader, $line);
320 # License and Readme file can be included automatically from the file list
322 if ( $installer::globals::iswindowsbuild )
324 $licensefilename = "license.txt";
325 $readmefilename = "readme.txt";
326 $readmefilenameen = "readme_en-US.txt";
328 else
330 $licensefilename = "LICENSE";
331 $readmefilename = "README";
332 $readmefilenameen = "README_en-US";
335 if (( $installer::globals::languagepack ) # in language packs and help packs the files LICENSE and README are removed, because they are not language specific
336 || ( $installer::globals::helppack )
337 || ( $variableshashref->{'NO_README_IN_ROOTDIR'} ))
339 if ( $installer::globals::iswindowsbuild )
341 $licensefilename = "license.txt";
342 $readmefilename = "readme_$searchlanguage.txt";
344 else
346 $licensefilename = "LICENSE";
347 $readmefilename = "README_$searchlanguage";
351 my $license_in_package_defined = 0;
353 if ( $installer::globals::issolarisbuild )
355 if ( $onepackage->{'solariscopyright'} )
357 $licensefilename = $onepackage->{'solariscopyright'};
358 $license_in_package_defined = 1;
362 # Process for Linux packages, in which only a very basic license file is
363 # included into the package.
365 if ( $installer::globals::islinuxbuild )
367 if ( $variableshashref->{'COPYRIGHT_INTO_LINUXPACKAGE'} )
369 $licensefilename = "linuxcopyrightfile";
370 $license_in_package_defined = 1;
374 # searching for and readme file;
375 # URE uses special README; others use README_en-US
376 # it does not matter which one is passed for epm if both are packaged
377 foreach my $possiblereadmefilename ($readmefilenameen, $readmefilename)
379 last if ($foundreadmefile);
380 for ( my $i = 0; $i <= $#{$filesinproduct}; $i++ )
382 my $onefile = ${$filesinproduct}[$i];
383 my $filename = $onefile->{'Name'};
384 # in the SDK it's in subdirectory sdk/share/readme
385 if ( $filename =~ /$possiblereadmefilename$/ )
387 $foundreadmefile = 1;
388 $line = "%readme" . " " . $onefile->{'sourcepath'} . "\n";
389 push(@epmheader, $line);
390 last;
395 # the readme file need not be packaged more times in the help content
396 # it needs to be installed in parallel with the main package anyway
397 # try to find the README file between all available files (not only between the packaged)
398 if (!($foundreadmefile) && $installer::globals::helppack)
400 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$readmefilenameen, "" , 0);
401 if($$fileref ne "" )
403 $infoline = "Fallback to readme file: \"$$fileref\"!\n";
404 push(@installer::globals::logfileinfo, $infoline);
406 $foundreadmefile = 1;
407 $line = "%readme" . " " . $$fileref . "\n";
408 push(@epmheader, $line);
412 # searching for and license file
414 if ( $license_in_package_defined )
416 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, "" , 0);
418 if ( $$fileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find license file $licensefilename (A)!", "create_epm_header"); }
420 # Special handling to add the content of the file "license_en-US" to the solaris copyrightfile. But not for all products
422 if (( $installer::globals::issolarispkgbuild ) && ( ! $variableshashref->{'NO_LICENSE_INTO_COPYRIGHT'} ))
424 if ( ! $installer::globals::englishlicenseset ) { _set_english_license($variableshashref) }
426 # The location for the new file
427 my $languagestring = "";
428 for ( my $i = 0; $i <= $#{$languagesref}; $i++ ) { $languagestring = $languagestring . "_" . ${$languagesref}[$i]; }
429 $languagestring =~ s/^\s*_//;
431 my $copyrightdir = installer::systemactions::create_directories("copyright", \$languagestring);
433 my $copyrightfile = installer::files::read_file($$fileref);
435 # Adding license content to copyright file
436 push(@{$copyrightfile}, "\n");
437 for ( my $i = 0; $i <= $#{$installer::globals::englishlicense}; $i++ ) { push(@{$copyrightfile}, ${$installer::globals::englishlicense}[$i]); }
439 # New destination for $$fileref
440 $$fileref = $copyrightdir . $installer::globals::separator . "solariscopyrightfile_" . $onepackage->{'module'};
441 if ( -f $$fileref ) { unlink $$fileref; }
442 installer::files::save_file($$fileref, $copyrightfile);
445 $infoline = "Using license file: \"$$fileref\"!\n";
446 push(@installer::globals::logfileinfo, $infoline);
448 $foundlicensefile = 1;
449 $line = "%license" . " " . $$fileref . "\n";
450 push(@epmheader, $line);
452 else
454 for my $onefile (@{$filesinproduct})
456 # in the SDK it's in subdirectory sdk/share/readme so try to match that
457 if ($onefile->{'Name'} =~ /$licensefilename$/)
459 push @epmheader, "%license" . " " . $onefile->{'sourcepath'} . "\n";
460 $foundlicensefile = 1;
461 last;
465 # the license file need not be packaged more times in the langpacks
466 # they need to be installed in parallel with the main package anyway
467 # try to find the LICENSE file between all available files (not only between the packaged)
468 if (!($foundlicensefile) && ($installer::globals::languagepack || $installer::globals::helppack))
470 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, "" , 0);
471 if($$fileref ne "" )
473 $infoline = "Fallback to license file: \"$$fileref\"!\n";
474 push(@installer::globals::logfileinfo, $infoline);
476 $foundlicensefile = 1;
477 $line = "%license" . " " . $$fileref . "\n";
478 push(@epmheader, $line);
483 if (!($foundlicensefile))
485 installer::exiter::exit_program("ERROR: Could not find license file $licensefilename (B)", "create_epm_header");
488 if (!($foundreadmefile))
490 installer::exiter::exit_program("ERROR: Could not find readme file $readmefilename (C)", "create_epm_header");
493 # including %replaces
495 my $replaces = "";
497 if ( $installer::globals::issolarispkgbuild )
499 $replaces = "solarisreplaces"; # the name in the packagelist
501 elsif ( $installer::globals::islinuxbuild )
503 $replaces = "linuxreplaces"; # the name in the packagelist
506 if ( $replaces )
508 if ( $onepackage->{$replaces} )
510 my $replacesstring = $onepackage->{$replaces};
512 my $allreplaces = installer::converter::convert_stringlist_into_array(\$replacesstring, ",");
514 for ( my $i = 0; $i <= $#{$allreplaces}; $i++ )
516 my $onereplaces = ${$allreplaces}[$i];
517 $onereplaces =~ s/\s*$//;
518 installer::packagelist::resolve_packagevariables(\$onereplaces, $variableshashref, 1);
519 $onereplaces = debian_rewrite($onereplaces);
520 $line = "%replaces" . " " . $onereplaces . "\n";
521 push(@epmheader, $line);
526 # including %incompat
528 my $incompat = "";
530 if (( $installer::globals::issolarispkgbuild ) && ( ! $installer::globals::patch ))
532 $incompat = "solarisincompat"; # the name in the packagelist
534 elsif (( $installer::globals::islinuxbuild ) && ( ! $installer::globals::patch ))
536 $incompat = "linuxincompat"; # the name in the packagelist
539 if (( $incompat ) && ( ! $installer::globals::patch ))
541 if ( $onepackage->{$incompat} )
543 my $incompatstring = $onepackage->{$incompat};
545 my $allincompat = installer::converter::convert_stringlist_into_array(\$incompatstring, ",");
547 for ( my $i = 0; $i <= $#{$allincompat}; $i++ )
549 my $oneincompat = ${$allincompat}[$i];
550 $oneincompat =~ s/\s*$//;
551 installer::packagelist::resolve_packagevariables(\$oneincompat, $variableshashref, 1);
552 $oneincompat = debian_rewrite($oneincompat);
553 $line = "%incompat" . " " . $oneincompat . "\n";
554 push(@epmheader, $line);
559 # including the directives for %requires and %provides
561 my $provides = "";
562 my $requires = "";
564 if ( $installer::globals::issolarispkgbuild )
566 $provides = "solarisprovides"; # the name in the packagelist
567 $requires = "solarisrequires"; # the name in the packagelist
569 elsif ( $installer::globals::isfreebsdpkgbuild )
571 $provides = "freebsdprovides"; # the name in the packagelist
572 $requires = "freebsdrequires"; # the name in the packagelist
574 else
576 $provides = "provides"; # the name in the packagelist
577 $requires = "requires"; # the name in the packagelist
580 my $isdict = 0;
581 if ( $onepackage->{'packagename'} =~ /-dict-/ ) { $isdict = 1; }
583 if ( $onepackage->{$provides} )
585 my $providesstring = $onepackage->{$provides};
587 my $allprovides = installer::converter::convert_stringlist_into_array(\$providesstring, ",");
589 for ( my $i = 0; $i <= $#{$allprovides}; $i++ )
591 my $oneprovides = ${$allprovides}[$i];
592 $oneprovides =~ s/\s*$//;
593 installer::packagelist::resolve_packagevariables(\$oneprovides, $variableshashref, 1);
594 $oneprovides = debian_rewrite($oneprovides);
595 $line = "%provides" . " " . $oneprovides . "\n";
596 push(@epmheader, $line);
600 if ( $onepackage->{$requires} )
602 my $requiresstring = $onepackage->{$requires};
604 # The requires string can contain the separator "," in the names (descriptions) of the packages
605 # (that are required for Solaris depend files). Therefore "," inside such a description has to
606 # masked with a backslash.
607 # This masked separator need to be found and replaced, before the stringlist is converted into an array.
608 # This replacement has to be turned back after the array is created.
610 my $replacementstring = "COMMAREPLACEMENT";
611 $requiresstring = installer::converter::replace_masked_separator($requiresstring, ",", "$replacementstring");
613 my $allrequires = installer::converter::convert_stringlist_into_array(\$requiresstring, ",");
615 installer::converter::resolve_masked_separator($allrequires, ",", $replacementstring);
617 for ( my $i = 0; $i <= $#{$allrequires}; $i++ )
619 my $onerequires = ${$allrequires}[$i];
620 $onerequires =~ s/\s*$//;
621 installer::packagelist::resolve_packagevariables2(\$onerequires, $variableshashref, 0, $isdict);
622 $onerequires = debian_rewrite($onerequires);
623 $line = "%requires" . " " . $onerequires . "\n";
624 push(@epmheader, $line);
628 return \@epmheader;
631 #######################################
632 # Adding header to epm file
633 #######################################
635 sub adding_header_to_epm_file
637 my ($epmfileref, $epmheaderref) = @_;
639 for ( my $i = 0; $i <= $#{$epmheaderref}; $i++ )
641 push( @{$epmfileref}, ${$epmheaderref}[$i] );
644 push( @{$epmfileref}, "\n\n" );
647 #####################################################
648 # Replace one in shell scripts ( ${VARIABLENAME} )
649 #####################################################
651 sub replace_variable_in_shellscripts
653 my ($scriptref, $variable, $searchstring) = @_;
655 for ( my $i = 0; $i <= $#{$scriptref}; $i++ )
657 ${$scriptref}[$i] =~ s/\$\{$searchstring\}/$variable/g;
661 ################################################
662 # Replacing many variables in shell scripts
663 ################################################
665 sub replace_many_variables_in_shellscripts
667 my ($scriptref, $variableshashref) = @_;
669 my $key;
671 foreach $key (keys %{$variableshashref})
673 my $value = $variableshashref->{$key};
674 replace_variable_in_shellscripts($scriptref, $value, $key);
678 #######################################
679 # Adding shell scripts to epm file
680 #######################################
682 sub adding_shellscripts_to_epm_file
684 my ($epmfileref, $shellscriptsfilename, $localrootpath, $allvariableshashref, $filesinpackage) = @_;
686 push( @{$epmfileref}, "\n\n" );
688 my $shellscriptsfileref = installer::files::read_file($shellscriptsfilename);
690 replace_variable_in_shellscripts($shellscriptsfileref, $localrootpath, "rootpath");
692 replace_many_variables_in_shellscripts($shellscriptsfileref, $allvariableshashref);
694 for ( my $i = 0; $i <= $#{$shellscriptsfileref}; $i++ )
696 push( @{$epmfileref}, ${$shellscriptsfileref}[$i] );
699 push( @{$epmfileref}, "\n" );
702 #################################################
703 # Determining the epm on the system
704 #################################################
706 sub find_epm_on_system
708 my ($includepatharrayref) = @_;
710 installer::logger::include_header_into_logfile("Check epm on system");
712 my $epmname = "epm";
714 # epm should be defined through the configure script but we need to
715 # check for it to be defined because of the Sun environment.
716 # Check the environment variable first and if it is not defined,
717 # or if it is but the location is not executable, search further.
718 # It has to be found in the solver or it has to be in the path
719 # (saved in $installer::globals::epm_in_path) or we get the specified
720 # one through the environment (i.e. when --with-epm=... is specified)
722 if ($ENV{'EPM'})
724 if (($ENV{'EPM'} ne "") && (-x "$ENV{'EPM'}"))
726 $epmname = $ENV{'EPM'};
728 else
730 installer::exiter::exit_program("Environment variable EPM set (\"$ENV{'EPM'}\"), but file does not exist or is not executable!", "find_epm_on_system");
733 else
735 my $epmfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$epmname, $includepatharrayref, 0);
737 if (($$epmfileref eq "") && (!($installer::globals::epm_in_path))) { installer::exiter::exit_program("ERROR: Could not find program $epmname!", "find_epm_on_system"); }
738 if (($$epmfileref eq "") && ($installer::globals::epm_in_path)) { $epmname = $installer::globals::epm_path; }
739 if (!($$epmfileref eq "")) { $epmname = $$epmfileref; }
742 my $infoline = "Using epmfile: $epmname\n";
743 push( @installer::globals::logfileinfo, $infoline);
745 return $epmname;
748 #################################################
749 # Determining the epm patch state
750 # saved in $installer::globals::is_special_epm
751 #################################################
753 sub set_patch_state
755 my ($epmexecutable) = @_;
757 my $infoline = "";
759 my $systemcall = "$epmexecutable |";
760 open (EPMPATCH, "$systemcall");
762 while (<EPMPATCH>)
764 chop;
765 if ( $_ =~ /Patched for .*Office/ ) { $installer::globals::is_special_epm = 1; }
768 close (EPMPATCH);
770 if ( $installer::globals::is_special_epm )
772 $infoline = "\nPatch state: This is a patched version of epm!\n\n";
773 push( @installer::globals::logfileinfo, $infoline);
775 else
777 $infoline = "\nPatch state: This is an unpatched version of epm!\n\n";
778 push( @installer::globals::logfileinfo, $infoline);
781 if ( ( $installer::globals::is_special_epm ) && (($installer::globals::isrpmbuild) || ($installer::globals::issolarispkgbuild)) )
783 # Special postprocess handling only for Linux RPM and Solaris packages
784 $installer::globals::postprocess_specialepm = 1;
785 $installer::globals::postprocess_standardepm = 0;
787 else
789 $installer::globals::postprocess_specialepm = 0;
790 $installer::globals::postprocess_standardepm = 1;
794 #################################################
795 # Calling epm to create the installation sets
796 #################################################
798 sub call_epm
800 my ($epmname, $epmlistfilename, $packagename, $includepatharrayref) = @_;
802 installer::logger::include_header_into_logfile("epm call for $packagename");
804 my $packageformat = $installer::globals::packageformat;
806 my $localpackagename = $packagename;
807 # Debian allows only lowercase letters in package name
808 if ( $installer::globals::debian ) { $localpackagename = lc($localpackagename); }
810 my $outdirstring = "";
811 if ( $installer::globals::epmoutpath ne "" ) { $outdirstring = " --output-dir $installer::globals::epmoutpath"; }
813 # Debian package build needs to be run with fakeroot for correct ownerships/permissions
815 my $fakerootstring = "";
817 if ( $installer::globals::debian ) { $fakerootstring = "fakeroot "; }
819 my $extraflags = "";
820 if ($ENV{'EPM_FLAGS'}) { $extraflags = $ENV{'EPM_FLAGS'}; }
822 $extraflags .= ' -g' unless $installer::globals::strip;
824 my $verboseflag = "-v";
825 if ( ! $installer::globals::quiet ) { $verboseflag = "-v2"; };
827 my $systemcall = $fakerootstring . $epmname . " -f " . $packageformat . " " . $extraflags . " " . $localpackagename . " " . $epmlistfilename . $outdirstring . " " . $verboseflag . " " . " 2\>\&1 |";
829 installer::logger::print_message( "... $systemcall ...\n" );
831 my $maxepmcalls = 3;
833 for ( my $i = 1; $i <= $maxepmcalls; $i++ )
835 my @epmoutput = ();
837 open (EPM, "$systemcall");
838 while (<EPM>) {push(@epmoutput, $_); }
839 close (EPM);
841 my $returnvalue = $?; # $? contains the return value of the systemcall
843 my $infoline = "Systemcall (Try $i): $systemcall\n";
844 push( @installer::globals::logfileinfo, $infoline);
846 for ( my $j = 0; $j <= $#epmoutput; $j++ )
848 if ( $i < $maxepmcalls ) { $epmoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; }
849 push( @installer::globals::logfileinfo, "$epmoutput[$j]");
852 if ($returnvalue)
854 $infoline = "Try $i : Could not execute \"$systemcall\"!\n";
855 push( @installer::globals::logfileinfo, $infoline);
856 if ( $i == $maxepmcalls ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "call_epm"); }
858 else
860 installer::logger::print_message( "Success (Try $i): \"$systemcall\"\n" );
861 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
862 push( @installer::globals::logfileinfo, $infoline);
863 last;
868 #####################################################################
869 # Adding the new line for relocatables into pkginfo file (Solaris)
870 # or spec file (Linux) created by epm
871 #####################################################################
873 sub add_one_line_into_file
875 my ($file, $insertline, $filename) = @_;
877 if ( $installer::globals::issolarispkgbuild )
879 push(@{$file}, $insertline); # simply adding at the end of pkginfo file
882 if ( $installer::globals::isrpmbuild )
884 # Adding behind the line beginning with: Group:
886 my $inserted_line = 0;
888 for ( my $i = 0; $i <= $#{$file}; $i++ )
890 if ( ${$file}[$i] =~ /^\s*Group\:\s*/ )
892 splice(@{$file},$i+1,0,$insertline);
893 $inserted_line = 1;
894 last;
898 if (! $inserted_line) { installer::exiter::exit_program("ERROR: Did not find string \"Group:\" in file: $filename", "add_one_line_into_file"); }
901 $insertline =~ s/\s*$//; # removing line end for correct logging
902 my $infoline = "Success: Added line $insertline into file $filename!\n";
903 push( @installer::globals::logfileinfo, $infoline);
906 #####################################################################
907 # Setting the revision VERSION=1.9,REV=66 .
908 # Also adding the new line: "AutoReqProv: no"
909 #####################################################################
911 sub set_revision_in_pkginfo
913 my ($file, $filename, $variables, $packagename) = @_;
915 my $revisionstring = "\,REV\=" . $installer::globals::packagerevision;
917 # Adding also a time string to the revision. Syntax: VERSION=8.0.0,REV=66.2005.01.24
919 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
921 $mday = $mday;
922 $mon = $mon + 1;
923 $year = $year + 1900;
925 if ( $mday < 10 ) { $mday = "0" . $mday; }
926 if ( $mon < 10 ) { $mon = "0" . $mon; }
927 my $datestring = $year . "." . $mon . "." . $mday;
928 $revisionstring = $revisionstring . "." . $datestring;
930 for ( my $i = 0; $i <= $#{$file}; $i++ )
932 if ( ${$file}[$i] =~ /^\s*(VERSION\=.*?)\s*$/ )
934 my $oldstring = $1;
935 my $newstring = $oldstring . $revisionstring; # also adding the date string
936 ${$file}[$i] =~ s/$oldstring/$newstring/;
937 my $infoline = "Info: Changed in $filename file: \"$oldstring\" to \"$newstring\"!\n";
938 push( @installer::globals::logfileinfo, $infoline);
939 last;
943 # For Update and Patch reasons, this string can also be kept constant
945 my $pkgversion = "SOLSPARCPKGVERSION";
946 if ( $installer::globals::issolarisx86build ) { $pkgversion = "SOLIAPKGVERSION"; }
948 if (( $variables->{$pkgversion} ) && ( $variables->{$pkgversion} ne "" ))
950 if ( $variables->{$pkgversion} ne "FINALVERSION" )
952 # In OOo 3.x timeframe, this string is no longer unique for all packages, because of the three layer.
953 # 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
954 # and therefore be set as $pkgversion.
955 # The first part "3.0.0" has to be derived from the
957 my $version = $installer::globals::packageversion;
958 if ( $version =~ /^\s*(\d+)\.(\d+)\.(\d+)\s*$/ )
960 my $major = $1;
961 my $minor = $2;
962 my $micro = $3;
964 my $finalmajor = $major;
965 my $finalminor = $minor;
966 my $finalmicro = 0;
968 $version = "$finalmajor.$finalminor.$finalmicro";
971 my $datestring = $variables->{$pkgversion};
973 # Allowing some packages to have another date of creation.
974 # They can be defined in product definition using a key like "SOLSPARCPKGVERSION_$packagename"
976 my $additionalkey = $pkgversion . "_" . $packagename;
977 if (( $variables->{$additionalkey} ) && ( $variables->{$additionalkey} ne "" )) { $datestring = $variables->{$additionalkey}; }
979 my $versionstring = "$version,$datestring";
981 for ( my $i = 0; $i <= $#{$file}; $i++ )
983 if ( ${$file}[$i] =~ /^\s*(VERSION\=).*?\s*$/ )
985 my $start = $1;
986 my $newstring = $start . $versionstring . "\n"; # setting the complete new string
987 my $oldstring = ${$file}[$i];
988 ${$file}[$i] = $newstring;
989 $oldstring =~ s/\s*$//;
990 $newstring =~ s/\s*$//;
991 my $infoline = "Info: Changed in $filename file: \"$oldstring\" to \"$newstring\"!\n";
992 push( @installer::globals::logfileinfo, $infoline);
993 last;
1000 ########################################################
1001 # Setting MAXINST=1000 into the pkginfo file.
1002 ########################################################
1004 sub set_maxinst_in_pkginfo
1006 my ($changefile, $filename) = @_;
1008 my $newline = "MAXINST\=1000\n";
1010 add_one_line_into_file($changefile, $newline, $filename);
1013 #############################################################
1014 # Setting several Solaris variables into the pkginfo file.
1015 #############################################################
1017 sub set_solaris_parameter_in_pkginfo
1019 my ($changefile, $filename, $allvariables) = @_;
1021 my $newline = "";
1023 # SUNW_PRODNAME
1024 # SUNW_PRODVERS
1025 # SUNW_PKGVERS
1026 # Not: SUNW_PKGTYPE
1027 # HOTLINE
1028 # EMAIL
1030 my $productname = $allvariables->{'PRODUCTNAME'};
1031 $newline = "SUNW_PRODNAME=$productname\n";
1032 add_one_line_into_file($changefile, $newline, $filename);
1034 my $productversion = "";
1035 if ( $allvariables->{'PRODUCTVERSION'} )
1037 $productversion = $allvariables->{'PRODUCTVERSION'};
1038 if ( $allvariables->{'PRODUCTEXTENSION'} ) { $productversion = $productversion . "/" . $allvariables->{'PRODUCTEXTENSION'}; }
1040 $newline = "SUNW_PRODVERS=$productversion\n";
1041 add_one_line_into_file($changefile, $newline, $filename);
1043 $newline = "SUNW_PKGVERS=1\.0\n";
1044 add_one_line_into_file($changefile, $newline, $filename);
1046 if ( $allvariables->{'SUNW_PKGTYPE'} )
1048 $newline = "SUNW_PKGTYPE=$allvariables->{'SUNW_PKGTYPE'}\n";
1049 add_one_line_into_file($changefile, $newline, $filename);
1051 else
1053 $newline = "SUNW_PKGTYPE=\n";
1054 add_one_line_into_file($changefile, $newline, $filename);
1057 $newline = "HOTLINE=Please contact your local service provider\n";
1058 add_one_line_into_file($changefile, $newline, $filename);
1060 $newline = "EMAIL=\n";
1061 add_one_line_into_file($changefile, $newline, $filename);
1065 #####################################################################
1066 # epm uses as architecture for Solaris x86 "i86pc". This has to be
1067 # changed to "i386".
1068 #####################################################################
1070 sub fix_architecture_setting
1072 my ($changefile) = @_;
1074 for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1076 if ( ${$changefile}[$i] =~ /^\s*ARCH=i86pc\s*$/ )
1078 ${$changefile}[$i] =~ s/i86pc/i386/;
1079 last;
1085 #####################################################################
1086 # Adding a new line for topdir into specfile, removing old
1087 # topdir if set.
1088 #####################################################################
1090 sub set_topdir_in_specfile
1092 my ($changefile, $filename, $newepmdir) = @_;
1094 $newepmdir = Cwd::cwd() . $installer::globals::separator . $newepmdir; # only absolute path allowed
1096 # removing "%define _topdir", if existing
1098 for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1100 if ( ${$changefile}[$i] =~ /^\s*\%define _topdir\s+/ )
1102 my $removeline = ${$changefile}[$i];
1103 $removeline =~ s/\s*$//;
1104 splice(@{$changefile},$i,1);
1105 my $infoline = "Info: Removed line \"$removeline\" from file $filename!\n";
1106 push( @installer::globals::logfileinfo, $infoline);
1107 last;
1111 # Adding "topdir" behind the line beginning with: Group:
1113 my $inserted_line = 0;
1115 my $topdirline = "\%define _topdir $newepmdir\n";
1117 for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1119 if ( ${$changefile}[$i] =~ /^\s*Group\:\s*/ )
1121 splice(@{$changefile},$i+1,0,$topdirline);
1122 $inserted_line = 1;
1123 $topdirline =~ s/\s*$//;
1124 my $infoline = "Success: Added line $topdirline into file $filename!\n";
1125 push( @installer::globals::logfileinfo, $infoline);
1129 if (! $inserted_line) { installer::exiter::exit_program("ERROR: Did not find string \"Group:\" in file: $filename", "set_topdir_in_specfile"); }
1133 #####################################################################
1134 # Setting the packager in the spec file
1135 # Syntax: Packager: abc@def
1136 #####################################################################
1138 sub set_packager_in_specfile
1140 my ($changefile) = @_;
1142 my $packager = $installer::globals::longmanufacturer;
1144 for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1146 if ( ${$changefile}[$i] =~ /^\s*Packager\s*:\s*(.+?)\s*$/ )
1148 my $oldstring = $1;
1149 ${$changefile}[$i] =~ s/\Q$oldstring\E/$packager/;
1150 my $infoline = "Info: Changed Packager in spec file from $oldstring to $packager!\n";
1151 push( @installer::globals::logfileinfo, $infoline);
1152 last;
1157 #####################################################################
1158 # Setting the requirements in the spec file (i81494)
1159 # Syntax: PreReq: "requirements" (only for shared extensions)
1160 #####################################################################
1162 sub set_prereq_in_specfile
1164 my ($changefile) = @_;
1166 my $prereq = "PreReq:";
1168 for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1170 if ( ${$changefile}[$i] =~ /^\s*Requires:\s*(.+?)\s*$/ )
1172 my $oldstring = ${$changefile}[$i];
1173 ${$changefile}[$i] =~ s/Requires:/$prereq/;
1174 my $infoline = "Info: Changed requirements in spec file from $oldstring to ${$changefile}[$i]!\n";
1175 push( @installer::globals::logfileinfo, $infoline);
1180 #####################################################################
1181 # Setting the Auto[Req]Prov line and __find_requires
1182 #####################################################################
1184 sub set_autoprovreq_in_specfile
1186 my ($changefile, $findrequires, $bindir) = @_;
1188 my $autoreqprovline = "AutoReqProv\: no\n";
1190 if ( $findrequires )
1192 # don't let rpm invoke it, we never want to use AutoReq because
1193 # rpm will generate Requires: config(packagename)
1194 open (FINDREQUIRES, "echo | $bindir/$findrequires |");
1195 while (<FINDREQUIRES>) { $autoreqprovline .= "Requires: $_\n"; }
1196 close (FINDREQUIRES);
1199 $autoreqprovline .= "%define _binary_filedigest_algorithm 1\n%define _binary_payload w1T.xzdio\n";
1201 for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1203 # Adding "autoreqprov" behind the line beginning with: Group:
1204 if ( ${$changefile}[$i] =~ /^\s*Group\:\s*/ )
1206 splice(@{$changefile},$i+1,0,$autoreqprovline);
1207 $autoreqprovline =~ s/\s*$//;
1208 my $infoline = "Success: Added line $autoreqprovline into spec file!\n";
1209 push( @installer::globals::logfileinfo, $infoline);
1211 last;
1216 #####################################################################
1217 # Replacing Copyright with License in the spec file
1218 # Syntax: License: LGPLv3 (or MPLv2 on ALv2, older usages were LGPL, SISSL)
1219 #####################################################################
1221 sub set_license_in_specfile
1223 my ($changefile, $variableshashref) = @_;
1225 my $license = $variableshashref->{'LICENSENAME'};
1227 for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1229 if ( ${$changefile}[$i] =~ /^\s*Copyright\s*:\s*(.+?)\s*$/ )
1231 ${$changefile}[$i] = "License: $license\n";
1232 my $infoline = "Info: Replaced Copyright with License: $license !\n";
1233 push( @installer::globals::logfileinfo, $infoline);
1234 last;
1239 #########################################################
1240 # Building relocatable Solaris packages means:
1241 # 1. Add "BASEDIR=/opt" into pkginfo
1242 # 2. Remove "/opt/" from all objects in prototype file
1243 # For step2 this function exists
1244 # Sample: d none /opt/openofficeorg20/help 0755 root other
1245 # -> d none openofficeorg20/help 0755 root other
1246 #########################################################
1248 sub make_prototypefile_relocatable
1250 my ($prototypefile, $relocatablepath) = @_;
1252 for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1254 if ( ${$prototypefile}[$i] =~ /^\s*\w\s+\w+\s+\/\w+/ ) # this is an object line
1256 ${$prototypefile}[$i] =~ s/$relocatablepath//; # Important: $relocatablepath has a "/" at the end. Example "/opt/"
1260 # If the $relocatablepath is "/opt/openoffice20/" the line "d none /opt/openoffice20" was not changed.
1261 # This line has to be removed now
1263 if ( $relocatablepath ne "/" ) { $relocatablepath =~ s/\/\s*$//; } # removing the ending slash
1265 for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1267 if ( ${$prototypefile}[$i] =~ /^\s*d\s+\w+\s+\Q$relocatablepath\E/ )
1269 my $line = ${$prototypefile}[$i];
1270 splice(@{$prototypefile},$i,1); # removing the line
1271 $line =~ s/\s*$//;
1272 my $infoline = "Info: Removed line \"$line\" from prototype file!\n";
1273 push( @installer::globals::logfileinfo, $infoline);
1274 last;
1278 # Making "\$" to "$" in prototype file. "\$" was created by epm.
1280 for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1282 if ( ${$prototypefile}[$i] =~ /\\\$/ )
1284 ${$prototypefile}[$i] =~ s/\\\$/\$/g;
1285 my $infoline2 = "Info: Changed line in prototype file: ${$prototypefile}[$i] !\n";
1286 push( @installer::globals::logfileinfo, $infoline2);
1291 #########################################################################
1292 # Replacing the variables in the shell scripts or in the epm list file
1293 # Linux: spec file
1294 # Solaris: preinstall, postinstall, preremove, postremove
1295 # If epm is used in the original version (not relocatable)
1296 # the variables have to be exchanged in the list file,
1297 # created for epm.
1298 #########################################################################
1300 sub replace_variables_in_shellscripts
1302 my ($scriptfile, $scriptfilename, $oldstring, $newstring) = @_;
1304 my $debug = 0;
1305 if ( $oldstring eq "PRODUCTDIRECTORYNAME" ) { $debug = 1; }
1307 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
1309 if ( ${$scriptfile}[$i] =~ /\Q$oldstring\E/ )
1311 my $oldline = ${$scriptfile}[$i];
1312 ${$scriptfile}[$i] =~ s/\Q$oldstring\E/$newstring/g;
1313 ${$scriptfile}[$i] =~ s/\/\//\//g; # replacing "//" by "/" , if path $newstring is empty!
1314 my $infoline = "Info: Substituting in $scriptfilename $oldstring by $newstring\n";
1315 push(@installer::globals::logfileinfo, $infoline);
1316 if ( $debug )
1318 $infoline = "Old Line: $oldline";
1319 push(@installer::globals::logfileinfo, $infoline);
1320 $infoline = "New Line: ${$scriptfile}[$i]";
1321 push(@installer::globals::logfileinfo, $infoline);
1327 ############################################################
1328 # Determining the directory created by epm, in which the
1329 # RPMS or Solaris packages are created.
1330 ############################################################
1332 sub determine_installdir_ooo
1334 # A simple "ls" command returns the directory name
1336 my $dirname = "";
1338 my $systemcall = "ls |";
1339 open (LS, "$systemcall");
1340 $dirname = <LS>;
1341 close (LS);
1343 $dirname =~ s/\s*$//;
1345 my $infoline = "Info: Directory created by epm: $dirname\n";
1346 push(@installer::globals::logfileinfo, $infoline);
1348 return $dirname;
1351 ############################################################
1352 # Setting the tab content into the file container
1353 ############################################################
1355 sub set_tab_into_datafile
1357 my ($changefile, $filesref) = @_;
1359 my @newclasses = ();
1360 my $newclassesstring = "";
1362 if ( $installer::globals::issolarispkgbuild )
1364 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1366 my $onefile = ${$filesref}[$i];
1368 if ( $onefile->{'SolarisClass'} )
1370 my $sourcepath = $onefile->{'sourcepath'};
1372 for ( my $j = 0; $j <= $#{$changefile}; $j++ )
1374 if (( ${$changefile}[$j] =~ /^\s*f\s+none\s+/ ) && ( ${$changefile}[$j] =~ /\=\Q$sourcepath\E\s+/ ))
1376 my $oldline = ${$changefile}[$j];
1377 ${$changefile}[$j] =~ s/f\s+none/e $onefile->{'SolarisClass'}/;
1378 my $newline = ${$changefile}[$j];
1379 $oldline =~ s/\s*$//;
1380 $newline =~ s/\s*$//;
1382 my $infoline = "TAB: Changing content from \"$oldline\" to \"$newline\" .\n";
1383 push(@installer::globals::logfileinfo, $infoline);
1385 # collecting all new classes
1386 if (! grep {$_ eq $onefile->{'SolarisClass'}} @newclasses)
1388 push(@newclasses, $onefile->{'SolarisClass'});
1391 last;
1397 $newclassesstring = installer::converter::convert_array_to_space_separated_string(\@newclasses);
1400 if ( $installer::globals::isrpmbuild )
1402 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1404 my $onefile = ${$filesref}[$i];
1406 if ( $onefile->{'SpecFileContent'} )
1408 my $destination = $onefile->{'destination'};
1410 for ( my $j = 0; $j <= $#{$changefile}; $j++ )
1412 if ( ${$changefile}[$j] =~ /^\s*(\%attr\(.*\))\s+(\".*?\Q$destination\E\"\s*)$/ )
1414 my $begin = $1;
1415 my $end = $2;
1417 my $oldline = ${$changefile}[$j];
1418 ${$changefile}[$j] = $begin . " " . $onefile->{'SpecFileContent'} . " " . $end;
1419 my $newline = ${$changefile}[$j];
1421 $oldline =~ s/\s*$//;
1422 $newline =~ s/\s*$//;
1424 my $infoline = "TAB: Changing content from \"$oldline\" to \"$newline\" .\n";
1425 push(@installer::globals::logfileinfo, $infoline);
1427 last;
1434 return $newclassesstring;
1437 ############################################################
1438 # Including additional classes into the pkginfo file
1439 ############################################################
1441 sub include_classes_into_pkginfo
1443 my ($changefile, $classesstring) = @_;
1445 for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1447 if ( ${$changefile}[$i] =~ /^\s*CLASSES\=none/ )
1449 ${$changefile}[$i] =~ s/\s*$//;
1450 my $oldline = ${$changefile}[$i];
1451 ${$changefile}[$i] = ${$changefile}[$i] . " " . $classesstring . "\n";
1452 my $newline = ${$changefile}[$i];
1453 $newline =~ s/\s*$//;
1455 my $infoline = "pkginfo file: Changing content from \"$oldline\" to \"$newline\" .\n";
1456 push(@installer::globals::logfileinfo, $infoline);
1461 ##########################################################################################
1462 # Checking, if an extension is included into the package (Linux).
1463 # All extension files have to be installed into directory
1464 # share/extension/install
1465 # %attr(0444,root,root) "/opt/staroffice8/share/extension/install/SunSearchToolbar.oxt"
1466 ##########################################################################################
1468 sub is_extension_package
1470 my ($specfile) = @_;
1472 my $is_extension_package = 0;
1474 for ( my $i = 0; $i <= $#{$specfile}; $i++ )
1476 my $line = ${$specfile}[$i];
1477 if ( $line =~ /share\/extension\/install\/.*?\.oxt\"\s*$/ )
1479 $is_extension_package = 1;
1480 last;
1484 return $is_extension_package;
1487 ######################################################################
1488 # Checking, if an extension is included into the package (Solaris).
1489 # All extension files have to be installed into directory
1490 # share/extension/install
1491 ######################################################################
1493 sub contains_extension_dir
1495 my ($prototypefile) = @_;
1497 my $contains_extension_dir = 0;
1499 # d none opt/libreoffice/share/extensions/
1501 for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1503 my $line = ${$prototypefile}[$i];
1504 if ( $line =~ /^\s*d\s+none\s.*\/share\/extensions\// )
1506 $contains_extension_dir = 1;
1507 last;
1511 return $contains_extension_dir;
1514 ############################################################
1515 # Setting the correct Solaris locales
1516 ############################################################
1518 sub get_solaris_language_for_langpack
1520 my ( $onelanguage ) = @_;
1522 my $sollanguage = $onelanguage;
1523 $sollanguage =~ s/\-/\_/;
1525 if ( $sollanguage eq "de" ) { $sollanguage = "de"; }
1526 elsif ( $sollanguage eq "en_US" ) { $sollanguage = "en_AU,en_CA,en_GB,en_IE,en_MT,en_NZ,en_US,en_US.UTF-8"; }
1527 elsif ( $sollanguage eq "es" ) { $sollanguage = "es"; }
1528 elsif ( $sollanguage eq "fr" ) { $sollanguage = "fr"; }
1529 elsif ( $sollanguage eq "hu" ) { $sollanguage = "hu_HU"; }
1530 elsif ( $sollanguage eq "it" ) { $sollanguage = "it"; }
1531 elsif ( $sollanguage eq "nl" ) { $sollanguage = "nl_BE,nl_NL"; }
1532 elsif ( $sollanguage eq "pl" ) { $sollanguage = "pl_PL"; }
1533 elsif ( $sollanguage eq "sv" ) { $sollanguage = "sv"; }
1534 elsif ( $sollanguage eq "pt" ) { $sollanguage = "pt_PT"; }
1535 elsif ( $sollanguage eq "pt_BR" ) { $sollanguage = "pt_BR"; }
1536 elsif ( $sollanguage eq "ru" ) { $sollanguage = "ru_RU"; }
1537 elsif ( $sollanguage eq "ja" ) { $sollanguage = "ja,ja_JP,ja_JP.PCK,ja_JP.UTF-8"; }
1538 elsif ( $sollanguage eq "ko" ) { $sollanguage = "ko,ko.UTF-8"; }
1539 elsif ( $sollanguage eq "zh_CN" ) { $sollanguage = "zh,zh.GBK,zh_CN.GB18030,zh.UTF-8"; }
1540 elsif ( $sollanguage eq "zh_TW" ) { $sollanguage = "zh_TW,zh_TW.BIG5,zh_TW.UTF-8,zh_HK.BIG5HK,zh_HK.UTF-8"; }
1542 return $sollanguage;
1545 ############################################################
1546 # Adding language infos in pkginfo file
1547 ############################################################
1549 sub include_languageinfos_into_pkginfo
1551 my ( $changefile, $filename, $languagestringref, $onepackage, $variableshashref ) = @_;
1553 # SUNWPKG_LIST=core01
1554 # SUNW_LOC=de
1556 my $locallang = $onepackage->{'language'};
1557 my $solarislanguage = get_solaris_language_for_langpack($locallang);
1559 my $newline = "SUNW_LOC=" . $solarislanguage . "\n";
1560 add_one_line_into_file($changefile, $newline, $filename);
1562 # SUNW_PKGLIST is required, if SUNW_LOC is defined.
1563 if ( $onepackage->{'pkg_list_entry'} )
1565 my $packagelistentry = $onepackage->{'pkg_list_entry'};
1566 installer::packagelist::resolve_packagevariables(\$packagelistentry, $variableshashref, 1);
1567 $newline = "SUNW_PKGLIST=" . $packagelistentry . "\n";
1568 add_one_line_into_file($changefile, $newline, $filename);
1570 else
1572 # Using default package ooobasis30-core01.
1573 my $packagelistentry = "%BASISPACKAGEPREFIX%WITHOUTDOTPRODUCTVERSION-core01";
1574 installer::packagelist::resolve_packagevariables(\$packagelistentry, $variableshashref, 1);
1575 $newline = "SUNW_PKGLIST=" . $packagelistentry . "\n";
1576 add_one_line_into_file($changefile, $newline, $filename);
1580 ############################################################
1581 # Including package names into the depend files.
1582 # The package names have to be included into
1583 # packagelist. They are already saved in
1584 # %installer::globals::dependfilenames.
1585 ############################################################
1587 sub put_packagenames_into_dependfile
1589 my ( $file ) = @_;
1591 for ( my $i = 0; $i <= $#{$file}; $i++ )
1593 my $line = ${$file}[$i];
1594 if ( $line =~ /^\s*\w\s+(.*?)\s*$/ )
1596 my $abbreviation = $1;
1598 if ( $abbreviation =~ /\%/ ) { installer::exiter::exit_program("ERROR: Could not resolve all properties in Solaris package abbreviation \"$abbreviation\"!", "read_packagemap"); }
1600 if ( exists($installer::globals::dependfilenames{$abbreviation}) )
1602 my $packagename = $installer::globals::dependfilenames{$abbreviation};
1603 if ( $packagename =~ /\%/ ) { installer::exiter::exit_program("ERROR: Could not resolve all properties in Solaris package name \"$packagename\"!", "read_packagemap"); }
1605 $line =~ s/\s*$//;
1606 ${$file}[$i] = $line . "\t" . $packagename . "\n";
1608 else
1610 installer::exiter::exit_program("ERROR: Missing packagename for Solaris package \"$abbreviation\"!", "put_packagenames_into_dependfile");
1616 ############################################################
1617 # Including the relocatable directory into
1618 # spec file and pkginfo file
1619 # Linux: set topdir in specfile
1620 # Solaris: remove $relocatablepath (/opt/)
1621 # for all objects in prototype file
1622 # and changing "topdir" for Linux
1623 ############################################################
1625 sub prepare_packages
1627 my ($loggingdir, $packagename, $staticpath, $relocatablepath, $onepackage, $variableshashref, $filesref, $languagestringref) = @_;
1629 my $filename = "";
1630 my $newline = "";
1631 my $newepmdir = $installer::globals::epmoutpath . $installer::globals::separator;
1633 my $localrelocatablepath = $relocatablepath;
1634 if ( $localrelocatablepath ne "/" ) { $localrelocatablepath =~ s/\/\s*$//; }
1636 if ( $installer::globals::issolarispkgbuild )
1638 $filename = $packagename . ".pkginfo";
1639 $newline = "BASEDIR\=" . $localrelocatablepath . "\n";
1642 if ( $installer::globals::isrpmbuild )
1644 $filename = $packagename . ".spec";
1645 $newline = "Prefix\:\ " . $localrelocatablepath . "\n";
1648 my $completefilename = $newepmdir . $filename;
1650 if ( ! -f $completefilename) { installer::exiter::exit_program("ERROR: Did not find file: $completefilename", "prepare_packages"); }
1651 my $changefile = installer::files::read_file($completefilename);
1652 if ( $newline ne "" )
1654 add_one_line_into_file($changefile, $newline, $filename);
1655 installer::files::save_file($completefilename, $changefile);
1658 # adding new "topdir" and removing old "topdir" in specfile
1660 if ( $installer::globals::isrpmbuild )
1662 set_topdir_in_specfile($changefile, $filename, $newepmdir);
1663 set_autoprovreq_in_specfile($changefile, $onepackage->{'findrequires'}, "$installer::globals::workpath" . "/bin");
1664 set_packager_in_specfile($changefile);
1665 if ( is_extension_package($changefile) ) { set_prereq_in_specfile($changefile); }
1666 set_license_in_specfile($changefile, $variableshashref);
1667 set_tab_into_datafile($changefile, $filesref);
1668 installer::files::save_file($completefilename, $changefile);
1671 # removing the relocatable path in prototype file
1673 if ( $installer::globals::issolarispkgbuild )
1675 set_revision_in_pkginfo($changefile, $filename, $variableshashref, $packagename);
1676 set_maxinst_in_pkginfo($changefile, $filename);
1677 set_solaris_parameter_in_pkginfo($changefile, $filename, $variableshashref);
1678 if ( $installer::globals::issolarisx86build ) { fix_architecture_setting($changefile); }
1679 if (( $onepackage->{'language'} ) && ( $onepackage->{'language'} ne "" ) && ( $onepackage->{'language'} ne "en-US" )) { include_languageinfos_into_pkginfo($changefile, $filename, $languagestringref, $onepackage, $variableshashref); }
1680 installer::files::save_file($completefilename, $changefile);
1682 my $prototypefilename = $packagename . ".prototype";
1683 $prototypefilename = $newepmdir . $prototypefilename;
1684 if (! -f $prototypefilename) { installer::exiter::exit_program("ERROR: Did not find prototype file: $prototypefilename", "prepare_packages"); }
1686 my $prototypefile = installer::files::read_file($prototypefilename);
1687 make_prototypefile_relocatable($prototypefile, $relocatablepath);
1688 my $classesstring = set_tab_into_datafile($prototypefile, $filesref);
1689 if ($classesstring)
1691 include_classes_into_pkginfo($changefile, $classesstring);
1692 installer::files::save_file($completefilename, $changefile);
1695 installer::files::save_file($prototypefilename, $prototypefile);
1697 # Adding package names into depend files for Solaris (not supported by epm)
1698 my $dependfilename = $packagename . ".depend";
1699 $dependfilename = $newepmdir . $dependfilename;
1700 if ( -f $dependfilename)
1702 my $dependfile = installer::files::read_file($dependfilename);
1703 put_packagenames_into_dependfile($dependfile);
1704 installer::files::save_file($dependfilename, $dependfile);
1708 return $newepmdir;
1711 ###############################################################################
1712 # Replacement of PRODUCTINSTALLLOCATION and PRODUCTDIRECTORYNAME in the
1713 # epm list file.
1714 # The complete rootpath is stored in $installer::globals::rootpath
1715 # or for each package in $onepackage->{'destpath'}
1716 # The static rootpath is stored in $staticpath
1717 # The relocatable path is stored in $relocatablepath
1718 # PRODUCTINSTALLLOCATION is the relocatable part ("/opt") and
1719 # PRODUCTDIRECTORYNAME the static path ("openofficeorg20").
1720 # In standard epm process:
1721 # No usage of package specific variables like $BASEDIR, because
1722 # 1. These variables would be replaced in epm process
1723 # 2. epm version 3.7 does not support relocatable packages
1724 ###############################################################################
1726 sub resolve_path_in_epm_list_before_packaging
1728 my ($listfile, $listfilename, $variable, $path) = @_;
1730 installer::logger::include_header_into_logfile("Replacing variables in epm list file:");
1732 $path =~ s/\/\s*$//;
1733 replace_variables_in_shellscripts($listfile, $listfilename, $variable, $path);
1737 #################################################################
1738 # Determining the rpm version. Beginning with rpm version 4.0
1739 # the tool to create RPMs is "rpmbuild" and no longer "rpm"
1740 #################################################################
1742 sub determine_rpm_version
1744 my $rpmversion = 0;
1745 my $rpmout = "";
1746 my $systemcall = "";
1748 # "rpm --version" has problems since LD_LIBRARY_PATH was removed. Therefore the content of $RPM has to be called.
1749 # "rpm --version" and "rpmbuild --version" have the same output. Therefore $RPM can be used. Its value
1750 # is saved in $installer::globals::rpm
1752 if ( $installer::globals::rpm ne "" )
1754 $systemcall = "$installer::globals::rpm --version |";
1756 else
1758 $systemcall = "rpm --version |";
1761 open (RPM, "$systemcall");
1762 $rpmout = <RPM>;
1763 close (RPM);
1765 if ( $rpmout ne "" )
1767 $rpmout =~ s/\s*$//g;
1769 my $infoline = "Systemcall: $systemcall\n";
1770 push( @installer::globals::logfileinfo, $infoline);
1772 if ( $rpmout eq "" ) { $infoline = "ERROR: Could not find file \"rpm\" !\n"; }
1773 else { $infoline = "Success: rpm version: $rpmout\n"; }
1775 push( @installer::globals::logfileinfo, $infoline);
1777 if ( $rpmout =~ /(\d+)\.(\d+)\.(\d+)/ ) { $rpmversion = $1; }
1778 elsif ( $rpmout =~ /(\d+)\.(\d+)/ ) { $rpmversion = $1; }
1779 elsif ( $rpmout =~ /(\d+)/ ) { $rpmversion = $1; }
1780 else { installer::exiter::exit_program("ERROR: Unknown format: $rpmout ! Expected: \"a.b.c\", or \"a.b\", or \"a\"", "determine_rpm_version"); }
1783 return $rpmversion;
1786 ####################################################
1787 # Writing some info about rpm into the log file
1788 ####################################################
1790 sub log_rpm_info
1792 my $systemcall = "";
1793 my $infoline = "";
1795 $infoline = "\nLogging rpmrc content using --showrc\n\n";
1796 push( @installer::globals::logfileinfo, $infoline);
1798 if ( $installer::globals::rpm ne "" )
1800 $systemcall = "$installer::globals::rpm --showrc |";
1802 else
1804 $systemcall = "rpm --showrc |";
1807 my @fullrpmout = ();
1809 open (RPM, "$systemcall");
1810 while (<RPM>) {push(@fullrpmout, $_); }
1811 close (RPM);
1813 if ( $#fullrpmout > -1 )
1815 for ( my $i = 0; $i <= $#fullrpmout; $i++ )
1817 my $rpmout = $fullrpmout[$i];
1818 $rpmout =~ s/\s*$//g;
1820 $infoline = "$rpmout\n";
1821 $infoline =~ s/error/e_r_r_o_r/gi; # avoiding log problems
1822 push( @installer::globals::logfileinfo, $infoline);
1825 else
1827 $infoline = "Problem in systemcall: $systemcall : No return value\n";
1828 push( @installer::globals::logfileinfo, $infoline);
1831 $infoline = "End of logging rpmrc\n\n";
1832 push( @installer::globals::logfileinfo, $infoline);
1835 #################################################
1836 # Systemcall to start the packaging process
1837 #################################################
1839 sub create_packages_without_epm
1841 my ($epmdir, $packagename, $includepatharrayref, $allvariables, $languagestringref) = @_;
1843 # Solaris: pkgmk -o -f solaris-2.8-sparc/SUNWso8m34.prototype -d solaris-2.8-sparc
1844 # Solaris: pkgtrans solaris-2.8-sparc SUNWso8m34.pkg SUNWso8m34
1845 # Solaris: tar -cf - SUNWso8m34 | $installer::globals::packertool > SUNWso8m34.tar.gz
1847 if ( $installer::globals::issolarispkgbuild )
1849 my $prototypefile = $epmdir . $packagename . ".prototype";
1850 if (! -f $prototypefile) { installer::exiter::exit_program("ERROR: Did not find file: $prototypefile", "create_packages_without_epm"); }
1852 my $destinationdir = $prototypefile;
1853 installer::pathanalyzer::get_path_from_fullqualifiedname(\$destinationdir);
1854 $destinationdir =~ s/\/\s*$//; # removing ending slashes
1856 my $systemcall = "pkgmk -l 1073741824 -o -f $prototypefile -d $destinationdir 2\>\&1 |";
1857 installer::logger::print_message( "... $systemcall ...\n" );
1859 my $maxpkgmkcalls = 3;
1861 for ( my $i = 1; $i <= $maxpkgmkcalls; $i++ )
1863 my @pkgmkoutput = ();
1865 open (PKGMK, "$systemcall");
1866 while (<PKGMK>) {push(@pkgmkoutput, $_); }
1867 close (PKGMK);
1869 my $returnvalue = $?; # $? contains the return value of the systemcall
1871 my $infoline = "Systemcall (Try $i): $systemcall\n";
1872 push( @installer::globals::logfileinfo, $infoline);
1874 for ( my $j = 0; $j <= $#pkgmkoutput; $j++ )
1876 if ( $i < $maxpkgmkcalls ) { $pkgmkoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; }
1877 push( @installer::globals::logfileinfo, "$pkgmkoutput[$j]");
1880 if ($returnvalue)
1882 $infoline = "Try $i : Could not execute \"$systemcall\"!\n";
1883 push( @installer::globals::logfileinfo, $infoline);
1884 if ( $i == $maxpkgmkcalls ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "create_packages_without_epm"); }
1886 else
1888 installer::logger::print_message( "Success (Try $i): \"$systemcall\"\n" );
1889 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
1890 push( @installer::globals::logfileinfo, $infoline);
1891 last;
1895 # It might be necessary to save uncompressed Solaris packages
1897 # compressing packages
1899 if ( ! $installer::globals::solarisdontcompress )
1901 my $faspac = "faspac-so.sh";
1903 my $compressorref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$faspac, $includepatharrayref, 0);
1904 if ($$compressorref ne "")
1906 # Saving original pkginfo, to set time stamp later
1907 my $pkginfoorig = "$destinationdir/$packagename/pkginfo";
1908 my $pkginfotmp = "$destinationdir/$packagename" . ".pkginfo.tmp";
1909 $systemcall = "cp -p $pkginfoorig $pkginfotmp";
1910 installer::systemactions::make_systemcall($systemcall);
1912 $faspac = $$compressorref;
1913 my $infoline = "Found compressor: $faspac\n";
1914 push( @installer::globals::logfileinfo, $infoline);
1916 installer::logger::print_message( "... $faspac ...\n" );
1917 installer::logger::include_timestamp_into_logfile("Starting $faspac");
1919 $systemcall = "/bin/sh $faspac -a -q -d $destinationdir $packagename"; # $faspac has to be the absolute path!
1920 installer::systemactions::make_systemcall($systemcall);
1922 # Setting time stamp for pkginfo, because faspac-so.sh
1923 # changed the pkginfo file, updated the size and
1924 # checksum, but not the time stamp.
1925 $systemcall = "touch -r $pkginfotmp $pkginfoorig";
1926 installer::systemactions::make_systemcall($systemcall);
1927 if ( -f $pkginfotmp ) { unlink($pkginfotmp); }
1929 installer::logger::include_timestamp_into_logfile("End of $faspac");
1931 else
1933 my $infoline = "Not found: $faspac\n";
1934 push( @installer::globals::logfileinfo, $infoline);
1938 # Setting unix rights to "775" for all created directories inside the package
1940 $systemcall = "cd $destinationdir; find $packagename -type d | xargs -i chmod 775 \{\} \;";
1941 installer::logger::print_message( "... $systemcall ...\n" );
1943 my $returnvalue = system($systemcall);
1945 my $infoline = "Systemcall: $systemcall\n";
1946 push( @installer::globals::logfileinfo, $infoline);
1948 if ($returnvalue)
1950 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
1951 push( @installer::globals::logfileinfo, $infoline);
1953 else
1955 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
1956 push( @installer::globals::logfileinfo, $infoline);
1960 ######################
1961 # making pkg files
1962 ######################
1964 # my $streamname = $packagename . ".pkg";
1965 # $systemcall = "pkgtrans $destinationdir $streamname $packagename";
1966 # print "... $systemcall ...\n";
1968 # $returnvalue = system($systemcall);
1970 # $infoline = "Systemcall: $systemcall\n";
1971 # push( @installer::globals::logfileinfo, $infoline);
1973 # if ($returnvalue)
1975 # $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
1976 # push( @installer::globals::logfileinfo, $infoline);
1978 # else
1980 # $infoline = "Success: Executed \"$systemcall\" successfully!\n";
1981 # push( @installer::globals::logfileinfo, $infoline);
1984 #########################
1985 # making tar.gz files
1986 #########################
1988 # my $targzname = $packagename . ".tar.gz";
1989 # $systemcall = "cd $destinationdir; tar -cf - $packagename | $installer::globals::packertool > $targzname";
1990 # print "... $systemcall ...\n";
1992 # $returnvalue = system($systemcall);
1994 # $infoline = "Systemcall: $systemcall\n";
1995 # push( @installer::globals::logfileinfo, $infoline);
1997 # if ($returnvalue)
1999 # $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2000 # push( @installer::globals::logfileinfo, $infoline);
2002 # else
2004 # $infoline = "Success: Executed \"$systemcall\" successfully!\n";
2005 # push( @installer::globals::logfileinfo, $infoline);
2010 # Linux: rpm -bb so8m35.spec ( -> dependency check abklemmen? )
2012 if ( $installer::globals::isrpmbuild )
2014 my $specfilename = $epmdir . $packagename . ".spec";
2015 if (! -f $specfilename) { installer::exiter::exit_program("ERROR: Did not find file: $specfilename", "create_packages_without_epm"); }
2017 my $rpmcommand = $installer::globals::rpm;
2018 my $rpmversion = determine_rpm_version();
2020 my $target = "";
2021 if ( $installer::globals::platformid eq 'linux_x86')
2023 $target = "i586";
2025 elsif ( $installer::globals::os eq 'LINUX')
2027 $target = (POSIX::uname())[4];
2030 # rpm 4.6 ignores buildroot tag in spec file
2032 my $buildrootstring = "";
2034 if ( $rpmversion >= 4 )
2036 my $dir = Cwd::getcwd;
2037 my $buildroot = $dir . "/" . $epmdir . "buildroot/";
2038 $buildrootstring = "--buildroot=$buildroot";
2039 mkdir($buildroot = $dir . "/" . $epmdir . "BUILD/");
2042 if ( ! $installer::globals::rpminfologged )
2044 log_rpm_info();
2045 $installer::globals::rpminfologged = 1;
2048 my $systemcall = "$rpmcommand -bb --define \"_unpackaged_files_terminate_build 0\" --define \"_build_id_links none\" $specfilename --target $target $buildrootstring 2\>\&1 |";
2050 installer::logger::print_message( "... $systemcall ...\n" );
2052 my $maxrpmcalls = 3;
2053 my $rpm_failed = 0;
2055 for ( my $i = 1; $i <= $maxrpmcalls; $i++ )
2057 my @rpmoutput = ();
2059 open (RPM, "$systemcall");
2060 while (<RPM>) {push(@rpmoutput, $_); }
2061 close (RPM);
2063 my $returnvalue = $?; # $? contains the return value of the systemcall
2065 my $infoline = "Systemcall (Try $i): $systemcall\n";
2066 push( @installer::globals::logfileinfo, $infoline);
2068 for ( my $j = 0; $j <= $#rpmoutput; $j++ )
2070 $rpmoutput[$j] =~ s/\bERROR\b/PROBLEM/ig;
2071 push( @installer::globals::logfileinfo, "$rpmoutput[$j]");
2074 if ($returnvalue)
2076 $infoline = "Try $i : Could not execute \"$systemcall\"!\n";
2077 push( @installer::globals::logfileinfo, $infoline);
2078 $rpm_failed = 1;
2080 else
2082 installer::logger::print_message( "Success (Try $i): \"$systemcall\"\n" );
2083 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
2084 push( @installer::globals::logfileinfo, $infoline);
2085 $rpm_failed = 0;
2086 last;
2090 if ( $rpm_failed )
2092 # Because of the problems with LD_LIBRARY_PATH, a direct call of local "rpm" or "rpmbuild" might be successful
2093 my $rpmprog = "";
2094 if ( -f "/usr/bin/rpmbuild" ) { $rpmprog = "/usr/bin/rpmbuild"; }
2095 elsif ( -f "/usr/bin/rpm" ) { $rpmprog = "/usr/bin/rpm"; }
2097 if ( $rpmprog ne "" )
2099 installer::logger::print_message( "... $rpmprog ...\n" );
2101 my $helpersystemcall = "$rpmprog -bb $specfilename --target $target $buildrootstring 2\>\&1 |";
2103 my @helperrpmoutput = ();
2105 open (RPM, "$helpersystemcall");
2106 while (<RPM>) {push(@helperrpmoutput, $_); }
2107 close (RPM);
2109 my $helperreturnvalue = $?; # $? contains the return value of the systemcall
2111 my $infoline = "\nLast try: Using $rpmprog directly (problem with LD_LIBRARY_PATH)\n";
2112 push( @installer::globals::logfileinfo, $infoline);
2114 $infoline = "\nSystemcall: $helpersystemcall\n";
2115 push( @installer::globals::logfileinfo, $infoline);
2117 for ( my $j = 0; $j <= $#helperrpmoutput; $j++ ) { push( @installer::globals::logfileinfo, "$helperrpmoutput[$j]"); }
2119 if ($helperreturnvalue)
2121 $infoline = "Could not execute \"$helpersystemcall\"!\n";
2122 push( @installer::globals::logfileinfo, $infoline);
2124 else
2126 installer::logger::print_message( "Success: \"$helpersystemcall\"\n" );
2127 $infoline = "Success: Executed \"$helpersystemcall\" successfully!\n";
2128 push( @installer::globals::logfileinfo, $infoline);
2129 $rpm_failed = 0;
2133 # Now it is really time to exit this packaging process, if the error still occurs
2134 if ( $rpm_failed ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "create_packages_without_epm"); }
2139 #################################################
2140 # Removing all temporary files created by epm
2141 #################################################
2143 sub remove_temporary_epm_files
2145 my ($epmdir, $loggingdir, $packagename) = @_;
2147 # saving the files into the loggingdir
2149 if ( $installer::globals::issolarispkgbuild )
2151 my @extensions = ();
2152 push(@extensions, ".pkginfo");
2153 push(@extensions, ".prototype");
2154 push(@extensions, ".postinstall");
2155 push(@extensions, ".postremove");
2156 push(@extensions, ".preinstall");
2157 push(@extensions, ".preremove");
2158 push(@extensions, ".depend");
2160 for ( my $i = 0; $i <= $#extensions; $i++ )
2162 my $removefile = $epmdir . $packagename . $extensions[$i];
2163 my $destfile = $loggingdir . $packagename . $extensions[$i] . ".log";
2165 if (! -f $removefile) { next; }
2167 my $systemcall = "mv -f $removefile $destfile";
2168 system($systemcall); # ignoring the return value
2169 my $infoline = "Systemcall: $systemcall\n";
2170 push( @installer::globals::logfileinfo, $infoline);
2174 if ( $installer::globals::isrpmbuild )
2176 my $removefile = $epmdir . $packagename . ".spec";
2177 my $destfile = $loggingdir . $packagename . ".spec.log";
2179 my $systemcall = "mv -f $removefile $destfile";
2180 system($systemcall); # ignoring the return value
2181 my $infoline = "Systemcall: $systemcall\n";
2182 push( @installer::globals::logfileinfo, $infoline);
2184 # removing the directory "buildroot"
2186 my $removedir = $epmdir . "buildroot";
2188 $systemcall = "rm -rf $removedir";
2190 installer::logger::print_message( "... $systemcall ...\n" );
2192 my $returnvalue = system($systemcall);
2194 $removedir = $epmdir . "BUILD";
2196 $systemcall = "rm -rf $removedir";
2198 installer::logger::print_message( "... $systemcall ...\n" );
2200 $returnvalue = system($systemcall);
2203 $infoline = "Systemcall: $systemcall\n";
2204 push( @installer::globals::logfileinfo, $infoline);
2206 if ($returnvalue)
2208 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2209 push( @installer::globals::logfileinfo, $infoline);
2211 else
2213 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
2214 push( @installer::globals::logfileinfo, $infoline);
2219 ###########################################################
2220 # Creating a better directory structure in the solver.
2221 ###########################################################
2223 sub create_new_directory_structure
2225 my ($newepmdir) = @_;
2227 my $newdir = $installer::globals::epmoutpath;
2229 if ( $installer::globals::isrpmbuild )
2231 my $rpmdir;
2232 my $machine = "";
2233 if ( $installer::globals::platformid eq 'linux_x86')
2235 $rpmdir = "$installer::globals::epmoutpath/RPMS/i586";
2237 elsif ( $installer::globals::os eq 'LINUX')
2239 $machine = (POSIX::uname())[4];
2240 $rpmdir = "$installer::globals::epmoutpath/RPMS/$machine";
2242 else
2244 installer::exiter::exit_program("ERROR: rpmdir undefined !", "create_new_directory_structure");
2247 my $systemcall = "mv $rpmdir/* $newdir"; # moving the rpms into the directory "RPMS"
2249 my $returnvalue = system($systemcall);
2251 my $infoline = "Systemcall: $systemcall\n";
2252 push( @installer::globals::logfileinfo, $infoline);
2254 if ($returnvalue)
2256 $infoline = "ERROR: Could not move content of \"$rpmdir\" to \"$newdir\"!\n";
2257 push( @installer::globals::logfileinfo, $infoline);
2259 else
2261 $infoline = "Success: Moved content of \"$rpmdir\" to \"$newdir\"!\n";
2262 push( @installer::globals::logfileinfo, $infoline);
2265 # and removing the empty directory
2267 if ( $machine ne "" )
2269 rmdir "$installer::globals::epmoutpath/RPMS/$machine";
2271 rmdir "$installer::globals::epmoutpath/RPMS/powerpc";
2272 rmdir "$installer::globals::epmoutpath/RPMS/x86_64";
2273 rmdir "$installer::globals::epmoutpath/RPMS/i586";
2274 rmdir "$installer::globals::epmoutpath/RPMS/i386";
2275 rmdir "$installer::globals::epmoutpath/RPMS"
2276 or warn "Could not remove RPMS dir: $!";
2279 # Setting unix rights to "775" for $newdir ("RPMS" or "packages")
2280 chmod 0775, $newdir;
2283 ######################################################
2284 # Collect modules with product specific styles.
2285 ######################################################
2287 sub collect_modules_with_style
2289 my ($style, $modulesarrayref) = @_;
2291 my @allmodules = ();
2293 for ( my $i = 0; $i <= $#{$modulesarrayref}; $i++ )
2295 my $onemodule = ${$modulesarrayref}[$i];
2296 my $styles = "";
2297 if ( $onemodule->{'Styles'} ) { $styles = $onemodule->{'Styles'}; }
2298 if ( $styles =~ /\b\Q$style\E\b/ )
2300 push(@allmodules, $onemodule);
2304 return \@allmodules;
2307 ######################################################
2308 # Remove modules without packagecontent.
2309 ######################################################
2311 sub remove_modules_without_package
2313 my ($allmodules) = @_;
2315 my @allmodules = ();
2317 for ( my $i = 0; $i <= $#{$allmodules}; $i++ )
2319 my $onemodule = ${$allmodules}[$i];
2320 my $packagename = "";
2321 if ( $onemodule->{'PackageName'} ) { $packagename = $onemodule->{'PackageName'}; }
2322 if ( $packagename ne "" )
2324 push(@allmodules, $onemodule);
2328 return \@allmodules;
2331 ######################################################
2332 # Copying files for system integration.
2333 ######################################################
2335 sub copy_and_unpack_tar_gz_files
2337 my ($sourcefile, $destdir) = @_;
2339 my $systemcall = "cd $destdir; cat $sourcefile | gunzip | tar -xf -";
2340 installer::systemactions::make_systemcall($systemcall);
2343 ######################################################
2344 # Checking whether the new content is a directory and
2345 # not a package. If it is a directory, the complete
2346 # content of the directory has to be added to the
2347 # array newcontent.
2348 ######################################################
2350 sub control_subdirectories
2352 my ($content, $subdir) = @_;
2354 my @newcontent = ();
2356 for ( my $i = 0; $i <= $#{$content}; $i++ )
2358 if ( -d ${$content}[$i] )
2360 $subdir = ${$content}[$i];
2361 installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$subdir);
2362 my $allpackages = installer::systemactions::read_directory(${$content}[$i]);
2363 for ( my $j = 0; $j <= $#{$allpackages}; $j++ )
2365 # Currently only Linux rpm is supported, debian packages cannot be installed via xpd installer
2366 if (( $installer::globals::islinuxbuild ) && ( ! ( ${$allpackages}[$j] =~ /\.rpm\s*$/ ))) { next; }
2367 push(@newcontent, ${$allpackages}[$j]);
2370 else
2372 push(@newcontent, ${$content}[$i]);
2376 return (\@newcontent, $subdir);
2379 ######################################################
2380 # Including the system integration files into the
2381 # installation sets.
2382 ######################################################
2384 sub put_systemintegration_into_installset
2386 my ($newdir, $includepatharrayref, $allvariables, $modulesarrayref) = @_;
2388 my $destdir = $newdir;
2390 # adding System integration files
2392 my $sourcefile = "";
2394 # Finding the modules defined in scp (with flag SYSTEMMODULE)
2395 # Getting name of package from scp-Module
2396 # Search package in list off all include files
2397 # Copy file into installation set and unpack it (always tar.gz)
2398 # tar.gz can contain a different number of packages -> automatically create hidden sub modules
2400 # Collect all modules with flag "SYSTEMMODULE"
2401 my $allmodules = collect_modules_with_style("SYSTEMMODULE", $modulesarrayref);
2402 $allmodules = remove_modules_without_package($allmodules);
2404 for ( my $i = 0; $i <= $#{$allmodules}; $i++ )
2406 my $onemodule = ${$allmodules}[$i];
2407 my $packagetarfilename = $onemodule->{'PackageName'};
2409 my $infoline = "Including into installation set: $packagetarfilename\n";
2410 push( @installer::globals::logfileinfo, $infoline);
2412 my $sourcepathref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$packagetarfilename, $includepatharrayref, 1);
2413 if ( $$sourcepathref eq "" ) { installer::exiter::exit_program("ERROR: Source path not found for $packagetarfilename!", "copy_systemintegration_files"); }
2415 # Collecting all packages in directory "packages" or "RPMS"
2416 my $oldcontent = installer::systemactions::read_directory($destdir);
2418 copy_and_unpack_tar_gz_files($$sourcepathref, $destdir);
2420 # Finding new content -> that is the package name
2421 my ($newcontent, $allcontent ) = installer::systemactions::find_new_content_in_directory($destdir, $oldcontent);
2423 # special handling, if new content is a directory
2424 my $subdir = "";
2425 if ( ! $installer::globals::issolarispkgbuild ) { ($newcontent, $subdir) = control_subdirectories($newcontent); }
2427 # Adding license content into Solaris packages
2428 if (( $installer::globals::issolarispkgbuild ) && ( $installer::globals::englishlicenseset ) && ( ! $allvariables->{'NO_LICENSE_INTO_COPYRIGHT'} )) { _add_license_into_systemintegrationpackages($destdir, $newcontent); }
2432 ######################################################
2433 # Analyzing the Unix installation path.
2434 # From the installation path /opt/openofficeorg20
2435 # is the part /opt relocatable and the part
2436 # openofficeorg20 static.
2437 ######################################################
2439 sub analyze_rootpath
2441 my ($rootpath, $staticpathref, $relocatablepathref, $allvariables) = @_;
2443 $rootpath =~ s/\/\s*$//; # removing ending slash
2445 ##############################################################
2446 # Version 3: "/" is variable and "/opt/openofficeorg20" fixed
2447 ##############################################################
2449 $$relocatablepathref = "/";
2450 # Static path has to contain the office directory name. This is replaced in shellscripts.
2451 $$staticpathref = $rootpath . $installer::globals::separator . $installer::globals::officedirhostname;
2452 # For RPM version 3.x it is required, that Prefix is not "/" in spec file. In this case --relocate will not work,
2453 # because RPM 3.x says, that the package is not relocatable. Therefore we have to use Prefix=/opt and for
2454 # all usages of --relocate this path has to be on both sides of the "=": --relocate /opt=<myselectdir>/opt .
2455 if ( $installer::globals::isrpmbuild )
2457 $$relocatablepathref = $rootpath . "\/"; # relocatable path must end with "/", will be "/opt/"
2458 $$staticpathref = $installer::globals::officedirhostname; # to be used as replacement in shell scripts
2461 if ( $installer::globals::isdebbuild )
2463 $$relocatablepathref = "";
2464 # $$staticpathref is already "/opt/libreoffice", no additional $rootpath required.
2469 ################################################
2470 # Defining the English license text to add
2471 # it into Solaris packages.
2472 ################################################
2474 sub _set_english_license
2476 my ($variableshashref) = @_;
2478 my $additional_license_name = $installer::globals::englishsolarislicensename; # always the English file
2479 my $licensefileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$additional_license_name, "" , 0);
2480 if ( $$licensefileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find license file $additional_license_name!", "set_english_license"); }
2481 $installer::globals::englishlicenseset = 1;
2482 $installer::globals::englishlicense = installer::files::read_file($$licensefileref);
2483 installer::scpzipfiles::replace_all_ziplistvariables_in_file($installer::globals::englishlicense, $variableshashref);
2486 ################################################
2487 # Adding the content of the English license
2488 # file into the system integration packages.
2489 ################################################
2491 sub _add_license_into_systemintegrationpackages
2493 my ($destdir, $packages) = @_;
2495 for ( my $i = 0; $i <= $#{$packages}; $i++ )
2497 my $copyrightfilename = ${$packages}[$i] . $installer::globals::separator . "install" . $installer::globals::separator . "copyright";
2498 if ( ! -f $copyrightfilename ) { installer::exiter::exit_program("ERROR: Could not find license file in system integration package: $copyrightfilename!", "add_license_into_systemintegrationpackages"); }
2499 my $copyrightfile = installer::files::read_file($copyrightfilename);
2501 # Saving time stamp of old copyrightfile
2502 my $savcopyrightfilename = $copyrightfilename . ".sav";
2503 installer::systemactions::copy_one_file($copyrightfilename, $savcopyrightfilename);
2504 _set_time_stamp_for_file($copyrightfilename, $savcopyrightfilename); # now $savcopyrightfile has the time stamp of $copyrightfile
2506 # Adding license content to copyright file
2507 push(@{$copyrightfile}, "\n");
2508 for ( my $i = 0; $i <= $#{$installer::globals::englishlicense}; $i++ ) { push(@{$copyrightfile}, ${$installer::globals::englishlicense}[$i]); }
2509 installer::files::save_file($copyrightfilename, $copyrightfile);
2511 # Setting the old time stamp saved with $savcopyrightfilename
2512 _set_time_stamp_for_file($savcopyrightfilename, $copyrightfilename); # now $copyrightfile has the time stamp of $savcopyrightfile
2513 unlink($savcopyrightfilename);
2515 # Changing content of copyright file in pkgmap
2516 my $pkgmapfilename = ${$packages}[$i] . $installer::globals::separator . "pkgmap";
2517 if ( ! -f $pkgmapfilename ) { installer::exiter::exit_program("ERROR: Could not find pkgmap in system integration package: $pkgmapfilename!", "add_license_into_systemintegrationpackages"); }
2518 my $pkgmap = installer::files::read_file($pkgmapfilename);
2519 _change_onefile_in_pkgmap($pkgmap, $copyrightfilename, "copyright");
2520 installer::files::save_file($pkgmapfilename, $pkgmap);
2524 ##############################################
2525 # Setting time stamp of copied files to avoid
2526 # errors from pkgchk.
2527 ##############################################
2529 sub _set_time_stamp_for_file
2531 my ($sourcefile, $destfile) = @_;
2533 my $systemcall = "touch -r $sourcefile $destfile";
2535 my $returnvalue = system($systemcall);
2537 my $infoline = "Systemcall: $systemcall\n";
2538 push( @installer::globals::logfileinfo, $infoline);
2540 if ($returnvalue)
2542 $infoline = "ERROR: \"$systemcall\" failed!\n";
2543 push( @installer::globals::logfileinfo, $infoline);
2545 else
2547 $infoline = "Success: \"$systemcall\" !\n";
2548 push( @installer::globals::logfileinfo, $infoline);
2552 ##############################################
2553 # Setting checksum and wordcount for changed
2554 # pkginfo file into pkgmap.
2555 ##############################################
2557 sub _change_onefile_in_pkgmap
2559 my ($pkgmapfile, $fullfilename, $shortfilename) = @_;
2561 # 1 i pkginfo 442 34577 1166716297
2562 # ->
2563 # 1 i pkginfo 443 34737 1166716297
2565 # wc -c pkginfo | cut -f6 -d' ' -> 442 (variable)
2566 # sum pkginfo | cut -f1 -d' ' -> 34577 (variable)
2567 # grep 'pkginfo' pkgmap | cut -f6 -d' ' -> 1166716297 (fix)
2569 my $checksum = _call_sum($fullfilename);
2570 if ( $checksum =~ /^\s*(\d+)\s+.*$/ ) { $checksum = $1; }
2572 my $wordcount = _call_wc($fullfilename);
2573 if ( $wordcount =~ /^\s*(\d+)\s+.*$/ ) { $wordcount = $1; }
2575 for ( my $i = 0; $i <= $#{$pkgmapfile}; $i++ )
2577 if ( ${$pkgmapfile}[$i] =~ /(^.*\b\Q$shortfilename\E\b\s+)(\d+)(\s+)(\d+)(\s+)(\d+)(\s*$)/ )
2579 my $newline = $1 . $wordcount . $3 . $checksum . $5 . $6 . $7;
2580 ${$pkgmapfile}[$i] = $newline;
2581 last;
2586 #########################################################
2587 # Calling sum
2588 #########################################################
2590 sub _call_sum
2592 my ($filename) = @_;
2594 my $sumfile = "/usr/bin/sum";
2596 if ( ! -f $sumfile ) { installer::exiter::exit_program("ERROR: No file /usr/bin/sum", "call_sum"); }
2598 my $systemcall = "$sumfile $filename |";
2600 my $sumoutput = "";
2602 open (SUM, "$systemcall");
2603 $sumoutput = <SUM>;
2604 close (SUM);
2606 my $returnvalue = $?; # $? contains the return value of the systemcall
2608 my $infoline = "Systemcall: $systemcall\n";
2609 push( @installer::globals::logfileinfo, $infoline);
2611 if ($returnvalue)
2613 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2614 push( @installer::globals::logfileinfo, $infoline);
2616 else
2618 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
2619 push( @installer::globals::logfileinfo, $infoline);
2622 return $sumoutput;
2625 #########################################################
2626 # Calling wc
2627 # wc -c pkginfo | cut -f6 -d' '
2628 #########################################################
2630 sub _call_wc
2632 my ($filename) = @_;
2634 my $wcfile = "/usr/bin/wc";
2636 if ( ! -f $wcfile ) { installer::exiter::exit_program("ERROR: No file /usr/bin/wc", "call_wc"); }
2638 my $systemcall = "$wcfile -c $filename |";
2640 my $wcoutput = "";
2642 open (WC, "$systemcall");
2643 $wcoutput = <WC>;
2644 close (WC);
2646 my $returnvalue = $?; # $? contains the return value of the systemcall
2648 my $infoline = "Systemcall: $systemcall\n";
2649 push( @installer::globals::logfileinfo, $infoline);
2651 if ($returnvalue)
2653 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2654 push( @installer::globals::logfileinfo, $infoline);
2656 else
2658 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
2659 push( @installer::globals::logfileinfo, $infoline);
2662 return $wcoutput;