| 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::control; |
| 20 |
|
| 21 |
use strict; |
| 22 |
use warnings; |
| 23 |
|
| 24 |
use Cwd; |
| 25 |
use installer::converter; |
| 26 |
use installer::exiter; |
| 27 |
use installer::files; |
| 28 |
use installer::globals; |
| 29 |
use installer::pathanalyzer; |
| 30 |
use installer::scriptitems; |
| 31 |
use installer::systemactions; |
| 32 |
|
| 33 |
######################################################### |
| 34 |
# Function that can be used for additional controls. |
| 35 |
# Search happens in $installer::globals::patharray. |
| 36 |
######################################################### |
| 37 |
|
| 38 |
sub check_needed_files_in_path |
| 39 |
{ |
| 40 |
my ( $filesref ) = @_; |
| 41 |
my $error = 0; |
| 42 |
|
| 43 |
foreach my $onefile ( @{$filesref} ) |
| 44 |
{ |
| 45 |
installer::logger::print_message( "... searching $onefile ..." ); |
| 46 |
|
| 47 |
my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$onefile, $installer::globals::patharray , 0); |
| 48 |
|
| 49 |
if ( $$fileref eq "" ) |
| 50 |
{ |
| 51 |
$error = 1; |
| 52 |
installer::logger::print_error( "$onefile not found\n" ); |
| 53 |
} |
| 54 |
else |
| 55 |
{ |
| 56 |
installer::logger::print_message( "\tFound: $$fileref\n" ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
if ( $error ) |
| 61 |
{ |
| 62 |
installer::exiter::exit_program("ERROR: Could not find all needed files in path!", "check_needed_files_in_path"); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
######################################################### |
| 67 |
# Checking the local system |
| 68 |
# Checking existence of needed files in include path |
| 69 |
######################################################### |
| 70 |
|
| 71 |
sub check_system_path |
| 72 |
{ |
| 73 |
# The following files have to be found in the environment variable PATH |
| 74 |
# All platforms: zip |
| 75 |
# Windows only: "msiinfo.exe", "msidb.exe", "uuidgen.exe", "makecab.exe", "msitran.exe", "expand.exe" for msi database and packaging |
| 76 |
|
| 77 |
my $onefile; |
| 78 |
my $error = 0; |
| 79 |
my $pathvariable = $ENV{'PATH'}; |
| 80 |
my $local_pathseparator = $installer::globals::pathseparator; |
| 81 |
|
| 82 |
if( $^O =~ /cygwin/i ) |
| 83 |
{ |
| 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 = ';'; |
| 92 |
} |
| 93 |
my $patharrayref = installer::converter::convert_stringlist_into_array(\$pathvariable, $local_pathseparator); |
| 94 |
|
| 95 |
$installer::globals::patharray = $patharrayref; |
| 96 |
|
| 97 |
my @needed_files_in_path = (); |
| 98 |
|
| 99 |
if (($installer::globals::iswin) && ($installer::globals::iswindowsbuild)) |
| 100 |
{ |
| 101 |
@needed_files_in_path = ("msiinfo.exe", "msidb.exe", "uuidgen.exe", "makecab.exe", "msitran.exe", "expand.exe"); |
| 102 |
} |
| 103 |
elsif ($installer::globals::iswin) |
| 104 |
{ |
| 105 |
@needed_files_in_path = ("zip.exe"); |
| 106 |
} |
| 107 |
else |
| 108 |
{ |
| 109 |
@needed_files_in_path = ("zip"); |
| 110 |
} |
| 111 |
|
| 112 |
foreach $onefile ( @needed_files_in_path ) |
| 113 |
{ |
| 114 |
installer::logger::print_message( "... searching $onefile ..." ); |
| 115 |
|
| 116 |
my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$onefile, $patharrayref , 0); |
| 117 |
|
| 118 |
if ( $$fileref eq "" ) |
| 119 |
{ |
| 120 |
$error = 1; |
| 121 |
installer::logger::print_error( "$onefile not found\n" ); |
| 122 |
} |
| 123 |
else |
| 124 |
{ |
| 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; } |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
if ( $error ) |
| 132 |
{ |
| 133 |
installer::exiter::exit_program("ERROR: Could not find all needed files in path!", "check_system_path"); |
| 134 |
} |
| 135 |
|
| 136 |
# checking for epm, which has to be in the path or in the solver |
| 137 |
|
| 138 |
if (( $installer::globals::call_epm ) && (!($installer::globals::iswindowsbuild))) |
| 139 |
{ |
| 140 |
my $onefile = "epm"; |
| 141 |
my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$onefile, $patharrayref , 0); |
| 142 |
if (!( $$fileref eq "" )) |
| 143 |
{ |
| 144 |
$installer::globals::epm_in_path = 1; |
| 145 |
|
| 146 |
if ( $$fileref =~ /^\s*\.\/epm\s*$/ ) |
| 147 |
{ |
| 148 |
my $currentdir = cwd(); |
| 149 |
$$fileref =~ s/\./$currentdir/; |
| 150 |
} |
| 151 |
|
| 152 |
$installer::globals::epm_path = $$fileref; |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
###################################################################### |
| 158 |
# Determining the version of file makecab.exe |
| 159 |
###################################################################### |
| 160 |
|
| 161 |
sub get_makecab_version |
| 162 |
{ |
| 163 |
my $makecabversion = -1; |
| 164 |
|
| 165 |
my $systemcall = "makecab.exe |"; |
| 166 |
my @makecaboutput = (); |
| 167 |
|
| 168 |
open (CAB, $systemcall); |
| 169 |
while (<CAB>) { push(@makecaboutput, $_); } |
| 170 |
close (CAB); |
| 171 |
|
| 172 |
my $returnvalue = $?; # $? contains the return value of the systemcall |
| 173 |
|
| 174 |
if ($returnvalue) |
| 175 |
{ |
| 176 |
my $infoline = "ERROR: Could not execute \"$systemcall\"!\n"; |
| 177 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 178 |
} |
| 179 |
else |
| 180 |
{ |
| 181 |
my $infoline = "Success: Executed \"$systemcall\" successfully!\n"; |
| 182 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 183 |
|
| 184 |
my $versionline = ""; |
| 185 |
|
| 186 |
for ( my $i = 0; $i <= $#makecaboutput; $i++ ) |
| 187 |
{ |
| 188 |
if ( $makecaboutput[$i] =~ /\bVersion\b/i ) |
| 189 |
{ |
| 190 |
$versionline = $makecaboutput[$i]; |
| 191 |
last; |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
$infoline = $versionline; |
| 196 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 197 |
|
| 198 |
if ( $versionline =~ /\bVersion\b\s+(\d+[\d\.]+\d+)\s+/ ) |
| 199 |
{ |
| 200 |
$makecabversion = $1; |
| 201 |
} |
| 202 |
|
| 203 |
# Only using the first number |
| 204 |
|
| 205 |
if ( $makecabversion =~ /^\s*(\d+?)\D*/ ) |
| 206 |
{ |
| 207 |
$makecabversion = $1; |
| 208 |
} |
| 209 |
|
| 210 |
$infoline = "Using version: " . $makecabversion . "\n"; |
| 211 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 212 |
} |
| 213 |
|
| 214 |
return $makecabversion; |
| 215 |
} |
| 216 |
|
| 217 |
###################################################################### |
| 218 |
# Checking the version of file makecab.exe |
| 219 |
###################################################################### |
| 220 |
|
| 221 |
sub check_makecab_version |
| 222 |
{ |
| 223 |
# checking version of makecab.exe |
| 224 |
# Now it is guaranteed, that makecab.exe is in the path |
| 225 |
|
| 226 |
my $do_check = 1; |
| 227 |
|
| 228 |
my $makecabversion = get_makecab_version(); |
| 229 |
|
| 230 |
my $infoline = "Tested version: " . $installer::globals::controlledmakecabversion . "\n"; |
| 231 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 232 |
|
| 233 |
if ( $makecabversion < 0 ) { $do_check = 0; } # version could not be determined |
| 234 |
|
| 235 |
if ( $do_check ) |
| 236 |
{ |
| 237 |
if ( $makecabversion < $installer::globals::controlledmakecabversion ) |
| 238 |
{ |
| 239 |
installer::exiter::exit_program("makecab.exe too old. Found version: \"$makecabversion\", required version: \"$installer::globals::controlledmakecabversion\"!", "check_makecab_version"); |
| 240 |
} |
| 241 |
} |
| 242 |
else |
| 243 |
{ |
| 244 |
$infoline = "Warning: No version check of makecab.exe\n"; |
| 245 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
###################################################################### |
| 250 |
# Reading the environment variables for the paths in ziplist. |
| 251 |
# solarenvpath, os, pmiscpath |
| 252 |
###################################################################### |
| 253 |
|
| 254 |
sub check_system_environment |
| 255 |
{ |
| 256 |
my %variables = (); |
| 257 |
my $error = 0; |
| 258 |
|
| 259 |
my @environmentvariables = qw( |
| 260 |
LIBO_VERSION_MAJOR |
| 261 |
LIBO_VERSION_MINOR |
| 262 |
CPUNAME |
| 263 |
OS |
| 264 |
COM |
| 265 |
PLATFORMID |
| 266 |
LOCAL_OUT |
| 267 |
LOCAL_COMMON_OUT |
| 268 |
WORKDIR |
| 269 |
SRCDIR |
| 270 |
); |
| 271 |
|
| 272 |
for my $key ( @environmentvariables ) |
| 273 |
{ |
| 274 |
$variables{$key} = defined($ENV{$key}) ? $ENV{$key} : ""; |
| 275 |
|
| 276 |
if ( $variables{$key} eq "" ) |
| 277 |
{ |
| 278 |
installer::logger::print_error( "$key not set in environment\n" ); |
| 279 |
$error = 1; |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
if ( $error ) |
| 284 |
{ |
| 285 |
installer::exiter::exit_program("ERROR: Environment variable not set!", "check_system_environment"); |
| 286 |
} |
| 287 |
|
| 288 |
return \%variables; |
| 289 |
} |
| 290 |
|
| 291 |
############################################################# |
| 292 |
# Controlling the log file at the end of the |
| 293 |
# packaging process |
| 294 |
############################################################# |
| 295 |
|
| 296 |
sub check_logfile |
| 297 |
{ |
| 298 |
my ($logfile) = @_; |
| 299 |
|
| 300 |
my @errors = (); |
| 301 |
my @output = (); |
| 302 |
my $contains_error = 0; |
| 303 |
|
| 304 |
my $ignore_error = 0; |
| 305 |
my $make_error_to_warning = 0; |
| 306 |
|
| 307 |
for ( my $i = 0; $i <= $#{$logfile}; $i++ ) |
| 308 |
{ |
| 309 |
my $line = ${$logfile}[$i]; |
| 310 |
|
| 311 |
# Errors are all errors, but not the Windows installer table "Error.idt" |
| 312 |
|
| 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; |
| 322 |
|
| 323 |
if ( $compareline =~ /\bError\b/i ) |
| 324 |
{ |
| 325 |
$contains_error = 1; |
| 326 |
push(@errors, $line); |
| 327 |
|
| 328 |
if ( $ignore_error ) |
| 329 |
{ |
| 330 |
$contains_error = 0; |
| 331 |
$make_error_to_warning = 1; |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
if ($contains_error) |
| 337 |
{ |
| 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); |
| 342 |
|
| 343 |
for ( my $i = 0; $i <= $#errors; $i++ ) |
| 344 |
{ |
| 345 |
$line = "$errors[$i]"; |
| 346 |
push(@output, $line); |
| 347 |
} |
| 348 |
|
| 349 |
$line = "*********************************************************************\n"; |
| 350 |
push(@output, $line); |
| 351 |
} |
| 352 |
else |
| 353 |
{ |
| 354 |
my $line = ""; |
| 355 |
|
| 356 |
if ( $make_error_to_warning ) |
| 357 |
{ |
| 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); |
| 362 |
|
| 363 |
for ( my $i = 0; $i <= $#errors; $i++ ) |
| 364 |
{ |
| 365 |
$line = "$errors[$i]"; |
| 366 |
push(@output, $line); |
| 367 |
} |
| 368 |
|
| 369 |
$line = "*********************************************************************\n"; |
| 370 |
push(@output, $line); |
| 371 |
} |
| 372 |
|
| 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); |
| 379 |
} |
| 380 |
|
| 381 |
# printing the output file and adding it to the logfile |
| 382 |
|
| 383 |
installer::logger::include_header_into_logfile("Summary:"); |
| 384 |
|
| 385 |
my $force = 1; # print this message even in 'quiet' mode |
| 386 |
for ( my $i = 0; $i <= $#output; $i++ ) |
| 387 |
{ |
| 388 |
my $line = "$output[$i]"; |
| 389 |
installer::logger::print_message( "$line", $force ); |
| 390 |
push( @installer::globals::logfileinfo, $line); |
| 391 |
push( @installer::globals::errorlogfileinfo, $line); |
| 392 |
} |
| 393 |
|
| 394 |
return $contains_error; |
| 395 |
} |
| 396 |
|
| 397 |
############################################################# |
| 398 |
# Reading the Windows list file for Windows language codes |
| 399 |
# Encoding field is no longer used. We use UTF-8 everywhere. |
| 400 |
############################################################# |
| 401 |
|
| 402 |
sub read_lcidlist |
| 403 |
{ |
| 404 |
my ($patharrayref) = @_; |
| 405 |
|
| 406 |
if ( ! -f $installer::globals::lcidlistname ) { installer::exiter::exit_program("ERROR: Did not find Windows LCID list $installer::globals::lcidlistname!", "read_lcidlist"); } |
| 407 |
|
| 408 |
my $infoline = "Found LCID file: $installer::globals::lcidlistname\n"; |
| 409 |
push(@installer::globals::globallogfileinfo, $infoline); |
| 410 |
|
| 411 |
my $lcidlist = installer::files::read_file($installer::globals::lcidlistname); |
| 412 |
my %msilanguage = (); |
| 413 |
|
| 414 |
for ( my $i = 0; $i <= $#{$lcidlist}; $i++ ) |
| 415 |
{ |
| 416 |
my $line = ${$lcidlist}[$i]; |
| 417 |
# de-mangle various potential DOS line-ending problems |
| 418 |
$line =~ s/\r//g; |
| 419 |
$line =~ s/\n//g; |
| 420 |
$line =~ s/\s*\#.*$//; # removing comments after "#" |
| 421 |
if ( $line =~ /^\s*$/ ) { next; } # this is an empty line |
| 422 |
|
| 423 |
if ( $line =~ /^\s*([\w-]+)\s+(\d+)\s+(\d+)\s*$/ ) |
| 424 |
{ |
| 425 |
my $onelanguage = $1; |
| 426 |
my $windowslanguage = $3; |
| 427 |
$msilanguage{$onelanguage} = $windowslanguage; |
| 428 |
} |
| 429 |
else |
| 430 |
{ |
| 431 |
installer::exiter::exit_program("ERROR: Wrong syntax in Windows LCID list $installer::globals::lcidlistname in line $i: '$line'", "read_lcidlist"); |
| 432 |
} |
| 433 |
} |
| 434 |
$installer::globals::msilanguage = \%msilanguage; |
| 435 |
} |
| 436 |
|
| 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 |
############################################################# |
| 444 |
|
| 445 |
sub check_oxtfiles |
| 446 |
{ |
| 447 |
my ( $filesarray ) = @_; |
| 448 |
|
| 449 |
for ( my $i = 0; $i <= $#{$filesarray}; $i++ ) |
| 450 |
{ |
| 451 |
my $onefile = ${$filesarray}[$i]; |
| 452 |
|
| 453 |
if (( $onefile->{'Name'} ) && ( $onefile->{'Dir'} )) |
| 454 |
{ |
| 455 |
if (( $onefile->{'Name'} =~ /\.oxt\s*$/ ) && ( $onefile->{'Dir'} eq $installer::globals::extensioninstalldir )) |
| 456 |
{ |
| 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"); |
| 458 |
} |
| 459 |
} |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
####################################################################### |
| 464 |
# Setting global variable "$installer::globals::addsystemintegration" |
| 465 |
####################################################################### |
| 466 |
|
| 467 |
sub set_addsystemintegration |
| 468 |
{ |
| 469 |
my ($allvariables) = @_; |
| 470 |
|
| 471 |
if ( $allvariables->{'ADDSYSTEMINTEGRATION'} ) { $installer::globals::addsystemintegration = 1; } |
| 472 |
|
| 473 |
if ( $installer::globals::languagepack ) { $installer::globals::addsystemintegration = 0; } |
| 474 |
if ( $installer::globals::helppack ) { $installer::globals::addsystemintegration = 0; } |
| 475 |
|
| 476 |
my $infoline = "Value of \$installer::globals::addsystemintegration: $installer::globals::addsystemintegration\n"; |
| 477 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 478 |
} |
| 479 |
|
| 480 |
1; |