| 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::worker; |
| 20 |
|
| 21 |
use strict; |
| 22 |
use warnings; |
| 23 |
|
| 24 |
use Cwd; |
| 25 |
use File::Copy; |
| 26 |
use File::stat; |
| 27 |
use File::Temp qw(tmpnam); |
| 28 |
use File::Path; |
| 29 |
use File::Basename; |
| 30 |
use installer::control; |
| 31 |
use installer::converter; |
| 32 |
use installer::exiter; |
| 33 |
use installer::files; |
| 34 |
use installer::globals; |
| 35 |
use installer::logger; |
| 36 |
use installer::pathanalyzer; |
| 37 |
use installer::scpzipfiles; |
| 38 |
use installer::scriptitems; |
| 39 |
use installer::systemactions; |
| 40 |
use installer::windows::language; |
| 41 |
|
| 42 |
######################################### |
| 43 |
# Saving the patchlist file |
| 44 |
######################################### |
| 45 |
|
| 46 |
sub _save_patchlist_file |
| 47 |
{ |
| 48 |
my ($installlogdir, $patchlistfilename) = @_; |
| 49 |
|
| 50 |
my $installpatchlistdir = installer::systemactions::create_directory_next_to_directory($installlogdir, "patchlist"); |
| 51 |
$patchlistfilename =~ s/log\_/patchfiles\_/; |
| 52 |
$patchlistfilename =~ s/\.log/\.txt/; |
| 53 |
installer::files::save_file($installpatchlistdir . $installer::globals::separator . $patchlistfilename, \@installer::globals::patchfilecollector); |
| 54 |
installer::logger::print_message( "... creating patchlist file $patchlistfilename \n" ); |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
############################################################### |
| 59 |
# Removing all directories of a special language |
| 60 |
# in the directory $basedir |
| 61 |
############################################################### |
| 62 |
|
| 63 |
sub remove_old_installation_sets |
| 64 |
{ |
| 65 |
my ($basedir) = @_; |
| 66 |
|
| 67 |
installer::logger::print_message( "... removing old installation directories ...\n" ); |
| 68 |
|
| 69 |
my $removedir = $basedir; |
| 70 |
|
| 71 |
if ( -d $removedir ) { installer::systemactions::remove_complete_directory($removedir, 1); } |
| 72 |
|
| 73 |
# looking for non successful old installation sets |
| 74 |
|
| 75 |
$removedir = $basedir . "_witherror"; |
| 76 |
if ( -d $removedir ) { installer::systemactions::remove_complete_directory($removedir, 1); } |
| 77 |
|
| 78 |
$removedir = $basedir . "_inprogress"; |
| 79 |
if ( -d $removedir ) { installer::systemactions::remove_complete_directory($removedir, 1); } |
| 80 |
|
| 81 |
# finally the $basedir can be created empty |
| 82 |
|
| 83 |
if ( $installer::globals::localinstalldirset ) { installer::systemactions::create_directory_structure($basedir); } |
| 84 |
|
| 85 |
installer::systemactions::create_directory($basedir); |
| 86 |
} |
| 87 |
|
| 88 |
############################################################### |
| 89 |
# Creating the installation directory structure |
| 90 |
############################################################### |
| 91 |
|
| 92 |
sub create_installation_directory |
| 93 |
{ |
| 94 |
my ($shipinstalldir, $languagestringref, $current_install_number_ref) = @_; |
| 95 |
|
| 96 |
my $installdir = ""; |
| 97 |
|
| 98 |
my $languageref = $languagestringref; |
| 99 |
|
| 100 |
$installdir = installer::systemactions::create_directories("install", $languageref); |
| 101 |
installer::logger::print_message( "... creating installation set in $installdir ...\n" ); |
| 102 |
remove_old_installation_sets($installdir); |
| 103 |
my $inprogressinstalldir = $installdir . "_inprogress"; |
| 104 |
installer::systemactions::rename_directory($installdir, $inprogressinstalldir); |
| 105 |
$installdir = $inprogressinstalldir; |
| 106 |
|
| 107 |
$installer::globals::saveinstalldir = $installdir; # saving directory globally, in case of exiting |
| 108 |
|
| 109 |
return $installdir; |
| 110 |
} |
| 111 |
|
| 112 |
############################################################### |
| 113 |
# Analyzing and creating the log file |
| 114 |
############################################################### |
| 115 |
|
| 116 |
sub analyze_and_save_logfile |
| 117 |
{ |
| 118 |
my ($loggingdir, $installdir, $installlogdir, $allsettingsarrayref, $languagestringref, $current_install_number) = @_; |
| 119 |
|
| 120 |
my $is_success = 1; |
| 121 |
my $finalinstalldir = ""; |
| 122 |
|
| 123 |
installer::logger::print_message( "... checking log file " . $loggingdir . $installer::globals::logfilename . "\n" ); |
| 124 |
|
| 125 |
my $contains_error = installer::control::check_logfile(\@installer::globals::logfileinfo); |
| 126 |
|
| 127 |
# Dependent from the success, the installation directory can be renamed. |
| 128 |
|
| 129 |
if ( $contains_error ) |
| 130 |
{ |
| 131 |
my $errordir = installer::systemactions::rename_string_in_directory($installdir, "_inprogress", "_witherror"); |
| 132 |
# Error output to STDERR |
| 133 |
for ( my $j = 0; $j <= $#installer::globals::errorlogfileinfo; $j++ ) |
| 134 |
{ |
| 135 |
my $line = $installer::globals::errorlogfileinfo[$j]; |
| 136 |
$line =~ s/\s*$//g; |
| 137 |
installer::logger::print_error( $line ); |
| 138 |
} |
| 139 |
$is_success = 0; |
| 140 |
|
| 141 |
$finalinstalldir = $errordir; |
| 142 |
} |
| 143 |
else |
| 144 |
{ |
| 145 |
my $destdir = ""; |
| 146 |
|
| 147 |
$destdir = installer::systemactions::rename_string_in_directory($installdir, "_inprogress", ""); |
| 148 |
|
| 149 |
$finalinstalldir = $destdir; |
| 150 |
} |
| 151 |
|
| 152 |
# Saving the logfile in the log file directory and additionally in a log directory in the install directory |
| 153 |
|
| 154 |
my $numberedlogfilename = $installer::globals::logfilename; |
| 155 |
installer::logger::print_message( "... creating log file $numberedlogfilename \n" ); |
| 156 |
installer::files::save_file($loggingdir . $numberedlogfilename, \@installer::globals::logfileinfo); |
| 157 |
installer::files::save_file($installlogdir . $installer::globals::separator . $numberedlogfilename, \@installer::globals::logfileinfo); |
| 158 |
|
| 159 |
# Saving the list of patchfiles in a patchlist directory in the install directory |
| 160 |
if ( $installer::globals::creating_windows_installer_patch ) { _save_patchlist_file($installlogdir, $numberedlogfilename); } |
| 161 |
|
| 162 |
if ( $installer::globals::creating_windows_installer_patch ) { $installer::globals::creating_windows_installer_patch = 0; } |
| 163 |
|
| 164 |
# Exiting the packaging process, if an error occurred. |
| 165 |
# This is important, to get an error code "-1", if an error was found in the log file, |
| 166 |
# that did not break the packaging process |
| 167 |
|
| 168 |
if ( ! $is_success) { installer::exiter::exit_program("ERROR: Found an error in the logfile " . $loggingdir . $installer::globals::logfilename . ". Packaging failed.", "analyze_and_save_logfile"); } |
| 169 |
|
| 170 |
return ($is_success, $finalinstalldir); |
| 171 |
} |
| 172 |
|
| 173 |
############################################################### |
| 174 |
# Removing all directories that are saved in the |
| 175 |
# global directory @installer::globals::removedirs |
| 176 |
############################################################### |
| 177 |
|
| 178 |
sub clean_output_tree |
| 179 |
{ |
| 180 |
installer::logger::print_message( "... cleaning the output tree ...\n" ); |
| 181 |
|
| 182 |
for ( my $i = 0; $i <= $#installer::globals::removedirs; $i++ ) |
| 183 |
{ |
| 184 |
if ( -d $installer::globals::removedirs[$i] ) |
| 185 |
{ |
| 186 |
installer::logger::print_message( "... removing directory $installer::globals::removedirs[$i] ...\n" ); |
| 187 |
installer::systemactions::remove_complete_directory($installer::globals::removedirs[$i], 1); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
# Last try to remove the ship test directory |
| 192 |
|
| 193 |
if ( $installer::globals::shiptestdirectory ) |
| 194 |
{ |
| 195 |
if ( -d $installer::globals::shiptestdirectory ) |
| 196 |
{ |
| 197 |
my $infoline = "Last try to remove $installer::globals::shiptestdirectory . \n"; |
| 198 |
push(@installer::globals::logfileinfo, $infoline); |
| 199 |
my $systemcall = "rmdir $installer::globals::shiptestdirectory"; |
| 200 |
my $returnvalue = system($systemcall); |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
########################################################### |
| 206 |
# Setting one language in the language independent |
| 207 |
# array of include paths with $(LANG) |
| 208 |
########################################################### |
| 209 |
|
| 210 |
sub get_language_specific_include_paths |
| 211 |
{ |
| 212 |
my ( $patharrayref, $onelanguage ) = @_; |
| 213 |
|
| 214 |
my @patharray = (); |
| 215 |
|
| 216 |
for ( my $i = 0; $i <= $#{$patharrayref}; $i++ ) |
| 217 |
{ |
| 218 |
my $line = ${$patharrayref}[$i]; |
| 219 |
$line =~ s/\$\(LANG\)/$onelanguage/g; |
| 220 |
push(@patharray ,$line); |
| 221 |
} |
| 222 |
|
| 223 |
return \@patharray; |
| 224 |
} |
| 225 |
|
| 226 |
############################################################## |
| 227 |
# Collecting all items with a defined flag |
| 228 |
############################################################## |
| 229 |
|
| 230 |
sub collect_all_items_with_special_flag |
| 231 |
{ |
| 232 |
my ($itemsref, $flag) = @_; |
| 233 |
|
| 234 |
my @allitems = (); |
| 235 |
|
| 236 |
for ( my $i = 0; $i <= $#{$itemsref}; $i++ ) |
| 237 |
{ |
| 238 |
my $oneitem = ${$itemsref}[$i]; |
| 239 |
my $styles = ""; |
| 240 |
if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'} }; |
| 241 |
|
| 242 |
if ( $styles =~ /\b$flag\b/ ) |
| 243 |
{ |
| 244 |
push( @allitems, $oneitem ); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
return \@allitems; |
| 249 |
} |
| 250 |
|
| 251 |
############################################################## |
| 252 |
# Removing all items with a defined flag from collector |
| 253 |
############################################################## |
| 254 |
|
| 255 |
sub remove_all_items_with_special_flag |
| 256 |
{ |
| 257 |
my ($itemsref, $flag) = @_; |
| 258 |
|
| 259 |
my @allitems = (); |
| 260 |
|
| 261 |
for ( my $i = 0; $i <= $#{$itemsref}; $i++ ) |
| 262 |
{ |
| 263 |
my $oneitem = ${$itemsref}[$i]; |
| 264 |
my $styles = ""; |
| 265 |
if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'} }; |
| 266 |
if ( $styles =~ /\b$flag\b/ ) |
| 267 |
{ |
| 268 |
my $infoline = "Attention: Removing from collector: $oneitem->{'Name'} !\n"; |
| 269 |
push( @installer::globals::logfileinfo, $infoline); |
| 270 |
if ( $flag eq "BINARYTABLE_ONLY" ) { push(@installer::globals::binarytableonlyfiles, $oneitem); } |
| 271 |
next; |
| 272 |
} |
| 273 |
push( @allitems, $oneitem ); |
| 274 |
} |
| 275 |
|
| 276 |
return \@allitems; |
| 277 |
} |
| 278 |
|
| 279 |
########################################################### |
| 280 |
# Mechanism for simple installation without packing |
| 281 |
########################################################### |
| 282 |
|
| 283 |
sub install_simple ($$$$$$) |
| 284 |
{ |
| 285 |
my ($packagename, $languagestring, $directoriesarray, $filesarray, $linksarray, $unixlinksarray) = @_; |
| 286 |
|
| 287 |
installer::logger::print_message( "... installing module $packagename ...\n" ); |
| 288 |
|
| 289 |
my $destdir = $installer::globals::destdir; |
| 290 |
my @lines = (); |
| 291 |
|
| 292 |
installer::logger::print_message( "DestDir: $destdir \n" ); |
| 293 |
installer::logger::print_message( "Rootpath: $installer::globals::rootpath \n" ); |
| 294 |
|
| 295 |
`mkdir -p $destdir` if $destdir ne ""; |
| 296 |
`mkdir -p $destdir$installer::globals::rootpath`; |
| 297 |
|
| 298 |
# Create Directories |
| 299 |
for ( my $i = 0; $i <= $#{$directoriesarray}; $i++ ) |
| 300 |
{ |
| 301 |
my $onedir = ${$directoriesarray}[$i]; |
| 302 |
my $dir = ""; |
| 303 |
|
| 304 |
if ( $onedir->{'Dir'} ) { $dir = $onedir->{'Dir'}; } |
| 305 |
|
| 306 |
if ((!($dir =~ /\bPREDEFINED_/ )) || ( $dir =~ /\bPREDEFINED_PROGDIR\b/ )) |
| 307 |
{ |
| 308 |
my $hostname = $onedir->{'HostName'}; |
| 309 |
|
| 310 |
# ignore '.' subdirectories |
| 311 |
next if ( $hostname =~ m/\.$/ ); |
| 312 |
# remove './' from the path |
| 313 |
$hostname =~ s/\.\///g; |
| 314 |
|
| 315 |
# printf "mkdir $destdir$hostname\n"; |
| 316 |
mkdir $destdir . $hostname; |
| 317 |
push @lines, "%dir " . $hostname . "\n"; |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
for ( my $i = 0; $i <= $#{$filesarray}; $i++ ) |
| 322 |
{ |
| 323 |
my $onefile = ${$filesarray}[$i]; |
| 324 |
my $unixrights = $onefile->{'UnixRights'}; |
| 325 |
my $destination = $onefile->{'destination'}; |
| 326 |
my $sourcepath = $onefile->{'sourcepath'}; |
| 327 |
|
| 328 |
# This is necessary to install SDK that includes files with $ in its name |
| 329 |
# Otherwise, the following shell commands does not work and the file list |
| 330 |
# is not correct |
| 331 |
$destination =~ s/\$\$/\$/; |
| 332 |
$sourcepath =~ s/\$\$/\$/; |
| 333 |
|
| 334 |
# remove './' from the path |
| 335 |
$sourcepath =~ s/\.\///g; |
| 336 |
$destination =~ s/\.\///g; |
| 337 |
|
| 338 |
push @lines, "$destination\n"; |
| 339 |
if(-d "$destdir$destination"){ |
| 340 |
rmtree("$destdir$destination"); |
| 341 |
} |
| 342 |
if(-e "$destdir$destination") { |
| 343 |
unlink "$destdir$destination"; |
| 344 |
} |
| 345 |
|
| 346 |
if ( -l "$sourcepath" ) { |
| 347 |
symlink (readlink ("$sourcepath"), "$destdir$destination") || die "Can't symlink $destdir$destination -> " . readlink ("$sourcepath") . "$!"; |
| 348 |
} |
| 349 |
elsif ( -d $sourcepath ) { |
| 350 |
`mkdir -p "$destdir$destination"`; |
| 351 |
} |
| 352 |
else { |
| 353 |
copy ("$sourcepath", "$destdir$destination") || die "Can't copy file: $sourcepath -> $destdir$destination $!"; |
| 354 |
my $sourcestat = stat($sourcepath); |
| 355 |
utime ($sourcestat->atime, $sourcestat->mtime, "$destdir$destination"); |
| 356 |
chmod (oct($unixrights), "$destdir$destination") || die "Can't change permissions: $!"; |
| 357 |
} |
| 358 |
push @lines, "$destination\n"; |
| 359 |
} |
| 360 |
|
| 361 |
for ( my $i = 0; $i <= $#{$linksarray}; $i++ ) |
| 362 |
{ |
| 363 |
my $onelink = ${$linksarray}[$i]; |
| 364 |
my $destination = $onelink->{'destination'}; |
| 365 |
my $destinationfile = $onelink->{'destinationfile'}; |
| 366 |
|
| 367 |
if(-e "$destdir$destination") { |
| 368 |
unlink "$destdir$destination"; |
| 369 |
} |
| 370 |
symlink ("$destinationfile", "$destdir$destination") || die "Can't create symlink: $!"; |
| 371 |
push @lines, "$destination\n"; |
| 372 |
} |
| 373 |
|
| 374 |
for ( my $i = 0; $i <= $#{$unixlinksarray}; $i++ ) |
| 375 |
{ |
| 376 |
my $onelink = ${$unixlinksarray}[$i]; |
| 377 |
my $target = $onelink->{'Target'}; |
| 378 |
my $destination = $onelink->{'destination'}; |
| 379 |
my $cmd = "mkdir -p '" . dirname($destdir . $destination) . "'"; |
| 380 |
system($cmd) && die "Failed to execute \"$cmd\""; |
| 381 |
$cmd = "ln -sf '$target' '$destdir$destination'"; |
| 382 |
|
| 383 |
system($cmd) && die "Failed \"$cmd\""; |
| 384 |
push @lines, "$destination\n"; |
| 385 |
} |
| 386 |
|
| 387 |
if ( $destdir ne "" ) |
| 388 |
{ |
| 389 |
my $filelist; |
| 390 |
my $fname = $installer::globals::destdir . "/$packagename"; |
| 391 |
open ($filelist, ">$fname") || die "Can't open $fname: $!"; |
| 392 |
print $filelist @lines; |
| 393 |
close ($filelist); |
| 394 |
} |
| 395 |
|
| 396 |
} |
| 397 |
|
| 398 |
########################################################### |
| 399 |
# Selecting langpack items |
| 400 |
########################################################### |
| 401 |
|
| 402 |
sub select_langpack_items |
| 403 |
{ |
| 404 |
my ( $itemsref, $itemname ) = @_; |
| 405 |
|
| 406 |
installer::logger::include_header_into_logfile("Selecting RegistryItems for Language Packs"); |
| 407 |
|
| 408 |
my @itemsarray = (); |
| 409 |
|
| 410 |
for ( my $i = 0; $i <= $#{$itemsref}; $i++ ) |
| 411 |
{ |
| 412 |
my $oneitem = ${$itemsref}[$i]; |
| 413 |
|
| 414 |
# Items with style "LANGUAGEPACK" have to be included into the patch |
| 415 |
my $styles = ""; |
| 416 |
if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; } |
| 417 |
if (( $styles =~ /\bLANGUAGEPACK\b/ ) || ( $styles =~ /\bFORCELANGUAGEPACK\b/ )) { push(@itemsarray, $oneitem); } |
| 418 |
} |
| 419 |
|
| 420 |
return \@itemsarray; |
| 421 |
} |
| 422 |
|
| 423 |
########################################################### |
| 424 |
# Selecting helppack items |
| 425 |
########################################################### |
| 426 |
|
| 427 |
sub select_helppack_items |
| 428 |
{ |
| 429 |
my ( $itemsref, $itemname ) = @_; |
| 430 |
|
| 431 |
installer::logger::include_header_into_logfile("Selecting RegistryItems for Help Packs"); |
| 432 |
|
| 433 |
my @itemsarray = (); |
| 434 |
|
| 435 |
for ( my $i = 0; $i <= $#{$itemsref}; $i++ ) |
| 436 |
{ |
| 437 |
my $oneitem = ${$itemsref}[$i]; |
| 438 |
|
| 439 |
# Items with style "HELPPACK" have to be included into the patch |
| 440 |
my $styles = ""; |
| 441 |
if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; } |
| 442 |
if (( $styles =~ /\bHELPPACK\b/ ) || ( $styles =~ /\bFORCEHELPPACK\b/ )) { push(@itemsarray, $oneitem); } |
| 443 |
} |
| 444 |
|
| 445 |
return \@itemsarray; |
| 446 |
} |
| 447 |
|
| 448 |
########################################################### |
| 449 |
# Replacing %-variables with the content |
| 450 |
# of $allvariableshashref |
| 451 |
########################################################### |
| 452 |
|
| 453 |
sub replace_variables_in_string |
| 454 |
{ |
| 455 |
my ( $string, $variableshashref ) = @_; |
| 456 |
|
| 457 |
if ( $string =~ /^.*\%\w+.*$/ ) |
| 458 |
{ |
| 459 |
my $key; |
| 460 |
|
| 461 |
# we want to substitute FOO_BR before FOO to avoid floating _BR suffixes |
| 462 |
foreach $key (sort { length ($b) <=> length ($a) } keys %{$variableshashref}) |
| 463 |
{ |
| 464 |
my $value = $variableshashref->{$key}; |
| 465 |
$key = "\%" . $key; |
| 466 |
$string =~ s/\Q$key\E/$value/g; |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
return $string; |
| 471 |
} |
| 472 |
|
| 473 |
################################################################# |
| 474 |
# Copying the files defined as ScpActions into the |
| 475 |
# installation set. |
| 476 |
################################################################# |
| 477 |
|
| 478 |
sub put_scpactions_into_installset |
| 479 |
{ |
| 480 |
my ($installdir) = @_; |
| 481 |
|
| 482 |
installer::logger::include_header_into_logfile("Start: Copying scp action files into installation set"); |
| 483 |
|
| 484 |
for ( my $i = 0; $i <= $#installer::globals::allscpactions; $i++ ) |
| 485 |
{ |
| 486 |
my $onescpaction = $installer::globals::allscpactions[$i]; |
| 487 |
|
| 488 |
my $subdir = ""; |
| 489 |
if ( $onescpaction->{'Subdir'} ) { $subdir = $onescpaction->{'Subdir'}; } |
| 490 |
|
| 491 |
if ( $onescpaction->{'Name'} eq "loader.exe" ) { next; } # do not copy this ScpAction loader |
| 492 |
|
| 493 |
my $destdir = $installdir; |
| 494 |
$destdir =~ s/\Q$installer::globals::separator\E\s*$//; |
| 495 |
if ( $subdir ) { $destdir = $destdir . $installer::globals::separator . $subdir; } |
| 496 |
|
| 497 |
my $sourcefile = $onescpaction->{'sourcepath'}; |
| 498 |
my $destfile = $destdir . $installer::globals::separator . $onescpaction->{'DestinationName'}; |
| 499 |
|
| 500 |
if (( $subdir =~ /\// ) || ( $subdir =~ /\\/ )) |
| 501 |
{ |
| 502 |
installer::systemactions::create_directory_structure($destdir); |
| 503 |
} |
| 504 |
else |
| 505 |
{ |
| 506 |
installer::systemactions::create_directory($destdir); |
| 507 |
} |
| 508 |
|
| 509 |
installer::systemactions::copy_one_file($sourcefile, $destfile); |
| 510 |
|
| 511 |
if ( $onescpaction->{'UnixRights'} ) |
| 512 |
{ |
| 513 |
chmod oct($onescpaction->{'UnixRights'}), $destfile; |
| 514 |
} |
| 515 |
|
| 516 |
} |
| 517 |
|
| 518 |
installer::logger::include_header_into_logfile("End: Copying scp action files into installation set"); |
| 519 |
|
| 520 |
} |
| 521 |
|
| 522 |
################################################################# |
| 523 |
# Collecting scp actions for all languages |
| 524 |
################################################################# |
| 525 |
|
| 526 |
sub collect_scpactions |
| 527 |
{ |
| 528 |
my ($allscpactions) = @_; |
| 529 |
|
| 530 |
for ( my $i = 0; $i <= $#{$allscpactions}; $i++ ) |
| 531 |
{ |
| 532 |
push(@installer::globals::allscpactions, ${$allscpactions}[$i]); |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
########################################################### |
| 537 |
# Adding additional variables into the variableshashref, |
| 538 |
# that are defined in include files in the source tree. The |
| 539 |
# names of the include files are stored in |
| 540 |
# ADD_INCLUDE_FILES (comma separated list). |
| 541 |
########################################################### |
| 542 |
|
| 543 |
sub add_variables_from_inc_to_hashref |
| 544 |
{ |
| 545 |
my ($allvariables, $includepatharrayref) = @_; |
| 546 |
|
| 547 |
my $infoline = ""; |
| 548 |
my $includefilelist = $allvariables->{'ADD_INCLUDE_FILES'} || ""; |
| 549 |
|
| 550 |
for my $includefilename (split /,\s*/, $includefilelist) |
| 551 |
{ |
| 552 |
$includefilename =~ s/^\s*//; |
| 553 |
$includefilename =~ s/\s*$//; |
| 554 |
my $includefilenameref = $ENV{'SRCDIR'} . "/" . $includefilename; |
| 555 |
if ( ! -f $includefilenameref ) { installer::exiter::exit_program("Include file $includefilename ($includefilenameref) not found!\nADD_INCLUDE_FILES = $allvariables->{'ADD_INCLUDE_FILES'}", "add_variables_from_inc_to_hashref"); } |
| 556 |
|
| 557 |
$infoline = "Including inc file: $includefilenameref \n"; |
| 558 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 559 |
|
| 560 |
my $includefile = installer::files::read_file($includefilenameref); |
| 561 |
|
| 562 |
for ( my $j = 0; $j <= $#{$includefile}; $j++ ) |
| 563 |
{ |
| 564 |
# Analyzing all "key=value" lines |
| 565 |
my $oneline = ${$includefile}[$j]; |
| 566 |
|
| 567 |
if ( $oneline =~ /^\s*(\S+)\s*\=\s*(.*?)\s*$/ ) # no white space allowed in key |
| 568 |
{ |
| 569 |
my $key = $1; |
| 570 |
my $value = $2; |
| 571 |
$allvariables->{$key} = $value; |
| 572 |
$infoline = "Setting of variable: $key = $value\n"; |
| 573 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 574 |
} |
| 575 |
} |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
############################################## |
| 580 |
# Collecting all files from include paths |
| 581 |
############################################## |
| 582 |
|
| 583 |
sub collect_all_files_from_includepaths |
| 584 |
{ |
| 585 |
my ($patharrayref) = @_; |
| 586 |
|
| 587 |
installer::logger::globallog("Reading all directories: Start"); |
| 588 |
installer::logger::print_message( "... reading include paths ...\n" ); |
| 589 |
# empty the global |
| 590 |
|
| 591 |
@installer::globals::allincludepaths =(); |
| 592 |
my $infoline; |
| 593 |
|
| 594 |
for ( my $i = 0; $i <= $#{$patharrayref}; $i++ ) |
| 595 |
{ |
| 596 |
my $includepath = ${$patharrayref}[$i]; |
| 597 |
installer::remover::remove_leading_and_ending_whitespaces(\$includepath); |
| 598 |
|
| 599 |
if ( ! -d $includepath ) |
| 600 |
{ |
| 601 |
$infoline = "$includepath does not exist. (Can be removed from include path list?)\n"; |
| 602 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 603 |
next; |
| 604 |
} |
| 605 |
|
| 606 |
my @sourcefiles = (); |
| 607 |
my $pathstring = ""; |
| 608 |
installer::systemactions::read_full_directory($includepath, $pathstring, \@sourcefiles); |
| 609 |
|
| 610 |
if ( ! ( $#sourcefiles > -1 )) |
| 611 |
{ |
| 612 |
$infoline = "$includepath is empty. (Can be removed from include path list?)\n"; |
| 613 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 614 |
} |
| 615 |
else |
| 616 |
{ |
| 617 |
my $number = $#sourcefiles + 1; |
| 618 |
$infoline = "Directory $includepath contains $number files (including subdirs)\n"; |
| 619 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 620 |
|
| 621 |
my %allfileshash = (); |
| 622 |
$allfileshash{'includepath'} = $includepath; |
| 623 |
|
| 624 |
for ( my $j = 0; $j <= $#sourcefiles; $j++ ) |
| 625 |
{ |
| 626 |
$allfileshash{$sourcefiles[$j]} = 1; |
| 627 |
} |
| 628 |
|
| 629 |
push(@installer::globals::allincludepaths, \%allfileshash); |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
$installer::globals::include_paths_read = 1; |
| 634 |
|
| 635 |
installer::logger::globallog("Reading all directories: End"); |
| 636 |
push( @installer::globals::globallogfileinfo, "\n"); |
| 637 |
} |
| 638 |
|
| 639 |
############################################## |
| 640 |
# Searching for a file with the gid |
| 641 |
############################################## |
| 642 |
|
| 643 |
sub find_file_by_id |
| 644 |
{ |
| 645 |
my ( $filesref, $gid ) = @_; |
| 646 |
|
| 647 |
my $foundfile = 0; |
| 648 |
my $onefile; |
| 649 |
|
| 650 |
for ( my $i = 0; $i <= $#{$filesref}; $i++ ) |
| 651 |
{ |
| 652 |
$onefile = ${$filesref}[$i]; |
| 653 |
my $filegid = $onefile->{'gid'}; |
| 654 |
|
| 655 |
if ( $filegid eq $gid ) |
| 656 |
{ |
| 657 |
$foundfile = 1; |
| 658 |
last; |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
if (! $foundfile ) { $onefile = ""; } |
| 663 |
|
| 664 |
return $onefile; |
| 665 |
} |
| 666 |
|
| 667 |
################################################# |
| 668 |
# Generating paths for cygwin (second version) |
| 669 |
# This function generates smaller files for |
| 670 |
################################################# |
| 671 |
|
| 672 |
sub generate_cygwin_paths |
| 673 |
{ |
| 674 |
my ($filesref) = @_; |
| 675 |
|
| 676 |
installer::logger::include_timestamp_into_logfile("Starting generating cygwin paths"); |
| 677 |
|
| 678 |
my $infoline = "Generating cygwin paths (generate_cygwin_paths)\n"; |
| 679 |
push( @installer::globals::logfileinfo, $infoline); |
| 680 |
|
| 681 |
my $max = 5000; # number of paths in one file |
| 682 |
|
| 683 |
my @pathcollector = (); |
| 684 |
my $startnumber = 0; |
| 685 |
my $counter = 0; |
| 686 |
|
| 687 |
for ( my $i = 0; $i <= $#{$filesref}; $i++ ) |
| 688 |
{ |
| 689 |
my $line = ${$filesref}[$i]->{'sourcepath'} . "\n"; |
| 690 |
push(@pathcollector, $line); |
| 691 |
$counter++; |
| 692 |
|
| 693 |
if (( $i == $#{$filesref} ) || ((( $counter % $max ) == 0 ) && ( $i > 0 ))) |
| 694 |
{ |
| 695 |
my $tmpfilename = "cygwinhelper_" . $i . ".txt"; |
| 696 |
my $temppath = $installer::globals::temppath; |
| 697 |
$temppath =~ s/\Q$installer::globals::separator\E\s*$//; |
| 698 |
$tmpfilename = $temppath . $installer::globals::separator . $tmpfilename; |
| 699 |
$infoline = "Creating temporary file for cygwin conversion: $tmpfilename (contains $counter paths)\n"; |
| 700 |
push( @installer::globals::logfileinfo, $infoline); |
| 701 |
if ( -f $tmpfilename ) { unlink $tmpfilename; } |
| 702 |
|
| 703 |
installer::files::save_file($tmpfilename, \@pathcollector); |
| 704 |
|
| 705 |
my $success = 0; |
| 706 |
my @cyg_sourcepathlist = qx{cygpath -w -f "$tmpfilename"}; |
| 707 |
chomp @cyg_sourcepathlist; |
| 708 |
|
| 709 |
# Validating the array, it has to contain the correct number of values |
| 710 |
my $new_paths = $#cyg_sourcepathlist + 1; |
| 711 |
if ( $new_paths == $counter ) { $success = 1; } |
| 712 |
|
| 713 |
if ($success) |
| 714 |
{ |
| 715 |
$infoline = "Success: Successfully converted to cygwin paths!\n"; |
| 716 |
push( @installer::globals::logfileinfo, $infoline); |
| 717 |
} |
| 718 |
else |
| 719 |
{ |
| 720 |
$infoline = "ERROR: Failed to convert to cygwin paths!\n"; |
| 721 |
push( @installer::globals::logfileinfo, $infoline); |
| 722 |
installer::exiter::exit_program("ERROR: Failed to convert to cygwin paths!", "generate_cygwin_paths"); |
| 723 |
} |
| 724 |
|
| 725 |
for ( my $j = 0; $j <= $#cyg_sourcepathlist; $j++ ) |
| 726 |
{ |
| 727 |
my $number = $startnumber + $j; |
| 728 |
${$filesref}[$number]->{'cyg_sourcepath'} = $cyg_sourcepathlist[$j]; |
| 729 |
} |
| 730 |
|
| 731 |
if ( -f $tmpfilename ) { unlink $tmpfilename; } |
| 732 |
|
| 733 |
@pathcollector = (); |
| 734 |
$startnumber = $startnumber + $max; |
| 735 |
$counter = 0; |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
# Checking existence of cyg_sourcepath for every file |
| 740 |
for ( my $i = 0; $i <= $#{$filesref}; $i++ ) |
| 741 |
{ |
| 742 |
if (( ! exists(${$filesref}[$i]->{'cyg_sourcepath'}) ) || ( ${$filesref}[$i]->{'cyg_sourcepath'} eq "" )) |
| 743 |
{ |
| 744 |
$infoline = "ERROR: No cygwin sourcepath defined for file ${$filesref}[$i]->{'sourcepath'}\n"; |
| 745 |
push( @installer::globals::logfileinfo, $infoline); |
| 746 |
installer::exiter::exit_program("ERROR: No cygwin sourcepath defined for file ${$filesref}[$i]->{'sourcepath'}!", "generate_cygwin_paths"); |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
installer::logger::include_timestamp_into_logfile("Ending generating cygwin paths"); |
| 751 |
} |
| 752 |
|
| 753 |
###################################################### |
| 754 |
# Getting the first entry from a list of languages |
| 755 |
###################################################### |
| 756 |
|
| 757 |
sub get_first_from_list |
| 758 |
{ |
| 759 |
my ( $list ) = @_; |
| 760 |
|
| 761 |
my $first = $list; |
| 762 |
|
| 763 |
if ( $list =~ /^\s*(.+?),(.+)\s*$/) # "?" for minimal matching |
| 764 |
{ |
| 765 |
$first = $1; |
| 766 |
} |
| 767 |
|
| 768 |
return $first; |
| 769 |
} |
| 770 |
|
| 771 |
################################################ |
| 772 |
# Setting all spellchecker languages |
| 773 |
################################################ |
| 774 |
|
| 775 |
sub set_spellcheckerlanguages |
| 776 |
{ |
| 777 |
my ( $productlanguagesarrayref, $allvariables ) = @_; |
| 778 |
|
| 779 |
my %productlanguages = (); |
| 780 |
for ( my $i = 0; $i <= $#{$productlanguagesarrayref}; $i++ ) { $productlanguages{${$productlanguagesarrayref}[$i]} = 1; } |
| 781 |
|
| 782 |
my $spellcheckfilename = $allvariables->{'SPELLCHECKERFILE'}; |
| 783 |
|
| 784 |
my $spellcheckfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$spellcheckfilename, "", 1); |
| 785 |
|
| 786 |
if ($$spellcheckfileref eq "") { installer::exiter::exit_program("ERROR: Could not find $spellcheckfilename!", "set_spellcheckerlanguages"); } |
| 787 |
|
| 788 |
my $infoline = "Using spellchecker file: $$spellcheckfileref \n"; |
| 789 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 790 |
|
| 791 |
my $spellcheckfile = installer::files::read_file($$spellcheckfileref); |
| 792 |
my %spellcheckhash = (); |
| 793 |
|
| 794 |
for ( my $j = 0; $j <= $#{$spellcheckfile}; $j++ ) |
| 795 |
{ |
| 796 |
# Analyzing all "key=value" lines |
| 797 |
my $oneline = ${$spellcheckfile}[$j]; |
| 798 |
|
| 799 |
if ( $oneline =~ /^\s*(\S+)\s*\=\s*\"(.*?)\"\s*$/ ) # no white space allowed in key |
| 800 |
{ |
| 801 |
my $onelang = $1; |
| 802 |
my $languagelist = $2; |
| 803 |
|
| 804 |
# Special handling for language packs. Only include the first language of the language list. |
| 805 |
# If no spellchecker shall be included, the keyword "EMPTY" can be used. |
| 806 |
|
| 807 |
if ( $installer::globals::languagepack ) |
| 808 |
{ |
| 809 |
my $first = get_first_from_list($languagelist); |
| 810 |
|
| 811 |
if ( $first eq "EMPTY" ) # no spellchecker into language pack |
| 812 |
{ |
| 813 |
$languagelist = ""; |
| 814 |
} |
| 815 |
else |
| 816 |
{ |
| 817 |
$languagelist = $first; |
| 818 |
} |
| 819 |
} |
| 820 |
else # no language pack, so EMPTY is not required |
| 821 |
{ |
| 822 |
$languagelist =~ s/^\s*EMPTY\s*,//; # removing the entry EMPTY |
| 823 |
} |
| 824 |
|
| 825 |
$spellcheckhash{$onelang} = $languagelist; |
| 826 |
} |
| 827 |
} |
| 828 |
|
| 829 |
# Collecting all required languages in %installer::globals::spellcheckerlanguagehash |
| 830 |
|
| 831 |
foreach my $lang (keys %productlanguages) |
| 832 |
{ |
| 833 |
my $languagelist = ""; |
| 834 |
if ( exists($spellcheckhash{$lang}) ) { $languagelist = $spellcheckhash{$lang}; } |
| 835 |
else { $languagelist = ""; } # no dictionary unless defined in SPELLCHECKERFILE |
| 836 |
|
| 837 |
my $langlisthash = installer::converter::convert_stringlist_into_hash(\$languagelist, ","); |
| 838 |
foreach my $onelang ( keys %{$langlisthash} ) { $installer::globals::spellcheckerlanguagehash{$onelang} = 1; } |
| 839 |
} |
| 840 |
|
| 841 |
$installer::globals::analyze_spellcheckerlanguage = 1; |
| 842 |
|
| 843 |
# Logging |
| 844 |
|
| 845 |
my $langstring = ""; |
| 846 |
foreach my $lang (sort keys %installer::globals::spellcheckerlanguagehash) { $langstring = $langstring . "," . $lang } |
| 847 |
$langstring =~ s/^\s*,//; |
| 848 |
|
| 849 |
$infoline = "Collected spellchecker languages for spellchecker: $langstring \n"; |
| 850 |
push( @installer::globals::globallogfileinfo, $infoline); |
| 851 |
} |
| 852 |
|
| 853 |
################################################ |
| 854 |
# Including a license text into setup script |
| 855 |
################################################ |
| 856 |
|
| 857 |
sub put_license_into_setup |
| 858 |
{ |
| 859 |
my ($installdir, $includepatharrayref) = @_; |
| 860 |
|
| 861 |
# find and read the license file |
| 862 |
my $licenselanguage = "en-US"; # always english ! |
| 863 |
my $licensefilename = "license"; |
| 864 |
# my $licensefilename = "LICENSE" . ".txt"; |
| 865 |
my $licenseincludepatharrayref = get_language_specific_include_paths($includepatharrayref, $licenselanguage); |
| 866 |
|
| 867 |
my $licenseref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $licenseincludepatharrayref, 0); |
| 868 |
if ($$licenseref eq "") { installer::exiter::exit_program("ERROR: Could not find License file $licensefilename!", "put_license_into_setup"); } |
| 869 |
my $licensefile = installer::files::read_file($$licenseref); |
| 870 |
|
| 871 |
# Read setup |
| 872 |
my $setupfilename = $installdir . $installer::globals::separator . "setup"; |
| 873 |
my $setupfile = installer::files::read_file($setupfilename); |
| 874 |
|
| 875 |
# Replacement |
| 876 |
my $infoline = "Adding licensefile into setup script\n"; |
| 877 |
push( @installer::globals::logfileinfo, $infoline); |
| 878 |
|
| 879 |
my $includestring = ""; |
| 880 |
for ( my $i = 0; $i <= $#{$licensefile}; $i++ ) { $includestring = $includestring . ${$licensefile}[$i]; } |
| 881 |
for ( my $i = 0; $i <= $#{$setupfile}; $i++ ) { ${$setupfile}[$i] =~ s/LICENSEFILEPLACEHOLDER/$includestring/; } |
| 882 |
|
| 883 |
# Write setup |
| 884 |
installer::files::save_file($setupfilename, $setupfile); |
| 885 |
} |
| 886 |
|
| 887 |
######################################################### |
| 888 |
# Collecting all pkgmap files from an installation set |
| 889 |
######################################################### |
| 890 |
|
| 891 |
sub collectpackagemaps |
| 892 |
{ |
| 893 |
my ( $installdir, $languagestringref, $allvariables ) = @_; |
| 894 |
|
| 895 |
installer::logger::include_header_into_logfile("Collecting all packagemaps (pkgmap):"); |
| 896 |
|
| 897 |
my $pkgmapdir = installer::systemactions::create_directories("pkgmap", $languagestringref); |
| 898 |
my $subdirname = $allvariables->{'UNIXPRODUCTNAME'} . "_pkgmaps"; |
| 899 |
my $pkgmapsubdir = $pkgmapdir . $installer::globals::separator . $subdirname; |
| 900 |
if ( -d $pkgmapsubdir ) { installer::systemactions::remove_complete_directory($pkgmapsubdir); } |
| 901 |
if ( ! -d $pkgmapsubdir ) { installer::systemactions::create_directory($pkgmapsubdir); } |
| 902 |
|
| 903 |
$installdir =~ s/\/\s*$//; |
| 904 |
# Collecting all packages in $installdir and its sub package ("packages") |
| 905 |
my $searchdir = $installdir . $installer::globals::separator . $installer::globals::epmoutpath; |
| 906 |
|
| 907 |
my $allpackages = installer::systemactions::get_all_directories_without_path($searchdir); |
| 908 |
|
| 909 |
for ( my $i = 0; $i <= $#{$allpackages}; $i++ ) |
| 910 |
{ |
| 911 |
my $pkgmapfile = $searchdir . $installer::globals::separator . ${$allpackages}[$i] . $installer::globals::separator . "pkgmap"; |
| 912 |
my $destfilename = $pkgmapsubdir . $installer::globals::separator . ${$allpackages}[$i] . "_pkgmap"; |
| 913 |
installer::systemactions::copy_one_file($pkgmapfile, $destfilename); |
| 914 |
} |
| 915 |
|
| 916 |
# Create a tar gz file with all package maps |
| 917 |
my $tarfilename = $subdirname . ".tar"; |
| 918 |
my $targzname = $tarfilename . ".gz"; |
| 919 |
my $systemcall = "cd $pkgmapdir; tar -cf - $subdirname | $installer::globals::packertool > $targzname"; |
| 920 |
installer::systemactions::make_systemcall($systemcall); |
| 921 |
installer::systemactions::remove_complete_directory($pkgmapsubdir, 1); |
| 922 |
} |
| 923 |
|
| 924 |
1; |