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 = ';';
90 } elsif ( $^O
=~ /MSWin/i ) {
91 $local_pathseparator = ';';
93 my $patharrayref = installer
::converter
::convert_stringlist_into_array
(\
$pathvariable, $local_pathseparator);
95 $installer::globals
::patharray
= $patharrayref;
97 my @needed_files_in_path = ();
99 if (($installer::globals
::iswin
) && ($installer::globals
::iswindowsbuild
))
101 @needed_files_in_path = ("msiinfo.exe", "msidb.exe", "uuidgen.exe", "makecab.exe", "msitran.exe", "expand.exe");
103 elsif ($installer::globals
::iswin
)
105 @needed_files_in_path = ("zip.exe");
109 @needed_files_in_path = ("zip");
112 foreach $onefile ( @needed_files_in_path )
114 installer
::logger
::print_message
( "... searching $onefile ..." );
116 my $fileref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath_classic
(\
$onefile, $patharrayref , 0);
118 if ( $$fileref eq "" )
121 installer
::logger
::print_error
( "$onefile not found\n" );
125 installer
::logger
::print_message
( "\tFound: $$fileref\n" );
126 # Saving the absolute path for msitran.exe. This is required for the determination of the checksum.
127 if ( $onefile eq "msitran.exe" ) { $installer::globals
::msitranpath
= $$fileref; }
133 installer
::exiter
::exit_program
("ERROR: Could not find all needed files in path!", "check_system_path");
136 # checking for epm, which has to be in the path or in the solver
138 if (( $installer::globals
::call_epm
) && (!($installer::globals
::iswindowsbuild
)))
141 my $fileref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath
(\
$onefile, $patharrayref , 0);
142 if (!( $$fileref eq "" ))
144 $installer::globals
::epm_in_path
= 1;
146 if ( $$fileref =~ /^\s*\.\/epm\s
*$/ )
148 my $currentdir = cwd
();
149 $$fileref =~ s/\./$currentdir/;
152 $installer::globals
::epm_path
= $$fileref;
157 ######################################################################
158 # Determining the version of file makecab.exe
159 ######################################################################
161 sub get_makecab_version
163 my $makecabversion = -1;
165 my $systemcall = "makecab.exe |";
166 my @makecaboutput = ();
168 open (CAB
, $systemcall);
169 while (<CAB
>) { push(@makecaboutput, $_); }
172 my $returnvalue = $?
; # $? contains the return value of the systemcall
176 my $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
177 push( @installer::globals
::globallogfileinfo
, $infoline);
181 my $infoline = "Success: Executed \"$systemcall\" successfully!\n";
182 push( @installer::globals
::globallogfileinfo
, $infoline);
184 my $versionline = "";
186 for ( my $i = 0; $i <= $#makecaboutput; $i++ )
188 if ( $makecaboutput[$i] =~ /\bVersion\b/i )
190 $versionline = $makecaboutput[$i];
195 $infoline = $versionline;
196 push( @installer::globals
::globallogfileinfo
, $infoline);
198 if ( $versionline =~ /\bVersion\b\s+(\d+[\d\.]+\d+)\s+/ )
200 $makecabversion = $1;
203 # Only using the first number
205 if ( $makecabversion =~ /^\s*(\d+?)\D*/ )
207 $makecabversion = $1;
210 $infoline = "Using version: " . $makecabversion . "\n";
211 push( @installer::globals
::globallogfileinfo
, $infoline);
214 return $makecabversion;
217 ######################################################################
218 # Checking the version of file makecab.exe
219 ######################################################################
221 sub check_makecab_version
223 # checking version of makecab.exe
224 # Now it is guaranteed, that makecab.exe is in the path
228 my $makecabversion = get_makecab_version
();
230 my $infoline = "Tested version: " . $installer::globals
::controlledmakecabversion
. "\n";
231 push( @installer::globals
::globallogfileinfo
, $infoline);
233 if ( $makecabversion < 0 ) { $do_check = 0; } # version could not be determined
237 if ( $makecabversion < $installer::globals
::controlledmakecabversion
)
239 installer
::exiter
::exit_program
("makecab.exe too old. Found version: \"$makecabversion\", required version: \"$installer::globals::controlledmakecabversion\"!", "check_makecab_version");
244 $infoline = "Warning: No version check of makecab.exe\n";
245 push( @installer::globals
::globallogfileinfo
, $infoline);
249 ######################################################################
250 # Reading the environment variables for the paths in ziplist.
251 # solarenvpath, os, pmiscpath
252 ######################################################################
254 sub check_system_environment
259 my @environmentvariables = qw(
272 for my $key ( @environmentvariables )
274 $variables{$key} = defined($ENV{$key}) ?
$ENV{$key} : "";
276 if ( $variables{$key} eq "" )
278 installer
::logger
::print_error
( "$key not set in environment\n" );
285 installer
::exiter
::exit_program
("ERROR: Environment variable not set!", "check_system_environment");
291 #############################################################
292 # Controlling the log file at the end of the
294 #############################################################
302 my $contains_error = 0;
304 my $ignore_error = 0;
305 my $make_error_to_warning = 0;
307 for ( my $i = 0; $i <= $#{$logfile}; $i++ )
309 my $line = ${$logfile}[$i];
311 # Errors are all errors, but not the Windows installer table "Error.idt"
313 my $compareline = $line;
314 $compareline =~ s/Error\.idt//g; # removing all occurrences of "Error.idt"
315 $compareline =~ s/Error\.ulf//g; # removing all occurrences of "Error.ulf"
316 $compareline =~ s/Error\.idl//g; # removing all occurrences of "Error.idl"
317 $compareline =~ s/Error\.html//g; # removing all occurrences of "Error.html"
318 $compareline =~ s/error\.py//g; # removing all occurrences of "error.py"
319 $compareline =~ s/error\.cpython\-3\d{1,2}(\.opt\-.|)\.py[co]//g; # removing all occurrences of "error-cpython"
320 $compareline =~ s/libgpg-error//g;
321 $compareline =~ s/Error-xref\.html//g;
323 if ( $compareline =~ /\bError\b/i )
326 push(@errors, $line);
331 $make_error_to_warning = 1;
338 my $line = "\n*********************************************************************\n";
339 push(@output, $line);
340 $line = "ERROR: The following errors occurred in packaging process:\n\n";
341 push(@output, $line);
343 for ( my $i = 0; $i <= $#errors; $i++ )
345 $line = "$errors[$i]";
346 push(@output, $line);
349 $line = "*********************************************************************\n";
350 push(@output, $line);
356 if ( $make_error_to_warning )
358 $line = "\n*********************************************************************\n";
359 push(@output, $line);
360 $line = "The following errors in the log file were ignored:\n\n";
361 push(@output, $line);
363 for ( my $i = 0; $i <= $#errors; $i++ )
365 $line = "$errors[$i]";
366 push(@output, $line);
369 $line = "*********************************************************************\n";
370 push(@output, $line);
373 $line = "\n***********************************************************\n";
374 push(@output, $line);
375 $line = "Successful packaging process!\n";
376 push(@output, $line);
377 $line = "***********************************************************\n";
378 push(@output, $line);
381 # printing the output file and adding it to the logfile
383 installer
::logger
::include_header_into_logfile
("Summary:");
385 my $force = 1; # print this message even in 'quiet' mode
386 for ( my $i = 0; $i <= $#output; $i++ )
388 my $line = "$output[$i]";
389 installer
::logger
::print_message
( "$line", $force );
390 push( @installer::globals
::logfileinfo
, $line);
391 push( @installer::globals
::errorlogfileinfo
, $line);
394 return $contains_error;
397 #############################################################
398 # Reading the Windows list file for Windows language codes
399 # Encoding field is no longer used. We use UTF-8 everywhere.
400 #############################################################
404 my ($patharrayref) = @_;
406 if ( ! -f
$installer::globals
::lcidlistname
) { installer
::exiter
::exit_program
("ERROR: Did not find Windows LCID list $installer::globals::lcidlistname!", "read_lcidlist"); }
408 my $infoline = "Found LCID file: $installer::globals::lcidlistname\n";
409 push(@installer::globals
::globallogfileinfo
, $infoline);
411 my $lcidlist = installer
::files
::read_file
($installer::globals
::lcidlistname
);
412 my %msilanguage = ();
414 for ( my $i = 0; $i <= $#{$lcidlist}; $i++ )
416 my $line = ${$lcidlist}[$i];
417 # de-mangle various potential DOS line-ending problems
420 $line =~ s/\s*\#.*$//; # removing comments after "#"
421 if ( $line =~ /^\s*$/ ) { next; } # this is an empty line
423 if ( $line =~ /^\s*([\w-]+)\s+(\d+)\s+(\d+)\s*$/ )
425 my $onelanguage = $1;
426 my $windowslanguage = $3;
427 $msilanguage{$onelanguage} = $windowslanguage;
431 installer
::exiter
::exit_program
("ERROR: Wrong syntax in Windows LCID list $installer::globals::lcidlistname in line $i: '$line'", "read_lcidlist");
434 $installer::globals
::msilanguage
= \
%msilanguage;
437 #############################################################
438 # Only for Windows and Linux (RPM)there is currently
439 # a reliable mechanism to register extensions during
440 # installation process. Therefore it is for all other
441 # platforms forbidden to install oxt files into that
442 # directory, in which they are searched for registration.
443 #############################################################
447 my ( $filesarray ) = @_;
449 for ( my $i = 0; $i <= $#{$filesarray}; $i++ )
451 my $onefile = ${$filesarray}[$i];
453 if (( $onefile->{'Name'} ) && ( $onefile->{'Dir'} ))
455 if (( $onefile->{'Name'} =~ /\.oxt\s*$/ ) && ( $onefile->{'Dir'} eq $installer::globals
::extensioninstalldir
))
457 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");
463 #######################################################################
464 # Setting global variable "$installer::globals::addsystemintegration"
465 #######################################################################
467 sub set_addsystemintegration
469 my ($allvariables) = @_;
471 if ( $allvariables->{'ADDSYSTEMINTEGRATION'} ) { $installer::globals
::addsystemintegration
= 1; }
473 if ( $installer::globals
::languagepack
) { $installer::globals
::addsystemintegration
= 0; }
474 if ( $installer::globals
::helppack
) { $installer::globals
::addsystemintegration
= 0; }
476 my $infoline = "Value of \$installer::globals::addsystemintegration: $installer::globals::addsystemintegration\n";
477 push( @installer::globals
::globallogfileinfo
, $infoline);