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
::download
;
25 use installer
::exiter
;
27 use installer
::globals
;
28 use installer
::logger
;
29 use installer
::pathanalyzer
;
30 use installer
::remover
;
31 use installer
::systemactions
;
33 BEGIN { # This is needed so that cygwin's perl evaluates ACLs
34 # (needed for correctly evaluating the -x test.)
35 if( $^O
=~ /cygwin/i ) {
36 require filetest
; import filetest
"access";
40 ##################################################################
41 # Including the lowercase product name into the script template
42 ##################################################################
44 sub put_productname_into_script
46 my ($scriptfile, $variableshashref) = @_;
48 my $productname = $variableshashref->{'PRODUCTNAME'};
49 $productname = lc($productname);
50 $productname =~ s/\.//g; # openoffice.org -> openofficeorg
51 $productname =~ s/\s*//g;
53 my $infoline = "Adding productname $productname into download shell script\n";
54 push( @installer::globals
::logfileinfo
, $infoline);
56 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
58 ${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/;
62 #########################################################
63 # Including the linenumber into the script template
64 #########################################################
66 sub put_linenumber_into_script
68 my ( $scriptfile ) = @_;
70 my $linenumber = $#{$scriptfile} + 2;
72 my $infoline = "Adding linenumber $linenumber into download shell script\n";
73 push( @installer::globals
::logfileinfo
, $infoline);
75 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
77 ${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/;
81 #########################################################
82 # Determining the name of the new scriptfile
83 #########################################################
85 sub determine_scriptfile_name
87 my ( $filename ) = @_;
89 $installer::globals
::downloadfileextension
= ".sh";
90 $filename = $filename . $installer::globals
::downloadfileextension
;
91 $installer::globals
::downloadfilename
= $filename;
93 my $infoline = "Setting download shell script file name to $filename\n";
94 push( @installer::globals
::logfileinfo
, $infoline);
99 #########################################################
100 # Saving the script file in the installation directory
101 #########################################################
105 my ($directory, $newscriptfilename, $scriptfile) = @_;
107 $newscriptfilename = $directory . $installer::globals
::separator
. $newscriptfilename;
108 installer
::files
::save_file
($newscriptfilename, $scriptfile);
110 my $infoline = "Saving script file $newscriptfilename\n";
111 push( @installer::globals
::logfileinfo
, $infoline);
113 if ( ! $installer::globals
::iswindowsbuild
)
115 chmod 0775, $newscriptfilename;
118 return $newscriptfilename;
121 #########################################################
122 # Including checksum and size into script file
123 #########################################################
125 sub put_checksum_and_size_into_script
127 my ($scriptfile, $sumout) = @_;
132 if ( $sumout =~ /^\s*(\d+)\s+(\d+)\s*$/ )
139 installer
::exiter
::exit_program
("ERROR: Incorrect return value from /usr/bin/sum: $sumout", "put_checksum_and_size_into_script");
142 my $infoline = "Adding checksum $checksum and size $size into download shell script\n";
143 push( @installer::globals
::logfileinfo
, $infoline);
145 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
147 ${$scriptfile}[$i] =~ s/CHECKSUMPLACEHOLDER/$checksum/;
148 ${$scriptfile}[$i] =~ s/DISCSPACEPLACEHOLDER/$size/;
153 #########################################################
154 # Determining checksum and size of tar file
155 #########################################################
161 my $systemcall = "/usr/bin/sum $filename |";
165 open (SUM
, "$systemcall");
169 my $returnvalue = $?
; # $? contains the return value of the systemcall
171 my $infoline = "Systemcall: $systemcall\n";
172 push( @installer::globals
::logfileinfo
, $infoline);
176 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
177 push( @installer::globals
::logfileinfo
, $infoline);
181 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
182 push( @installer::globals
::logfileinfo
, $infoline);
185 $sumoutput =~ s/\s+$filename\s$//;
189 #########################################################
190 # Searching for the getuid.so
191 #########################################################
193 sub get_path_for_library
195 my $getuidlibrary = $ENV{'WORKDIR'} . '/LinkTarget/Library/libgetuid.so';
196 if ( ! -e
$getuidlibrary ) { installer
::exiter
::exit_program
("File $getuidlibrary does not exist!", "get_path_for_library"); }
197 return $getuidlibrary;
200 #########################################################
201 # Include the tar file into the script
202 #########################################################
204 sub include_tar_into_script
206 my ($scriptfile, $temporary_tarfile) = @_;
208 my $systemcall = "cat $temporary_tarfile >> $scriptfile && rm $temporary_tarfile";
209 my $returnvalue = system($systemcall);
211 my $infoline = "Systemcall: $systemcall\n";
212 push( @installer::globals
::logfileinfo
, $infoline);
216 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
217 push( @installer::globals
::logfileinfo
, $infoline);
221 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
222 push( @installer::globals
::logfileinfo
, $infoline);
227 #########################################################
228 # Create a tar file from the binary package
229 #########################################################
233 my ( $installdir, $tarfilename, $getuidlibrary) = @_;
235 my $ldpreloadstring = "";
236 if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
238 my $systemcall = "cd $installdir; $ldpreloadstring tar -cf - * > $tarfilename";
240 my $returnvalue = system($systemcall);
242 my $infoline = "Systemcall: $systemcall\n";
243 push( @installer::globals
::logfileinfo
, $infoline);
247 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
248 push( @installer::globals
::logfileinfo
, $infoline);
252 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
253 push( @installer::globals
::logfileinfo
, $infoline);
256 chmod 0775, $tarfilename;
258 return ( -s
$tarfilename );
261 #########################################################
262 # Setting installation languages
263 #########################################################
265 sub get_downloadname_language
267 my ($languagestringref) = @_;
269 my $languages = $$languagestringref;
271 if ( $installer::globals
::added_english
)
273 $languages =~ s/en-US_//;
274 $languages =~ s/_en-US//;
277 # do not list languages if there are too many
278 if ( length ($languages) > $installer::globals
::max_lang_length
)
283 # do not list pure en-US, except for helppack and langpack
284 if ( ( $languages eq "en-US" ) &&
285 ( ! $installer::globals
::languagepack
) &&
286 ( ! $installer::globals
::helppack
) )
294 #########################################################
295 # Setting download name
296 #########################################################
298 sub get_downloadname_productname
300 my ($allvariables) = @_;
302 my $start = "LibreOffice";
304 if ( $allvariables->{'PRODUCTNAME'} eq "LibreOffice" ) { $start = "LibreOffice"; }
306 if ( $allvariables->{'PRODUCTNAME'} eq "LibreOfficeDev" ) { $start = "LibreOfficeDev"; }
308 if ( $allvariables->{'PRODUCTNAME'} eq "OxygenOffice" ) { $start = "OOOP"; }
313 #########################################################
314 # Setting download version
315 #########################################################
317 sub get_download_version
319 my ($allvariables) = @_;
323 $version = $allvariables->{'PRODUCTVERSION'};
324 if (( $allvariables->{'PRODUCTEXTENSION'} ) && ( $allvariables->{'PRODUCTEXTENSION'} ne "" )) { $version = $version . $allvariables->{'PRODUCTEXTENSION'}; }
329 #################################################################
330 # Setting the platform name for download
331 #################################################################
333 sub get_download_platformname
335 my $platformname = "";
337 if ( $installer::globals
::islinuxbuild
)
339 $platformname = "Linux";
341 elsif ( $installer::globals
::issolarisbuild
)
343 $platformname = "Solaris";
345 elsif ( $installer::globals
::iswindowsbuild
)
347 $platformname = "Win";
349 elsif ( $installer::globals
::isfreebsdbuild
)
351 $platformname = "FreeBSD";
353 elsif ( $installer::globals
::ismacbuild
)
355 $platformname = "MacOS";
359 $platformname = $installer::globals
::compiler
;
362 return $platformname;
365 #########################################################
366 # Setting the architecture for the download name
367 #########################################################
369 sub get_download_architecture
373 if ( $installer::globals
::compiler
=~ /unxlngi/ )
377 elsif ( $installer::globals
::compiler
=~ /unxlngppc/ )
381 elsif ( $installer::globals
::compiler
=~ /unxlngx/ )
385 elsif ( $installer::globals
::issolarissparcbuild
)
389 elsif ( $installer::globals
::issolarisx86build
)
393 elsif ( $installer::globals
::iswindowsbuild
)
395 if ( $installer::globals
::iswin64build
)
404 elsif ( $installer::globals
::compiler
=~ /^unxmacxi/ )
408 elsif ( $installer::globals
::compiler
=~ /^unxmacxx/ )
416 #########################################################
417 # Setting the content type for the download name
418 #########################################################
420 sub get_download_content
422 my ($allvariables) = @_;
426 # content type included in the installer
427 if ( $installer::globals
::isrpmbuild
)
431 elsif ( $installer::globals
::isdebbuild
)
435 elsif ( $installer::globals
::packageformat
eq "archive" )
437 $content = "archive";
443 #########################################################
444 # Setting the functionality type for the download name
445 #########################################################
447 sub get_download_functionality
449 my ($allvariables) = @_;
451 my $functionality = "";
453 if ( $installer::globals
::languagepack
)
455 $functionality = "langpack";
457 elsif ( $installer::globals
::helppack
)
459 $functionality = "helppack";
461 elsif ( $allvariables->{'POSTVERSIONEXTENSION'} eq "SDK" )
463 $functionality = "sdk";
465 elsif ( $allvariables->{'POSTVERSIONEXTENSION'} eq "TEST" )
467 $functionality = "test";
469 elsif ( $allvariables->{'PRODUCTNAME'} eq "URE" )
471 $functionality = "ure";
474 return $functionality;
477 ###############################################################################################
478 # Setting the download file name
480 # (PRODUCTNAME)_(VERSION)_(OS)_(ARCH)_(INSTALLTYPE)_(LANGUAGE).(FILEEXTENSION)
481 ###############################################################################################
483 sub set_download_filename
485 my ($languagestringref, $allvariables) = @_;
487 my $start = get_downloadname_productname
($allvariables);
488 my $versionstring = get_download_version
($allvariables);
489 my $platform = get_download_platformname
();
490 my $architecture = get_download_architecture
();
491 my $content = get_download_content
($allvariables);
492 my $functionality = get_download_functionality
($allvariables);
493 my $language = get_downloadname_language
($languagestringref);
495 # Setting the extension happens automatically
497 my $filename = $start . "_" . $versionstring . "_" . $platform . "_" . $architecture . "_" . $content . "_" . $functionality . "_" . $language;
499 # get rid of duplicit "_" delimiters when some strings are empty
500 $filename =~ s/\_\_\_/\_/g;
501 $filename =~ s/\_\_/\_/g;
502 $filename =~ s/\_\s*$//;
504 $installer::globals
::ooodownloadfilename
= $filename;
510 #########################################################
511 # Creating a tar.gz file
512 #########################################################
514 sub create_tar_gz_file_from_directory
516 my ($installdir, $getuidlibrary, $downloaddir, $downloadfilename) = @_;
520 my $packdir = $installdir;
521 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$packdir);
522 my $changedir = $installdir;
523 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$changedir);
525 my $ldpreloadstring = "";
526 if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
528 $installer::globals
::downloadfileextension
= ".tar.gz";
529 $installer::globals
::downloadfilename
= $downloadfilename . $installer::globals
::downloadfileextension
;
530 my $targzname = $downloaddir . $installer::globals
::separator
. $installer::globals
::downloadfilename
;
532 # fdo#67060 - install script is for RPM only
533 if ( -e
"$installdir/install" && !$installer::globals
::isrpmbuild
)
535 unlink("$installdir/install");
538 my $systemcall = "cd $changedir; $ldpreloadstring tar -cf - $packdir | gzip > $targzname";
540 my $returnvalue = system($systemcall);
542 $infoline = "Systemcall: $systemcall\n";
543 push( @installer::globals
::logfileinfo
, $infoline);
547 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
548 push( @installer::globals
::logfileinfo
, $infoline);
552 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
553 push( @installer::globals
::logfileinfo
, $infoline);
559 #########################################################
560 # Setting the variables in the download name
561 #########################################################
563 sub resolve_variables_in_downloadname
565 my ($allvariables, $downloadname, $languagestringref) = @_;
567 # Typical name: soa-{productversion}-{extension}-bin-{os}-{languages}
569 my $productversion = "";
570 if ( $allvariables->{'PRODUCTVERSION'} ) { $productversion = $allvariables->{'PRODUCTVERSION'}; }
571 $downloadname =~ s/\{productversion\}/$productversion/;
573 my $packageversion = "";
574 if ( $allvariables->{'PACKAGEVERSION'} ) { $packageversion = $allvariables->{'PACKAGEVERSION'}; }
575 $downloadname =~ s/\{packageversion\}/$packageversion/;
578 if ( $allvariables->{'PRODUCTEXTENSION'} ) { $extension = $allvariables->{'PRODUCTEXTENSION'}; }
579 $extension = lc($extension);
580 $downloadname =~ s/\{extension\}/$extension/;
583 if ( $installer::globals
::iswindowsbuild
) { $os = "windows"; }
584 elsif ( $installer::globals
::issolarissparcbuild
) { $os = "solsparc"; }
585 elsif ( $installer::globals
::issolarisx86build
) { $os = "solia"; }
586 elsif ( $installer::globals
::islinuxbuild
) { $os = "linux"; }
587 elsif ( $installer::globals
::compiler
=~ /unxmacxi/ ) { $os = "macosxi"; }
588 elsif ( $installer::globals
::compiler
=~ /unxmacxx/ ) { $os = "macosxx"; }
590 $downloadname =~ s/\{os\}/$os/;
592 my $languages = $$languagestringref;
593 $downloadname =~ s/\{languages\}/$languages/;
595 $downloadname =~ s/\-\-\-/\-/g;
596 $downloadname =~ s/\-\-/\-/g;
597 $downloadname =~ s/\-\s*$//;
599 return $downloadname;
602 ##############################################################
603 # Returning the complete block in all languages
604 # for a specified string
605 ##############################################################
607 sub get_language_block_from_language_file
609 my ($searchstring, $languagefile) = @_;
611 my @language_block = ();
613 for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
615 if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
619 push(@language_block, ${$languagefile}[$counter]);
622 while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
624 push(@language_block, ${$languagefile}[$counter]);
632 return \
@language_block;
635 ##############################################################
636 # Returning a specific language string from the block
637 # of all translations
638 ##############################################################
640 sub get_language_string_from_language_block
642 my ($language_block, $language) = @_;
646 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
648 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
655 if ( $newstring eq "" )
657 $language = "en-US"; # defaulting to english
659 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
661 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
672 ####################################################
673 # Creating download installation sets
674 ####################################################
676 sub create_download_sets
678 my ($installationdir, $includepatharrayref, $allvariableshashref, $downloadname, $languagestringref, $languagesarrayref) = @_;
682 my $force = 1; # print this message even in 'quiet' mode
683 installer
::logger
::print_message
( "\n******************************************\n" );
684 installer
::logger
::print_message
( "... creating download installation set ...\n", $force );
685 installer
::logger
::print_message
( "******************************************\n" );
687 installer
::logger
::include_header_into_logfile
("Creating download installation sets:");
689 my $firstdir = $installationdir;
690 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$firstdir);
692 my $lastdir = $installationdir;
693 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$lastdir);
695 if ( $installer::globals
::iswindowsbuild
&& $lastdir =~ /\./ ) { $lastdir =~ s/\./_download_inprogress\./ }
696 else { $lastdir = $lastdir . "_download_inprogress"; }
698 # removing existing directory "_native_packed_inprogress" and "_native_packed_witherror" and "_native_packed"
700 my $downloaddir = $firstdir . $lastdir;
702 if ( -d
$downloaddir ) { installer
::systemactions
::remove_complete_directory
($downloaddir); }
704 my $olddir = $downloaddir;
705 $olddir =~ s/_inprogress/_witherror/;
706 if ( -d
$olddir ) { installer
::systemactions
::remove_complete_directory
($olddir); }
708 $olddir = $downloaddir;
709 $olddir =~ s/_inprogress//;
710 if ( -d
$olddir ) { installer
::systemactions
::remove_complete_directory
($olddir); }
712 # creating the new directory
714 installer
::systemactions
::create_directory
($downloaddir);
716 $installer::globals
::saveinstalldir
= $downloaddir;
718 # evaluating the name of the download file
720 if ( $allvariableshashref->{'OOODOWNLOADNAME'} ) { $downloadname = set_download_filename
($languagestringref, $allvariableshashref); }
721 else { $downloadname = resolve_variables_in_downloadname
($allvariableshashref, $downloadname, $languagestringref); }
723 if ( ! $installer::globals
::iswindowsbuild
) # Unix specific part
726 # getting the path of the getuid.so (only required for Solaris and Linux)
727 my $getuidlibrary = "";
728 if (( $installer::globals
::issolarisbuild
) || ( $installer::globals
::islinuxbuild
)) { $getuidlibrary = get_path_for_library
(); }
730 if ( $allvariableshashref->{'OOODOWNLOADNAME'} )
732 my $downloadfile = create_tar_gz_file_from_directory
($installationdir, $getuidlibrary, $downloaddir, $downloadname);
736 # find and read setup script template
737 my $scriptfilename = $ENV{'SRCDIR'} . "/setup_native/scripts/downloadscript.sh";
739 if (! -f
$scriptfilename) { installer
::exiter
::exit_program
("ERROR: Could not find script file $scriptfilename!", "create_download_sets"); }
740 my $scriptfile = installer
::files
::read_file
($scriptfilename);
742 $infoline = "Found script file $scriptfilename \n";
743 push( @installer::globals
::logfileinfo
, $infoline);
745 # add product name into script template
746 put_productname_into_script
($scriptfile, $allvariableshashref);
748 # replace linenumber in script template
749 put_linenumber_into_script
($scriptfile);
752 my $temporary_tarfile_name = $downloaddir . $installer::globals
::separator
. 'installset.tar';
753 my $size = tar_package
($installationdir, $temporary_tarfile_name, $getuidlibrary);
754 installer
::exiter
::exit_program
("ERROR: Could not create tar file $temporary_tarfile_name!", "create_download_sets") unless $size;
756 # calling sum to determine checksum and size of the tar file
757 my $sumout = call_sum
($temporary_tarfile_name);
759 # writing checksum and size into scriptfile
760 put_checksum_and_size_into_script
($scriptfile, $sumout);
762 # saving the script file
763 my $newscriptfilename = determine_scriptfile_name
($downloadname);
764 $newscriptfilename = save_script_file
($downloaddir, $newscriptfilename, $scriptfile);
766 installer
::logger
::print_message
( "... including installation set into $newscriptfilename ... \n" );
767 # Append tar file to script
768 include_tar_into_script
($newscriptfilename, $temporary_tarfile_name);