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
::helppack
;
24 use installer
::converter
;
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
;
36 my ( $itemsref, $languagesarrayref, $itemname ) = @_;
38 installer
::logger
::include_header_into_logfile
("Selecting items for help pack. Item: $itemname");
42 for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
44 my $oneitem = ${$itemsref}[$i];
47 if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; }
49 if (( $styles =~ /\bHELPPACK\b/ ) || ( $styles =~ /\bFORCEHELPPACK\b/ ))
51 # Files with style "HELPPACK" and "FORCEHELPPACK" also have to be included into the help pack.
52 # Files with style "HELPPACK" are only included into help packs.
53 # Files with style "FORCEHELPPACK" are included into help packs and non help packs. They are
54 # forced, because otherwise they may not be included into helppacks.
56 my $ismultilingual = $oneitem->{'ismultilingual'};
60 my $specificlanguage = "";
61 if ( $oneitem->{'specificlanguage'} ) { $specificlanguage = $oneitem->{'specificlanguage'}; }
63 for ( my $j = 0; $j <= $#{$languagesarrayref}; $j++ ) # iterating over all languages
65 my $onelanguage = ${$languagesarrayref}[$j];
66 my $locallang = $onelanguage;
69 if ( $specificlanguage eq $onelanguage )
71 push(@itemsarray, $oneitem);
77 push(@itemsarray, $oneitem);
85 sub replace_languagestring_variable
87 my ($onepackageref, $languagestringref) = @_;
91 foreach $key (keys %{$onepackageref})
93 my $value = $onepackageref->{$key};
94 $value =~ s/\%LANGUAGESTRING/$$languagestringref/g;
95 $onepackageref->{$key} = $value;
99 #########################################################
100 # Including the license text into the script template
101 #########################################################
103 sub put_license_file_into_script
105 my ($scriptfile, $licensefile) = @_;
107 my $infoline = "Adding licensefile into help pack script\n";
108 push( @installer::globals
::logfileinfo
, $infoline);
110 my $includestring = "";
112 for ( my $i = 0; $i <= $#{$licensefile}; $i++ )
114 $includestring = $includestring . ${$licensefile}[$i];
117 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
119 ${$scriptfile}[$i] =~ s/LICENSEFILEPLACEHOLDER/$includestring/;
123 #########################################################
124 # Creating a tar.gz file from a Solaris package
125 #########################################################
127 sub create_tar_gz_file
129 my ($installdir, $packagename, $packagestring) = @_;
131 $packagename =~ s/\.rpm\s*$//;
132 my $targzname = $packagename . ".tar.gz";
133 my $systemcall = "cd $installdir; tar -cf - $packagestring | gzip > $targzname";
134 installer
::logger
::print_message
( "... $systemcall ...\n" );
136 my $returnvalue = system($systemcall);
138 my $infoline = "Systemcall: $systemcall\n";
139 push( @installer::globals
::logfileinfo
, $infoline);
143 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
144 push( @installer::globals
::logfileinfo
, $infoline);
148 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
149 push( @installer::globals
::logfileinfo
, $infoline);
155 #########################################################
156 # Determining the name of the package file
157 #########################################################
159 sub get_packagename_from_packagelist
161 my ( $alldirs, $allvariables, $languagestringref ) = @_;
163 # my $packagename = "";
165 # for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
167 # if ( ${$alldirs}[$i] =~ /-fonts/ ) { next; }
168 # if ( ${$alldirs}[$i] =~ /-help/ ) { next; }
169 # if ( ${$alldirs}[$i] =~ /-res/ ) { next; }
171 # $packagename = ${$alldirs}[$i];
175 # if ( $packagename eq "" ) { installer::exiter::exit_program("ERROR: Could not find base package in directory $installdir!", "get_packagename_from_packagelist"); }
177 my $localproductname = $allvariables->{'PRODUCTNAME'};
178 $localproductname = lc($localproductname);
179 $localproductname =~ s/ //g;
180 $localproductname =~ s/-/_/g;
182 my $packagename = $localproductname . "_" . $$languagestringref;
187 #########################################################
188 # Determining the name of the package file or the rpm
189 # in the installation directory. For help packs
190 # there is only one file in this directory
191 #########################################################
193 sub determine_packagename
195 my ( $installdir, $allvariables, $languagestringref ) = @_;
197 my $packagename = "";
200 if ( $installer::globals
::isrpmbuild
)
202 # determining the rpm file in directory $installdir
204 my $fileextension = "rpm";
205 my $rpmfiles = installer
::systemactions
::find_file_with_file_extension
($fileextension, $installdir);
206 if ( ! ( $#{$rpmfiles} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
207 my $rpmsav = [@
{$rpmfiles}];
208 for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$rpmfiles}[$i]); }
210 $packagename = get_packagename_from_packagelist
($rpmfiles, $allvariables, $languagestringref);
212 my $packagestring = installer
::converter
::convert_array_to_space_separated_string
($rpmfiles);
213 $packagename = create_tar_gz_file
($installdir, $packagename, $packagestring); # only one file
214 for ( my $i = 0; $i <= $#{$rpmsav}; $i++ )
216 my $onefile = $installdir . $installer::globals
::separator
. ${$rpmsav}[$i];
220 $allnames = $rpmfiles;
223 if ( $installer::globals
::issolarisbuild
)
225 # determining the Solaris package file in directory $installdir
226 my $alldirs = installer
::systemactions
::get_all_directories
($installdir);
228 if ( ! ( $#{$alldirs} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
229 my $alldirssav = [@
{$alldirs}];
230 for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$alldirs}[$i]); }
232 $packagename = get_packagename_from_packagelist
($alldirs, $allvariables, $languagestringref);
233 my $packagestring = installer
::converter
::convert_array_to_space_separated_string
($alldirs);
234 $packagename = create_tar_gz_file
($installdir, $packagename, $packagestring); # only a file (not a directory) can be included into the shell script
235 for ( my $i = 0; $i <= $#{$alldirssav}; $i++ ) { installer::systemactions::remove_complete_directory(${$alldirssav}[$i], 1); }
236 $allnames = $alldirs;
239 my $infoline = "Found package in installation directory $installdir : $packagename\n";
240 push( @installer::globals
::logfileinfo
, $infoline);
242 return ( $packagename, $allnames);
245 #########################################################
246 # Including the name of the package file or the rpm
247 # into the script template
248 #########################################################
250 sub put_packagename_into_script
252 my ($scriptfile, $packagename, $allnames) = @_;
254 my $localpackagename = $packagename;
255 $localpackagename =~ s/\.tar\.gz//; # making "OOOopenoffice-it-ea.tar.gz" to "OOOopenoffice-it-ea"
256 my $infoline = "Adding packagename $localpackagename into help pack script\n";
257 push( @installer::globals
::logfileinfo
, $infoline);
259 my $installline = "";
261 if ( $installer::globals
::issolarisbuild
) { $installline = " /usr/sbin/pkgadd -d \$outdir -a \$adminfile"; }
263 if ( $installer::globals
::isrpmbuild
) { $installline = " rpm --prefix \$PRODUCTINSTALLLOCATION --replacepkgs -i"; }
265 for ( my $i = 0; $i <= $#{$allnames}; $i++ )
267 if ( $installer::globals
::issolarisbuild
) { $installline = $installline . " ${$allnames}[$i]"; }
269 if ( $installer::globals
::isrpmbuild
) { $installline = $installline . " \$outdir/${$allnames}[$i]"; }
272 for ( my $j = 0; $j <= $#{$scriptfile}; $j++ )
274 ${$scriptfile}[$j] =~ s/INSTALLLINES/$installline/;
278 ##################################################################
279 # Including the lowercase product name into the script template
280 ##################################################################
282 sub put_productname_into_script
284 my ($scriptfile, $variableshashref) = @_;
286 my $productname = $variableshashref->{'PRODUCTNAME'};
287 $productname = lc($productname);
288 $productname =~ s/\.//g; # openoffice.org -> openofficeorg
290 my $infoline = "Adding productname $productname into help pack script\n";
291 push( @installer::globals
::logfileinfo
, $infoline);
293 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
295 ${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/;
299 ##################################################################
300 # Including the full product name into the script template
302 ##################################################################
304 sub put_fullproductname_into_script
306 my ($scriptfile, $variableshashref) = @_;
308 my $productname = $variableshashref->{'PRODUCTNAME'};
309 my $productversion = "";
310 if ( $variableshashref->{'PRODUCTVERSION'} ) { $productversion = $variableshashref->{'PRODUCTVERSION'}; };
311 my $fullproductname = $productname . " " . $productversion;
313 my $infoline = "Adding full productname \"$fullproductname\" into help pack script\n";
314 push( @installer::globals
::logfileinfo
, $infoline);
316 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
318 ${$scriptfile}[$i] =~ s/FULLPRODUCTNAMELONGPLACEHOLDER/$fullproductname/;
322 ##################################################################
323 # Including the name of the search package (-core01)
324 # into the script template
325 ##################################################################
327 sub put_searchpackage_into_script
329 my ($scriptfile, $variableshashref) = @_;
331 my $basispackageprefix = $variableshashref->{'BASISPACKAGEPREFIX'};
332 my $productversion = $variableshashref->{'PRODUCTVERSION'};
334 if ( $installer::globals
::issolarisbuild
) { $productversion =~ s/\.//g; } # "3.0" -> "30"
336 my $infoline = "Adding basis package prefix $basispackageprefix into help pack script\n";
337 push( @installer::globals
::logfileinfo
, $infoline);
339 $infoline = "Adding basis package version $productversion into help pack script\n";
340 push( @installer::globals
::logfileinfo
, $infoline);
342 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
344 ${$scriptfile}[$i] =~ s/BASISPACKAGEPREFIXPLACEHOLDER/$basispackageprefix/;
345 ${$scriptfile}[$i] =~ s/PRODUCTVERSIONPLACEHOLDER/$productversion/;
350 #########################################################
351 # Including the linenumber into the script template
352 #########################################################
354 sub put_linenumber_into_script
356 my ( $scriptfile, $licensefile, $allnames ) = @_;
358 my $linenumber = $#{$scriptfile} + $#{$licensefile} + 3; # also adding the content of the license file!
360 my $infoline = "Adding linenumber $linenumber into help pack script\n";
361 push( @installer::globals
::logfileinfo
, $infoline);
363 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
365 ${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/;
369 #########################################################
370 # Determining the name of the new scriptfile
371 #########################################################
373 sub determine_scriptfile_name
375 my ( $packagename ) = @_;
377 my $scriptfilename = $packagename;
379 # if ( $installer::globals::isrpmbuild ) { $scriptfilename =~ s/\.rpm\s*$/\.sh/; }
380 # if ( $installer::globals::issolarisbuild ) { $scriptfilename =~ s/\.tar\.gz\s*$/\.sh/; }
382 $scriptfilename =~ s/\.tar\.gz\s*$/\.sh/;
384 my $infoline = "Setting help pack script file name to $scriptfilename\n";
385 push( @installer::globals
::logfileinfo
, $infoline);
387 return $scriptfilename;
390 #########################################################
391 # Saving the script file in the installation directory
392 #########################################################
396 my ($installdir, $newscriptfilename, $scriptfile) = @_;
398 $newscriptfilename = $installdir . $installer::globals
::separator
. $newscriptfilename;
399 installer
::files
::save_file
($newscriptfilename, $scriptfile);
401 my $infoline = "Saving script file $newscriptfilename\n";
402 push( @installer::globals
::logfileinfo
, $infoline);
404 return $newscriptfilename;
407 #########################################################
408 # Including the binary package into the script
409 #########################################################
411 sub include_package_into_script
413 my ( $scriptfilename, $installdir, $packagename ) = @_;
415 my $longpackagename = $installdir . $installer::globals
::separator
. $packagename;
416 my $systemcall = "cat $longpackagename >>$scriptfilename";
418 my $returnvalue = system($systemcall);
420 my $infoline = "Systemcall: $systemcall\n";
421 push( @installer::globals
::logfileinfo
, $infoline);
425 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
426 push( @installer::globals
::logfileinfo
, $infoline);
430 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
431 push( @installer::globals
::logfileinfo
, $infoline);
434 my $localcall = "chmod 775 $scriptfilename \>\/dev\/null 2\>\&1";
439 #########################################################
440 # Removing the binary package
441 #########################################################
445 my ( $installdir, $packagename ) = @_;
447 my $remove_package = 1;
449 if ( $ENV{'DONT_REMOVE_PACKAGE'} ) { $remove_package = 0; }
451 if ( $remove_package )
453 my $longpackagename = $installdir . $installer::globals
::separator
. $packagename;
454 unlink $longpackagename;
456 my $infoline = "Removing package: $longpackagename \n";
457 push( @installer::globals
::logfileinfo
, $infoline);
461 ####################################################
462 # Unix help packs, that are not part of
463 # multilingual installation sets, need a
464 # shell script installer
465 ####################################################
467 sub build_installer_for_helppack
469 my ($installdir, $allvariableshashref, $includepatharrayref, $languagesarrayref, $languagestringref) = @_;
471 installer
::logger
::print_message
( "... creating shell script installer ...\n" );
473 installer
::logger
::include_header_into_logfile
("Creating shell script installer:");
475 # find and read setup script template
477 my $scriptfilename = "langpackscript.sh";
478 my $scriptref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath
(\
$scriptfilename, $includepatharrayref, 0);
479 if ($$scriptref eq "") { installer
::exiter
::exit_program
("ERROR: Could not find script file $scriptfilename!", "build_installer_for_helppack"); }
480 my $scriptfile = installer
::files
::read_file
($$scriptref);
482 my $infoline = "Found script file $scriptfilename: $$scriptref \n";
483 push( @installer::globals
::logfileinfo
, $infoline);
485 # find and read english license file
486 my $licenselanguage = "en-US"; # always english !
487 my $licensefilename = "LICENSE";
488 my $licenseincludepatharrayref = installer
::worker
::get_language_specific_include_paths
($includepatharrayref, $licenselanguage);
490 my $licenseref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath
(\
$licensefilename, $licenseincludepatharrayref, 0);
491 if ($$licenseref eq "") { installer
::exiter
::exit_program
("ERROR: Could not find License file $licensefilename!", "build_installer_for_helppack"); }
492 my $licensefile = installer
::files
::read_file
($$licenseref);
494 $infoline = "Found licensefile $licensefilename: $$licenseref \n";
495 push( @installer::globals
::logfileinfo
, $infoline);
497 # including variables into license file
498 installer
::scpzipfiles
::replace_all_ziplistvariables_in_file
($licensefile, $allvariableshashref);
500 # add license text into script template
501 put_license_file_into_script
($scriptfile, $licensefile);
503 # add rpm or package file name into script template
504 my ( $packagename, $allnames) = determine_packagename
($installdir, $allvariableshashref, $languagestringref);
505 put_packagename_into_script
($scriptfile, $packagename, $allnames);
507 # add product name into script template
508 put_productname_into_script
($scriptfile, $allvariableshashref);
510 # add product name into script template
511 put_fullproductname_into_script
($scriptfile, $allvariableshashref);
513 # add product name into script template
514 put_searchpackage_into_script
($scriptfile, $allvariableshashref);
516 # replace linenumber in script template
517 put_linenumber_into_script
($scriptfile, $licensefile, $allnames);
519 # saving the script file
520 my $newscriptfilename = determine_scriptfile_name
($packagename);
521 $newscriptfilename = save_script_file
($installdir, $newscriptfilename, $scriptfile);
523 # include rpm or package into script
524 include_package_into_script
($newscriptfilename, $installdir, $packagename);
526 # remove rpm or package
527 remove_package
($installdir, $packagename);