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
::control
;
25 use installer
::converter
;
26 use installer
::exiter
;
28 use installer
::globals
;
29 use installer
::pathanalyzer
;
30 use installer
::scriptitems
;
31 use installer
::systemactions
;
33 #########################################################
34 # Function that can be used for additional controls.
35 # Search happens in $installer::globals::patharray.
36 #########################################################
38 sub check_needed_files_in_path
40 my ( $filesref ) = @_;
43 foreach my $onefile ( @
{$filesref} )
45 installer
::logger
::print_message
( "... searching $onefile ..." );
47 my $fileref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath_classic
(\
$onefile, $installer::globals
::patharray
, 0);
49 if ( $$fileref eq "" )
52 installer
::logger
::print_error
( "$onefile not found\n" );
56 installer
::logger
::print_message
( "\tFound: $$fileref\n" );
62 installer
::exiter
::exit_program
("ERROR: Could not find all needed files in path!", "check_needed_files_in_path");
66 #########################################################
67 # Checking the local system
68 # Checking existence of needed files in include path
69 #########################################################
73 # The following files have to be found in the environment variable PATH
75 # Windows only: "msiinfo.exe", "msidb.exe", "uuidgen.exe", "makecab.exe", "msitran.exe", "expand.exe" for msi database and packaging
79 my $pathvariable = $ENV{'PATH'};
80 my $local_pathseparator = $installer::globals
::pathseparator
;
82 if( $^O
=~ /cygwin/i )
84 # When using cygwin's perl the PATH variable is POSIX style and
85 # has to be converted to DOS style for further use.
86 $pathvariable = join ';',
87 map { my $dir = qx{cygpath
-m
"$_"}; chomp($dir); $dir }
88 split /\Q$local_pathseparator\E\s*/, $pathvariable;
89 $local_pathseparator = ';';
91 my $patharrayref = installer
::converter
::convert_stringlist_into_array
(\
$pathvariable, $local_pathseparator);
93 $installer::globals
::patharray
= $patharrayref;
95 my @needed_files_in_path = ();
97 if (($installer::globals
::iswin
) && ($installer::globals
::iswindowsbuild
))
99 @needed_files_in_path = ("zip.exe", "msiinfo.exe", "msidb.exe", "uuidgen", "makecab.exe", "msitran.exe", "expand.exe");
101 elsif ($installer::globals
::iswin
)
103 @needed_files_in_path = ("zip.exe");
107 @needed_files_in_path = ("zip");
110 foreach $onefile ( @needed_files_in_path )
112 installer
::logger
::print_message
( "... searching $onefile ..." );
114 my $fileref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath_classic
(\
$onefile, $patharrayref , 0);
116 if ( $$fileref eq "" )
119 installer
::logger
::print_error
( "$onefile not found\n" );
123 installer
::logger
::print_message
( "\tFound: $$fileref\n" );
124 # Saving the absolute path for msitran.exe. This is required for the determination of the checksum.
125 if ( $onefile eq "msitran.exe" ) { $installer::globals
::msitranpath
= $$fileref; }
131 installer
::exiter
::exit_program
("ERROR: Could not find all needed files in path!", "check_system_path");
134 # checking for epm, which has to be in the path or in the solver
136 if (( $installer::globals
::call_epm
) && (!($installer::globals
::iswindowsbuild
)))
139 my $fileref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath
(\
$onefile, $patharrayref , 0);
140 if (!( $$fileref eq "" ))
142 $installer::globals
::epm_in_path
= 1;
144 if ( $$fileref =~ /^\s*\.\/epm\s
*$/ )
146 my $currentdir = cwd
();
147 $$fileref =~ s/\./$currentdir/;
150 $installer::globals
::epm_path
= $$fileref;
155 ######################################################################
156 # Determining the version of file makecab.exe
157 ######################################################################
159 sub get_makecab_version
161 my $makecabversion = -1;
163 my $systemcall = "makecab.exe |";
164 my @makecaboutput = ();
166 open (CAB
, $systemcall);
167 while (<CAB
>) { push(@makecaboutput, $_); }
170 my $returnvalue = $?
; # $? contains the return value of the systemcall
174 my $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
175 push( @installer::globals
::globallogfileinfo
, $infoline);
179 my $infoline = "Success: Executed \"$systemcall\" successfully!\n";
180 push( @installer::globals
::globallogfileinfo
, $infoline);
182 my $versionline = "";
184 for ( my $i = 0; $i <= $#makecaboutput; $i++ )
186 if ( $makecaboutput[$i] =~ /\bVersion\b/i )
188 $versionline = $makecaboutput[$i];
193 $infoline = $versionline;
194 push( @installer::globals
::globallogfileinfo
, $infoline);
196 if ( $versionline =~ /\bVersion\b\s+(\d+[\d\.]+\d+)\s+/ )
198 $makecabversion = $1;
201 # Only using the first number
203 if ( $makecabversion =~ /^\s*(\d+?)\D*/ )
205 $makecabversion = $1;
208 $infoline = "Using version: " . $makecabversion . "\n";
209 push( @installer::globals
::globallogfileinfo
, $infoline);
212 return $makecabversion;
215 ######################################################################
216 # Checking the version of file makecab.exe
217 ######################################################################
219 sub check_makecab_version
221 # checking version of makecab.exe
222 # Now it is guaranteed, that makecab.exe is in the path
226 my $makecabversion = get_makecab_version
();
228 my $infoline = "Tested version: " . $installer::globals
::controlledmakecabversion
. "\n";
229 push( @installer::globals
::globallogfileinfo
, $infoline);
231 if ( $makecabversion < 0 ) { $do_check = 0; } # version could not be determined
235 if ( $makecabversion < $installer::globals
::controlledmakecabversion
)
237 installer
::exiter
::exit_program
("makecab.exe too old. Found version: \"$makecabversion\", required version: \"$installer::globals::controlledmakecabversion\"!", "check_makecab_version");
242 $infoline = "Warning: No version check of makecab.exe\n";
243 push( @installer::globals
::globallogfileinfo
, $infoline);
247 ######################################################################
248 # Reading the environment variables for the paths in ziplist.
249 # solarenvpath, os, pmiscpath
250 ######################################################################
252 sub check_system_environment
257 my @environmentvariables = qw(
270 for my $key ( @environmentvariables )
272 $variables{$key} = defined($ENV{$key}) ?
$ENV{$key} : "";
274 if ( $variables{$key} eq "" )
276 installer
::logger
::print_error
( "$key not set in environment\n" );
283 installer
::exiter
::exit_program
("ERROR: Environment variable not set!", "check_system_environment");
289 #############################################################
290 # Controlling the log file at the end of the
292 #############################################################
300 my $contains_error = 0;
302 my $ignore_error = 0;
303 my $make_error_to_warning = 0;
305 for ( my $i = 0; $i <= $#{$logfile}; $i++ )
307 my $line = ${$logfile}[$i];
309 # Errors are all errors, but not the Windows installer table "Error.idt"
311 my $compareline = $line;
312 $compareline =~ s/Error\.idt//g; # removing all occurrences of "Error.idt"
313 $compareline =~ s/Error\.ulf//g; # removing all occurrences of "Error.ulf"
314 $compareline =~ s/Error\.idl//g; # removing all occurrences of "Error.idl"
315 $compareline =~ s/Error\.html//g; # removing all occurrences of "Error.html"
316 $compareline =~ s/error\.py//g; # removing all occurrences of "error.py"
317 $compareline =~ s/error\.cpython\-3.(\.opt\-.|)\.py[co]//g; # removing all occurrences of "error-cpython"
318 $compareline =~ s/libgpg-error//g;
319 $compareline =~ s/Error-xref\.html//g;
321 if ( $compareline =~ /\bError\b/i )
324 push(@errors, $line);
329 $make_error_to_warning = 1;
336 my $line = "\n*********************************************************************\n";
337 push(@output, $line);
338 $line = "ERROR: The following errors occurred in packaging process:\n\n";
339 push(@output, $line);
341 for ( my $i = 0; $i <= $#errors; $i++ )
343 $line = "$errors[$i]";
344 push(@output, $line);
347 $line = "*********************************************************************\n";
348 push(@output, $line);
354 if ( $make_error_to_warning )
356 $line = "\n*********************************************************************\n";
357 push(@output, $line);
358 $line = "The following errors in the log file were ignored:\n\n";
359 push(@output, $line);
361 for ( my $i = 0; $i <= $#errors; $i++ )
363 $line = "$errors[$i]";
364 push(@output, $line);
367 $line = "*********************************************************************\n";
368 push(@output, $line);
371 $line = "\n***********************************************************\n";
372 push(@output, $line);
373 $line = "Successful packaging process!\n";
374 push(@output, $line);
375 $line = "***********************************************************\n";
376 push(@output, $line);
379 # printing the output file and adding it to the logfile
381 installer
::logger
::include_header_into_logfile
("Summary:");
383 my $force = 1; # print this message even in 'quiet' mode
384 for ( my $i = 0; $i <= $#output; $i++ )
386 my $line = "$output[$i]";
387 installer
::logger
::print_message
( "$line", $force );
388 push( @installer::globals
::logfileinfo
, $line);
389 push( @installer::globals
::errorlogfileinfo
, $line);
392 return $contains_error;
395 #############################################################
396 # Reading the Windows list file for Windows language codes
397 # Encoding field is no longer used. We use UTF-8 everywhere.
398 #############################################################
402 my ($patharrayref) = @_;
404 if ( ! -f
$installer::globals
::lcidlistname
) { installer
::exiter
::exit_program
("ERROR: Did not find Windows LCID list $installer::globals::lcidlistname!", "read_lcidlist"); }
406 my $infoline = "Found LCID file: $installer::globals::lcidlistname\n";
407 push(@installer::globals
::globallogfileinfo
, $infoline);
409 my $lcidlist = installer
::files
::read_file
($installer::globals
::lcidlistname
);
410 my %msilanguage = ();
412 for ( my $i = 0; $i <= $#{$lcidlist}; $i++ )
414 my $line = ${$lcidlist}[$i];
415 # de-mangle various potential DOS line-ending problems
418 $line =~ s/\s*\#.*$//; # removing comments after "#"
419 if ( $line =~ /^\s*$/ ) { next; } # this is an empty line
421 if ( $line =~ /^\s*([\w-]+)\s+(\d+)\s+(\d+)\s*$/ )
423 my $onelanguage = $1;
424 my $windowslanguage = $3;
425 $msilanguage{$onelanguage} = $windowslanguage;
429 installer
::exiter
::exit_program
("ERROR: Wrong syntax in Windows LCID list $installer::globals::lcidlistname in line $i: '$line'", "read_lcidlist");
432 $installer::globals
::msilanguage
= \
%msilanguage;
435 #############################################################
436 # Only for Windows and Linux (RPM)there is currently
437 # a reliable mechanism to register extensions during
438 # installation process. Therefore it is for all other
439 # platforms forbidden to install oxt files into that
440 # directory, in which they are searched for registration.
441 #############################################################
445 my ( $filesarray ) = @_;
447 for ( my $i = 0; $i <= $#{$filesarray}; $i++ )
449 my $onefile = ${$filesarray}[$i];
451 if (( $onefile->{'Name'} ) && ( $onefile->{'Dir'} ))
453 if (( $onefile->{'Name'} =~ /\.oxt\s*$/ ) && ( $onefile->{'Dir'} eq $installer::globals
::extensioninstalldir
))
455 installer
::exiter
::exit_program
("There is currently only for Linux (RPM) and Windows a reliable mechanism to register extensions during installation.\nPlease remove file \"$onefile->{'gid'}\" from your installation set!\nYou can use \"\#ifdef _WIN32\" and \"\#ifdef LINUX\" in scp.", "check_oxtfiles");
461 #######################################################################
462 # Setting global variable "$installer::globals::addsystemintegration"
463 #######################################################################
465 sub set_addsystemintegration
467 my ($allvariables) = @_;
469 if ( $allvariables->{'ADDSYSTEMINTEGRATION'} ) { $installer::globals
::addsystemintegration
= 1; }
471 if ( $installer::globals
::languagepack
) { $installer::globals
::addsystemintegration
= 0; }
472 if ( $installer::globals
::helppack
) { $installer::globals
::addsystemintegration
= 0; }
474 my $infoline = "Value of \$installer::globals::addsystemintegration: $installer::globals::addsystemintegration\n";
475 push( @installer::globals
::globallogfileinfo
, $infoline);