1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21 22 23 24package installer::languagepack; 25 26use installer::converter; 27use installer::existence; 28use installer::files; 29use installer::globals; 30use installer::logger; 31use installer::pathanalyzer; 32use installer::scpzipfiles; 33use installer::scriptitems; 34use installer::systemactions; 35use installer::worker; 36 37#################################################### 38# Selecting all files with the correct language 39#################################################### 40 41sub select_language_items 42{ 43 my ( $itemsref, $languagesarrayref, $itemname ) = @_; 44 45 installer::logger::include_header_into_logfile("Selecting languages for language pack. Item: $itemname"); 46 47 my @itemsarray = (); 48 49 for ( my $i = 0; $i <= $#{$itemsref}; $i++ ) 50 { 51 my $oneitem = ${$itemsref}[$i]; 52 53 my $ismultilingual = $oneitem->{'ismultilingual'}; 54 55 if (!($ismultilingual)) 56 { 57 # Files with style "LANGUAGEPACK" and "FORCELANGUAGEPACK" also have to be included into the language pack. 58 # Files with style "LANGUAGEPACK" are only included into language packs. 59 # Files with style "FORCELANGUAGEPACK" are included into language packs and non language packs. They are 60 # forced, because otherwise they not not be included into languagepacks. 61 62 my $styles = ""; 63 if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; } 64 65 if (( $styles =~ /\bLANGUAGEPACK\b/ ) || ( $styles =~ /\bFORCELANGUAGEPACK\b/ )) { push(@itemsarray, $oneitem); } 66 67 next; # single language files are not included into language pack 68 } 69 70 my $specificlanguage = ""; 71 if ( $oneitem->{'specificlanguage'} ) { $specificlanguage = $oneitem->{'specificlanguage'}; } 72 73 for ( my $j = 0; $j <= $#{$languagesarrayref}; $j++ ) # iterating over all languages 74 { 75 my $onelanguage = ${$languagesarrayref}[$j]; 76 my $locallang = $onelanguage; 77 $locallang =~ s/-/_/; 78 79 if ( $specificlanguage eq $onelanguage ) 80 { 81 # $oneitem->{'modules'} = $installer::globals::rootmodulegid; # all files in a language pack are root files 82 # Using $installer::globals::languagemodulesbase (?) 83 84# # no more automatic change of module assignments 85# $oneitem->{'modules'} = $installer::globals::rootmodulegid . "_$locallang"; # all files in a language pack are root files 86# 87# if (( $installer::globals::islinuxbuild ) || ( $installer::globals::issolarispkgbuild )) 88# { 89# if ( $oneitem->{'Dir'} ) 90# { 91# if ( $oneitem->{'Dir'} eq "gid_Dir_Fonts_Truetype" ) { $oneitem->{'modules'} = "gid_Module_Langpack_Fonts_$locallang"; } 92# if ( $oneitem->{'Dir'} eq "gid_Dir_Resource" ) { $oneitem->{'modules'} = "gid_Module_Langpack_Resource_$locallang"; } 93# if ( $oneitem->{'Dir'} eq "gid_Dir_Help_Isolanguage" ) { $oneitem->{'modules'} = "gid_Module_Langpack_Help_$locallang"; } 94# } 95# } 96 97 # preparing different modules for Windows Installer language packs 98 # my $underlinelanguage = $specificlanguage; 99 # $underlinelanguage =~ s/-/_/; 100 # if ( $installer::globals::iswindowsbuild ) { $oneitem->{'modules'} = $installer::globals::languagemodulesbase . $underlinelanguage; } 101 102# # no more collecting of language pack feature 103# if (! installer::existence::exists_in_array($oneitem->{'modules'}, \@installer::globals::languagepackfeature)) 104# { 105# push(@installer::globals::languagepackfeature, $oneitem->{'modules'}); # Collecting all language pack feature 106# } 107 108 push(@itemsarray, $oneitem); 109 } 110 } 111 } 112 113 return \@itemsarray; 114} 115 116sub replace_languagestring_variable 117{ 118 my ($onepackageref, $languagestringref) = @_; 119 120 my $key; 121 122 foreach $key (keys %{$onepackageref}) 123 { 124 my $value = $onepackageref->{$key}; 125 $value =~ s/\%LANGUAGESTRING/$$languagestringref/g; 126 $onepackageref->{$key} = $value; 127 } 128} 129 130######################################################### 131# Including the license text into the script template 132######################################################### 133 134sub put_license_file_into_script 135{ 136 my ($scriptfile, $licensefile) = @_; 137 138 my $infoline = "Adding licensefile into language pack script\n"; 139 $installer::logger::Lang->print($infoline); 140 141 my $includestring = ""; 142 143 for ( my $i = 0; $i <= $#{$licensefile}; $i++ ) 144 { 145 $includestring = $includestring . ${$licensefile}[$i]; 146 } 147 148 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ ) 149 { 150 ${$scriptfile}[$i] =~ s/LICENSEFILEPLACEHOLDER/$includestring/; 151 } 152} 153 154######################################################### 155# Creating a tar.gz file from a Solaris package 156######################################################### 157 158sub create_tar_gz_file 159{ 160 my ($installdir, $packagename, $packagestring) = @_; 161 162 $packagename =~ s/\.rpm\s*$//; 163 my $targzname = $packagename . ".tar.gz"; 164 $systemcall = "cd $installdir; tar -cf - $packagestring | gzip > $targzname"; 165 installer::logger::print_message( "... $systemcall ...\n" ); 166 167 my $returnvalue = system($systemcall); 168 169 my $infoline = "Systemcall: $systemcall\n"; 170 $installer::logger::Lang->print($infoline); 171 172 if ($returnvalue) 173 { 174 $infoline = "ERROR: Could not execute \"$systemcall\"!\n"; 175 $installer::logger::Lang->print($infoline); 176 } 177 else 178 { 179 $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 180 $installer::logger::Lang->print($infoline); 181 } 182 183 return $targzname; 184} 185 186######################################################### 187# Determining the name of the package file 188######################################################### 189 190sub get_packagename_from_packagelist 191{ 192 my ( $alldirs, $allvariables, $languagestringref ) = @_; 193 194 # my $packagename = ""; 195 196 # for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) 197 # { 198 # if ( ${$alldirs}[$i] =~ /-fonts/ ) { next; } 199 # if ( ${$alldirs}[$i] =~ /-help/ ) { next; } 200 # if ( ${$alldirs}[$i] =~ /-res/ ) { next; } 201 # 202 # $packagename = ${$alldirs}[$i]; 203 # last; 204 # } 205 206 # if ( $packagename eq "" ) { installer::exiter::exit_program("ERROR: Could not find base package in directory $installdir!", "get_packagename_from_packagelist"); } 207 208 my $localproductname = $allvariables->{'PRODUCTNAME'}; 209 $localproductname = lc($localproductname); 210 $localproductname =~ s/ //g; 211 $localproductname =~ s/-/_/g; 212 213 my $packagename = $localproductname . "_" . $$languagestringref; 214 215 return $packagename; 216} 217 218######################################################### 219# Determining the name of the package file or the rpm 220# in the installation directory. For language packs 221# there is only one file in this directory 222######################################################### 223 224sub determine_packagename 225{ 226 my ( $installdir, $allvariables, $languagestringref ) = @_; 227 228 my $packagename = ""; 229 my $allnames = ""; 230 231 if ( $installer::globals::islinuxrpmbuild ) 232 { 233 # determining the rpm file in directory $installdir 234 235 my $fileextension = "rpm"; 236 my $rpmfiles = installer::systemactions::find_file_with_file_extension($fileextension, $installdir); 237 if ( ! ( $#{$rpmfiles} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); } 238 my $rpmsav = installer::converter::copy_array_from_references($rpmfiles); 239 for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$rpmfiles}[$i]); } 240 241 $packagename = get_packagename_from_packagelist($rpmfiles, $allvariables, $languagestringref); 242 243 my $packagestring = installer::converter::convert_array_to_space_separated_string($rpmfiles); 244 $packagename = create_tar_gz_file($installdir, $packagename, $packagestring); # only one file 245 for ( my $i = 0; $i <= $#{$rpmsav}; $i++ ) 246 { 247 my $onefile = $installdir . $installer::globals::separator . ${$rpmsav}[$i]; 248 unlink($onefile); 249 } 250 251 $allnames = $rpmfiles; 252 } 253 254 if ( $installer::globals::issolarisbuild ) 255 { 256 # determining the Solaris package file in directory $installdir 257 my $alldirs = installer::systemactions::get_all_directories($installdir); 258 259 if ( ! ( $#{$alldirs} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); } 260 my $alldirssav = installer::converter::copy_array_from_references($alldirs); 261 for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$alldirs}[$i]); } 262 263 $packagename = get_packagename_from_packagelist($alldirs, $allvariables, $languagestringref); 264 my $packagestring = installer::converter::convert_array_to_space_separated_string($alldirs); 265 $packagename = create_tar_gz_file($installdir, $packagename, $packagestring); # only a file (not a directory) can be included into the shell script 266 for ( my $i = 0; $i <= $#{$alldirssav}; $i++ ) { installer::systemactions::remove_complete_directory(${$alldirssav}[$i], 1); } 267 $allnames = $alldirs; 268 } 269 270 my $infoline = "Found package in installation directory $installdir : $packagename\n"; 271 $installer::logger::Lang->print($infoline); 272 273 return ( $packagename, $allnames); 274} 275 276######################################################### 277# Including the name of the package file or the rpm 278# into the script template 279######################################################### 280 281sub put_packagename_into_script 282{ 283 my ($scriptfile, $packagename, $allnames) = @_; 284 285 my $localpackagename = $packagename; 286 $localpackagename =~ s/\.tar\.gz//; # making "OOOopenoffice-it-ea.tar.gz" to "OOOopenoffice-it-ea" 287 my $infoline = "Adding packagename $localpackagename into language pack script\n"; 288 $installer::logger::Lang->print($infoline); 289 290 my $installline = ""; 291 292 if ( $installer::globals::issolarisbuild ) { $installline = " /usr/sbin/pkgadd -d \$outdir -a \$adminfile"; } 293 294 if ( $installer::globals::islinuxrpmbuild ) { $installline = " rpm --prefix \$PRODUCTINSTALLLOCATION --replacepkgs -i"; } 295 296 for ( my $i = 0; $i <= $#{$allnames}; $i++ ) 297 { 298 if ( $installer::globals::issolarisbuild ) { $installline = $installline . " ${$allnames}[$i]"; } 299 300 if ( $installer::globals::islinuxrpmbuild ) { $installline = $installline . " \$outdir/${$allnames}[$i]"; } 301 } 302 303 for ( my $j = 0; $j <= $#{$scriptfile}; $j++ ) 304 { 305 ${$scriptfile}[$j] =~ s/INSTALLLINES/$installline/; 306 } 307} 308 309################################################################## 310# Including the lowercase product name into the script template 311################################################################## 312 313sub put_productname_into_script 314{ 315 my ($scriptfile, $variableshashref) = @_; 316 317 my $productname = $variableshashref->{'PRODUCTNAME'}; 318 $productname = lc($productname); 319 $productname =~ s/\.//g; # openoffice.org -> openofficeorg 320 321 my $infoline = "Adding productname $productname into language pack script\n"; 322 $installer::logger::Lang->print($infoline); 323 324 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ ) 325 { 326 ${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/; 327 } 328} 329 330################################################################## 331# Including the full product name into the script template 332# (name and version) 333################################################################## 334 335sub put_fullproductname_into_script 336{ 337 my ($scriptfile, $variableshashref) = @_; 338 339 my $productname = $variableshashref->{'PRODUCTNAME'}; 340 my $productversion = ""; 341 if ( $variableshashref->{'PRODUCTVERSION'} ) { $productversion = $variableshashref->{'PRODUCTVERSION'}; }; 342 my $fullproductname = $productname . " " . $productversion; 343 344 my $infoline = "Adding full productname \"$fullproductname\" into language pack script\n"; 345 $installer::logger::Lang->print($infoline); 346 347 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ ) 348 { 349 ${$scriptfile}[$i] =~ s/FULLPRODUCTNAMELONGPLACEHOLDER/$fullproductname/; 350 } 351} 352 353################################################################## 354# Including the name of the search package (-core01) 355# into the script template 356################################################################## 357 358sub put_searchpackage_into_script 359{ 360 my ($scriptfile, $variableshashref) = @_; 361 362 my $basispackageprefix = $variableshashref->{'BASISPACKAGEPREFIX'}; 363 my $basispackageversion = $variableshashref->{'OOOBASEVERSION'}; 364 365 if ( $installer::globals::issolarisbuild ) { $basispackageversion =~ s/\.//g; } # "3.0" -> "30" 366 367 my $infoline = "Adding basis package prefix $basispackageprefix into language pack script\n"; 368 $installer::logger::Lang->print($infoline); 369 370 $infoline = "Adding basis package version $basispackageversion into language pack script\n"; 371 $installer::logger::Lang->print($infoline); 372 373 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ ) 374 { 375 ${$scriptfile}[$i] =~ s/BASISPACKAGEPREFIXPLACEHOLDER/$basispackageprefix/; 376 ${$scriptfile}[$i] =~ s/OOOBASEVERSIONPLACEHOLDER/$basispackageversion/; 377 } 378 379} 380 381######################################################### 382# Including the linenumber into the script template 383######################################################### 384 385sub put_linenumber_into_script 386{ 387 my ( $scriptfile, $licensefile, $allnames ) = @_; 388 389 my $linenumber = $#{$scriptfile} + $#{$licensefile} + 3; # also adding the content of the license file! 390 391 my $infoline = "Adding linenumber $linenumber into language pack script\n"; 392 $installer::logger::Lang->print($infoline); 393 394 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ ) 395 { 396 ${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/; 397 } 398} 399 400######################################################### 401# Determining the name of the new scriptfile 402######################################################### 403 404sub determine_scriptfile_name 405{ 406 my ( $packagename ) = @_; 407 408 my $scriptfilename = $packagename; 409 410# if ( $installer::globals::islinuxrpmbuild ) { $scriptfilename =~ s/\.rpm\s*$/\.sh/; } 411# if ( $installer::globals::issolarisbuild ) { $scriptfilename =~ s/\.tar\.gz\s*$/\.sh/; } 412 413 $scriptfilename =~ s/\.tar\.gz\s*$/\.sh/; 414 415 my $infoline = "Setting language pack script file name to $scriptfilename\n"; 416 $installer::logger::Lang->print($infoline); 417 418 return $scriptfilename; 419} 420 421######################################################### 422# Saving the script file in the installation directory 423######################################################### 424 425sub save_script_file 426{ 427 my ($installdir, $newscriptfilename, $scriptfile) = @_; 428 429 $newscriptfilename = $installdir . $installer::globals::separator . $newscriptfilename; 430 installer::files::save_file($newscriptfilename, $scriptfile); 431 432 my $infoline = "Saving script file $newscriptfilename\n"; 433 $installer::logger::Lang->print($infoline); 434 435 return $newscriptfilename; 436} 437 438######################################################### 439# Including the binary package into the script 440######################################################### 441 442sub include_package_into_script 443{ 444 my ( $scriptfilename, $installdir, $packagename ) = @_; 445 446 my $longpackagename = $installdir . $installer::globals::separator . $packagename; 447 my $systemcall = "cat $longpackagename >>$scriptfilename"; 448 449 my $returnvalue = system($systemcall); 450 451 my $infoline = "Systemcall: $systemcall\n"; 452 $installer::logger::Lang->print($infoline); 453 454 if ($returnvalue) 455 { 456 $infoline = "ERROR: Could not execute \"$systemcall\"!\n"; 457 $installer::logger::Lang->print($infoline); 458 } 459 else 460 { 461 $infoline = "Success: Executed \"$systemcall\" successfully!\n"; 462 $installer::logger::Lang->print($infoline); 463 } 464 465 my $localcall = "chmod 775 $scriptfilename \>\/dev\/null 2\>\&1"; 466 system($localcall); 467 468} 469 470######################################################### 471# Removing the binary package 472######################################################### 473 474sub remove_package 475{ 476 my ( $installdir, $packagename ) = @_; 477 478 my $remove_package = 1; 479 480 if ( $ENV{'DONT_REMOVE_PACKAGE'} ) { $remove_package = 0; } 481 482 if ( $remove_package ) 483 { 484 my $longpackagename = $installdir . $installer::globals::separator . $packagename; 485 unlink $longpackagename; 486 487 my $infoline = "Removing package: $longpackagename \n"; 488 $installer::logger::Lang->print($infoline); 489 } 490} 491 492#################################################### 493# Unix language packs, that are not part of 494# multilingual installation sets, need a 495# shell script installer 496#################################################### 497 498sub build_installer_for_languagepack 499{ 500 my ($installdir, $allvariableshashref, $includepatharrayref, $languagesarrayref, $languagestringref) = @_; 501 502 installer::logger::print_message( "... creating shell script installer ...\n" ); 503 504 installer::logger::include_header_into_logfile("Creating shell script installer:"); 505 506 # find and read setup script template 507 508 my $scriptfilename = "langpackscript.sh"; 509 my $scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$scriptfilename, $includepatharrayref, 0); 510 if ($$scriptref eq "") { installer::exiter::exit_program("ERROR: Could not find script file $scriptfilename!", "build_installer_for_languagepack"); } 511 my $scriptfile = installer::files::read_file($$scriptref); 512 513 my $infoline = "Found script file $scriptfilename: $$scriptref \n"; 514 $installer::logger::Lang->print($infoline); 515 516 # find and read english license file 517 my $licenselanguage = "en-US"; # always english ! 518 my $licensefilename = "LICENSE"; 519 my $licenseincludepatharrayref = installer::worker::get_language_specific_include_pathes($includepatharrayref, $licenselanguage); 520 521 my $licenseref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $licenseincludepatharrayref, 0); 522 if ($$licenseref eq "") { installer::exiter::exit_program("ERROR: Could not find License file $licensefilename!", "build_installer_for_languagepack"); } 523 my $licensefile = installer::files::read_file($$licenseref); 524 525 $infoline = "Found licensefile $licensefilename: $$licenseref \n"; 526 $installer::logger::Lang->print($infoline); 527 528 # including variables into license file 529 installer::scpzipfiles::replace_all_ziplistvariables_in_file($licensefile, $allvariableshashref); 530 531 # add license text into script template 532 put_license_file_into_script($scriptfile, $licensefile); 533 534 # add rpm or package file name into script template 535 my ( $packagename, $allnames) = determine_packagename($installdir, $allvariableshashref, $languagestringref); 536 put_packagename_into_script($scriptfile, $packagename, $allnames); 537 538 # add product name into script template 539 put_productname_into_script($scriptfile, $allvariableshashref); 540 541 # add product name into script template 542 put_fullproductname_into_script($scriptfile, $allvariableshashref); 543 544 # add product name into script template 545 put_searchpackage_into_script($scriptfile, $allvariableshashref); 546 547 # replace linenumber in script template 548 put_linenumber_into_script($scriptfile, $licensefile, $allnames); 549 550 # saving the script file 551 my $newscriptfilename = determine_scriptfile_name($packagename); 552 $newscriptfilename = save_script_file($installdir, $newscriptfilename, $scriptfile); 553 554 # include rpm or package into script 555 include_package_into_script($newscriptfilename, $installdir, $packagename); 556 557 # remove rpm or package 558 remove_package($installdir, $packagename); 559} 560 5611; 562