Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / bin / modules / installer / languagepack.pm
bloba39769144de6ec996c8301fdb3b1d4b196b30bae
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer::languagepack;
21 use installer::converter;
22 use installer::files;
23 use installer::globals;
24 use installer::logger;
25 use installer::pathanalyzer;
26 use installer::scpzipfiles;
27 use installer::scriptitems;
28 use installer::systemactions;
29 use installer::worker;
31 ####################################################
32 # Selecting all files with the correct language
33 ####################################################
35 sub select_language_items
37 my ( $itemsref, $languagesarrayref, $itemname ) = @_;
39 installer::logger::include_header_into_logfile("Selecting languages for language pack. Item: $itemname");
41 my @itemsarray = ();
43 for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
45 my $oneitem = ${$itemsref}[$i];
47 my $ismultilingual = $oneitem->{'ismultilingual'};
49 if (!($ismultilingual))
51 # Files with style "LANGUAGEPACK" and "FORCELANGUAGEPACK" also have to be included into the language pack.
52 # Files with style "LANGUAGEPACK" are only included into language packs.
53 # Files with style "FORCELANGUAGEPACK" are included into language packs and non language packs. They are
54 # forced, because otherwise they may not be included into languagepacks.
56 my $styles = "";
57 if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; }
59 if (( $styles =~ /\bLANGUAGEPACK\b/ ) || ( $styles =~ /\bFORCELANGUAGEPACK\b/ )) { push(@itemsarray, $oneitem); }
61 next; # single language files are not included into language pack
64 my $specificlanguage = "";
65 if ( $oneitem->{'specificlanguage'} ) { $specificlanguage = $oneitem->{'specificlanguage'}; }
67 for ( my $j = 0; $j <= $#{$languagesarrayref}; $j++ ) # iterating over all languages
69 my $onelanguage = ${$languagesarrayref}[$j];
70 my $locallang = $onelanguage;
71 $locallang =~ s/-/_/;
73 if ( $specificlanguage eq $onelanguage )
75 push(@itemsarray, $oneitem);
80 return \@itemsarray;
83 sub replace_languagestring_variable
85 my ($onepackageref, $languagestringref) = @_;
87 my $key;
89 foreach $key (keys %{$onepackageref})
91 my $value = $onepackageref->{$key};
92 $value =~ s/\%LANGUAGESTRING/$$languagestringref/g;
93 $onepackageref->{$key} = $value;
97 #########################################################
98 # Including the license text into the script template
99 #########################################################
101 sub put_license_file_into_script
103 my ($scriptfile, $licensefile) = @_;
105 my $infoline = "Adding licensefile into language pack script\n";
106 push( @installer::globals::logfileinfo, $infoline);
108 my $includestring = "";
110 for ( my $i = 0; $i <= $#{$licensefile}; $i++ )
112 $includestring = $includestring . ${$licensefile}[$i];
115 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
117 ${$scriptfile}[$i] =~ s/LICENSEFILEPLACEHOLDER/$includestring/;
121 #########################################################
122 # Creating a tar.gz file from a Solaris package
123 #########################################################
125 sub create_tar_gz_file
127 my ($installdir, $packagename, $packagestring) = @_;
129 $packagename =~ s/\.rpm\s*$//;
130 my $targzname = $packagename . ".tar.gz";
131 $systemcall = "cd $installdir; tar -cf - $packagestring | gzip > $targzname";
132 installer::logger::print_message( "... $systemcall ...\n" );
134 my $returnvalue = system($systemcall);
136 my $infoline = "Systemcall: $systemcall\n";
137 push( @installer::globals::logfileinfo, $infoline);
139 if ($returnvalue)
141 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
142 push( @installer::globals::logfileinfo, $infoline);
144 else
146 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
147 push( @installer::globals::logfileinfo, $infoline);
150 return $targzname;
153 #########################################################
154 # Determining the name of the package file
155 #########################################################
157 sub get_packagename_from_packagelist
159 my ( $alldirs, $allvariables, $languagestringref ) = @_;
161 my $localproductname = $allvariables->{'PRODUCTNAME'};
162 $localproductname = lc($localproductname);
163 $localproductname =~ s/ //g;
164 $localproductname =~ s/-/_/g;
166 my $packagename = $localproductname . "_" . $$languagestringref;
168 return $packagename;
171 #########################################################
172 # Determining the name of the package file or the rpm
173 # in the installation directory. For language packs
174 # there is only one file in this directory
175 #########################################################
177 sub determine_packagename
179 my ( $installdir, $allvariables, $languagestringref ) = @_;
181 my $packagename = "";
182 my $allnames = "";
184 if ( $installer::globals::isrpmbuild )
186 # determining the rpm file in directory $installdir
188 my $fileextension = "rpm";
189 my $rpmfiles = installer::systemactions::find_file_with_file_extension($fileextension, $installdir);
190 if ( ! ( $#{$rpmfiles} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
191 my $rpmsav = [@{$rpmfiles}];
192 for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$rpmfiles}[$i]); }
194 $packagename = get_packagename_from_packagelist($rpmfiles, $allvariables, $languagestringref);
196 my $packagestring = installer::converter::convert_array_to_space_separated_string($rpmfiles);
197 $packagename = create_tar_gz_file($installdir, $packagename, $packagestring); # only one file
198 for ( my $i = 0; $i <= $#{$rpmsav}; $i++ )
200 my $onefile = $installdir . $installer::globals::separator . ${$rpmsav}[$i];
201 unlink($onefile);
204 $allnames = $rpmfiles;
207 if ( $installer::globals::issolarisbuild )
209 # determining the Solaris package file in directory $installdir
210 my $alldirs = installer::systemactions::get_all_directories($installdir);
212 if ( ! ( $#{$alldirs} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
213 my $alldirssav = [@{$alldirs}];
214 for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$alldirs}[$i]); }
216 $packagename = get_packagename_from_packagelist($alldirs, $allvariables, $languagestringref);
217 my $packagestring = installer::converter::convert_array_to_space_separated_string($alldirs);
218 $packagename = create_tar_gz_file($installdir, $packagename, $packagestring); # only a file (not a directory) can be included into the shell script
219 for ( my $i = 0; $i <= $#{$alldirssav}; $i++ ) { installer::systemactions::remove_complete_directory(${$alldirssav}[$i], 1); }
220 $allnames = $alldirs;
223 my $infoline = "Found package in installation directory $installdir : $packagename\n";
224 push( @installer::globals::logfileinfo, $infoline);
226 return ( $packagename, $allnames);
229 #########################################################
230 # Including the name of the package file or the rpm
231 # into the script template
232 #########################################################
234 sub put_packagename_into_script
236 my ($scriptfile, $packagename, $allnames) = @_;
238 my $localpackagename = $packagename;
239 $localpackagename =~ s/\.tar\.gz//; # making "OOOopenoffice-it-ea.tar.gz" to "OOOopenoffice-it-ea"
240 my $infoline = "Adding packagename $localpackagename into language pack script\n";
241 push( @installer::globals::logfileinfo, $infoline);
243 my $installline = "";
245 if ( $installer::globals::issolarisbuild ) { $installline = " /usr/sbin/pkgadd -d \$outdir -a \$adminfile"; }
247 if ( $installer::globals::isrpmbuild ) { $installline = " rpm --prefix \$PRODUCTINSTALLLOCATION --replacepkgs -i"; }
249 for ( my $i = 0; $i <= $#{$allnames}; $i++ )
251 if ( $installer::globals::issolarisbuild ) { $installline = $installline . " ${$allnames}[$i]"; }
253 if ( $installer::globals::isrpmbuild ) { $installline = $installline . " \$outdir/${$allnames}[$i]"; }
256 for ( my $j = 0; $j <= $#{$scriptfile}; $j++ )
258 ${$scriptfile}[$j] =~ s/INSTALLLINES/$installline/;
262 ##################################################################
263 # Including the lowercase product name into the script template
264 ##################################################################
266 sub put_productname_into_script
268 my ($scriptfile, $variableshashref) = @_;
270 my $productname = $variableshashref->{'PRODUCTNAME'};
271 $productname = lc($productname);
272 $productname =~ s/\.//g; # openoffice.org -> openofficeorg
274 my $infoline = "Adding productname $productname into language pack script\n";
275 push( @installer::globals::logfileinfo, $infoline);
277 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
279 ${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/;
283 ##################################################################
284 # Including the full product name into the script template
285 # (name and version)
286 ##################################################################
288 sub put_fullproductname_into_script
290 my ($scriptfile, $variableshashref) = @_;
292 my $productname = $variableshashref->{'PRODUCTNAME'};
293 my $productversion = "";
294 if ( $variableshashref->{'PRODUCTVERSION'} ) { $productversion = $variableshashref->{'PRODUCTVERSION'}; };
295 my $fullproductname = $productname . " " . $productversion;
297 my $infoline = "Adding full productname \"$fullproductname\" into language pack script\n";
298 push( @installer::globals::logfileinfo, $infoline);
300 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
302 ${$scriptfile}[$i] =~ s/FULLPRODUCTNAMELONGPLACEHOLDER/$fullproductname/;
306 ##################################################################
307 # Including the name of the search package (-core01)
308 # into the script template
309 ##################################################################
311 sub put_searchpackage_into_script
313 my ($scriptfile, $variableshashref) = @_;
315 my $basispackageprefix = $variableshashref->{'BASISPACKAGEPREFIX'};
316 my $productversion = $variableshashref->{'PRODUCTVERSION'};
318 if ( $installer::globals::issolarisbuild ) { $productversion =~ s/\.//g; } # "3.0" -> "30"
320 my $infoline = "Adding basis package prefix $basispackageprefix into language pack script\n";
321 push( @installer::globals::logfileinfo, $infoline);
323 $infoline = "Adding basis package version $productversion into language pack script\n";
324 push( @installer::globals::logfileinfo, $infoline);
326 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
328 ${$scriptfile}[$i] =~ s/BASISPACKAGEPREFIXPLACEHOLDER/$basispackageprefix/;
329 ${$scriptfile}[$i] =~ s/PRODUCTVERSIONPLACEHOLDER/$productversion/;
334 #########################################################
335 # Including the linenumber into the script template
336 #########################################################
338 sub put_linenumber_into_script
340 my ( $scriptfile, $licensefile, $allnames ) = @_;
342 my $linenumber = $#{$scriptfile} + $#{$licensefile} + 3; # also adding the content of the license file!
344 my $infoline = "Adding linenumber $linenumber into language pack script\n";
345 push( @installer::globals::logfileinfo, $infoline);
347 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
349 ${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/;
353 #########################################################
354 # Determining the name of the new scriptfile
355 #########################################################
357 sub determine_scriptfile_name
359 my ( $packagename ) = @_;
361 my $scriptfilename = $packagename;
363 $scriptfilename =~ s/\.tar\.gz\s*$/\.sh/;
365 my $infoline = "Setting language pack script file name to $scriptfilename\n";
366 push( @installer::globals::logfileinfo, $infoline);
368 return $scriptfilename;
371 #########################################################
372 # Saving the script file in the installation directory
373 #########################################################
375 sub save_script_file
377 my ($installdir, $newscriptfilename, $scriptfile) = @_;
379 $newscriptfilename = $installdir . $installer::globals::separator . $newscriptfilename;
380 installer::files::save_file($newscriptfilename, $scriptfile);
382 my $infoline = "Saving script file $newscriptfilename\n";
383 push( @installer::globals::logfileinfo, $infoline);
385 return $newscriptfilename;
388 #########################################################
389 # Including the binary package into the script
390 #########################################################
392 sub include_package_into_script
394 my ( $scriptfilename, $installdir, $packagename ) = @_;
396 my $longpackagename = $installdir . $installer::globals::separator . $packagename;
397 my $systemcall = "cat $longpackagename >>$scriptfilename";
399 my $returnvalue = system($systemcall);
401 my $infoline = "Systemcall: $systemcall\n";
402 push( @installer::globals::logfileinfo, $infoline);
404 if ($returnvalue)
406 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
407 push( @installer::globals::logfileinfo, $infoline);
409 else
411 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
412 push( @installer::globals::logfileinfo, $infoline);
415 chmod 0775, $scriptfilename;
419 #########################################################
420 # Removing the binary package
421 #########################################################
423 sub remove_package
425 my ( $installdir, $packagename ) = @_;
427 my $remove_package = 1;
429 if ( $ENV{'DONT_REMOVE_PACKAGE'} ) { $remove_package = 0; }
431 if ( $remove_package )
433 my $longpackagename = $installdir . $installer::globals::separator . $packagename;
434 unlink $longpackagename;
436 my $infoline = "Removing package: $longpackagename \n";
437 push( @installer::globals::logfileinfo, $infoline);
441 ####################################################
442 # Unix language packs, that are not part of
443 # multilingual installation sets, need a
444 # shell script installer
445 ####################################################
447 sub build_installer_for_languagepack
449 my ($installdir, $allvariableshashref, $includepatharrayref, $languagesarrayref, $languagestringref) = @_;
451 installer::logger::print_message( "... creating shell script installer ...\n" );
453 installer::logger::include_header_into_logfile("Creating shell script installer:");
455 # find and read setup script template
457 my $scriptfilename = $ENV{'SRCDIR'} . "/setup_native/scripts/langpackscript.sh";
458 if (! -f $scriptfilename) { installer::exiter::exit_program("ERROR: Could not find script file $scriptfilename!", "build_installer_for_languagepack"); }
459 my $scriptfile = installer::files::read_file($scriptfilename);
461 my $infoline = "Found script file $scriptfilename: $scriptfile \n";
462 push( @installer::globals::logfileinfo, $infoline);
464 # find and read english license file
465 my $licenselanguage = "en-US"; # always english !
466 my $licensefilename = "LICENSE";
467 my $licenseincludepatharrayref = installer::worker::get_language_specific_include_paths($includepatharrayref, $licenselanguage);
469 my $licenseref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $licenseincludepatharrayref, 0);
470 if ($$licenseref eq "") { installer::exiter::exit_program("ERROR: Could not find License file $licensefilename!", "build_installer_for_languagepack"); }
471 my $licensefile = installer::files::read_file($$licenseref);
473 $infoline = "Found licensefile $licensefilename: $$licenseref \n";
474 push( @installer::globals::logfileinfo, $infoline);
476 # including variables into license file
477 installer::scpzipfiles::replace_all_ziplistvariables_in_file($licensefile, $allvariableshashref);
479 # add license text into script template
480 put_license_file_into_script($scriptfile, $licensefile);
482 # add rpm or package file name into script template
483 my ( $packagename, $allnames) = determine_packagename($installdir, $allvariableshashref, $languagestringref);
484 put_packagename_into_script($scriptfile, $packagename, $allnames);
486 # add product name into script template
487 put_productname_into_script($scriptfile, $allvariableshashref);
489 # add product name into script template
490 put_fullproductname_into_script($scriptfile, $allvariableshashref);
492 # add product name into script template
493 put_searchpackage_into_script($scriptfile, $allvariableshashref);
495 # replace linenumber in script template
496 put_linenumber_into_script($scriptfile, $licensefile, $allnames);
498 # saving the script file
499 my $newscriptfilename = determine_scriptfile_name($packagename);
500 $newscriptfilename = save_script_file($installdir, $newscriptfilename, $scriptfile);
502 # include rpm or package into script
503 include_package_into_script($newscriptfilename, $installdir, $packagename);
505 # remove rpm or package
506 remove_package($installdir, $packagename);