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 in the solver
191 #########################################################
193 sub get_path_for_library
195 my ($includepatharrayref) = @_;
197 my $getuidlibraryname = "libgetuid.so";
199 my $getuidlibraryref = "";
201 if ( $installer::globals
::include_paths_read
)
203 $getuidlibraryref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath
(\
$getuidlibraryname, $includepatharrayref, 0);
207 $getuidlibraryref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath_classic
(\
$getuidlibraryname, $includepatharrayref, 0);
210 return $$getuidlibraryref;
213 #########################################################
214 # Include the tar file into the script
215 #########################################################
217 sub include_tar_into_script
219 my ($scriptfile, $temporary_tarfile) = @_;
221 my $systemcall = "cat $temporary_tarfile >> $scriptfile && rm $temporary_tarfile";
222 my $returnvalue = system($systemcall);
224 my $infoline = "Systemcall: $systemcall\n";
225 push( @installer::globals
::logfileinfo
, $infoline);
229 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
230 push( @installer::globals
::logfileinfo
, $infoline);
234 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
235 push( @installer::globals
::logfileinfo
, $infoline);
240 #########################################################
241 # Create a tar file from the binary package
242 #########################################################
246 my ( $installdir, $tarfilename, $getuidlibrary) = @_;
248 my $ldpreloadstring = "";
249 if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
251 my $systemcall = "cd $installdir; $ldpreloadstring tar -cf - * > $tarfilename";
253 my $returnvalue = system($systemcall);
255 my $infoline = "Systemcall: $systemcall\n";
256 push( @installer::globals
::logfileinfo
, $infoline);
260 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
261 push( @installer::globals
::logfileinfo
, $infoline);
265 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
266 push( @installer::globals
::logfileinfo
, $infoline);
269 chmod 0775, $tarfilename;
271 return ( -s
$tarfilename );
274 #########################################################
275 # Setting installation languages
276 #########################################################
278 sub get_downloadname_language
280 my ($languagestringref) = @_;
282 my $languages = $$languagestringref;
284 if ( $installer::globals
::added_english
)
286 $languages =~ s/en-US_//;
287 $languages =~ s/_en-US//;
290 # do not list languages if there are too many
291 if ( length ($languages) > $installer::globals
::max_lang_length
)
296 # do not list pure en-US, except for helppack and langpack
297 if ( ( $languages eq "en-US" ) &&
298 ( ! $installer::globals
::languagepack
) &&
299 ( ! $installer::globals
::helppack
) )
307 #########################################################
308 # Setting download name
309 #########################################################
311 sub get_downloadname_productname
313 my ($allvariables) = @_;
315 my $start = "LibreOffice";
317 if ( $allvariables->{'PRODUCTNAME'} eq "LibreOffice" ) { $start = "LibreOffice"; }
319 if ( $allvariables->{'PRODUCTNAME'} eq "LibreOfficeDev" ) { $start = "LibreOfficeDev"; }
321 if ( $allvariables->{'PRODUCTNAME'} eq "OxygenOffice" ) { $start = "OOOP"; }
326 #########################################################
327 # Setting download version
328 #########################################################
330 sub get_download_version
332 my ($allvariables) = @_;
336 $version = $allvariables->{'PRODUCTVERSION'};
337 if (( $allvariables->{'PRODUCTEXTENSION'} ) && ( $allvariables->{'PRODUCTEXTENSION'} ne "" )) { $version = $version . $allvariables->{'PRODUCTEXTENSION'}; }
342 #################################################################
343 # Setting the platform name for download
344 #################################################################
346 sub get_download_platformname
348 my $platformname = "";
350 if ( $installer::globals
::islinuxbuild
)
352 $platformname = "Linux";
354 elsif ( $installer::globals
::issolarisbuild
)
356 $platformname = "Solaris";
358 elsif ( $installer::globals
::iswindowsbuild
)
360 $platformname = "Win";
362 elsif ( $installer::globals
::isfreebsdbuild
)
364 $platformname = "FreeBSD";
366 elsif ( $installer::globals
::ismacbuild
)
368 $platformname = "MacOS";
372 $platformname = $installer::globals
::compiler
;
375 return $platformname;
378 #########################################################
379 # Setting the architecture for the download name
380 #########################################################
382 sub get_download_architecture
386 if ( $installer::globals
::compiler
=~ /unxlngi/ )
390 elsif ( $installer::globals
::compiler
=~ /unxlngppc/ )
394 elsif ( $installer::globals
::compiler
=~ /unxlngx/ )
398 elsif ( $installer::globals
::issolarissparcbuild
)
402 elsif ( $installer::globals
::issolarisx86build
)
406 elsif ( $installer::globals
::iswindowsbuild
)
410 elsif ( $installer::globals
::compiler
=~ /^unxmacxi/ )
414 elsif ( $installer::globals
::compiler
=~ /^unxmacxx/ )
422 #########################################################
423 # Setting the content type for the download name
424 #########################################################
426 sub get_download_content
428 my ($allvariables) = @_;
432 # content type included in the installer
433 if ( $installer::globals
::isrpmbuild
)
437 elsif ( $installer::globals
::isdebbuild
)
441 elsif ( $installer::globals
::packageformat
eq "archive" )
443 $content = "archive";
449 #########################################################
450 # Setting the functionality type for the download name
451 #########################################################
453 sub get_download_functionality
455 my ($allvariables) = @_;
457 my $functionality = "";
459 if ( $installer::globals
::languagepack
)
461 $functionality = "langpack";
463 elsif ( $installer::globals
::helppack
)
465 $functionality = "helppack";
467 elsif ( $allvariables->{'POSTVERSIONEXTENSION'} eq "SDK" )
469 $functionality = "sdk";
471 elsif ( $allvariables->{'POSTVERSIONEXTENSION'} eq "TEST" )
473 $functionality = "test";
475 elsif ( $allvariables->{'PRODUCTNAME'} eq "URE" )
477 $functionality = "ure";
480 return $functionality;
483 ###############################################################################################
484 # Setting the download file name
486 # (PRODUCTNAME)_(VERSION)_(OS)_(ARCH)_(INSTALLTYPE)_(LANGUAGE).(FILEEXTENSION)
487 ###############################################################################################
489 sub set_download_filename
491 my ($languagestringref, $allvariables) = @_;
493 my $start = get_downloadname_productname
($allvariables);
494 my $versionstring = get_download_version
($allvariables);
495 my $platform = get_download_platformname
();
496 my $architecture = get_download_architecture
();
497 my $content = get_download_content
($allvariables);
498 my $functionality = get_download_functionality
($allvariables);
499 my $language = get_downloadname_language
($languagestringref);
501 # Setting the extension happens automatically
503 my $filename = $start . "_" . $versionstring . "_" . $platform . "_" . $architecture . "_" . $content . "_" . $functionality . "_" . $language;
505 # get rid of duplicit "_" delimiters when some strings are empty
506 $filename =~ s/\_\_\_/\_/g;
507 $filename =~ s/\_\_/\_/g;
508 $filename =~ s/\_\s*$//;
510 $installer::globals
::ooodownloadfilename
= $filename;
516 #########################################################
517 # Creating a tar.gz file
518 #########################################################
520 sub create_tar_gz_file_from_directory
522 my ($installdir, $getuidlibrary, $downloaddir, $downloadfilename) = @_;
526 my $packdir = $installdir;
527 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$packdir);
528 my $changedir = $installdir;
529 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$changedir);
531 my $ldpreloadstring = "";
532 if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
534 $installer::globals
::downloadfileextension
= ".tar.gz";
535 $installer::globals
::downloadfilename
= $downloadfilename . $installer::globals
::downloadfileextension
;
536 my $targzname = $downloaddir . $installer::globals
::separator
. $installer::globals
::downloadfilename
;
538 # fdo#67060 - install script is for RPM only
539 if ( -e
"$installdir/install" && !$installer::globals
::isrpmbuild
)
541 unlink("$installdir/install");
544 my $systemcall = "cd $changedir; $ldpreloadstring tar -cf - $packdir | gzip > $targzname";
546 my $returnvalue = system($systemcall);
548 $infoline = "Systemcall: $systemcall\n";
549 push( @installer::globals
::logfileinfo
, $infoline);
553 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
554 push( @installer::globals
::logfileinfo
, $infoline);
558 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
559 push( @installer::globals
::logfileinfo
, $infoline);
565 #########################################################
566 # Setting the variables in the download name
567 #########################################################
569 sub resolve_variables_in_downloadname
571 my ($allvariables, $downloadname, $languagestringref) = @_;
573 # Typical name: soa-{productversion}-{extension}-bin-{os}-{languages}
575 my $productversion = "";
576 if ( $allvariables->{'PRODUCTVERSION'} ) { $productversion = $allvariables->{'PRODUCTVERSION'}; }
577 $downloadname =~ s/\{productversion\}/$productversion/;
579 my $packageversion = "";
580 if ( $allvariables->{'PACKAGEVERSION'} ) { $packageversion = $allvariables->{'PACKAGEVERSION'}; }
581 $downloadname =~ s/\{packageversion\}/$packageversion/;
584 if ( $allvariables->{'PRODUCTEXTENSION'} ) { $extension = $allvariables->{'PRODUCTEXTENSION'}; }
585 $extension = lc($extension);
586 $downloadname =~ s/\{extension\}/$extension/;
589 if ( $installer::globals
::iswindowsbuild
) { $os = "windows"; }
590 elsif ( $installer::globals
::issolarissparcbuild
) { $os = "solsparc"; }
591 elsif ( $installer::globals
::issolarisx86build
) { $os = "solia"; }
592 elsif ( $installer::globals
::islinuxbuild
) { $os = "linux"; }
593 elsif ( $installer::globals
::compiler
=~ /unxmacxi/ ) { $os = "macosxi"; }
594 elsif ( $installer::globals
::compiler
=~ /unxmacxx/ ) { $os = "macosxx"; }
596 $downloadname =~ s/\{os\}/$os/;
598 my $languages = $$languagestringref;
599 $downloadname =~ s/\{languages\}/$languages/;
601 $downloadname =~ s/\-\-\-/\-/g;
602 $downloadname =~ s/\-\-/\-/g;
603 $downloadname =~ s/\-\s*$//;
605 return $downloadname;
608 ##############################################################
609 # Returning the complete block in all languages
610 # for a specified string
611 ##############################################################
613 sub get_language_block_from_language_file
615 my ($searchstring, $languagefile) = @_;
617 my @language_block = ();
619 for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
621 if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
625 push(@language_block, ${$languagefile}[$counter]);
628 while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
630 push(@language_block, ${$languagefile}[$counter]);
638 return \
@language_block;
641 ##############################################################
642 # Returning a specific language string from the block
643 # of all translations
644 ##############################################################
646 sub get_language_string_from_language_block
648 my ($language_block, $language) = @_;
652 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
654 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
661 if ( $newstring eq "" )
663 $language = "en-US"; # defaulting to english
665 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
667 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
678 ####################################################
679 # Creating download installation sets
680 ####################################################
682 sub create_download_sets
684 my ($installationdir, $includepatharrayref, $allvariableshashref, $downloadname, $languagestringref, $languagesarrayref) = @_;
688 my $force = 1; # print this message even in 'quiet' mode
689 installer
::logger
::print_message
( "\n******************************************\n" );
690 installer
::logger
::print_message
( "... creating download installation set ...\n", $force );
691 installer
::logger
::print_message
( "******************************************\n" );
693 installer
::logger
::include_header_into_logfile
("Creating download installation sets:");
695 my $firstdir = $installationdir;
696 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$firstdir);
698 my $lastdir = $installationdir;
699 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$lastdir);
701 if ( $installer::globals
::iswindowsbuild
&& $lastdir =~ /\./ ) { $lastdir =~ s/\./_download_inprogress\./ }
702 else { $lastdir = $lastdir . "_download_inprogress"; }
704 # removing existing directory "_native_packed_inprogress" and "_native_packed_witherror" and "_native_packed"
706 my $downloaddir = $firstdir . $lastdir;
708 if ( -d
$downloaddir ) { installer
::systemactions
::remove_complete_directory
($downloaddir); }
710 my $olddir = $downloaddir;
711 $olddir =~ s/_inprogress/_witherror/;
712 if ( -d
$olddir ) { installer
::systemactions
::remove_complete_directory
($olddir); }
714 $olddir = $downloaddir;
715 $olddir =~ s/_inprogress//;
716 if ( -d
$olddir ) { installer
::systemactions
::remove_complete_directory
($olddir); }
718 # creating the new directory
720 installer
::systemactions
::create_directory
($downloaddir);
722 $installer::globals
::saveinstalldir
= $downloaddir;
724 # evaluating the name of the download file
726 if ( $allvariableshashref->{'OOODOWNLOADNAME'} ) { $downloadname = set_download_filename
($languagestringref, $allvariableshashref); }
727 else { $downloadname = resolve_variables_in_downloadname
($allvariableshashref, $downloadname, $languagestringref); }
729 if ( ! $installer::globals
::iswindowsbuild
) # Unix specific part
732 # getting the path of the getuid.so (only required for Solaris and Linux)
733 my $getuidlibrary = "";
734 if (( $installer::globals
::issolarisbuild
) || ( $installer::globals
::islinuxbuild
)) { $getuidlibrary = get_path_for_library
($includepatharrayref); }
736 if ( $allvariableshashref->{'OOODOWNLOADNAME'} )
738 my $downloadfile = create_tar_gz_file_from_directory
($installationdir, $getuidlibrary, $downloaddir, $downloadname);
742 # find and read setup script template
743 my $scriptfilename = "downloadscript.sh";
747 if ( $installer::globals
::include_paths_read
)
749 $scriptref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath
(\
$scriptfilename, $includepatharrayref, 0);
753 $scriptref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath_classic
(\
$scriptfilename, $includepatharrayref, 0);
756 if ($$scriptref eq "") { installer
::exiter
::exit_program
("ERROR: Could not find script file $scriptfilename!", "create_download_sets"); }
757 my $scriptfile = installer
::files
::read_file
($$scriptref);
759 $infoline = "Found script file $scriptfilename: $$scriptref \n";
760 push( @installer::globals
::logfileinfo
, $infoline);
762 # add product name into script template
763 put_productname_into_script
($scriptfile, $allvariableshashref);
765 # replace linenumber in script template
766 put_linenumber_into_script
($scriptfile);
769 my $temporary_tarfile_name = $downloaddir . $installer::globals
::separator
. 'installset.tar';
770 my $size = tar_package
($installationdir, $temporary_tarfile_name, $getuidlibrary);
771 installer
::exiter
::exit_program
("ERROR: Could not create tar file $temporary_tarfile_name!", "create_download_sets") unless $size;
773 # calling sum to determine checksum and size of the tar file
774 my $sumout = call_sum
($temporary_tarfile_name);
776 # writing checksum and size into scriptfile
777 put_checksum_and_size_into_script
($scriptfile, $sumout);
779 # saving the script file
780 my $newscriptfilename = determine_scriptfile_name
($downloadname);
781 $newscriptfilename = save_script_file
($downloaddir, $newscriptfilename, $scriptfile);
783 installer
::logger
::print_message
( "... including installation set into $newscriptfilename ... \n" );
784 # Append tar file to script
785 include_tar_into_script
($newscriptfilename, $temporary_tarfile_name);