1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: languagepack.pm,v $
11 # $Revision: 1.16.226.1 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer
::languagepack
;
34 use installer
::converter
;
35 use installer
::existence
;
37 use installer
::globals
;
38 use installer
::logger
;
39 use installer
::pathanalyzer
;
40 use installer
::scpzipfiles
;
41 use installer
::scriptitems
;
42 use installer
::systemactions
;
43 use installer
::worker
;
45 ####################################################
46 # Selecting all files with the correct language
47 ####################################################
49 sub select_language_items
51 my ( $itemsref, $languagesarrayref, $itemname ) = @_;
53 installer
::logger
::include_header_into_logfile
("Selecting languages for language pack. Item: $itemname");
57 for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
59 my $oneitem = ${$itemsref}[$i];
61 my $ismultilingual = $oneitem->{'ismultilingual'};
63 if (!($ismultilingual))
65 # Files with style "LANGUAGEPACK" and "FORCELANGUAGEPACK" also have to be included into the language pack.
66 # Files with style "LANGUAGEPACK" are only included into language packs.
67 # Files with style "FORCELANGUAGEPACK" are included into language packs and non language packs. They are
68 # forced, because otherwise they not not be included into languagepacks.
71 if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; }
73 if (( $styles =~ /\bLANGUAGEPACK\b/ ) || ( $styles =~ /\bFORCELANGUAGEPACK\b/ )) { push(@itemsarray, $oneitem); }
75 next; # single language files are not included into language pack
78 my $specificlanguage = "";
79 if ( $oneitem->{'specificlanguage'} ) { $specificlanguage = $oneitem->{'specificlanguage'}; }
81 for ( my $j = 0; $j <= $#{$languagesarrayref}; $j++ ) # iterating over all languages
83 my $onelanguage = ${$languagesarrayref}[$j];
84 my $locallang = $onelanguage;
87 if ( $specificlanguage eq $onelanguage )
89 # $oneitem->{'modules'} = $installer::globals::rootmodulegid; # all files in a language pack are root files
90 # Using $installer::globals::languagemodulesbase (?)
92 # # no more automatic change of module assignments
93 # $oneitem->{'modules'} = $installer::globals::rootmodulegid . "_$locallang"; # all files in a language pack are root files
95 # if (( $installer::globals::islinuxbuild ) || ( $installer::globals::issolarispkgbuild ))
97 # if ( $oneitem->{'Dir'} )
99 # if ( $oneitem->{'Dir'} eq "gid_Dir_Fonts_Truetype" ) { $oneitem->{'modules'} = "gid_Module_Langpack_Fonts_$locallang"; }
100 # if ( $oneitem->{'Dir'} eq "gid_Dir_Resource" ) { $oneitem->{'modules'} = "gid_Module_Langpack_Resource_$locallang"; }
101 # if ( $oneitem->{'Dir'} eq "gid_Dir_Help_Isolanguage" ) { $oneitem->{'modules'} = "gid_Module_Langpack_Help_$locallang"; }
105 # preparing different modules for Windows Installer language packs
106 # my $underlinelanguage = $specificlanguage;
107 # $underlinelanguage =~ s/-/_/;
108 # if ( $installer::globals::iswindowsbuild ) { $oneitem->{'modules'} = $installer::globals::languagemodulesbase . $underlinelanguage; }
110 # # no more collecting of language pack feature
111 # if (! installer::existence::exists_in_array($oneitem->{'modules'}, \@installer::globals::languagepackfeature))
113 # push(@installer::globals::languagepackfeature, $oneitem->{'modules'}); # Collecting all language pack feature
116 push(@itemsarray, $oneitem);
124 sub replace_languagestring_variable
126 my ($onepackageref, $languagestringref) = @_;
130 foreach $key (keys %{$onepackageref})
132 my $value = $onepackageref->{$key};
133 $value =~ s/\%LANGUAGESTRING/$$languagestringref/g;
134 $onepackageref->{$key} = $value;
138 #########################################################
139 # Including the license text into the script template
140 #########################################################
142 sub put_license_file_into_script
144 my ($scriptfile, $licensefile) = @_;
146 my $infoline = "Adding licensefile into language pack script\n";
147 push( @installer::globals
::logfileinfo
, $infoline);
149 my $includestring = "";
151 for ( my $i = 0; $i <= $#{$licensefile}; $i++ )
153 $includestring = $includestring . ${$licensefile}[$i];
156 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
158 ${$scriptfile}[$i] =~ s/LICENSEFILEPLACEHOLDER/$includestring/;
162 #########################################################
163 # Creating a tar.gz file from a Solaris package
164 #########################################################
166 sub create_tar_gz_file
168 my ($installdir, $packagename, $packagestring) = @_;
170 $packagename =~ s/\.rpm\s*$//;
171 my $targzname = $packagename . ".tar.gz";
172 $systemcall = "cd $installdir; tar -cf - $packagestring | gzip > $targzname";
173 installer
::logger
::print_message
( "... $systemcall ...\n" );
175 my $returnvalue = system($systemcall);
177 my $infoline = "Systemcall: $systemcall\n";
178 push( @installer::globals
::logfileinfo
, $infoline);
182 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
183 push( @installer::globals
::logfileinfo
, $infoline);
187 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
188 push( @installer::globals
::logfileinfo
, $infoline);
194 #########################################################
195 # Determining the name of the package file
196 #########################################################
198 sub get_packagename_from_packagelist
200 my ( $alldirs, $allvariables, $languagestringref ) = @_;
202 # my $packagename = "";
204 # for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
206 # if ( ${$alldirs}[$i] =~ /-fonts/ ) { next; }
207 # if ( ${$alldirs}[$i] =~ /-help/ ) { next; }
208 # if ( ${$alldirs}[$i] =~ /-res/ ) { next; }
210 # $packagename = ${$alldirs}[$i];
214 # if ( $packagename eq "" ) { installer::exiter::exit_program("ERROR: Could not find base package in directory $installdir!", "get_packagename_from_packagelist"); }
216 my $localproductname = $allvariables->{'PRODUCTNAME'};
217 $localproductname = lc($localproductname);
218 $localproductname =~ s/ //g;
219 $localproductname =~ s/-/_/g;
221 my $packagename = $localproductname . "_" . $$languagestringref;
226 #########################################################
227 # Determining the name of the package file or the rpm
228 # in the installation directory. For language packs
229 # there is only one file in this directory
230 #########################################################
232 sub determine_packagename
234 my ( $installdir, $allvariables, $languagestringref ) = @_;
236 my $packagename = "";
239 if ( $installer::globals
::islinuxrpmbuild
)
241 # determining the rpm file in directory $installdir
243 my $fileextension = "rpm";
244 my $rpmfiles = installer
::systemactions
::find_file_with_file_extension
($fileextension, $installdir);
245 if ( ! ( $#{$rpmfiles} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
246 my $rpmsav = installer
::converter
::copy_array_from_references
($rpmfiles);
247 for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$rpmfiles}[$i]); }
249 $packagename = get_packagename_from_packagelist
($rpmfiles, $allvariables, $languagestringref);
251 my $packagestring = installer
::converter
::convert_array_to_space_separated_string
($rpmfiles);
252 $packagename = create_tar_gz_file
($installdir, $packagename, $packagestring); # only one file
253 for ( my $i = 0; $i <= $#{$rpmsav}; $i++ )
255 my $onefile = $installdir . $installer::globals
::separator
. ${$rpmsav}[$i];
259 $allnames = $rpmfiles;
262 if ( $installer::globals
::issolarisbuild
)
264 # determining the Solaris package file in directory $installdir
265 my $alldirs = installer
::systemactions
::get_all_directories
($installdir);
267 if ( ! ( $#{$alldirs} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
268 my $alldirssav = installer
::converter
::copy_array_from_references
($alldirs);
269 for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$alldirs}[$i]); }
271 $packagename = get_packagename_from_packagelist
($alldirs, $allvariables, $languagestringref);
272 my $packagestring = installer
::converter
::convert_array_to_space_separated_string
($alldirs);
273 $packagename = create_tar_gz_file
($installdir, $packagename, $packagestring); # only a file (not a directory) can be included into the shell script
274 for ( my $i = 0; $i <= $#{$alldirssav}; $i++ ) { installer::systemactions::remove_complete_directory(${$alldirssav}[$i], 1); }
275 $allnames = $alldirs;
278 my $infoline = "Found package in installation directory $installdir : $packagename\n";
279 push( @installer::globals
::logfileinfo
, $infoline);
281 return ( $packagename, $allnames);
284 #########################################################
285 # Including the name of the package file or the rpm
286 # into the script template
287 #########################################################
289 sub put_packagename_into_script
291 my ($scriptfile, $packagename, $allnames) = @_;
293 my $localpackagename = $packagename;
294 $localpackagename =~ s/\.tar\.gz//; # making "OOOopenoffice-it-ea.tar.gz" to "OOOopenoffice-it-ea"
295 my $infoline = "Adding packagename $localpackagename into language pack script\n";
296 push( @installer::globals
::logfileinfo
, $infoline);
298 my $installline = "";
300 if ( $installer::globals
::issolarisbuild
) { $installline = " /usr/sbin/pkgadd -d \$outdir -a \$adminfile"; }
302 if ( $installer::globals
::islinuxrpmbuild
) { $installline = " rpm --prefix \$PRODUCTINSTALLLOCATION --replacepkgs -i"; }
304 for ( my $i = 0; $i <= $#{$allnames}; $i++ )
306 if ( $installer::globals
::issolarisbuild
) { $installline = $installline . " ${$allnames}[$i]"; }
308 if ( $installer::globals
::islinuxrpmbuild
) { $installline = $installline . " \$outdir/${$allnames}[$i]"; }
311 for ( my $j = 0; $j <= $#{$scriptfile}; $j++ )
313 ${$scriptfile}[$j] =~ s/INSTALLLINES/$installline/;
317 ##################################################################
318 # Including the lowercase product name into the script template
319 ##################################################################
321 sub put_productname_into_script
323 my ($scriptfile, $variableshashref) = @_;
325 my $productname = $variableshashref->{'PRODUCTNAME'};
326 $productname = lc($productname);
327 $productname =~ s/\.//g; # openoffice.org -> openofficeorg
329 my $infoline = "Adding productname $productname into language pack script\n";
330 push( @installer::globals
::logfileinfo
, $infoline);
332 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
334 ${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/;
338 ##################################################################
339 # Including the full product name into the script template
341 ##################################################################
343 sub put_fullproductname_into_script
345 my ($scriptfile, $variableshashref) = @_;
347 my $productname = $variableshashref->{'PRODUCTNAME'};
348 my $productversion = "";
349 if ( $variableshashref->{'PRODUCTVERSION'} ) { $productversion = $variableshashref->{'PRODUCTVERSION'}; };
350 my $fullproductname = $productname . " " . $productversion;
352 my $infoline = "Adding full productname \"$fullproductname\" into language pack script\n";
353 push( @installer::globals
::logfileinfo
, $infoline);
355 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
357 ${$scriptfile}[$i] =~ s/FULLPRODUCTNAMELONGPLACEHOLDER/$fullproductname/;
361 ##################################################################
362 # Including the name of the search package (-core01)
363 # into the script template
364 ##################################################################
366 sub put_searchpackage_into_script
368 my ($scriptfile, $variableshashref) = @_;
370 my $basispackageprefix = $variableshashref->{'BASISPACKAGEPREFIX'};
371 my $basispackageversion = $variableshashref->{'OOOBASEVERSION'};
373 if ( $installer::globals
::issolarisbuild
) { $basispackageversion =~ s/\.//g; } # "3.0" -> "30"
375 my $infoline = "Adding basis package prefix $basispackageprefix into language pack script\n";
376 push( @installer::globals
::logfileinfo
, $infoline);
378 $infoline = "Adding basis package version $basispackageversion into language pack script\n";
379 push( @installer::globals
::logfileinfo
, $infoline);
381 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
383 ${$scriptfile}[$i] =~ s/BASISPACKAGEPREFIXPLACEHOLDER/$basispackageprefix/;
384 ${$scriptfile}[$i] =~ s/OOOBASEVERSIONPLACEHOLDER/$basispackageversion/;
389 #########################################################
390 # Including the linenumber into the script template
391 #########################################################
393 sub put_linenumber_into_script
395 my ( $scriptfile, $licensefile, $allnames ) = @_;
397 my $linenumber = $#{$scriptfile} + $#{$licensefile} + 3; # also adding the content of the license file!
399 my $infoline = "Adding linenumber $linenumber into language pack script\n";
400 push( @installer::globals
::logfileinfo
, $infoline);
402 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
404 ${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/;
408 #########################################################
409 # Determining the name of the new scriptfile
410 #########################################################
412 sub determine_scriptfile_name
414 my ( $packagename ) = @_;
416 my $scriptfilename = $packagename;
418 # if ( $installer::globals::islinuxrpmbuild ) { $scriptfilename =~ s/\.rpm\s*$/\.sh/; }
419 # if ( $installer::globals::issolarisbuild ) { $scriptfilename =~ s/\.tar\.gz\s*$/\.sh/; }
421 $scriptfilename =~ s/\.tar\.gz\s*$/\.sh/;
423 my $infoline = "Setting language pack script file name to $scriptfilename\n";
424 push( @installer::globals
::logfileinfo
, $infoline);
426 return $scriptfilename;
429 #########################################################
430 # Saving the script file in the installation directory
431 #########################################################
435 my ($installdir, $newscriptfilename, $scriptfile) = @_;
437 $newscriptfilename = $installdir . $installer::globals
::separator
. $newscriptfilename;
438 installer
::files
::save_file
($newscriptfilename, $scriptfile);
440 my $infoline = "Saving script file $newscriptfilename\n";
441 push( @installer::globals
::logfileinfo
, $infoline);
443 return $newscriptfilename;
446 #########################################################
447 # Including the binary package into the script
448 #########################################################
450 sub include_package_into_script
452 my ( $scriptfilename, $installdir, $packagename ) = @_;
454 my $longpackagename = $installdir . $installer::globals
::separator
. $packagename;
455 my $systemcall = "cat $longpackagename >>$scriptfilename";
457 my $returnvalue = system($systemcall);
459 my $infoline = "Systemcall: $systemcall\n";
460 push( @installer::globals
::logfileinfo
, $infoline);
464 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
465 push( @installer::globals
::logfileinfo
, $infoline);
469 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
470 push( @installer::globals
::logfileinfo
, $infoline);
473 my $localcall = "chmod 775 $scriptfilename \>\/dev\/null 2\>\&1";
478 #########################################################
479 # Removing the binary package
480 #########################################################
484 my ( $installdir, $packagename ) = @_;
486 my $remove_package = 1;
488 if ( $ENV{'DONT_REMOVE_PACKAGE'} ) { $remove_package = 0; }
490 if ( $remove_package )
492 my $longpackagename = $installdir . $installer::globals
::separator
. $packagename;
493 unlink $longpackagename;
495 my $infoline = "Removing package: $longpackagename \n";
496 push( @installer::globals
::logfileinfo
, $infoline);
500 ####################################################
501 # Unix language packs, that are not part of
502 # multilingual installation sets, need a
503 # shell script installer
504 ####################################################
506 sub build_installer_for_languagepack
508 my ($installdir, $allvariableshashref, $includepatharrayref, $languagesarrayref, $languagestringref) = @_;
510 installer
::logger
::print_message
( "... creating shell script installer ...\n" );
512 installer
::logger
::include_header_into_logfile
("Creating shell script installer:");
514 # find and read setup script template
516 my $scriptfilename = "langpackscript.sh";
517 my $scriptref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath
(\
$scriptfilename, $includepatharrayref, 0);
518 if ($$scriptref eq "") { installer
::exiter
::exit_program
("ERROR: Could not find script file $scriptfilename!", "build_installer_for_languagepack"); }
519 my $scriptfile = installer
::files
::read_file
($$scriptref);
521 my $infoline = "Found script file $scriptfilename: $$scriptref \n";
522 push( @installer::globals
::logfileinfo
, $infoline);
524 # find and read english license file
525 my $licenselanguage = "en-US"; # always english !
526 my $licensefilename = "LICENSE_" . $licenselanguage;
527 my $licenseincludepatharrayref = installer
::worker
::get_language_specific_include_pathes
($includepatharrayref, $licenselanguage);
529 my $licenseref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath
(\
$licensefilename, $licenseincludepatharrayref, 0);
530 if ($$licenseref eq "") { installer
::exiter
::exit_program
("ERROR: Could not find License file $licensefilename!", "build_installer_for_languagepack"); }
531 my $licensefile = installer
::files
::read_file
($$licenseref);
533 $infoline = "Found licensefile $licensefilename: $$licenseref \n";
534 push( @installer::globals
::logfileinfo
, $infoline);
536 # including variables into license file
537 installer
::scpzipfiles
::replace_all_ziplistvariables_in_file
($licensefile, $allvariableshashref);
539 # add license text into script template
540 put_license_file_into_script
($scriptfile, $licensefile);
542 # add rpm or package file name into script template
543 my ( $packagename, $allnames) = determine_packagename
($installdir, $allvariableshashref, $languagestringref);
544 put_packagename_into_script
($scriptfile, $packagename, $allnames);
546 # add product name into script template
547 put_productname_into_script
($scriptfile, $allvariableshashref);
549 # add product name into script template
550 put_fullproductname_into_script
($scriptfile, $allvariableshashref);
552 # add product name into script template
553 put_searchpackage_into_script
($scriptfile, $allvariableshashref);
555 # replace linenumber in script template
556 put_linenumber_into_script
($scriptfile, $licensefile, $allnames);
558 # saving the script file
559 my $newscriptfilename = determine_scriptfile_name
($packagename);
560 $newscriptfilename = save_script_file
($installdir, $newscriptfilename, $scriptfile);
562 # include rpm or package into script
563 include_package_into_script
($newscriptfilename, $installdir, $packagename);
565 # remove rpm or package
566 remove_package
($installdir, $packagename);