Debian Codegraph @

solenv/bin/modules/installer/languagepack.pm

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