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 # Include the tar file into the script
191 #########################################################
193 sub include_tar_into_script
195 my ($scriptfile, $temporary_tarfile) = @_;
197 my $systemcall = "cat $temporary_tarfile >> $scriptfile && rm $temporary_tarfile";
198 my $returnvalue = system($systemcall);
200 my $infoline = "Systemcall: $systemcall\n";
201 push( @installer::globals
::logfileinfo
, $infoline);
205 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
206 push( @installer::globals
::logfileinfo
, $infoline);
210 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
211 push( @installer::globals
::logfileinfo
, $infoline);
216 #########################################################
217 # Create a tar file from the binary package
218 #########################################################
222 my ( $installdir, $tarfilename, $usefakeroot) = @_;
224 my $fakerootstring = "";
225 if ( $usefakeroot ) { $fakerootstring = "fakeroot"; }
227 my $systemcall = "cd $installdir; $fakerootstring tar -cf - * > $tarfilename";
229 my $returnvalue = system($systemcall);
231 my $infoline = "Systemcall: $systemcall\n";
232 push( @installer::globals
::logfileinfo
, $infoline);
236 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
237 push( @installer::globals
::logfileinfo
, $infoline);
241 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
242 push( @installer::globals
::logfileinfo
, $infoline);
245 chmod 0775, $tarfilename;
247 return ( -s
$tarfilename );
250 #########################################################
251 # Setting installation languages
252 #########################################################
254 sub get_downloadname_language
256 my ($languagestringref) = @_;
258 my $languages = $$languagestringref;
260 if ( $installer::globals
::added_english
)
262 $languages =~ s/en-US_//;
263 $languages =~ s/_en-US//;
266 # do not list languages if there are too many
267 if ( length ($languages) > $installer::globals
::max_lang_length
)
272 # do not list pure en-US, except for helppack and langpack
273 if ( ( $languages eq "en-US" ) &&
274 ( ! $installer::globals
::languagepack
) &&
275 ( ! $installer::globals
::helppack
) )
283 #########################################################
284 # Setting download name
285 #########################################################
287 sub get_downloadname_productname
289 my ($allvariables) = @_;
293 $start = $allvariables->{'PRODUCTNAME'};
298 #########################################################
299 # Setting download version
300 #########################################################
302 sub get_download_version
304 my ($allvariables) = @_;
308 $version = $allvariables->{'PRODUCTVERSION'};
309 if (( $allvariables->{'PRODUCTEXTENSION'} ) && ( $allvariables->{'PRODUCTEXTENSION'} ne "" )) { $version = $version . $allvariables->{'PRODUCTEXTENSION'}; }
314 #################################################################
315 # Setting the platform name for download
316 #################################################################
318 sub get_download_platformname
320 my $platformname = "";
322 if ( $installer::globals
::islinuxbuild
)
324 $platformname = "Linux";
326 elsif ( $installer::globals
::issolarisbuild
)
328 $platformname = "Solaris";
330 elsif ( $installer::globals
::iswindowsbuild
)
332 $platformname = "Win";
334 elsif ( $installer::globals
::isfreebsdbuild
)
336 $platformname = "FreeBSD";
338 elsif ( $installer::globals
::ismacbuild
)
340 $platformname = "MacOS";
344 $platformname = $installer::globals
::os
;
347 return $platformname;
350 #########################################################
351 # Setting the architecture for the download name
352 #########################################################
354 sub get_download_architecture
358 if ( $installer::globals
::issolarissparcbuild
)
362 elsif ( $installer::globals
::issolarisx86build
)
366 elsif ( $installer::globals
::cpuname
eq 'INTEL' )
370 elsif ( $installer::globals
::cpuname
eq 'POWERPC' )
374 elsif ( $installer::globals
::cpuname
eq 'POWERPC64' )
378 elsif ( $installer::globals
::cpuname
eq 'X86_64' )
382 elsif ( $installer::globals
::cpuname
eq 'AARCH64' )
390 #########################################################
391 # Setting the content type for the download name
392 #########################################################
394 sub get_download_content
396 my ($allvariables) = @_;
400 # content type included in the installer
401 if ( $installer::globals
::isrpmbuild
)
405 elsif ( $installer::globals
::isdebbuild
)
409 elsif ( $installer::globals
::packageformat
eq "archive" )
411 $content = "archive";
417 #########################################################
418 # Setting the functionality type for the download name
419 #########################################################
421 sub get_download_functionality
423 my ($allvariables) = @_;
425 my $functionality = "";
427 if ( $installer::globals
::languagepack
)
429 $functionality = "langpack";
431 elsif ( $installer::globals
::helppack
)
433 $functionality = "helppack";
435 elsif ( $allvariables->{'POSTVERSIONEXTENSION'} eq "SDK" )
437 $functionality = "sdk";
439 elsif ( $allvariables->{'POSTVERSIONEXTENSION'} eq "TEST" )
441 $functionality = "test";
443 elsif ( $allvariables->{'PRODUCTNAME'} eq "URE" )
445 $functionality = "ure";
448 return $functionality;
451 ###############################################################################################
452 # Setting the download file name
454 # (PRODUCTNAME)_(VERSION)_(OS)_(ARCH)_(INSTALLTYPE)_(LANGUAGE).(FILEEXTENSION)
455 ###############################################################################################
457 sub set_download_filename
459 my ($languagestringref, $allvariables) = @_;
461 my $start = get_downloadname_productname
($allvariables);
462 my $versionstring = get_download_version
($allvariables);
463 my $platform = get_download_platformname
();
464 my $architecture = get_download_architecture
();
465 my $content = get_download_content
($allvariables);
466 my $functionality = get_download_functionality
($allvariables);
467 my $language = get_downloadname_language
($languagestringref);
469 # Setting the extension happens automatically
471 my $filename = $start . "_" . $versionstring . "_" . $platform . "_" . $architecture . "_" . $content . "_" . $functionality . "_" . $language;
473 # get rid of duplicit "_" delimiters when some strings are empty
474 $filename =~ s/\_\_\_/\_/g;
475 $filename =~ s/\_\_/\_/g;
476 $filename =~ s/\_\s*$//;
478 $installer::globals
::ooodownloadfilename
= $filename;
484 #########################################################
485 # Creating a tar.gz file
486 #########################################################
488 sub create_tar_gz_file_from_directory
490 my ($installdir, $usefakeroot, $downloaddir, $downloadfilename) = @_;
494 my $packdir = $installdir;
495 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$packdir);
496 my $changedir = $installdir;
497 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$changedir);
499 my $fakerootstring = "";
500 if ( $usefakeroot ) { $fakerootstring = "fakeroot"; }
502 $installer::globals
::downloadfileextension
= ".tar.gz";
503 $installer::globals
::downloadfilename
= $downloadfilename . $installer::globals
::downloadfileextension
;
504 my $targzname = $downloaddir . $installer::globals
::separator
. $installer::globals
::downloadfilename
;
506 # fdo#67060 - install script is for RPM only
507 if ( -e
"$installdir/install" && !$installer::globals
::isrpmbuild
)
509 unlink("$installdir/install");
512 my $systemcall = "cd $changedir; $fakerootstring tar -cf - $packdir | $installer::globals::packertool > $targzname";
514 my $returnvalue = system($systemcall);
516 $infoline = "Systemcall: $systemcall\n";
517 push( @installer::globals
::logfileinfo
, $infoline);
521 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
522 push( @installer::globals
::logfileinfo
, $infoline);
526 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
527 push( @installer::globals
::logfileinfo
, $infoline);
533 ##############################################################
534 # Returning the complete block in all languages
535 # for a specified string
536 ##############################################################
538 sub get_language_block_from_language_file
540 my ($searchstring, $languagefile) = @_;
542 my @language_block = ();
544 for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
546 if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
550 push(@language_block, ${$languagefile}[$counter]);
553 while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
555 push(@language_block, ${$languagefile}[$counter]);
563 return \
@language_block;
566 ##############################################################
567 # Returning a specific language string from the block
568 # of all translations
569 ##############################################################
571 sub get_language_string_from_language_block
573 my ($language_block, $language) = @_;
577 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
579 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
586 if ( $newstring eq "" )
588 $language = "en-US"; # defaulting to english
590 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
592 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
603 ####################################################
604 # Creating download installation sets
605 ####################################################
607 sub create_download_sets
609 my ($installationdir, $includepatharrayref, $allvariableshashref, $downloadname, $languagestringref, $languagesarrayref) = @_;
613 my $force = 1; # print this message even in 'quiet' mode
614 installer
::logger
::print_message
( "\n******************************************\n" );
615 installer
::logger
::print_message
( "... creating download installation set ...\n", $force );
616 installer
::logger
::print_message
( "******************************************\n" );
618 installer
::logger
::include_header_into_logfile
("Creating download installation sets:");
620 my $firstdir = $installationdir;
621 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$firstdir);
623 my $lastdir = $installationdir;
624 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$lastdir);
626 if ( $installer::globals
::iswindowsbuild
&& $lastdir =~ /\./ ) { $lastdir =~ s/\./_download_inprogress\./ }
627 else { $lastdir = $lastdir . "_download_inprogress"; }
629 # removing existing directory "_native_packed_inprogress" and "_native_packed_witherror" and "_native_packed"
631 my $downloaddir = $firstdir . $lastdir;
633 if ( -d
$downloaddir ) { installer
::systemactions
::remove_complete_directory
($downloaddir); }
635 my $olddir = $downloaddir;
636 $olddir =~ s/_inprogress/_witherror/;
637 if ( -d
$olddir ) { installer
::systemactions
::remove_complete_directory
($olddir); }
639 $olddir = $downloaddir;
640 $olddir =~ s/_inprogress//;
641 if ( -d
$olddir ) { installer
::systemactions
::remove_complete_directory
($olddir); }
643 # creating the new directory
645 installer
::systemactions
::create_directory
($downloaddir);
647 $installer::globals
::saveinstalldir
= $downloaddir;
649 # evaluating the name of the download file
651 $downloadname = set_download_filename
($languagestringref, $allvariableshashref);
653 if ( ! $installer::globals
::iswindowsbuild
) # Unix specific part
656 # whether to use fakeroot (only required for Solaris and Linux)
658 if (( $installer::globals
::issolarisbuild
) || ( $installer::globals
::islinuxbuild
)) { $usefakeroot = 1; }
660 my $downloadfile = create_tar_gz_file_from_directory
($installationdir, $usefakeroot, $downloaddir, $downloadname);