Debian Codegraph @

solenv/bin/modules/installer/download.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::download;
20
21 use strict;
22 use warnings;
23
24 use File::Spec;
25 use installer::exiter;
26 use installer::files;
27 use installer::globals;
28 use installer::logger;
29 use installer::pathanalyzer;
30 use installer::remover;
31 use installer::systemactions;
32
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";
37 }
38 }
39
40 ##################################################################
41 # Including the lowercase product name into the script template
42 ##################################################################
43
44 sub put_productname_into_script
45 {
46 my ($scriptfile, $variableshashref) = @_;
47
48 my $productname = $variableshashref->{'PRODUCTNAME'};
49 $productname = lc($productname);
50 $productname =~ s/\.//g; # openoffice.org -> openofficeorg
51 $productname =~ s/\s*//g;
52
53 my $infoline = "Adding productname $productname into download shell script\n";
54 push( @installer::globals::logfileinfo, $infoline);
55
56 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
57 {
58 ${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/;
59 }
60 }
61
62 #########################################################
63 # Including the linenumber into the script template
64 #########################################################
65
66 sub put_linenumber_into_script
67 {
68 my ( $scriptfile ) = @_;
69
70 my $linenumber = $#{$scriptfile} + 2;
71
72 my $infoline = "Adding linenumber $linenumber into download shell script\n";
73 push( @installer::globals::logfileinfo, $infoline);
74
75 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
76 {
77 ${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/;
78 }
79 }
80
81 #########################################################
82 # Determining the name of the new scriptfile
83 #########################################################
84
85 sub determine_scriptfile_name
86 {
87 my ( $filename ) = @_;
88
89 $installer::globals::downloadfileextension = ".sh";
90 $filename = $filename . $installer::globals::downloadfileextension;
91 $installer::globals::downloadfilename = $filename;
92
93 my $infoline = "Setting download shell script file name to $filename\n";
94 push( @installer::globals::logfileinfo, $infoline);
95
96 return $filename;
97 }
98
99 #########################################################
100 # Saving the script file in the installation directory
101 #########################################################
102
103 sub save_script_file
104 {
105 my ($directory, $newscriptfilename, $scriptfile) = @_;
106
107 $newscriptfilename = $directory . $installer::globals::separator . $newscriptfilename;
108 installer::files::save_file($newscriptfilename, $scriptfile);
109
110 my $infoline = "Saving script file $newscriptfilename\n";
111 push( @installer::globals::logfileinfo, $infoline);
112
113 if ( ! $installer::globals::iswindowsbuild )
114 {
115 chmod 0775, $newscriptfilename;
116 }
117
118 return $newscriptfilename;
119 }
120
121 #########################################################
122 # Including checksum and size into script file
123 #########################################################
124
125 sub put_checksum_and_size_into_script
126 {
127 my ($scriptfile, $sumout) = @_;
128
129 my $checksum = "";
130 my $size = "";
131
132 if ( $sumout =~ /^\s*(\d+)\s+(\d+)\s*$/ )
133 {
134 $checksum = $1;
135 $size = $2;
136 }
137 else
138 {
139 installer::exiter::exit_program("ERROR: Incorrect return value from /usr/bin/sum: $sumout", "put_checksum_and_size_into_script");
140 }
141
142 my $infoline = "Adding checksum $checksum and size $size into download shell script\n";
143 push( @installer::globals::logfileinfo, $infoline);
144
145 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
146 {
147 ${$scriptfile}[$i] =~ s/CHECKSUMPLACEHOLDER/$checksum/;
148 ${$scriptfile}[$i] =~ s/DISCSPACEPLACEHOLDER/$size/;
149 }
150
151 }
152
153 #########################################################
154 # Determining checksum and size of tar file
155 #########################################################
156
157 sub call_sum
158 {
159 my ($filename) = @_;
160
161 my $systemcall = "/usr/bin/sum $filename |";
162
163 my $sumoutput = "";
164
165 open (SUM, "$systemcall");
166 $sumoutput = <SUM>;
167 close (SUM);
168
169 my $returnvalue = $?; # $? contains the return value of the systemcall
170
171 my $infoline = "Systemcall: $systemcall\n";
172 push( @installer::globals::logfileinfo, $infoline);
173
174 if ($returnvalue)
175 {
176 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
177 push( @installer::globals::logfileinfo, $infoline);
178 }
179 else
180 {
181 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
182 push( @installer::globals::logfileinfo, $infoline);
183 }
184
185 $sumoutput =~ s/\s+$filename\s$//;
186 return $sumoutput;
187 }
188
189 #########################################################
190 # Include the tar file into the script
191 #########################################################
192
193 sub include_tar_into_script
194 {
195 my ($scriptfile, $temporary_tarfile) = @_;
196
197 my $systemcall = "cat $temporary_tarfile >> $scriptfile && rm $temporary_tarfile";
198 my $returnvalue = system($systemcall);
199
200 my $infoline = "Systemcall: $systemcall\n";
201 push( @installer::globals::logfileinfo, $infoline);
202
203 if ($returnvalue)
204 {
205 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
206 push( @installer::globals::logfileinfo, $infoline);
207 }
208 else
209 {
210 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
211 push( @installer::globals::logfileinfo, $infoline);
212 }
213 return $returnvalue;
214 }
215
216 #########################################################
217 # Create a tar file from the binary package
218 #########################################################
219
220 sub tar_package
221 {
222 my ( $installdir, $tarfilename, $usefakeroot) = @_;
223
224 my $fakerootstring = "";
225 if ( $usefakeroot ) { $fakerootstring = "fakeroot"; }
226
227 my $systemcall = "cd $installdir; $fakerootstring tar -cf - * > $tarfilename";
228
229 my $returnvalue = system($systemcall);
230
231 my $infoline = "Systemcall: $systemcall\n";
232 push( @installer::globals::logfileinfo, $infoline);
233
234 if ($returnvalue)
235 {
236 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
237 push( @installer::globals::logfileinfo, $infoline);
238 }
239 else
240 {
241 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
242 push( @installer::globals::logfileinfo, $infoline);
243 }
244
245 chmod 0775, $tarfilename;
246
247 return ( -s $tarfilename );
248 }
249
250 #########################################################
251 # Setting installation languages
252 #########################################################
253
254 sub get_downloadname_language
255 {
256 my ($languagestringref) = @_;
257
258 my $languages = $$languagestringref;
259
260 if ( $installer::globals::added_english )
261 {
262 $languages =~ s/en-US_//;
263 $languages =~ s/_en-US//;
264 }
265
266 # do not list languages if there are too many
267 if ( length ($languages) > $installer::globals::max_lang_length )
268 {
269 $languages = '';
270 }
271
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 ) )
276 {
277 $languages = '';
278 }
279
280 return $languages;
281 }
282
283 #########################################################
284 # Setting download name
285 #########################################################
286
287 sub get_downloadname_productname
288 {
289 my ($allvariables) = @_;
290
291 my $start = "";
292
293 $start = $allvariables->{'PRODUCTNAME'};
294
295 return $start;
296 }
297
298 #########################################################
299 # Setting download version
300 #########################################################
301
302 sub get_download_version
303 {
304 my ($allvariables) = @_;
305
306 my $version = "";
307
308 $version = $allvariables->{'PRODUCTVERSION'};
309 if (( $allvariables->{'PRODUCTEXTENSION'} ) && ( $allvariables->{'PRODUCTEXTENSION'} ne "" )) { $version = $version . $allvariables->{'PRODUCTEXTENSION'}; }
310
311 return $version;
312 }
313
314 #################################################################
315 # Setting the platform name for download
316 #################################################################
317
318 sub get_download_platformname
319 {
320 my $platformname = "";
321
322 if ( $installer::globals::islinuxbuild )
323 {
324 $platformname = "Linux";
325 }
326 elsif ( $installer::globals::issolarisbuild )
327 {
328 $platformname = "Solaris";
329 }
330 elsif ( $installer::globals::iswindowsbuild )
331 {
332 $platformname = "Win";
333 }
334 elsif ( $installer::globals::isfreebsdbuild )
335 {
336 $platformname = "FreeBSD";
337 }
338 elsif ( $installer::globals::ismacbuild )
339 {
340 $platformname = "MacOS";
341 }
342 else
343 {
344 $platformname = $installer::globals::os;
345 }
346
347 return $platformname;
348 }
349
350 #########################################################
351 # Setting the architecture for the download name
352 #########################################################
353
354 sub get_download_architecture
355 {
356 my $arch = "";
357
358 if ( $installer::globals::issolarissparcbuild )
359 {
360 $arch = "Sparc";
361 }
362 elsif ( $installer::globals::issolarisx86build )
363 {
364 $arch = "x86";
365 }
366 elsif ( $installer::globals::cpuname eq 'INTEL' )
367 {
368 $arch = "x86";
369 }
370 elsif ( $installer::globals::cpuname eq 'POWERPC' )
371 {
372 $arch = "PPC";
373 }
374 elsif ( $installer::globals::cpuname eq 'POWERPC64' )
375 {
376 $arch = "PPC";
377 }
378 elsif ( $installer::globals::cpuname eq 'X86_64' )
379 {
380 $arch = 'x86-64';
381 }
382 elsif ( $installer::globals::cpuname eq 'AARCH64' )
383 {
384 $arch = "aarch64";
385 }
386
387 return $arch;
388 }
389
390 #########################################################
391 # Setting the content type for the download name
392 #########################################################
393
394 sub get_download_content
395 {
396 my ($allvariables) = @_;
397
398 my $content = "";
399
400 # content type included in the installer
401 if ( $installer::globals::isrpmbuild )
402 {
403 $content = "rpm";
404 }
405 elsif ( $installer::globals::isdebbuild )
406 {
407 $content = "deb";
408 }
409 elsif ( $installer::globals::packageformat eq "archive" )
410 {
411 $content = "archive";
412 }
413
414 return $content;
415 }
416
417 #########################################################
418 # Setting the functionality type for the download name
419 #########################################################
420
421 sub get_download_functionality
422 {
423 my ($allvariables) = @_;
424
425 my $functionality = "";
426
427 if ( $installer::globals::languagepack )
428 {
429 $functionality = "langpack";
430 }
431 elsif ( $installer::globals::helppack )
432 {
433 $functionality = "helppack";
434 }
435 elsif ( $allvariables->{'POSTVERSIONEXTENSION'} eq "SDK" )
436 {
437 $functionality = "sdk";
438 }
439 elsif ( $allvariables->{'POSTVERSIONEXTENSION'} eq "TEST" )
440 {
441 $functionality = "test";
442 }
443 elsif ( $allvariables->{'PRODUCTNAME'} eq "URE" )
444 {
445 $functionality = "ure";
446 }
447
448 return $functionality;
449 }
450
451 ###############################################################################################
452 # Setting the download file name
453 # Syntax:
454 # (PRODUCTNAME)_(VERSION)_(OS)_(ARCH)_(INSTALLTYPE)_(LANGUAGE).(FILEEXTENSION)
455 ###############################################################################################
456
457 sub set_download_filename
458 {
459 my ($languagestringref, $allvariables) = @_;
460
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);
468
469 # Setting the extension happens automatically
470
471 my $filename = $start . "_" . $versionstring . "_" . $platform . "_" . $architecture . "_" . $content . "_" . $functionality . "_" . $language;
472
473 # get rid of duplicit "_" delimiters when some strings are empty
474 $filename =~ s/\_\_\_/\_/g;
475 $filename =~ s/\_\_/\_/g;
476 $filename =~ s/\_\s*$//;
477
478 $installer::globals::ooodownloadfilename = $filename;
479
480 return $filename;
481 }
482
483
484 #########################################################
485 # Creating a tar.gz file
486 #########################################################
487
488 sub create_tar_gz_file_from_directory
489 {
490 my ($installdir, $usefakeroot, $downloaddir, $downloadfilename) = @_;
491
492 my $infoline = "";
493
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);
498
499 my $fakerootstring = "";
500 if ( $usefakeroot ) { $fakerootstring = "fakeroot"; }
501
502 $installer::globals::downloadfileextension = ".tar.gz";
503 $installer::globals::downloadfilename = $downloadfilename . $installer::globals::downloadfileextension;
504 my $targzname = $downloaddir . $installer::globals::separator . $installer::globals::downloadfilename;
505
506 # fdo#67060 - install script is for RPM only
507 if ( -e "$installdir/install" && !$installer::globals::isrpmbuild )
508 {
509 unlink("$installdir/install");
510 }
511
512 my $systemcall = "cd $changedir; $fakerootstring tar -cf - $packdir | $installer::globals::packertool > $targzname";
513
514 my $returnvalue = system($systemcall);
515
516 $infoline = "Systemcall: $systemcall\n";
517 push( @installer::globals::logfileinfo, $infoline);
518
519 if ($returnvalue)
520 {
521 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
522 push( @installer::globals::logfileinfo, $infoline);
523 }
524 else
525 {
526 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
527 push( @installer::globals::logfileinfo, $infoline);
528 }
529
530 return $targzname;
531 }
532
533 ##############################################################
534 # Returning the complete block in all languages
535 # for a specified string
536 ##############################################################
537
538 sub get_language_block_from_language_file
539 {
540 my ($searchstring, $languagefile) = @_;
541
542 my @language_block = ();
543
544 for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
545 {
546 if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
547 {
548 my $counter = $i;
549
550 push(@language_block, ${$languagefile}[$counter]);
551 $counter++;
552
553 while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
554 {
555 push(@language_block, ${$languagefile}[$counter]);
556 $counter++;
557 }
558
559 last;
560 }
561 }
562
563 return \@language_block;
564 }
565
566 ##############################################################
567 # Returning a specific language string from the block
568 # of all translations
569 ##############################################################
570
571 sub get_language_string_from_language_block
572 {
573 my ($language_block, $language) = @_;
574
575 my $newstring = "";
576
577 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
578 {
579 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
580 {
581 $newstring = $1;
582 last;
583 }
584 }
585
586 if ( $newstring eq "" )
587 {
588 $language = "en-US"; # defaulting to english
589
590 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
591 {
592 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
593 {
594 $newstring = $1;
595 last;
596 }
597 }
598 }
599
600 return $newstring;
601 }
602
603 ####################################################
604 # Creating download installation sets
605 ####################################################
606
607 sub create_download_sets
608 {
609 my ($installationdir, $includepatharrayref, $allvariableshashref, $downloadname, $languagestringref, $languagesarrayref) = @_;
610
611 my $infoline = "";
612
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" );
617
618 installer::logger::include_header_into_logfile("Creating download installation sets:");
619
620 my $firstdir = $installationdir;
621 installer::pathanalyzer::get_path_from_fullqualifiedname(\$firstdir);
622
623 my $lastdir = $installationdir;
624 installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$lastdir);
625
626 if ( $installer::globals::iswindowsbuild && $lastdir =~ /\./ ) { $lastdir =~ s/\./_download_inprogress\./ }
627 else { $lastdir = $lastdir . "_download_inprogress"; }
628
629 # removing existing directory "_native_packed_inprogress" and "_native_packed_witherror" and "_native_packed"
630
631 my $downloaddir = $firstdir . $lastdir;
632
633 if ( -d $downloaddir ) { installer::systemactions::remove_complete_directory($downloaddir); }
634
635 my $olddir = $downloaddir;
636 $olddir =~ s/_inprogress/_witherror/;
637 if ( -d $olddir ) { installer::systemactions::remove_complete_directory($olddir); }
638
639 $olddir = $downloaddir;
640 $olddir =~ s/_inprogress//;
641 if ( -d $olddir ) { installer::systemactions::remove_complete_directory($olddir); }
642
643 # creating the new directory
644
645 installer::systemactions::create_directory($downloaddir);
646
647 $installer::globals::saveinstalldir = $downloaddir;
648
649 # evaluating the name of the download file
650
651 $downloadname = set_download_filename($languagestringref, $allvariableshashref);
652
653 if ( ! $installer::globals::iswindowsbuild ) # Unix specific part
654 {
655
656 # whether to use fakeroot (only required for Solaris and Linux)
657 my $usefakeroot = 0;
658 if (( $installer::globals::issolarisbuild ) || ( $installer::globals::islinuxbuild )) { $usefakeroot = 1; }
659
660 my $downloadfile = create_tar_gz_file_from_directory($installationdir, $usefakeroot, $downloaddir, $downloadname);
661 }
662
663 return $downloaddir;
664 }
665
666 1;