1# 2# This file is part of the LibreOffice project. 3# 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/. 7# 8# This file incorporates work covered by the following license notice: 9# 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 . 17# 18 19package installer::epmfile; 20 21use Cwd qw(); 22use installer::converter; 23use installer::exiter; 24use installer::files; 25use installer::globals; 26use installer::logger; 27use installer::packagelist; 28use installer::pathanalyzer; 29use installer::remover; 30use installer::scpzipfiles; 31use installer::scriptitems; 32use installer::systemactions; 33use POSIX; 34 35# please Debian packaging, fdo#53341 36sub debian_rewrite($) 37{ 38 my $dep = shift; 39 if ( $installer::globals::debian ) { 40 $dep =~ s/_/-/g; # Debian allows no underline in package name 41 $dep = lc ($dep); 42 } 43 return $dep; 44} 45 46############################################################################ 47# Reading the package map to find Solaris package names for 48# the corresponding abbreviations 49############################################################################ 50 51sub read_packagemap 52{ 53 my ($allvariables, $includepatharrayref, $languagesarrayref) = @_; 54 55 my $packagemapname = ""; 56 if ( $allvariables->{'PACKAGEMAP'} ) { $packagemapname = $allvariables->{'PACKAGEMAP'}; } 57 if ( $packagemapname eq "" ) { installer::exiter::exit_program("ERROR: Property PACKAGEMAP must be defined!", "read_packagemap"); } 58 59 my $infoline = "\n\nCollected abbreviations and package names:\n"; 60 push(@installer::globals::logfileinfo, $infoline); 61 62 # Can be a comma separated list. All files have to be found in include paths 63 my $allpackagemapnames = installer::converter::convert_stringlist_into_hash(\$packagemapname, ","); 64 foreach my $onepackagemapname ( keys %{$allpackagemapnames} ) 65 { 66 my $packagemapref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$onepackagemapname, $includepatharrayref, 0); 67 68 if ( $$packagemapref eq "" ) { installer::exiter::exit_program("ERROR: Could not find package map file \"$onepackagemapname\" (property PACKAGEMAP)!", "read_packagemap"); } 69 70 my $packagemapcontent = installer::files::read_file($$packagemapref); 71 72 for ( my $i = 0; $i <= $#{$packagemapcontent}; $i++ ) 73 { 74 my $line = ${$packagemapcontent}[$i]; 75 76 if ( $line =~ /^\s*\#/ ) { next; } # comment line 77 if ( $line =~ /^\s*$/ ) { next; } # empty line 78 79 if ( $line =~ /^\s*(.*?)\t(.*?)\s*$/ ) 80 { 81 my $abbreviation = $1; 82 my $packagename = $2; 83 installer::packagelist::resolve_packagevariables(\$abbreviation, $allvariables, 0); 84 installer::packagelist::resolve_packagevariables(\$packagename, $allvariables, 0); 85 86 # Special handling for language strings %LANGUAGESTRING 87 88 if (( $abbreviation =~ /\%LANGUAGESTRING/ ) || ( $packagename =~ /\%LANGUAGESTRING/ )) 89 { 90 foreach my $onelang ( @{$languagesarrayref} ) 91 { 92 my $local_abbreviation = $abbreviation; 93 my $local_packagename = $packagename; 94 $local_abbreviation =~ s/\%LANGUAGESTRING/$onelang/g; 95 $local_packagename =~ s/\%LANGUAGESTRING/$onelang/g; 96 97 # Logging all abbreviations and packagenames 98 $infoline = "$onelang : $local_abbreviation : $local_packagename\n"; 99 push(@installer::globals::logfileinfo, $infoline); 100 101 if ( exists($installer::globals::dependfilenames{$local_abbreviation}) ) 102 { 103 installer::exiter::exit_program("ERROR: Packagename for Solaris package $local_abbreviation already defined ($installer::globals::dependfilenames{$local_abbreviation})!", "read_packagemap"); 104 } 105 else 106 { 107 $installer::globals::dependfilenames{$local_abbreviation} = $local_packagename; 108 } 109 } 110 } 111 else 112 { 113 # Logging all abbreviations and packagenames 114 $infoline = "$abbreviation : $packagename\n"; 115 push(@installer::globals::logfileinfo, $infoline); 116 117 if ( exists($installer::globals::dependfilenames{$abbreviation}) ) 118 { 119 installer::exiter::exit_program("ERROR: Packagename for Solaris package $abbreviation already defined ($installer::globals::dependfilenames{$abbreviation})!", "read_packagemap"); 120 } 121 else 122 { 123 $installer::globals::dependfilenames{$abbreviation} = $packagename; 124 } 125 } 126 } 127 else 128 { 129 my $errorline = $i + 1; 130 installer::exiter::exit_program("ERROR: Wrong syntax in file \"$onepackagemapname\" (line $errorline)!", "read_packagemap"); 131 } 132 } 133 } 134 135 $infoline = "\n\n"; 136 push(@installer::globals::logfileinfo, $infoline); 137 138} 139 140########################################################## 141# Filling the epm file with directories, files and links 142########################################################## 143 144sub put_directories_into_epmfile 145{ 146 my ($directoriesarrayref, $epmfileref, $allvariables, $packagerootpath) = @_; 147 my $group = "bin"; 148 149 if ( $installer::globals::islinuxbuild ) 150 { 151 $group = "root"; 152 } 153 154 for ( my $i = 0; $i <= $#{$directoriesarrayref}; $i++ ) 155 { 156 my $onedir = ${$directoriesarrayref}[$i]; 157 my $dir = ""; 158 159 if ( $onedir->{'Dir'} ) { $dir = $onedir->{'Dir'}; } 160 161 if ((!($dir =~ /\bPREDEFINED_/ )) || ( $dir =~ /\bPREDEFINED_PROGDIR\b/ )) 162 { 163 my $hostname = $onedir->{'HostName'}; 164 165 my $line = "d 755 root $group $hostname -\n"; 166 167 push(@{$epmfileref}, $line) 168 } 169 } 170} 171 172sub put_files_into_epmfile 173{ 174 my ($filesinproductarrayref, $epmfileref) = @_; 175 176 for ( my $i = 0; $i <= $#{$filesinproductarrayref}; $i++ ) 177 { 178 my $onefile = ${$filesinproductarrayref}[$i]; 179 180 my $unixrights = $onefile->{'UnixRights'}; 181 my $destination = $onefile->{'destination'}; 182 my $sourcepath = $onefile->{'sourcepath'}; 183 184 my $filetype = "f"; 185 my $styles = ""; 186 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; } 187 if ( $styles =~ /\bCONFIGFILE\b/ ) { $filetype = "c"; } 188 189 my $group = "bin"; 190 if ( $installer::globals::islinuxbuild ) { $group = "root"; } 191 if (( $installer::globals::issolarisbuild ) && ( $onefile->{'SolarisGroup'} )) { $group = $onefile->{'SolarisGroup'}; } 192 193 my $line = "$filetype $unixrights root $group $destination $sourcepath\n"; 194 195 push(@{$epmfileref}, $line); 196 } 197} 198 199sub put_links_into_epmfile 200{ 201 my ($linksinproductarrayref, $epmfileref) = @_; 202 my $group = "bin"; 203 204 if ( $installer::globals::islinuxbuild ) 205 { 206 $group = "root"; 207 } 208 209 210 for ( my $i = 0; $i <= $#{$linksinproductarrayref}; $i++ ) 211 { 212 my $onelink = ${$linksinproductarrayref}[$i]; 213 my $destination = $onelink->{'destination'}; 214 my $destinationfile = $onelink->{'destinationfile'}; 215 216 my $line = "l 000 root $group $destination $destinationfile\n"; 217 218 push(@{$epmfileref}, $line) 219 } 220} 221 222sub put_unixlinks_into_epmfile 223{ 224 my ($unixlinksinproductarrayref, $epmfileref) = @_; 225 my $group = "bin"; 226 227 if ( $installer::globals::islinuxbuild ) { $group = "root"; } 228 229 for ( my $i = 0; $i <= $#{$unixlinksinproductarrayref}; $i++ ) 230 { 231 my $onelink = ${$unixlinksinproductarrayref}[$i]; 232 my $destination = $onelink->{'destination'}; 233 my $target = $onelink->{'Target'}; 234 235 my $line = "l 000 root $group $destination $target\n"; 236 237 push(@{$epmfileref}, $line) 238 } 239} 240 241############################################### 242# Creating epm header file 243############################################### 244 245sub create_epm_header 246{ 247 my ($variableshashref, $filesinproduct, $languagesref, $onepackage) = @_; 248 249 my @epmheader = (); 250 251 my ($licensefilename, $readmefilename, $readmefilenameen); 252 253 my $foundlicensefile = 0; 254 my $foundreadmefile = 0; 255 256 my $line = ""; 257 my $infoline = ""; 258 259 # %product LibreOffice Software 260 # %version 2.0 261 # %description A really great software 262 # %copyright 1999-2003 by OOo 263 # %vendor LibreOffice 264 # %license /test/replace/01/LICENSE01 265 # %readme /test/replace/01/README01 266 # %requires foo 267 # %provides bar 268 # %replaces bar 269 # %incompat bar 270 271 # The first language in the languages array determines the language of license and readme file 272 273 my $searchlanguage = ${$languagesref}[0]; 274 275 # using the description for the %product line in the epm list file 276 277 my $productnamestring = $onepackage->{'description'}; 278 installer::packagelist::resolve_packagevariables(\$productnamestring, $variableshashref, 0); 279 if ( $variableshashref->{'PRODUCTEXTENSION'} ) { $productnamestring = $productnamestring . " " . $variableshashref->{'PRODUCTEXTENSION'}; } 280 281 $line = "%product" . " " . $productnamestring . "\n"; 282 push(@epmheader, $line); 283 284 # Determining the release version 285 # This release version has to be listed in the line %version : %version versionnumber releasenumber 286 287 if ( ! $onepackage->{'packageversion'} ) { installer::exiter::exit_program("ERROR: No packageversion defined for package: $onepackage->{'module'}!", "create_epm_header"); } 288 $installer::globals::packageversion = $onepackage->{'packageversion'}; 289 installer::packagelist::resolve_packagevariables(\$installer::globals::packageversion, $variableshashref, 0); 290 if ( $variableshashref->{'PACKAGEREVISION'} ) { $installer::globals::packagerevision = $variableshashref->{'PACKAGEREVISION'}; } 291 292 $line = "%version" . " " . $installer::globals::packageversion . "\n"; 293 push(@epmheader, $line); 294 295 $line = "%release" . " " . $installer::globals::packagerevision . "\n"; 296 if ( $installer::globals::isrpmbuild ) { $line = "%release" . " " . $installer::globals::buildid . "\n"; } 297 push(@epmheader, $line); 298 299 # Description, Copyright and Vendor are multilingual and are defined in 300 # the string file for the header file ($headerfileref) 301 302 my $descriptionstring = $onepackage->{'description'}; 303 installer::packagelist::resolve_packagevariables(\$descriptionstring, $variableshashref, 0); 304 $line = "%description" . " " . $descriptionstring . "\n"; 305 push(@epmheader, $line); 306 307 my $copyrightstring = $onepackage->{'copyright'}; 308 installer::packagelist::resolve_packagevariables(\$copyrightstring, $variableshashref, 0); 309 $line = "%copyright" . " " . $copyrightstring . "\n"; 310 push(@epmheader, $line); 311 312 my $vendorstring = $onepackage->{'vendor'}; 313 installer::packagelist::resolve_packagevariables(\$vendorstring, $variableshashref, 0); 314 $line = "%vendor" . " " . $vendorstring . "\n"; 315 push(@epmheader, $line); 316 317 # License and Readme file can be included automatically from the file list 318 319 if ( $installer::globals::iswindowsbuild ) 320 { 321 $licensefilename = "license.txt"; 322 $readmefilename = "readme.txt"; 323 $readmefilenameen = "readme_en-US.txt"; 324 } 325 else 326 { 327 $licensefilename = "LICENSE"; 328 $readmefilename = "README"; 329 $readmefilenameen = "README_en-US"; 330 } 331 332 if (( $installer::globals::languagepack ) # in language packs and help packs the files LICENSE and README are removed, because they are not language specific 333 || ( $installer::globals::helppack ) 334 || ( $variableshashref->{'NO_README_IN_ROOTDIR'} )) 335 { 336 if ( $installer::globals::iswindowsbuild ) 337 { 338 $licensefilename = "license.txt"; 339 $readmefilename = "readme_$searchlanguage.txt"; 340 } 341 else 342 { 343 $licensefilename = "LICENSE"; 344 $readmefilename = "README_$searchlanguage"; 345 } 346 } 347 348 my $license_in_package_defined = 0; 349 350 if ( $installer::globals::issolarisbuild ) 351 { 352 if ( $onepackage->{'solariscopyright'} ) 353 { 354 $licensefilename = $onepackage->{'solariscopyright'}; 355 $license_in_package_defined = 1; 356 } 357 } 358 359 # Process for Linux packages, in which only a very basic license file is 360 # included into the package. 361 362 if ( $installer::globals::islinuxbuild ) 363 { 364 if ( $variableshashref->{'COPYRIGHT_INTO_LINUXPACKAGE'} ) 365 { 366 $licensefilename = "linuxcopyrightfile"; 367 $license_in_package_defined = 1; 368 } 369 } 370 371 # searching for and readme file; 372 # URE uses special README; others use README_en-US 373 # it does not matter which one is passed for epm if both are packaged 374 foreach my $possiblereadmefilename ($readmefilenameen, $readmefilename) 375 { 376 last if ($foundreadmefile); 377 for ( my $i = 0; $i <= $#{$filesinproduct}; $i++ ) 378 { 379 my $onefile = ${$filesinproduct}[$i]; 380 my $filename = $onefile->{'Name'}; 381 # in the SDK it's in subdirectory sdk/share/readme 382 if ( $filename =~ /$possiblereadmefilename$/ ) 383 { 384 $foundreadmefile = 1; 385 $line = "%readme" . " " . $onefile->{'sourcepath'} . "\n"; 386 push(@epmheader, $line); 387 last; 388 } 389 } 390 } 391 392 # the readme file need not be packaged more times in the help content 393 # it needs to be installed in parallel with the main package anyway 394 # try to find the README file between all available files (not only between the packaged) 395 if (!($foundreadmefile) && $installer::globals::helppack) 396 { 397 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$readmefilenameen, "" , 0); 398 if($$fileref ne "" ) 399 { 400 $infoline = "Fallback to readme file: \"$$fileref\"!\n"; 401 push(@installer::globals::logfileinfo, $infoline); 402 403 $foundreadmefile = 1; 404 $line = "%readme" . " " . $$fileref . "\n"; 405 push(@epmheader, $line); 406 } 407 } 408 409 # searching for and license file 410 411 if ( $license_in_package_defined ) 412 { 413 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, "" , 0); 414 415 if ( $$fileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find license file $licensefilename (A)!", "create_epm_header"); } 416 417 # Special handling to add the content of the file "license_en-US" to the solaris copyrightfile. But not for all products 418 419 if (( $installer::globals::issolarispkgbuild ) && ( ! $variableshashref->{'NO_LICENSE_INTO_COPYRIGHT'} )) 420 { 421 if ( ! $installer::globals::englishlicenseset ) { _set_english_license() } 422 423 # The location for the new file 424 my $languagestring = ""; 425 for ( my $i = 0; $i <= $#{$languagesref}; $i++ ) { $languagestring = $languagestring . "_" . ${$languagesref}[$i]; } 426 $languagestring =~ s/^\s*_//; 427 428 my $copyrightdir = installer::systemactions::create_directories("copyright", \$languagestring); 429 430 my $copyrightfile = installer::files::read_file($$fileref); 431 432 # Adding license content to copyright file 433 push(@{$copyrightfile}, "\n"); 434 for ( my $i = 0; $i <= $#{$installer::globals::englishlicense}; $i++ ) { push(@{$copyrightfile}, ${$installer::globals::englishlicense}[$i]); } 435 436 # New destination for $$fileref 437 $$fileref = $copyrightdir . $installer::globals::separator . "solariscopyrightfile_" . $onepackage->{'module'}; 438 if ( -f $$fileref ) { unlink $$fileref; } 439 installer::files::save_file($$fileref, $copyrightfile); 440 } 441 442 $infoline = "Using license file: \"$$fileref\"!\n"; 443 push(@installer::globals::logfileinfo, $infoline); 444 445 $foundlicensefile = 1; 446 $line = "%license" . " " . $$fileref . "\n"; 447 push(@epmheader, $line); 448 } 449 else 450 { 451 for my $onefile (@{$filesinproduct}) 452 { 453 # in the SDK it's in subdirectory sdk/share/readme so try to match that 454 if ($onefile->{'Name'} =~ /$licensefilename$/) 455 { 456 push @epmheader, "%license" . " " . $onefile->{'sourcepath'} . "\n"; 457 $foundlicensefile = 1; 458 last; 459 } 460 } 461 462 # the license file need not be packaged more times in the langpacks 463 # they need to be installed in parallel with the main package anyway 464 # try to find the LICENSE file between all available files (not only between the packaged) 465 if (!($foundlicensefile) && ($installer::globals::languagepack || $installer::globals::helppack)) 466 { 467 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, "" , 0); 468 if($$fileref ne "" ) 469 { 470 $infoline = "Fallback to license file: \"$$fileref\"!\n"; 471 push(@installer::globals::logfileinfo, $infoline); 472 473 $foundlicensefile = 1; 474 $line = "%license" . " " . $$fileref . "\n"; 475 push(@epmheader, $line); 476 } 477 } 478 } 479 480 if (!($foundlicensefile)) 481 { 482 installer::exiter::exit_program("ERROR: Could not find license file $licensefilename (B)", "create_epm_header"); 483 } 484 485 if (!($foundreadmefile)) 486 { 487 installer::exiter::exit_program("ERROR: Could not find readme file $readmefilename (C)", "create_epm_header"); 488 } 489 490 # including %replaces 491 492 my $replaces = ""; 493 494 if ( $installer::globals::issolarispkgbuild ) 495 { 496 $replaces = "solarisreplaces"; # the name in the packagelist 497 } 498 elsif ( $installer::globals::islinuxbuild ) 499 { 500 $replaces = "linuxreplaces"; # the name in the packagelist 501 } 502 503 if ( $replaces ) 504 { 505 if ( $onepackage->{$replaces} ) 506 { 507 my $replacesstring = $onepackage->{$replaces}; 508 509 my $allreplaces = installer::converter::convert_stringlist_into_array(\$replacesstring, ","); 510 511 for ( my $i = 0; $i <= $#{$allreplaces}; $i++ ) 512 { 513 my $onereplaces = ${$allreplaces}[$i]; 514 $onereplaces =~ s/\s*$//; 515 installer::packagelist::resolve_packagevariables(\$onereplaces, $variableshashref, 1); 516 $onereplaces = debian_rewrite($onereplaces); 517 $line = "%replaces" . " " . $onereplaces . "\n"; 518 push(@epmheader, $line); 519 } 520 } 521 } 522 523 # including %incompat 524 525 my $incompat = ""; 526 527 if (( $installer::globals::issolarispkgbuild ) && ( ! $installer::globals::patch )) 528 { 529 $incompat = "solarisincompat"; # the name in the packagelist 530 } 531 elsif (( $installer::globals::islinuxbuild ) && ( ! $installer::globals::patch )) 532 { 533 $incompat = "linuxincompat"; # the name in the packagelist 534 } 535 536 if (( $incompat ) && ( ! $installer::globals::patch )) 537 { 538 if ( $onepackage->{$incompat} ) 539 { 540 my $incompatstring = $onepackage->{$incompat}; 541 542 my $allincompat = installer::converter::convert_stringlist_into_array(\$incompatstring, ","); 543 544 for ( my $i = 0; $i <= $#{$allincompat}; $i++ ) 545 { 546 my $oneincompat = ${$allincompat}[$i]; 547 $oneincompat =~ s/\s*$//; 548 installer::packagelist::resolve_packagevariables(\$oneincompat, $variableshashref, 1); 549 $oneincompat = debian_rewrite($oneincompat); 550 $line = "%incompat" . " " . $oneincompat . "\n"; 551 push(@epmheader, $line); 552 } 553 } 554 } 555 556 # including the directives for %requires and %provides 557 558 my $provides = ""; 559 my $requires = ""; 560 561 if ( $installer::globals::issolarispkgbuild ) 562 { 563 $provides = "solarisprovides"; # the name in the packagelist 564 $requires = "solarisrequires"; # the name in the packagelist 565 } 566 elsif ( $installer::globals::isfreebsdpkgbuild ) 567 { 568 $provides = "freebsdprovides"; # the name in the packagelist 569 $requires = "freebsdrequires"; # the name in the packagelist 570 } 571 else 572 { 573 $provides = "provides"; # the name in the packagelist 574 $requires = "requires"; # the name in the packagelist 575 } 576 577 my $isdict = 0; 578 if ( $onepackage->{'packagename'} =~ /-dict-/ ) { $isdict = 1; } 579 580 if ( $onepackage->{$provides} ) 581 { 582 my $providesstring = $onepackage->{$provides}; 583 584 my $allprovides = installer::converter::convert_stringlist_into_array(\$providesstring, ","); 585 586 for ( my $i = 0; $i <= $#{$allprovides}; $i++ ) 587 { 588 my $oneprovides = ${$allprovides}[$i]; 589 $oneprovides =~ s/\s*$//; 590 installer::packagelist::resolve_packagevariables(\$oneprovides, $variableshashref, 1); 591 $oneprovides = debian_rewrite($oneprovides); 592 $line = "%provides" . " " . $oneprovides . "\n"; 593 push(@epmheader, $line); 594 } 595 } 596 597 if ( $onepackage->{$requires} ) 598 { 599 my $requiresstring = $onepackage->{$requires}; 600 601 # The requires string can contain the separator "," in the names (descriptions) of the packages 602 # (that are required for Solaris depend files). Therefore "," inside such a description has to 603 # masked with a backslash. 604 # This masked separator need to be found and replaced, before the stringlist is converted into an array. 605 # This replacement has to be turned back after the array is created. 606 607 my $replacementstring = "COMMAREPLACEMENT"; 608 $requiresstring = installer::converter::replace_masked_separator($requiresstring, ",", "$replacementstring"); 609 610 my $allrequires = installer::converter::convert_stringlist_into_array(\$requiresstring, ","); 611 612 installer::converter::resolve_masked_separator($allrequires, ",", $replacementstring); 613 614 for ( my $i = 0; $i <= $#{$allrequires}; $i++ ) 615 { 616 my $onerequires = ${$allrequires}[$i]; 617 $onerequires =~ s/\s*$//; 618 installer::packagelist::resolve_packagevariables2(\$onerequires, $variableshashref, 0, $isdict); 619 $onerequires = debian_rewrite($onerequires); 620 $line = "%requires" . " " . $onerequires . "\n"; 621 push(@epmheader, $line); 622 } 623 } 624 625 return \@epmheader; 626} 627 628####################################### 629# Adding header to epm file 630####################################### 631 632sub adding_header_to_epm_file 633{ 634 my ($epmfileref, $epmheaderref) = @_; 635 636 for ( my $i = 0; $i <= $#{$epmheaderref}; $i++ ) 637 { 638 push( @{$epmfileref}, ${$epmheaderref}[$i] ); 639 } 640 641 push( @{$epmfileref}, "\n\n" ); 642} 643 644##################################################### 645# Replace one in shell scripts ( ${VARIABLENAME} ) 646##################################################### 647 648sub replace_variable_in_shellscripts 649{ 650 my ($scriptref, $variable, $searchstring) = @_; 651 652 for ( my $i = 0; $i <= $#{$scriptref}; $i++ ) 653 { 654 ${$scriptref}[$i] =~ s/\$\{$searchstring\}/$variable/g; 655 } 656} 657 658################################################ 659# Replacing many variables in shell scripts 660################################################ 661 662sub replace_many_variables_in_shellscripts 663{ 664 my ($scriptref, $variableshashref) = @_; 665 666 my $key; 667 668 foreach $key (keys %{$variableshashref}) 669 { 670 my $value = $variableshashref->{$key}; 671 replace_variable_in_shellscripts($scriptref, $value, $key); 672 } 673} 674 675####################################### 676# Adding shell scripts to epm file 677####################################### 678 679sub adding_shellscripts_to_epm_file 680{ 681 my ($epmfileref, $shellscriptsfilename, $localrootpath, $allvariableshashref, $filesinpackage) = @_; 682 683 push( @{$epmfileref}, "\n\n" ); 684 685 my $shellscriptsfileref = installer::files::read_file($shellscriptsfilename); 686 687 replace_variable_in_shellscripts($shellscriptsfileref, $localrootpath, "rootpath"); 688 689 replace_many_variables_in_shellscripts($shellscriptsfileref, $allvariableshashref); 690 691 for ( my $i = 0; $i <= $#{$shellscriptsfileref}; $i++ ) 692 { 693 push( @{$epmfileref}, ${$shellscriptsfileref}[$i] ); 694 } 695 696 push( @{$epmfileref}, "\n" ); 697} 698 699################################################# 700# Determining the epm on the system 701################################################# 702 703sub find_epm_on_system 704{ 705 my ($includepatharrayref) = @_; 706 707 installer::logger::include_header_into_logfile("Check epm on system"); 708 709 my $epmname = "epm"; 710 711 # epm should be defined through the configure script but we need to 712 # check for it to be defined because of the Sun environment. 713 # Check the environment variable first and if it is not defined, 714 # or if it is but the location is not executable, search further. 715 # It has to be found in the solver or it has to be in the path 716 # (saved in $installer::globals::epm_in_path) or we get the specified 717 # one through the environment (i.e. when --with-epm=... is specified) 718 719 if ($ENV{'EPM'}) 720 { 721 if (($ENV{'EPM'} ne "") && (-x "$ENV{'EPM'}")) 722 { 723 $epmname = $ENV{'EPM'}; 724 } 725 else 726 { 727 installer::exiter::exit_program("Environment variable EPM set (\"$ENV{'EPM'}\"), but file does not exist or is not executable!", "find_epm_on_system"); 728 } 729 } 730 else 731 { 732 my $epmfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$epmname, $includepatharrayref, 0); 733 734 if (($$epmfileref eq "") && (!($installer::globals::epm_in_path))) { installer::exiter::exit_program("ERROR: Could not find program $epmname!", "find_epm_on_system"); } 735 if (($$epmfileref eq "") && ($installer::globals::epm_in_path)) { $epmname = $installer::globals::epm_path; } 736 if (!($$epmfileref eq "")) { $epmname = $$epmfileref; } 737 } 738 739 my $infoline = "Using epmfile: $epmname\n"; 740 push( @installer::globals::logfileinfo, $infoline); 741 742 return $epmname; 743} 744 745################################################# 746# Determining the epm patch state 747# saved in $installer::globals::is_special_epm 748################################################# 749 750sub set_patch_state 751{ 752 my ($epmexecutable) = @_; 753 754 my $infoline = ""; 755 756 my $systemcall = "$epmexecutable |"; 757 open (EPMPATCH, "$systemcall"); 758 759 while (<EPMPATCH>) 760 { 761 chop; 762 if ( $_ =~ /Patched for .*Office/ ) { $installer::globals::is_special_epm = 1; } 763 } 764 765 close (EPMPATCH); 766 767 if ( $installer::globals::is_special_epm ) 768 { 769 $infoline = "\nPatch state: This is a patched version of epm!\n\n"; 770 push( @installer::globals::logfileinfo, $infoline); 771 } 772 else 773 { 774 $infoline = "\nPatch state: This is an unpatched version of epm!\n\n"; 775 push( @installer::globals::logfileinfo, $infoline); 776 } 777 778 if ( ( $installer::globals::is_special_epm ) && (($installer::globals::isrpmbuild) || ($installer::globals::issolarispkgbuild)) ) 779 { 780 # Special postprocess handling only for Linux RPM and Solaris packages 781 $installer::globals::postprocess_specialepm = 1; 782 $installer::globals::postprocess_standardepm = 0; 783 } 784 else 785 { 786 $installer::globals::postprocess_specialepm = 0; 787 $installer::globals::postprocess_standardepm = 1; 788 } 789} 790 791################################################# 792# Calling epm to create the installation sets 793################################################# 794 795sub call_epm 796{ 797 my ($epmname, $epmlistfilename, $packagename, $includepatharrayref) = @_; 798 799 installer::logger::include_header_into_logfile("epm call for $packagename"); 800 801 my $packageformat = $installer::globals::packageformat; 802 803 my $localpackagename = $packagename; 804 # Debian allows only lowercase letters in package name 805 if ( $installer::globals::debian ) { $localpackagename = lc($localpackagename); } 806 807 my $outdirstring = ""; 808 if ( $installer::globals::epmoutpath ne "" ) { $outdirstring = " --output-dir $installer::globals::epmoutpath"; } 809 810 # Debian package build needs to be run with fakeroot for correct ownerships/permissions 811 812 my $fakerootstring = ""; 813 814 if ( $installer::globals::debian ) { $fakerootstring = "fakeroot "; } 815 816 my $extraflags = ""; 817 if ($ENV{'EPM_FLAGS'}) { $extraflags = $ENV{'EPM_FLAGS'}; } 818 819 $extraflags .= ' -g' unless $installer::globals::strip; 820 821 my $verboseflag = "-v"; 822 if ( ! $installer::globals::quiet ) { $verboseflag = "-v2"; }; 823 824 my $systemcall = $fakerootstring . $epmname . " -f " . $packageformat . " " . $extraflags . " " . $localpackagename . " " . $epmlistfilename . $outdirstring . " " . $verboseflag . " " . " 2\>\&1 |"; 825 826 installer::logger::print_message( "... $systemcall ...\n" ); 827 828 my $maxepmcalls = 3; 829 830 for ( my $i = 1; $i <= $maxepmcalls; $i++ ) 831 { 832 my @epmoutput = (); 833 834 open (EPM, "$systemcall"); 835 while (<EPM>) {push(@epmoutput, $_); } 836 close (EPM); 837 838 my $returnvalue = $?; # $? contains the return value of the systemcall 839 840 my $infoline = "Systemcall (Try $i): $systemcall\n"; 841 push( @installer::globals::logfileinfo, $infoline); 842 843 for ( my $j = 0; $j <= $#epmoutput; $j++ ) 844 { 845 if ( $i < $maxepmcalls ) { $epmoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; } 846 push( @installer::globals::logfileinfo, "$epmoutput[$j]"); 847 } 848 849 if ($returnvalue) 850 { 851 $infoline = "Try $i : Could not execute \"$systemcall\"!\n"; 852 push( @installer::globals::logfileinfo, $infoline); 853 if ( $i == $maxepmcalls ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "call_epm"); } 854 } 855 else 856 { 857 installer::logger::print_message( "Success (Try $i): \"$systemcall\"\n" ); 858 $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 859 push( @installer::globals::logfileinfo, $infoline); 860 last; 861 } 862 } 863} 864 865##################################################################### 866# Adding the new line for relocatables into pkginfo file (Solaris) 867# or spec file (Linux) created by epm 868##################################################################### 869 870sub add_one_line_into_file 871{ 872 my ($file, $insertline, $filename) = @_; 873 874 if ( $installer::globals::issolarispkgbuild ) 875 { 876 push(@{$file}, $insertline); # simply adding at the end of pkginfo file 877 } 878 879 if ( $installer::globals::isrpmbuild ) 880 { 881 # Adding behind the line beginning with: Group: 882 883 my $inserted_line = 0; 884 885 for ( my $i = 0; $i <= $#{$file}; $i++ ) 886 { 887 if ( ${$file}[$i] =~ /^\s*Group\:\s*/ ) 888 { 889 splice(@{$file},$i+1,0,$insertline); 890 $inserted_line = 1; 891 last; 892 } 893 } 894 895 if (! $inserted_line) { installer::exiter::exit_program("ERROR: Did not find string \"Group:\" in file: $filename", "add_one_line_into_file"); } 896 } 897 898 $insertline =~ s/\s*$//; # removing line end for correct logging 899 my $infoline = "Success: Added line $insertline into file $filename!\n"; 900 push( @installer::globals::logfileinfo, $infoline); 901} 902 903##################################################################### 904# Setting the revision VERSION=1.9,REV=66 . 905# Also adding the new line: "AutoReqProv: no" 906##################################################################### 907 908sub set_revision_in_pkginfo 909{ 910 my ($file, $filename, $variables, $packagename) = @_; 911 912 my $revisionstring = "\,REV\=" . $installer::globals::packagerevision; 913 914 # Adding also a time string to the revision. Syntax: VERSION=8.0.0,REV=66.2005.01.24 915 916 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); 917 918 $mday = $mday; 919 $mon = $mon + 1; 920 $year = $year + 1900; 921 922 if ( $mday < 10 ) { $mday = "0" . $mday; } 923 if ( $mon < 10 ) { $mon = "0" . $mon; } 924 $datestring = $year . "." . $mon . "." . $mday; 925 $revisionstring = $revisionstring . "." . $datestring; 926 927 for ( my $i = 0; $i <= $#{$file}; $i++ ) 928 { 929 if ( ${$file}[$i] =~ /^\s*(VERSION\=.*?)\s*$/ ) 930 { 931 my $oldstring = $1; 932 my $newstring = $oldstring . $revisionstring; # also adding the date string 933 ${$file}[$i] =~ s/$oldstring/$newstring/; 934 my $infoline = "Info: Changed in $filename file: \"$oldstring\" to \"$newstring\"!\n"; 935 push( @installer::globals::logfileinfo, $infoline); 936 last; 937 } 938 } 939 940 # For Update and Patch reasons, this string can also be kept constant 941 942 my $pkgversion = "SOLSPARCPKGVERSION"; 943 if ( $installer::globals::issolarisx86build ) { $pkgversion = "SOLIAPKGVERSION"; } 944 945 if (( $variables->{$pkgversion} ) && ( $variables->{$pkgversion} ne "" )) 946 { 947 if ( $variables->{$pkgversion} ne "FINALVERSION" ) 948 { 949 # In OOo 3.x timeframe, this string is no longer unique for all packages, because of the three layer. 950 # 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 951 # and therefore be set as $pkgversion. 952 # The first part "3.0.0" has to be derived from the 953 954 my $version = $installer::globals::packageversion; 955 if ( $version =~ /^\s*(\d+)\.(\d+)\.(\d+)\s*$/ ) 956 { 957 my $major = $1; 958 my $minor = $2; 959 my $micro = $3; 960 961 my $finalmajor = $major; 962 my $finalminor = $minor; 963 my $finalmicro = 0; 964 965 $version = "$finalmajor.$finalminor.$finalmicro"; 966 } 967 968 my $datestring = $variables->{$pkgversion}; 969 970 # Allowing some packages to have another date of creation. 971 # They can be defined in product definition using a key like "SOLSPARCPKGVERSION_$packagename" 972 973 my $additionalkey = $pkgversion . "_" . $packagename; 974 if (( $variables->{$additionalkey} ) && ( $variables->{$additionalkey} ne "" )) { $datestring = $variables->{$additionalkey}; } 975 976 my $versionstring = "$version,$datestring"; 977 978 for ( my $i = 0; $i <= $#{$file}; $i++ ) 979 { 980 if ( ${$file}[$i] =~ /^\s*(VERSION\=).*?\s*$/ ) 981 { 982 my $start = $1; 983 my $newstring = $start . $versionstring . "\n"; # setting the complete new string 984 my $oldstring = ${$file}[$i]; 985 ${$file}[$i] = $newstring; 986 $oldstring =~ s/\s*$//; 987 $newstring =~ s/\s*$//; 988 my $infoline = "Info: Changed in $filename file: \"$oldstring\" to \"$newstring\"!\n"; 989 push( @installer::globals::logfileinfo, $infoline); 990 last; 991 } 992 } 993 } 994 } 995} 996 997######################################################## 998# Setting MAXINST=1000 into the pkginfo file. 999######################################################## 1000 1001sub set_maxinst_in_pkginfo 1002{ 1003 my ($changefile, $filename) = @_; 1004 1005 my $newline = "MAXINST\=1000\n"; 1006 1007 add_one_line_into_file($changefile, $newline, $filename); 1008} 1009 1010############################################################# 1011# Setting several Solaris variables into the pkginfo file. 1012############################################################# 1013 1014sub set_solaris_parameter_in_pkginfo 1015{ 1016 my ($changefile, $filename, $allvariables) = @_; 1017 1018 my $newline = ""; 1019 1020 # SUNW_PRODNAME 1021 # SUNW_PRODVERS 1022 # SUNW_PKGVERS 1023 # Not: SUNW_PKGTYPE 1024 # HOTLINE 1025 # EMAIL 1026 1027 my $productname = $allvariables->{'PRODUCTNAME'}; 1028 $newline = "SUNW_PRODNAME=$productname\n"; 1029 add_one_line_into_file($changefile, $newline, $filename); 1030 1031 my $productversion = ""; 1032 if ( $allvariables->{'PRODUCTVERSION'} ) 1033 { 1034 $productversion = $allvariables->{'PRODUCTVERSION'}; 1035 if ( $allvariables->{'PRODUCTEXTENSION'} ) { $productversion = $productversion . "/" . $allvariables->{'PRODUCTEXTENSION'}; } 1036 } 1037 $newline = "SUNW_PRODVERS=$productversion\n"; 1038 add_one_line_into_file($changefile, $newline, $filename); 1039 1040 $newline = "SUNW_PKGVERS=1\.0\n"; 1041 add_one_line_into_file($changefile, $newline, $filename); 1042 1043 if ( $allvariables->{'SUNW_PKGTYPE'} ) 1044 { 1045 $newline = "SUNW_PKGTYPE=$allvariables->{'SUNW_PKGTYPE'}\n"; 1046 add_one_line_into_file($changefile, $newline, $filename); 1047 } 1048 else 1049 { 1050 $newline = "SUNW_PKGTYPE=\n"; 1051 add_one_line_into_file($changefile, $newline, $filename); 1052 } 1053 1054 $newline = "HOTLINE=Please contact your local service provider\n"; 1055 add_one_line_into_file($changefile, $newline, $filename); 1056 1057 $newline = "EMAIL=\n"; 1058 add_one_line_into_file($changefile, $newline, $filename); 1059 1060} 1061 1062##################################################################### 1063# epm uses as architecture for Solaris x86 "i86pc". This has to be 1064# changed to "i386". 1065##################################################################### 1066 1067sub fix_architecture_setting 1068{ 1069 my ($changefile) = @_; 1070 1071 for ( my $i = 0; $i <= $#{$changefile}; $i++ ) 1072 { 1073 if ( ${$changefile}[$i] =~ /^\s*ARCH=i86pc\s*$/ ) 1074 { 1075 ${$changefile}[$i] =~ s/i86pc/i386/; 1076 last; 1077 } 1078 1079 } 1080} 1081 1082##################################################################### 1083# Adding a new line for topdir into specfile, removing old 1084# topdir if set. 1085##################################################################### 1086 1087sub set_topdir_in_specfile 1088{ 1089 my ($changefile, $filename, $newepmdir) = @_; 1090 1091 $newepmdir = Cwd::cwd() . $installer::globals::separator . $newepmdir; # only absolute path allowed 1092 1093 # removing "%define _topdir", if existing 1094 1095 for ( my $i = 0; $i <= $#{$changefile}; $i++ ) 1096 { 1097 if ( ${$changefile}[$i] =~ /^\s*\%define _topdir\s+/ ) 1098 { 1099 my $removeline = ${$changefile}[$i]; 1100 $removeline =~ s/\s*$//; 1101 splice(@{$changefile},$i,1); 1102 my $infoline = "Info: Removed line \"$removeline\" from file $filename!\n"; 1103 push( @installer::globals::logfileinfo, $infoline); 1104 last; 1105 } 1106 } 1107 1108 # Adding "topdir" behind the line beginning with: Group: 1109 1110 my $inserted_line = 0; 1111 1112 my $topdirline = "\%define _topdir $newepmdir\n"; 1113 1114 for ( my $i = 0; $i <= $#{$changefile}; $i++ ) 1115 { 1116 if ( ${$changefile}[$i] =~ /^\s*Group\:\s*/ ) 1117 { 1118 splice(@{$changefile},$i+1,0,$topdirline); 1119 $inserted_line = 1; 1120 $topdirline =~ s/\s*$//; 1121 my $infoline = "Success: Added line $topdirline into file $filename!\n"; 1122 push( @installer::globals::logfileinfo, $infoline); 1123 } 1124 } 1125 1126 if (! $inserted_line) { installer::exiter::exit_program("ERROR: Did not find string \"Group:\" in file: $filename", "set_topdir_in_specfile"); } 1127 1128} 1129 1130##################################################################### 1131# Setting the packager in the spec file 1132# Syntax: Packager: abc@def 1133##################################################################### 1134 1135sub set_packager_in_specfile 1136{ 1137 my ($changefile) = @_; 1138 1139 my $packager = $installer::globals::longmanufacturer; 1140 1141 for ( my $i = 0; $i <= $#{$changefile}; $i++ ) 1142 { 1143 if ( ${$changefile}[$i] =~ /^\s*Packager\s*:\s*(.+?)\s*$/ ) 1144 { 1145 my $oldstring = $1; 1146 ${$changefile}[$i] =~ s/\Q$oldstring\E/$packager/; 1147 my $infoline = "Info: Changed Packager in spec file from $oldstring to $packager!\n"; 1148 push( @installer::globals::logfileinfo, $infoline); 1149 last; 1150 } 1151 } 1152} 1153 1154##################################################################### 1155# Setting the requirements in the spec file (i81494) 1156# Syntax: PreReq: "requirements" (only for shared extensions) 1157##################################################################### 1158 1159sub set_prereq_in_specfile 1160{ 1161 my ($changefile) = @_; 1162 1163 my $prereq = "PreReq:"; 1164 1165 for ( my $i = 0; $i <= $#{$changefile}; $i++ ) 1166 { 1167 if ( ${$changefile}[$i] =~ /^\s*Requires:\s*(.+?)\s*$/ ) 1168 { 1169 my $oldstring = ${$changefile}[$i]; 1170 ${$changefile}[$i] =~ s/Requires:/$prereq/; 1171 my $infoline = "Info: Changed requirements in spec file from $oldstring to ${$changefile}[$i]!\n"; 1172 push( @installer::globals::logfileinfo, $infoline); 1173 } 1174 } 1175} 1176 1177##################################################################### 1178# Setting the Auto[Req]Prov line and __find_requires 1179##################################################################### 1180 1181sub set_autoprovreq_in_specfile 1182{ 1183 my ($changefile, $findrequires, $bindir) = @_; 1184 1185 my $autoreqprovline = "AutoReqProv\: no\n"; 1186 1187 if ( $findrequires ) 1188 { 1189 # don't let rpm invoke it, we never want to use AutoReq because 1190 # rpm will generate Requires: config(packagename) 1191 open (FINDREQUIRES, "echo | $bindir/$findrequires |"); 1192 while (<FINDREQUIRES>) { $autoreqprovline .= "Requires: $_\n"; } 1193 close (FINDREQUIRES); 1194 } 1195 1196 $autoreqprovline .= "%define _binary_filedigest_algorithm 1\n%define _binary_payload w9.gzdio\n"; 1197 1198 for ( my $i = 0; $i <= $#{$changefile}; $i++ ) 1199 { 1200 # Adding "autoreqprov" behind the line beginning with: Group: 1201 if ( ${$changefile}[$i] =~ /^\s*Group\:\s*/ ) 1202 { 1203 splice(@{$changefile},$i+1,0,$autoreqprovline); 1204 $autoreqprovline =~ s/\s*$//; 1205 $infoline = "Success: Added line $autoreqprovline into spec file!\n"; 1206 push( @installer::globals::logfileinfo, $infoline); 1207 1208 last; 1209 } 1210 } 1211} 1212 1213##################################################################### 1214# Replacing Copyright with License in the spec file 1215# Syntax: License: LGPLv3 (or MPLv2 on ALv2, older usages were LGPL, SISSL) 1216##################################################################### 1217 1218sub set_license_in_specfile 1219{ 1220 my ($changefile, $variableshashref) = @_; 1221 1222 my $license = $variableshashref->{'LICENSENAME'}; 1223 1224 for ( my $i = 0; $i <= $#{$changefile}; $i++ ) 1225 { 1226 if ( ${$changefile}[$i] =~ /^\s*Copyright\s*:\s*(.+?)\s*$/ ) 1227 { 1228 ${$changefile}[$i] = "License: $license\n"; 1229 my $infoline = "Info: Replaced Copyright with License: $license !\n"; 1230 push( @installer::globals::logfileinfo, $infoline); 1231 last; 1232 } 1233 } 1234} 1235 1236######################################################### 1237# Building relocatable Solaris packages means: 1238# 1. Add "BASEDIR=/opt" into pkginfo 1239# 2. Remove "/opt/" from all objects in prototype file 1240# For step2 this function exists 1241# Sample: d none /opt/openofficeorg20/help 0755 root other 1242# -> d none openofficeorg20/help 0755 root other 1243######################################################### 1244 1245sub make_prototypefile_relocatable 1246{ 1247 my ($prototypefile, $relocatablepath) = @_; 1248 1249 for ( my $i = 0; $i <= $#{$prototypefile}; $i++ ) 1250 { 1251 if ( ${$prototypefile}[$i] =~ /^\s*\w\s+\w+\s+\/\w+/ ) # this is an object line 1252 { 1253 ${$prototypefile}[$i] =~ s/$relocatablepath//; # Important: $relocatablepath has a "/" at the end. Example "/opt/" 1254 } 1255 } 1256 1257 # If the $relocatablepath is "/opt/openoffice20/" the line "d none /opt/openoffice20" was not changed. 1258 # This line has to be removed now 1259 1260 if ( $relocatablepath ne "/" ) { $relocatablepath =~ s/\/\s*$//; } # removing the ending slash 1261 1262 for ( my $i = 0; $i <= $#{$prototypefile}; $i++ ) 1263 { 1264 if ( ${$prototypefile}[$i] =~ /^\s*d\s+\w+\s+\Q$relocatablepath\E/ ) 1265 { 1266 my $line = ${$prototypefile}[$i]; 1267 splice(@{$prototypefile},$i,1); # removing the line 1268 $line =~ s/\s*$//; 1269 my $infoline = "Info: Removed line \"$line\" from prototype file!\n"; 1270 push( @installer::globals::logfileinfo, $infoline); 1271 last; 1272 } 1273 } 1274 1275 # Making "\$" to "$" in prototype file. "\$" was created by epm. 1276 1277 for ( my $i = 0; $i <= $#{$prototypefile}; $i++ ) 1278 { 1279 if ( ${$prototypefile}[$i] =~ /\\\$/ ) 1280 { 1281 ${$prototypefile}[$i] =~ s/\\\$/\$/g; 1282 my $infoline2 = "Info: Changed line in prototype file: ${$prototypefile}[$i] !\n"; 1283 push( @installer::globals::logfileinfo, $infoline2); 1284 } 1285 } 1286} 1287 1288######################################################################### 1289# Replacing the variables in the shell scripts or in the epm list file 1290# Linux: spec file 1291# Solaris: preinstall, postinstall, preremove, postremove 1292# If epm is used in the original version (not relocatable) 1293# the variables have to be exchanged in the list file, 1294# created for epm. 1295######################################################################### 1296 1297sub replace_variables_in_shellscripts 1298{ 1299 my ($scriptfile, $scriptfilename, $oldstring, $newstring) = @_; 1300 1301 my $debug = 0; 1302 if ( $oldstring eq "PRODUCTDIRECTORYNAME" ) { $debug = 1; } 1303 1304 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ ) 1305 { 1306 if ( ${$scriptfile}[$i] =~ /\Q$oldstring\E/ ) 1307 { 1308 my $oldline = ${$scriptfile}[$i]; 1309 ${$scriptfile}[$i] =~ s/\Q$oldstring\E/$newstring/g; 1310 ${$scriptfile}[$i] =~ s/\/\//\//g; # replacing "//" by "/" , if path $newstring is empty! 1311 my $infoline = "Info: Substituting in $scriptfilename $oldstring by $newstring\n"; 1312 push(@installer::globals::logfileinfo, $infoline); 1313 if ( $debug ) 1314 { 1315 $infoline = "Old Line: $oldline"; 1316 push(@installer::globals::logfileinfo, $infoline); 1317 $infoline = "New Line: ${$scriptfile}[$i]"; 1318 push(@installer::globals::logfileinfo, $infoline); 1319 } 1320 } 1321 } 1322} 1323 1324############################################################ 1325# Determining the directory created by epm, in which the 1326# RPMS or Solaris packages are created. 1327############################################################ 1328 1329sub determine_installdir_ooo 1330{ 1331 # A simple "ls" command returns the directory name 1332 1333 my $dirname = ""; 1334 1335 my $systemcall = "ls |"; 1336 open (LS, "$systemcall"); 1337 $dirname = <LS>; 1338 close (LS); 1339 1340 $dirname =~ s/\s*$//; 1341 1342 my $infoline = "Info: Directory created by epm: $dirname\n"; 1343 push(@installer::globals::logfileinfo, $infoline); 1344 1345 return $dirname; 1346} 1347 1348############################################################ 1349# Setting the tab content into the file container 1350############################################################ 1351 1352sub set_tab_into_datafile 1353{ 1354 my ($changefile, $filesref) = @_; 1355 1356 my @newclasses = (); 1357 my $newclassesstring = ""; 1358 1359 if ( $installer::globals::issolarispkgbuild ) 1360 { 1361 for ( my $i = 0; $i <= $#{$filesref}; $i++ ) 1362 { 1363 my $onefile = ${$filesref}[$i]; 1364 1365 if ( $onefile->{'SolarisClass'} ) 1366 { 1367 my $sourcepath = $onefile->{'sourcepath'}; 1368 1369 for ( my $j = 0; $j <= $#{$changefile}; $j++ ) 1370 { 1371 if (( ${$changefile}[$j] =~ /^\s*f\s+none\s+/ ) && ( ${$changefile}[$j] =~ /\=\Q$sourcepath\E\s+/ )) 1372 { 1373 my $oldline = ${$changefile}[$j]; 1374 ${$changefile}[$j] =~ s/f\s+none/e $onefile->{'SolarisClass'}/; 1375 my $newline = ${$changefile}[$j]; 1376 $oldline =~ s/\s*$//; 1377 $newline =~ s/\s*$//; 1378 1379 my $infoline = "TAB: Changing content from \"$oldline\" to \"$newline\" .\n"; 1380 push(@installer::globals::logfileinfo, $infoline); 1381 1382 # collecting all new classes 1383 if (! grep {$_ eq $onefile->{'SolarisClass'}} @newclasses) 1384 { 1385 push(@newclasses, $onefile->{'SolarisClass'}); 1386 } 1387 1388 last; 1389 } 1390 } 1391 } 1392 } 1393 1394 $newclassesstring = installer::converter::convert_array_to_space_separated_string(\@newclasses); 1395 } 1396 1397 if ( $installer::globals::isrpmbuild ) 1398 { 1399 for ( my $i = 0; $i <= $#{$filesref}; $i++ ) 1400 { 1401 my $onefile = ${$filesref}[$i]; 1402 1403 if ( $onefile->{'SpecFileContent'} ) 1404 { 1405 my $destination = $onefile->{'destination'}; 1406 1407 for ( my $j = 0; $j <= $#{$changefile}; $j++ ) 1408 { 1409 if ( ${$changefile}[$j] =~ /^\s*(\%attr\(.*\))\s+(\".*?\Q$destination\E\"\s*)$/ ) 1410 { 1411 my $begin = $1; 1412 my $end = $2; 1413 1414 my $oldline = ${$changefile}[$j]; 1415 ${$changefile}[$j] = $begin . " " . $onefile->{'SpecFileContent'} . " " . $end; 1416 my $newline = ${$changefile}[$j]; 1417 1418 $oldline =~ s/\s*$//; 1419 $newline =~ s/\s*$//; 1420 1421 my $infoline = "TAB: Changing content from \"$oldline\" to \"$newline\" .\n"; 1422 push(@installer::globals::logfileinfo, $infoline); 1423 1424 last; 1425 } 1426 } 1427 } 1428 } 1429 } 1430 1431 return $newclassesstring; 1432} 1433 1434############################################################ 1435# Including additional classes into the pkginfo file 1436############################################################ 1437 1438sub include_classes_into_pkginfo 1439{ 1440 my ($changefile, $classesstring) = @_; 1441 1442 for ( my $i = 0; $i <= $#{$changefile}; $i++ ) 1443 { 1444 if ( ${$changefile}[$i] =~ /^\s*CLASSES\=none/ ) 1445 { 1446 ${$changefile}[$i] =~ s/\s*$//; 1447 my $oldline = ${$changefile}[$i]; 1448 ${$changefile}[$i] = ${$changefile}[$i] . " " . $classesstring . "\n"; 1449 my $newline = ${$changefile}[$i]; 1450 $newline =~ s/\s*$//; 1451 1452 my $infoline = "pkginfo file: Changing content from \"$oldline\" to \"$newline\" .\n"; 1453 push(@installer::globals::logfileinfo, $infoline); 1454 } 1455 } 1456} 1457 1458########################################################################################## 1459# Checking, if an extension is included into the package (Linux). 1460# All extension files have to be installed into directory 1461# share/extension/install 1462# %attr(0444,root,root) "/opt/staroffice8/share/extension/install/SunSearchToolbar.oxt" 1463########################################################################################## 1464 1465sub is_extension_package 1466{ 1467 my ($specfile) = @_; 1468 1469 my $is_extension_package = 0; 1470 1471 for ( my $i = 0; $i <= $#{$specfile}; $i++ ) 1472 { 1473 my $line = ${$specfile}[$i]; 1474 if ( $line =~ /share\/extension\/install\/.*?\.oxt\"\s*$/ ) 1475 { 1476 $is_extension_package = 1; 1477 last; 1478 } 1479 } 1480 1481 return $is_extension_package; 1482} 1483 1484###################################################################### 1485# Checking, if an extension is included into the package (Solaris). 1486# All extension files have to be installed into directory 1487# share/extension/install 1488###################################################################### 1489 1490sub contains_extension_dir 1491{ 1492 my ($prototypefile) = @_; 1493 1494 my $contains_extension_dir = 0; 1495 1496 # d none opt/libreoffice/share/extensions/ 1497 1498 for ( my $i = 0; $i <= $#{$prototypefile}; $i++ ) 1499 { 1500 my $line = ${$prototypefile}[$i]; 1501 if ( $line =~ /^\s*d\s+none\s.*\/share\/extensions\// ) 1502 { 1503 $contains_extension_dir = 1; 1504 last; 1505 } 1506 } 1507 1508 return $contains_extension_dir; 1509} 1510 1511############################################################ 1512# Setting the correct Solaris locales 1513############################################################ 1514 1515sub get_solaris_language_for_langpack 1516{ 1517 my ( $onelanguage ) = @_; 1518 1519 my $sollanguage = $onelanguage; 1520 $sollanguage =~ s/\-/\_/; 1521 1522 if ( $sollanguage eq "de" ) { $sollanguage = "de"; } 1523 elsif ( $sollanguage eq "en_US" ) { $sollanguage = "en_AU,en_CA,en_GB,en_IE,en_MT,en_NZ,en_US,en_US.UTF-8"; } 1524 elsif ( $sollanguage eq "es" ) { $sollanguage = "es"; } 1525 elsif ( $sollanguage eq "fr" ) { $sollanguage = "fr"; } 1526 elsif ( $sollanguage eq "hu" ) { $sollanguage = "hu_HU"; } 1527 elsif ( $sollanguage eq "it" ) { $sollanguage = "it"; } 1528 elsif ( $sollanguage eq "nl" ) { $sollanguage = "nl_BE,nl_NL"; } 1529 elsif ( $sollanguage eq "pl" ) { $sollanguage = "pl_PL"; } 1530 elsif ( $sollanguage eq "sv" ) { $sollanguage = "sv"; } 1531 elsif ( $sollanguage eq "pt" ) { $sollanguage = "pt_PT"; } 1532 elsif ( $sollanguage eq "pt_BR" ) { $sollanguage = "pt_BR"; } 1533 elsif ( $sollanguage eq "ru" ) { $sollanguage = "ru_RU"; } 1534 elsif ( $sollanguage eq "ja" ) { $sollanguage = "ja,ja_JP,ja_JP.PCK,ja_JP.UTF-8"; } 1535 elsif ( $sollanguage eq "ko" ) { $sollanguage = "ko,ko.UTF-8"; } 1536 elsif ( $sollanguage eq "zh_CN" ) { $sollanguage = "zh,zh.GBK,zh_CN.GB18030,zh.UTF-8"; } 1537 elsif ( $sollanguage eq "zh_TW" ) { $sollanguage = "zh_TW,zh_TW.BIG5,zh_TW.UTF-8,zh_HK.BIG5HK,zh_HK.UTF-8"; } 1538 1539 return $sollanguage; 1540} 1541 1542############################################################ 1543# Adding language infos in pkginfo file 1544############################################################ 1545 1546sub include_languageinfos_into_pkginfo 1547{ 1548 my ( $changefile, $filename, $languagestringref, $onepackage, $variableshashref ) = @_; 1549 1550 # SUNWPKG_LIST=core01 1551 # SUNW_LOC=de 1552 1553 my $locallang = $onepackage->{'language'}; 1554 my $solarislanguage = get_solaris_language_for_langpack($locallang); 1555 1556 my $newline = "SUNW_LOC=" . $solarislanguage . "\n"; 1557 add_one_line_into_file($changefile, $newline, $filename); 1558 1559 # SUNW_PKGLIST is required, if SUNW_LOC is defined. 1560 if ( $onepackage->{'pkg_list_entry'} ) 1561 { 1562 my $packagelistentry = $onepackage->{'pkg_list_entry'}; 1563 installer::packagelist::resolve_packagevariables(\$packagelistentry, $variableshashref, 1); 1564 $newline = "SUNW_PKGLIST=" . $packagelistentry . "\n"; 1565 add_one_line_into_file($changefile, $newline, $filename); 1566 } 1567 else 1568 { 1569 # Using default package ooobasis30-core01. 1570 my $packagelistentry = "%BASISPACKAGEPREFIX%WITHOUTDOTPRODUCTVERSION-core01"; 1571 installer::packagelist::resolve_packagevariables(\$packagelistentry, $variableshashref, 1); 1572 $newline = "SUNW_PKGLIST=" . $packagelistentry . "\n"; 1573 add_one_line_into_file($changefile, $newline, $filename); 1574 } 1575} 1576 1577############################################################ 1578# Including package names into the depend files. 1579# The package names have to be included into 1580# packagelist. They are already saved in 1581# %installer::globals::dependfilenames. 1582############################################################ 1583 1584sub put_packagenames_into_dependfile 1585{ 1586 my ( $file ) = @_; 1587 1588 for ( my $i = 0; $i <= $#{$file}; $i++ ) 1589 { 1590 my $line = ${$file}[$i]; 1591 if ( $line =~ /^\s*\w\s+(.*?)\s*$/ ) 1592 { 1593 my $abbreviation = $1; 1594 1595 if ( $abbreviation =~ /\%/ ) { installer::exiter::exit_program("ERROR: Could not resolve all properties in Solaris package abbreviation \"$abbreviation\"!", "read_packagemap"); } 1596 1597 if ( exists($installer::globals::dependfilenames{$abbreviation}) ) 1598 { 1599 my $packagename = $installer::globals::dependfilenames{$abbreviation}; 1600 if ( $packagename =~ /\%/ ) { installer::exiter::exit_program("ERROR: Could not resolve all properties in Solaris package name \"$packagename\"!", "read_packagemap"); } 1601 1602 $line =~ s/\s*$//; 1603 ${$file}[$i] = $line . "\t" . $packagename . "\n"; 1604 } 1605 else 1606 { 1607 installer::exiter::exit_program("ERROR: Missing packagename for Solaris package \"$abbreviation\"!", "put_packagenames_into_dependfile"); 1608 } 1609 } 1610 } 1611} 1612 1613############################################################ 1614# Including the relocatable directory into 1615# spec file and pkginfo file 1616# Linux: set topdir in specfile 1617# Solaris: remove $relocatablepath (/opt/) 1618# for all objects in prototype file 1619# and changing "topdir" for Linux 1620############################################################ 1621 1622sub prepare_packages 1623{ 1624 my ($loggingdir, $packagename, $staticpath, $relocatablepath, $onepackage, $variableshashref, $filesref, $languagestringref) = @_; 1625 1626 my $filename = ""; 1627 my $newline = ""; 1628 my $newepmdir = $installer::globals::epmoutpath . $installer::globals::separator; 1629 1630 my $localrelocatablepath = $relocatablepath; 1631 if ( $localrelocatablepath ne "/" ) { $localrelocatablepath =~ s/\/\s*$//; } 1632 1633 if ( $installer::globals::issolarispkgbuild ) 1634 { 1635 $filename = $packagename . ".pkginfo"; 1636 $newline = "BASEDIR\=" . $localrelocatablepath . "\n"; 1637 } 1638 1639 if ( $installer::globals::isrpmbuild ) 1640 { 1641 $filename = $packagename . ".spec"; 1642 $newline = "Prefix\:\ " . $localrelocatablepath . "\n"; 1643 } 1644 1645 my $completefilename = $newepmdir . $filename; 1646 1647 if ( ! -f $completefilename) { installer::exiter::exit_program("ERROR: Did not find file: $completefilename", "prepare_packages"); } 1648 my $changefile = installer::files::read_file($completefilename); 1649 if ( $newline ne "" ) 1650 { 1651 add_one_line_into_file($changefile, $newline, $filename); 1652 installer::files::save_file($completefilename, $changefile); 1653 } 1654 1655 # adding new "topdir" and removing old "topdir" in specfile 1656 1657 if ( $installer::globals::isrpmbuild ) 1658 { 1659 set_topdir_in_specfile($changefile, $filename, $newepmdir); 1660 set_autoprovreq_in_specfile($changefile, $onepackage->{'findrequires'}, "$installer::globals::workpath" . "/bin"); 1661 set_packager_in_specfile($changefile); 1662 if ( is_extension_package($changefile) ) { set_prereq_in_specfile($changefile); } 1663 set_license_in_specfile($changefile, $variableshashref); 1664 set_tab_into_datafile($changefile, $filesref); 1665 installer::files::save_file($completefilename, $changefile); 1666 } 1667 1668 # removing the relocatable path in prototype file 1669 1670 if ( $installer::globals::issolarispkgbuild ) 1671 { 1672 set_revision_in_pkginfo($changefile, $filename, $variableshashref, $packagename); 1673 set_maxinst_in_pkginfo($changefile, $filename); 1674 set_solaris_parameter_in_pkginfo($changefile, $filename, $variableshashref); 1675 if ( $installer::globals::issolarisx86build ) { fix_architecture_setting($changefile); } 1676 if (( $onepackage->{'language'} ) && ( $onepackage->{'language'} ne "" ) && ( $onepackage->{'language'} ne "en-US" )) { include_languageinfos_into_pkginfo($changefile, $filename, $languagestringref, $onepackage, $variableshashref); } 1677 installer::files::save_file($completefilename, $changefile); 1678 1679 my $prototypefilename = $packagename . ".prototype"; 1680 $prototypefilename = $newepmdir . $prototypefilename; 1681 if (! -f $prototypefilename) { installer::exiter::exit_program("ERROR: Did not find prototype file: $prototypefilename", "prepare_packages"); } 1682 1683 my $prototypefile = installer::files::read_file($prototypefilename); 1684 make_prototypefile_relocatable($prototypefile, $relocatablepath); 1685 my $classesstring = set_tab_into_datafile($prototypefile, $filesref); 1686 if ($classesstring) 1687 { 1688 include_classes_into_pkginfo($changefile, $classesstring); 1689 installer::files::save_file($completefilename, $changefile); 1690 } 1691 1692 installer::files::save_file($prototypefilename, $prototypefile); 1693 1694 # Adding package names into depend files for Solaris (not supported by epm) 1695 my $dependfilename = $packagename . ".depend"; 1696 $dependfilename = $newepmdir . $dependfilename; 1697 if ( -f $dependfilename) 1698 { 1699 my $dependfile = installer::files::read_file($dependfilename); 1700 put_packagenames_into_dependfile($dependfile); 1701 installer::files::save_file($dependfilename, $dependfile); 1702 } 1703 } 1704 1705 return $newepmdir; 1706} 1707 1708############################################################################### 1709# Replacement of PRODUCTINSTALLLOCATION and PRODUCTDIRECTORYNAME in the 1710# epm list file. 1711# The complete rootpath is stored in $installer::globals::rootpath 1712# or for each package in $onepackage->{'destpath'} 1713# The static rootpath is stored in $staticpath 1714# The relocatable path is stored in $relocatablepath 1715# PRODUCTINSTALLLOCATION is the relocatable part ("/opt") and 1716# PRODUCTDIRECTORYNAME the static path ("openofficeorg20"). 1717# In standard epm process: 1718# No usage of package specific variables like $BASEDIR, because 1719# 1. These variables would be replaced in epm process 1720# 2. epm version 3.7 does not support relocatable packages 1721############################################################################### 1722 1723sub resolve_path_in_epm_list_before_packaging 1724{ 1725 my ($listfile, $listfilename, $variable, $path) = @_; 1726 1727 installer::logger::include_header_into_logfile("Replacing variables in epm list file:"); 1728 1729 $path =~ s/\/\s*$//; 1730 replace_variables_in_shellscripts($listfile, $listfilename, $variable, $path); 1731 1732} 1733 1734################################################################# 1735# Determining the rpm version. Beginning with rpm version 4.0 1736# the tool to create RPMs is "rpmbuild" and no longer "rpm" 1737################################################################# 1738 1739sub determine_rpm_version 1740{ 1741 my $rpmversion = 0; 1742 my $rpmout = ""; 1743 my $systemcall = ""; 1744 1745 # "rpm --version" has problems since LD_LIBRARY_PATH was removed. Therefore the content of $RPM has to be called. 1746 # "rpm --version" and "rpmbuild --version" have the same output. Therefore $RPM can be used. Its value 1747 # is saved in $installer::globals::rpm 1748 1749 if ( $installer::globals::rpm ne "" ) 1750 { 1751 $systemcall = "$installer::globals::rpm --version |"; 1752 } 1753 else 1754 { 1755 $systemcall = "rpm --version |"; 1756 } 1757 1758 open (RPM, "$systemcall"); 1759 $rpmout = <RPM>; 1760 close (RPM); 1761 1762 if ( $rpmout ne "" ) 1763 { 1764 $rpmout =~ s/\s*$//g; 1765 1766 my $infoline = "Systemcall: $systemcall\n"; 1767 push( @installer::globals::logfileinfo, $infoline); 1768 1769 if ( $rpmout eq "" ) { $infoline = "ERROR: Could not find file \"rpm\" !\n"; } 1770 else { $infoline = "Success: rpm version: $rpmout\n"; } 1771 1772 push( @installer::globals::logfileinfo, $infoline); 1773 1774 if ( $rpmout =~ /(\d+)\.(\d+)\.(\d+)/ ) { $rpmversion = $1; } 1775 elsif ( $rpmout =~ /(\d+)\.(\d+)/ ) { $rpmversion = $1; } 1776 elsif ( $rpmout =~ /(\d+)/ ) { $rpmversion = $1; } 1777 else { installer::exiter::exit_program("ERROR: Unknown format: $rpmout ! Expected: \"a.b.c\", or \"a.b\", or \"a\"", "determine_rpm_version"); } 1778 } 1779 1780 return $rpmversion; 1781} 1782 1783#################################################### 1784# Writing some info about rpm into the log file 1785#################################################### 1786 1787sub log_rpm_info 1788{ 1789 my $systemcall = ""; 1790 my $infoline = ""; 1791 1792 $infoline = "\nLogging rpmrc content using --showrc\n\n"; 1793 push( @installer::globals::logfileinfo, $infoline); 1794 1795 if ( $installer::globals::rpm ne "" ) 1796 { 1797 $systemcall = "$installer::globals::rpm --showrc |"; 1798 } 1799 else 1800 { 1801 $systemcall = "rpm --showrc |"; 1802 } 1803 1804 my @fullrpmout = (); 1805 1806 open (RPM, "$systemcall"); 1807 while (<RPM>) {push(@fullrpmout, $_); } 1808 close (RPM); 1809 1810 if ( $#fullrpmout > -1 ) 1811 { 1812 for ( my $i = 0; $i <= $#fullrpmout; $i++ ) 1813 { 1814 my $rpmout = $fullrpmout[$i]; 1815 $rpmout =~ s/\s*$//g; 1816 1817 $infoline = "$rpmout\n"; 1818 $infoline =~ s/error/e_r_r_o_r/gi; # avoiding log problems 1819 push( @installer::globals::logfileinfo, $infoline); 1820 } 1821 } 1822 else 1823 { 1824 $infoline = "Problem in systemcall: $systemcall : No return value\n"; 1825 push( @installer::globals::logfileinfo, $infoline); 1826 } 1827 1828 $infoline = "End of logging rpmrc\n\n"; 1829 push( @installer::globals::logfileinfo, $infoline); 1830} 1831 1832################################################# 1833# Systemcall to start the packaging process 1834################################################# 1835 1836sub create_packages_without_epm 1837{ 1838 my ($epmdir, $packagename, $includepatharrayref, $allvariables, $languagestringref) = @_; 1839 1840 # Solaris: pkgmk -o -f solaris-2.8-sparc/SUNWso8m34.prototype -d solaris-2.8-sparc 1841 # Solaris: pkgtrans solaris-2.8-sparc SUNWso8m34.pkg SUNWso8m34 1842 # Solaris: tar -cf - SUNWso8m34 | gzip > SUNWso8m34.tar.gz 1843 1844 if ( $installer::globals::issolarispkgbuild ) 1845 { 1846 my $prototypefile = $epmdir . $packagename . ".prototype"; 1847 if (! -f $prototypefile) { installer::exiter::exit_program("ERROR: Did not find file: $prototypefile", "create_packages_without_epm"); } 1848 1849 my $destinationdir = $prototypefile; 1850 installer::pathanalyzer::get_path_from_fullqualifiedname(\$destinationdir); 1851 $destinationdir =~ s/\/\s*$//; # removing ending slashes 1852 1853 my $systemcall = "pkgmk -l 1073741824 -o -f $prototypefile -d $destinationdir 2\>\&1 |"; 1854 installer::logger::print_message( "... $systemcall ...\n" ); 1855 1856 my $maxpkgmkcalls = 3; 1857 1858 for ( my $i = 1; $i <= $maxpkgmkcalls; $i++ ) 1859 { 1860 my @pkgmkoutput = (); 1861 1862 open (PKGMK, "$systemcall"); 1863 while (<PKGMK>) {push(@pkgmkoutput, $_); } 1864 close (PKGMK); 1865 1866 my $returnvalue = $?; # $? contains the return value of the systemcall 1867 1868 my $infoline = "Systemcall (Try $i): $systemcall\n"; 1869 push( @installer::globals::logfileinfo, $infoline); 1870 1871 for ( my $j = 0; $j <= $#pkgmkoutput; $j++ ) 1872 { 1873 if ( $i < $maxpkgmkcalls ) { $pkgmkoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; } 1874 push( @installer::globals::logfileinfo, "$pkgmkoutput[$j]"); 1875 } 1876 1877 if ($returnvalue) 1878 { 1879 $infoline = "Try $i : Could not execute \"$systemcall\"!\n"; 1880 push( @installer::globals::logfileinfo, $infoline); 1881 if ( $i == $maxpkgmkcalls ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "create_packages_without_epm"); } 1882 } 1883 else 1884 { 1885 installer::logger::print_message( "Success (Try $i): \"$systemcall\"\n" ); 1886 $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 1887 push( @installer::globals::logfileinfo, $infoline); 1888 last; 1889 } 1890 } 1891 1892 # It might be necessary to save uncompressed Solaris packages 1893 1894 # compressing packages 1895 1896 if ( ! $installer::globals::solarisdontcompress ) 1897 { 1898 my $faspac = "faspac-so.sh"; 1899 1900 my $compressorref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$faspac, $includepatharrayref, 0); 1901 if ($$compressorref ne "") 1902 { 1903 # Saving original pkginfo, to set time stamp later 1904 my $pkginfoorig = "$destinationdir/$packagename/pkginfo"; 1905 my $pkginfotmp = "$destinationdir/$packagename" . ".pkginfo.tmp"; 1906 $systemcall = "cp -p $pkginfoorig $pkginfotmp"; 1907 installer::systemactions::make_systemcall($systemcall); 1908 1909 $faspac = $$compressorref; 1910 $infoline = "Found compressor: $faspac\n"; 1911 push( @installer::globals::logfileinfo, $infoline); 1912 1913 installer::logger::print_message( "... $faspac ...\n" ); 1914 installer::logger::include_timestamp_into_logfile("Starting $faspac"); 1915 1916 $systemcall = "/bin/sh $faspac -a -q -d $destinationdir $packagename"; # $faspac has to be the absolute path! 1917 installer::systemactions::make_systemcall($systemcall); 1918 1919 # Setting time stamp for pkginfo, because faspac-so.sh 1920 # changed the pkginfo file, updated the size and 1921 # checksum, but not the time stamp. 1922 $systemcall = "touch -r $pkginfotmp $pkginfoorig"; 1923 installer::systemactions::make_systemcall($systemcall); 1924 if ( -f $pkginfotmp ) { unlink($pkginfotmp); } 1925 1926 installer::logger::include_timestamp_into_logfile("End of $faspac"); 1927 } 1928 else 1929 { 1930 $infoline = "Not found: $faspac\n"; 1931 push( @installer::globals::logfileinfo, $infoline); 1932 } 1933 } 1934 1935 # Setting unix rights to "775" for all created directories inside the package 1936 1937 $systemcall = "cd $destinationdir; find $packagename -type d | xargs -i chmod 775 \{\} \;"; 1938 installer::logger::print_message( "... $systemcall ...\n" ); 1939 1940 $returnvalue = system($systemcall); 1941 1942 $infoline = "Systemcall: $systemcall\n"; 1943 push( @installer::globals::logfileinfo, $infoline); 1944 1945 if ($returnvalue) 1946 { 1947 $infoline = "ERROR: Could not execute \"$systemcall\"!\n"; 1948 push( @installer::globals::logfileinfo, $infoline); 1949 } 1950 else 1951 { 1952 $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 1953 push( @installer::globals::logfileinfo, $infoline); 1954 } 1955 1956 1957 ###################### 1958 # making pkg files 1959 ###################### 1960 1961 # my $streamname = $packagename . ".pkg"; 1962 # $systemcall = "pkgtrans $destinationdir $streamname $packagename"; 1963 # print "... $systemcall ...\n"; 1964 1965 # $returnvalue = system($systemcall); 1966 1967 # $infoline = "Systemcall: $systemcall\n"; 1968 # push( @installer::globals::logfileinfo, $infoline); 1969 1970 # if ($returnvalue) 1971 # { 1972 # $infoline = "ERROR: Could not execute \"$systemcall\"!\n"; 1973 # push( @installer::globals::logfileinfo, $infoline); 1974 # } 1975 # else 1976 # { 1977 # $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 1978 # push( @installer::globals::logfileinfo, $infoline); 1979 # } 1980 1981 ######################### 1982 # making tar.gz files 1983 ######################### 1984 1985 # my $targzname = $packagename . ".tar.gz"; 1986 # $systemcall = "cd $destinationdir; tar -cf - $packagename | gzip > $targzname"; 1987 # print "... $systemcall ...\n"; 1988 1989 # $returnvalue = system($systemcall); 1990 1991 # $infoline = "Systemcall: $systemcall\n"; 1992 # push( @installer::globals::logfileinfo, $infoline); 1993 1994 # if ($returnvalue) 1995 # { 1996 # $infoline = "ERROR: Could not execute \"$systemcall\"!\n"; 1997 # push( @installer::globals::logfileinfo, $infoline); 1998 # } 1999 # else 2000 # { 2001 # $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 2002 # push( @installer::globals::logfileinfo, $infoline); 2003 # } 2004 2005 } 2006 2007 # Linux: rpm -bb so8m35.spec ( -> dependency check abklemmen? ) 2008 2009 if ( $installer::globals::isrpmbuild ) 2010 { 2011 my $specfilename = $epmdir . $packagename . ".spec"; 2012 if (! -f $specfilename) { installer::exiter::exit_program("ERROR: Did not find file: $specfilename", "create_packages_without_epm"); } 2013 2014 my $rpmcommand = $installer::globals::rpm; 2015 my $rpmversion = determine_rpm_version(); 2016 2017 my $target = ""; 2018 if ( $installer::globals::platformid eq 'linux_x86') 2019 { 2020 $target = "i586"; 2021 } 2022 elsif ( $installer::globals::platformid eq 'aix_powerpc') 2023 { 2024 $target = "ppc"; 2025 } 2026 elsif ( $installer::globals::os eq 'LINUX') 2027 { 2028 $target = (POSIX::uname())[4]; 2029 } 2030 2031 # rpm 4.6 ignores buildroot tag in spec file 2032 2033 my $buildrootstring = ""; 2034 2035 if ( $rpmversion >= 4 ) 2036 { 2037 my $dir = Cwd::getcwd; 2038 my $buildroot = $dir . "/" . $epmdir . "buildroot/"; 2039 $buildrootstring = "--buildroot=$buildroot"; 2040 mkdir($buildroot = $dir . "/" . $epmdir . "BUILD/"); 2041 } 2042 2043 if ( ! $installer::globals::rpminfologged ) 2044 { 2045 log_rpm_info(); 2046 $installer::globals::rpminfologged = 1; 2047 } 2048 2049 my $systemcall = "$rpmcommand -bb --define \"_unpackaged_files_terminate_build 0\" $specfilename --target $target $buildrootstring 2\>\&1 |"; 2050 2051 installer::logger::print_message( "... $systemcall ...\n" ); 2052 2053 my $maxrpmcalls = 3; 2054 my $rpm_failed = 0; 2055 2056 for ( my $i = 1; $i <= $maxrpmcalls; $i++ ) 2057 { 2058 my @rpmoutput = (); 2059 2060 open (RPM, "$systemcall"); 2061 while (<RPM>) {push(@rpmoutput, $_); } 2062 close (RPM); 2063 2064 my $returnvalue = $?; # $? contains the return value of the systemcall 2065 2066 my $infoline = "Systemcall (Try $i): $systemcall\n"; 2067 push( @installer::globals::logfileinfo, $infoline); 2068 2069 for ( my $j = 0; $j <= $#rpmoutput; $j++ ) 2070 { 2071 $rpmoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; 2072 push( @installer::globals::logfileinfo, "$rpmoutput[$j]"); 2073 } 2074 2075 if ($returnvalue) 2076 { 2077 $infoline = "Try $i : Could not execute \"$systemcall\"!\n"; 2078 push( @installer::globals::logfileinfo, $infoline); 2079 $rpm_failed = 1; 2080 } 2081 else 2082 { 2083 installer::logger::print_message( "Success (Try $i): \"$systemcall\"\n" ); 2084 $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 2085 push( @installer::globals::logfileinfo, $infoline); 2086 $rpm_failed = 0; 2087 last; 2088 } 2089 } 2090 2091 if ( $rpm_failed ) 2092 { 2093 # Because of the problems with LD_LIBRARY_PATH, a direct call of local "rpm" or "rpmbuild" might be successful 2094 my $rpmprog = ""; 2095 if ( -f "/usr/bin/rpmbuild" ) { $rpmprog = "/usr/bin/rpmbuild"; } 2096 elsif ( -f "/usr/bin/rpm" ) { $rpmprog = "/usr/bin/rpm"; } 2097 2098 if ( $rpmprog ne "" ) 2099 { 2100 installer::logger::print_message( "... $rpmprog ...\n" ); 2101 2102 my $helpersystemcall = "$rpmprog -bb $specfilename --target $target $buildrootstring 2\>\&1 |"; 2103 2104 my @helperrpmoutput = (); 2105 2106 open (RPM, "$helpersystemcall"); 2107 while (<RPM>) {push(@helperrpmoutput, $_); } 2108 close (RPM); 2109 2110 my $helperreturnvalue = $?; # $? contains the return value of the systemcall 2111 2112 $infoline = "\nLast try: Using $rpmprog directly (problem with LD_LIBRARY_PATH)\n"; 2113 push( @installer::globals::logfileinfo, $infoline); 2114 2115 $infoline = "\nSystemcall: $helpersystemcall\n"; 2116 push( @installer::globals::logfileinfo, $infoline); 2117 2118 for ( my $j = 0; $j <= $#helperrpmoutput; $j++ ) { push( @installer::globals::logfileinfo, "$helperrpmoutput[$j]"); } 2119 2120 if ($helperreturnvalue) 2121 { 2122 $infoline = "Could not execute \"$helpersystemcall\"!\n"; 2123 push( @installer::globals::logfileinfo, $infoline); 2124 } 2125 else 2126 { 2127 installer::logger::print_message( "Success: \"$helpersystemcall\"\n" ); 2128 $infoline = "Success: Executed \"$helpersystemcall\" successfully!\n"; 2129 push( @installer::globals::logfileinfo, $infoline); 2130 $rpm_failed = 0; 2131 } 2132 } 2133 2134 # Now it is really time to exit this packaging process, if the error still occurs 2135 if ( $rpm_failed ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "create_packages_without_epm"); } 2136 } 2137 } 2138} 2139 2140################################################# 2141# Removing all temporary files created by epm 2142################################################# 2143 2144sub remove_temporary_epm_files 2145{ 2146 my ($epmdir, $loggingdir, $packagename) = @_; 2147 2148 # saving the files into the loggingdir 2149 2150 if ( $installer::globals::issolarispkgbuild ) 2151 { 2152 my @extensions = (); 2153 push(@extensions, ".pkginfo"); 2154 push(@extensions, ".prototype"); 2155 push(@extensions, ".postinstall"); 2156 push(@extensions, ".postremove"); 2157 push(@extensions, ".preinstall"); 2158 push(@extensions, ".preremove"); 2159 push(@extensions, ".depend"); 2160 2161 for ( my $i = 0; $i <= $#extensions; $i++ ) 2162 { 2163 my $removefile = $epmdir . $packagename . $extensions[$i]; 2164 my $destfile = $loggingdir . $packagename . $extensions[$i] . ".log"; 2165 2166 if (! -f $removefile) { next; } 2167 2168 my $systemcall = "mv -f $removefile $destfile"; 2169 system($systemcall); # ignoring the return value 2170 $infoline = "Systemcall: $systemcall\n"; 2171 push( @installer::globals::logfileinfo, $infoline); 2172 } 2173 } 2174 2175 if ( $installer::globals::isrpmbuild ) 2176 { 2177 my $removefile = $epmdir . $packagename . ".spec"; 2178 my $destfile = $loggingdir . $packagename . ".spec.log"; 2179 2180 my $systemcall = "mv -f $removefile $destfile"; 2181 system($systemcall); # ignoring the return value 2182 $infoline = "Systemcall: $systemcall\n"; 2183 push( @installer::globals::logfileinfo, $infoline); 2184 2185 # removing the directory "buildroot" 2186 2187 my $removedir = $epmdir . "buildroot"; 2188 2189 $systemcall = "rm -rf $removedir"; 2190 2191 installer::logger::print_message( "... $systemcall ...\n" ); 2192 2193 my $returnvalue = system($systemcall); 2194 2195 $removedir = $epmdir . "BUILD"; 2196 2197 $systemcall = "rm -rf $removedir"; 2198 2199 installer::logger::print_message( "... $systemcall ...\n" ); 2200 2201 $returnvalue = system($systemcall); 2202 2203 2204 my $infoline = "Systemcall: $systemcall\n"; 2205 push( @installer::globals::logfileinfo, $infoline); 2206 2207 if ($returnvalue) 2208 { 2209 $infoline = "ERROR: Could not execute \"$systemcall\"!\n"; 2210 push( @installer::globals::logfileinfo, $infoline); 2211 } 2212 else 2213 { 2214 $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 2215 push( @installer::globals::logfileinfo, $infoline); 2216 } 2217 } 2218} 2219 2220########################################################### 2221# Creating a better directory structure in the solver. 2222########################################################### 2223 2224sub create_new_directory_structure 2225{ 2226 my ($newepmdir) = @_; 2227 2228 my $newdir = $installer::globals::epmoutpath; 2229 2230 if ( $installer::globals::isrpmbuild ) 2231 { 2232 my $rpmdir; 2233 my $machine = ""; 2234 if ( $installer::globals::platformid eq 'linux_x86') 2235 { 2236 $rpmdir = "$installer::globals::epmoutpath/RPMS/i586"; 2237 } 2238 elsif ( $installer::globals::platformid eq 'aix_powerpc') 2239 { 2240 $machine = "ppc"; 2241 $rpmdir = "$installer::globals::epmoutpath/RPMS/$machine"; 2242 } 2243 elsif ( $installer::globals::os eq 'LINUX') 2244 { 2245 $machine = (POSIX::uname())[4]; 2246 $rpmdir = "$installer::globals::epmoutpath/RPMS/$machine"; 2247 } 2248 else 2249 { 2250 installer::exiter::exit_program("ERROR: rpmdir undefined !", "create_new_directory_structure"); 2251 } 2252 2253 my $systemcall = "mv $rpmdir/* $newdir"; # moving the rpms into the directory "RPMS" 2254 2255 my $returnvalue = system($systemcall); 2256 2257 my $infoline = "Systemcall: $systemcall\n"; 2258 push( @installer::globals::logfileinfo, $infoline); 2259 2260 if ($returnvalue) 2261 { 2262 $infoline = "ERROR: Could not move content of \"$rpmdir\" to \"$newdir\"!\n"; 2263 push( @installer::globals::logfileinfo, $infoline); 2264 } 2265 else 2266 { 2267 $infoline = "Success: Moved content of \"$rpmdir\" to \"$newdir\"!\n"; 2268 push( @installer::globals::logfileinfo, $infoline); 2269 } 2270 2271 # and removing the empty directory 2272 2273 if ( $machine ne "" ) 2274 { 2275 rmdir "$installer::globals::epmoutpath/RPMS/$machine"; 2276 } 2277 rmdir "$installer::globals::epmoutpath/RPMS/powerpc"; 2278 rmdir "$installer::globals::epmoutpath/RPMS/x86_64"; 2279 rmdir "$installer::globals::epmoutpath/RPMS/i586"; 2280 rmdir "$installer::globals::epmoutpath/RPMS/i386"; 2281 rmdir "$installer::globals::epmoutpath/RPMS" 2282 or warn "Could not remove RPMS dir: $!"; 2283 } 2284 2285 # Setting unix rights to "775" for $newdir ("RPMS" or "packages") 2286 chmod 0775, $newdir; 2287} 2288 2289###################################################### 2290# Collect modules with product specific styles. 2291###################################################### 2292 2293sub collect_modules_with_style 2294{ 2295 my ($style, $modulesarrayref) = @_; 2296 2297 my @allmodules = (); 2298 2299 for ( my $i = 0; $i <= $#{$modulesarrayref}; $i++ ) 2300 { 2301 my $onemodule = ${$modulesarrayref}[$i]; 2302 my $styles = ""; 2303 if ( $onemodule->{'Styles'} ) { $styles = $onemodule->{'Styles'}; } 2304 if ( $styles =~ /\b\Q$style\E\b/ ) 2305 { 2306 push(@allmodules, $onemodule); 2307 } 2308 } 2309 2310 return \@allmodules; 2311} 2312 2313###################################################### 2314# Remove modules without packagecontent. 2315###################################################### 2316 2317sub remove_modules_without_package 2318{ 2319 my ($allmodules) = @_; 2320 2321 my @allmodules = (); 2322 2323 for ( my $i = 0; $i <= $#{$allmodules}; $i++ ) 2324 { 2325 my $onemodule = ${$allmodules}[$i]; 2326 my $packagename = ""; 2327 if ( $onemodule->{'PackageName'} ) { $packagename = $onemodule->{'PackageName'}; } 2328 if ( $packagename ne "" ) 2329 { 2330 push(@allmodules, $onemodule); 2331 } 2332 } 2333 2334 return \@allmodules; 2335} 2336 2337###################################################### 2338# Copying files for system integration. 2339###################################################### 2340 2341sub copy_and_unpack_tar_gz_files 2342{ 2343 my ($sourcefile, $destdir) = @_; 2344 2345 my $systemcall = "cd $destdir; cat $sourcefile | gunzip | tar -xf -"; 2346 installer::systemactions::make_systemcall($systemcall); 2347} 2348 2349###################################################### 2350# Checking whether the new content is a directory and 2351# not a package. If it is a directory, the complete 2352# content of the directory has to be added to the 2353# array newcontent. 2354###################################################### 2355 2356sub control_subdirectories 2357{ 2358 my ($content, $subdir) = @_; 2359 2360 my @newcontent = (); 2361 2362 for ( my $i = 0; $i <= $#{$content}; $i++ ) 2363 { 2364 if ( -d ${$content}[$i] ) 2365 { 2366 $subdir = ${$content}[$i]; 2367 installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$subdir); 2368 my $allpackages = installer::systemactions::read_directory(${$content}[$i]); 2369 for ( my $j = 0; $j <= $#{$allpackages}; $j++ ) 2370 { 2371 # Currently only Linux rpm is supported, debian packages cannot be installed via xpd installer 2372 if (( $installer::globals::islinuxbuild ) && ( ! ( ${$allpackages}[$j] =~ /\.rpm\s*$/ ))) { next; } 2373 push(@newcontent, ${$allpackages}[$j]); 2374 } 2375 } 2376 else 2377 { 2378 push(@newcontent, ${$content}[$i]); 2379 } 2380 } 2381 2382 return (\@newcontent, $subdir); 2383} 2384 2385###################################################### 2386# Including the system integration files into the 2387# installation sets. 2388###################################################### 2389 2390sub put_systemintegration_into_installset 2391{ 2392 my ($newdir, $includepatharrayref, $allvariables, $modulesarrayref) = @_; 2393 2394 my $destdir = $newdir; 2395 2396 # adding System integration files 2397 2398 my $sourcefile = ""; 2399 2400 # Finding the modules defined in scp (with flag SYSTEMMODULE) 2401 # Getting name of package from scp-Module 2402 # Search package in list off all include files 2403 # Copy file into installation set and unpack it (always tar.gz) 2404 # tar.gz can contain a different number of packages -> automatically create hidden sub modules 2405 2406 # Collect all modules with flag "SYSTEMMODULE" 2407 my $allmodules = collect_modules_with_style("SYSTEMMODULE", $modulesarrayref); 2408 $allmodules = remove_modules_without_package($allmodules); 2409 2410 for ( my $i = 0; $i <= $#{$allmodules}; $i++ ) 2411 { 2412 my $onemodule = ${$allmodules}[$i]; 2413 my $packagetarfilename = $onemodule->{'PackageName'}; 2414 2415 my $infoline = "Including into installation set: $packagetarfilename\n"; 2416 push( @installer::globals::logfileinfo, $infoline); 2417 2418 my $sourcepathref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$packagetarfilename, $includepatharrayref, 1); 2419 if ( $$sourcepathref eq "" ) { installer::exiter::exit_program("ERROR: Source path not found for $packagetarfilename!", "copy_systemintegration_files"); } 2420 2421 # Collecting all packages in directory "packages" or "RPMS" 2422 my $oldcontent = installer::systemactions::read_directory($destdir); 2423 2424 copy_and_unpack_tar_gz_files($$sourcepathref, $destdir); 2425 2426 # Finding new content -> that is the package name 2427 my ($newcontent, $allcontent ) = installer::systemactions::find_new_content_in_directory($destdir, $oldcontent); 2428 2429 # special handling, if new content is a directory 2430 my $subdir = ""; 2431 if ( ! $installer::globals::issolarispkgbuild ) { ($newcontent, $subdir) = control_subdirectories($newcontent); } 2432 2433 # Adding license content into Solaris packages 2434 if (( $installer::globals::issolarispkgbuild ) && ( $installer::globals::englishlicenseset ) && ( ! $variableshashref->{'NO_LICENSE_INTO_COPYRIGHT'} )) { _add_license_into_systemintegrationpackages($destdir, $newcontent); } 2435 } 2436} 2437 2438###################################################### 2439# Analyzing the Unix installation path. 2440# From the installation path /opt/openofficeorg20 2441# is the part /opt relocatable and the part 2442# openofficeorg20 static. 2443###################################################### 2444 2445sub analyze_rootpath 2446{ 2447 my ($rootpath, $staticpathref, $relocatablepathref, $allvariables) = @_; 2448 2449 $rootpath =~ s/\/\s*$//; # removing ending slash 2450 2451 ############################################################## 2452 # Version 3: "/" is variable and "/opt/openofficeorg20" fixed 2453 ############################################################## 2454 2455 $$relocatablepathref = "/"; 2456 # Static path has to contain the office directory name. This is replaced in shellscripts. 2457 $$staticpathref = $rootpath . $installer::globals::separator . $installer::globals::officedirhostname; 2458 # For RPM version 3.x it is required, that Prefix is not "/" in spec file. In this case --relocate will not work, 2459 # because RPM 3.x says, that the package is not relocatable. Therefore we have to use Prefix=/opt and for 2460 # all usages of --relocate this path has to be on both sides of the "=": --relocate /opt=<myselectdir>/opt . 2461 if ( $installer::globals::isrpmbuild ) 2462 { 2463 $$relocatablepathref = $rootpath . "\/"; # relocatable path must end with "/", will be "/opt/" 2464 $$staticpathref = $installer::globals::officedirhostname; # to be used as replacement in shell scripts 2465 } 2466 2467 if ( $installer::globals::isdebbuild ) 2468 { 2469 $$relocatablepathref = ""; 2470 # $$staticpathref is already "/opt/libreoffice", no additional $rootpath required. 2471 } 2472 2473} 2474 2475################################################ 2476# Defining the English license text to add 2477# it into Solaris packages. 2478################################################ 2479 2480sub _set_english_license 2481{ 2482 my $additional_license_name = $installer::globals::englishsolarislicensename; # always the English file 2483 my $licensefileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$additional_license_name, "" , 0); 2484 if ( $$licensefileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find license file $additional_license_name!", "set_english_license"); } 2485 $installer::globals::englishlicenseset = 1; 2486 $installer::globals::englishlicense = installer::files::read_file($$licensefileref); 2487 installer::scpzipfiles::replace_all_ziplistvariables_in_file($installer::globals::englishlicense, $variableshashref); 2488} 2489 2490################################################ 2491# Adding the content of the English license 2492# file into the system integration packages. 2493################################################ 2494 2495sub _add_license_into_systemintegrationpackages 2496{ 2497 my ($destdir, $packages) = @_; 2498 2499 for ( my $i = 0; $i <= $#{$packages}; $i++ ) 2500 { 2501 my $copyrightfilename = ${$packages}[$i] . $installer::globals::separator . "install" . $installer::globals::separator . "copyright"; 2502 if ( ! -f $copyrightfilename ) { installer::exiter::exit_program("ERROR: Could not find license file in system integration package: $copyrightfilename!", "add_license_into_systemintegrationpackages"); } 2503 my $copyrightfile = installer::files::read_file($copyrightfilename); 2504 2505 # Saving time stamp of old copyrightfile 2506 my $savcopyrightfilename = $copyrightfilename . ".sav"; 2507 installer::systemactions::copy_one_file($copyrightfilename, $savcopyrightfilename); 2508 _set_time_stamp_for_file($copyrightfilename, $savcopyrightfilename); # now $savcopyrightfile has the time stamp of $copyrightfile 2509 2510 # Adding license content to copyright file 2511 push(@{$copyrightfile}, "\n"); 2512 for ( my $i = 0; $i <= $#{$installer::globals::englishlicense}; $i++ ) { push(@{$copyrightfile}, ${$installer::globals::englishlicense}[$i]); } 2513 installer::files::save_file($copyrightfilename, $copyrightfile); 2514 2515 # Setting the old time stamp saved with $savcopyrightfilename 2516 _set_time_stamp_for_file($savcopyrightfilename, $copyrightfilename); # now $copyrightfile has the time stamp of $savcopyrightfile 2517 unlink($savcopyrightfilename); 2518 2519 # Changing content of copyright file in pkgmap 2520 my $pkgmapfilename = ${$packages}[$i] . $installer::globals::separator . "pkgmap"; 2521 if ( ! -f $pkgmapfilename ) { installer::exiter::exit_program("ERROR: Could not find pkgmap in system integration package: $pkgmapfilename!", "add_license_into_systemintegrationpackages"); } 2522 my $pkgmap = installer::files::read_file($pkgmapfilename); 2523 _change_onefile_in_pkgmap($pkgmap, $copyrightfilename, "copyright"); 2524 installer::files::save_file($pkgmapfilename, $pkgmap); 2525 } 2526} 2527 2528############################################## 2529# Setting time stamp of copied files to avoid 2530# errors from pkgchk. 2531############################################## 2532 2533sub _set_time_stamp_for_file 2534{ 2535 my ($sourcefile, $destfile) = @_; 2536 2537 my $systemcall = "touch -r $sourcefile $destfile"; 2538 2539 my $returnvalue = system($systemcall); 2540 2541 my $infoline = "Systemcall: $systemcall\n"; 2542 push( @installer::globals::logfileinfo, $infoline); 2543 2544 if ($returnvalue) 2545 { 2546 $infoline = "ERROR: \"$systemcall\" failed!\n"; 2547 push( @installer::globals::logfileinfo, $infoline); 2548 } 2549 else 2550 { 2551 $infoline = "Success: \"$systemcall\" !\n"; 2552 push( @installer::globals::logfileinfo, $infoline); 2553 } 2554} 2555 2556############################################## 2557# Setting checksum and wordcount for changed 2558# pkginfo file into pkgmap. 2559############################################## 2560 2561sub _change_onefile_in_pkgmap 2562{ 2563 my ($pkgmapfile, $fullfilename, $shortfilename) = @_; 2564 2565 # 1 i pkginfo 442 34577 1166716297 2566 # -> 2567 # 1 i pkginfo 443 34737 1166716297 2568 # 2569 # wc -c pkginfo | cut -f6 -d' ' -> 442 (variable) 2570 # sum pkginfo | cut -f1 -d' ' -> 34577 (variable) 2571 # grep 'pkginfo' pkgmap | cut -f6 -d' ' -> 1166716297 (fix) 2572 2573 my $checksum = _call_sum($fullfilename); 2574 if ( $checksum =~ /^\s*(\d+)\s+.*$/ ) { $checksum = $1; } 2575 2576 my $wordcount = _call_wc($fullfilename); 2577 if ( $wordcount =~ /^\s*(\d+)\s+.*$/ ) { $wordcount = $1; } 2578 2579 for ( my $i = 0; $i <= $#{$pkgmapfile}; $i++ ) 2580 { 2581 if ( ${$pkgmapfile}[$i] =~ /(^.*\b\Q$shortfilename\E\b\s+)(\d+)(\s+)(\d+)(\s+)(\d+)(\s*$)/ ) 2582 { 2583 my $newline = $1 . $wordcount . $3 . $checksum . $5 . $6 . $7; 2584 ${$pkgmapfile}[$i] = $newline; 2585 last; 2586 } 2587 } 2588} 2589 2590######################################################### 2591# Calling sum 2592######################################################### 2593 2594sub _call_sum 2595{ 2596 my ($filename) = @_; 2597 2598 $sumfile = "/usr/bin/sum"; 2599 2600 if ( ! -f $sumfile ) { installer::exiter::exit_program("ERROR: No file /usr/bin/sum", "call_sum"); } 2601 2602 my $systemcall = "$sumfile $filename |"; 2603 2604 my $sumoutput = ""; 2605 2606 open (SUM, "$systemcall"); 2607 $sumoutput = <SUM>; 2608 close (SUM); 2609 2610 my $returnvalue = $?; # $? contains the return value of the systemcall 2611 2612 my $infoline = "Systemcall: $systemcall\n"; 2613 push( @installer::globals::logfileinfo, $infoline); 2614 2615 if ($returnvalue) 2616 { 2617 $infoline = "ERROR: Could not execute \"$systemcall\"!\n"; 2618 push( @installer::globals::logfileinfo, $infoline); 2619 } 2620 else 2621 { 2622 $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 2623 push( @installer::globals::logfileinfo, $infoline); 2624 } 2625 2626 return $sumoutput; 2627} 2628 2629######################################################### 2630# Calling wc 2631# wc -c pkginfo | cut -f6 -d' ' 2632######################################################### 2633 2634sub _call_wc 2635{ 2636 my ($filename) = @_; 2637 2638 $wcfile = "/usr/bin/wc"; 2639 2640 if ( ! -f $wcfile ) { installer::exiter::exit_program("ERROR: No file /usr/bin/wc", "call_wc"); } 2641 2642 my $systemcall = "$wcfile -c $filename |"; 2643 2644 my $wcoutput = ""; 2645 2646 open (WC, "$systemcall"); 2647 $wcoutput = <WC>; 2648 close (WC); 2649 2650 my $returnvalue = $?; # $? contains the return value of the systemcall 2651 2652 my $infoline = "Systemcall: $systemcall\n"; 2653 push( @installer::globals::logfileinfo, $infoline); 2654 2655 if ($returnvalue) 2656 { 2657 $infoline = "ERROR: Could not execute \"$systemcall\"!\n"; 2658 push( @installer::globals::logfileinfo, $infoline); 2659 } 2660 else 2661 { 2662 $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 2663 push( @installer::globals::logfileinfo, $infoline); 2664 } 2665 2666 return $wcoutput; 2667} 2668 26691; 2670