Make installer compression tool configurable
[LibreOffice.git] / solenv / bin / modules / installer / worker.pm
blobfb2969f77e1cdd7ef5c32094e45c97bff4f9539f
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::worker;
21 use Cwd;
22 use File::Copy;
23 use File::stat;
24 use File::Temp qw(tmpnam);
25 use File::Path;
26 use File::Basename;
27 use installer::control;
28 use installer::converter;
29 use installer::exiter;
30 use installer::files;
31 use installer::globals;
32 use installer::logger;
33 use installer::pathanalyzer;
34 use installer::scpzipfiles;
35 use installer::scriptitems;
36 use installer::systemactions;
37 use installer::windows::language;
39 #########################################
40 # Saving the patchlist file
41 #########################################
43 sub _save_patchlist_file
45 my ($installlogdir, $patchlistfilename) = @_;
47 my $installpatchlistdir = installer::systemactions::create_directory_next_to_directory($installlogdir, "patchlist");
48 $patchlistfilename =~ s/log\_/patchfiles\_/;
49 $patchlistfilename =~ s/\.log/\.txt/;
50 installer::files::save_file($installpatchlistdir . $installer::globals::separator . $patchlistfilename, \@installer::globals::patchfilecollector);
51 installer::logger::print_message( "... creating patchlist file $patchlistfilename \n" );
55 ###############################################################
56 # Removing all directories of a special language
57 # in the directory $basedir
58 ###############################################################
60 sub remove_old_installation_sets
62 my ($basedir) = @_;
64 installer::logger::print_message( "... removing old installation directories ...\n" );
66 my $removedir = $basedir;
68 if ( -d $removedir ) { installer::systemactions::remove_complete_directory($removedir, 1); }
70 # looking for non successful old installation sets
72 $removedir = $basedir . "_witherror";
73 if ( -d $removedir ) { installer::systemactions::remove_complete_directory($removedir, 1); }
75 $removedir = $basedir . "_inprogress";
76 if ( -d $removedir ) { installer::systemactions::remove_complete_directory($removedir, 1); }
78 # finally the $basedir can be created empty
80 if ( $installer::globals::localinstalldirset ) { installer::systemactions::create_directory_structure($basedir); }
82 installer::systemactions::create_directory($basedir);
85 ###############################################################
86 # Creating the installation directory structure
87 ###############################################################
89 sub create_installation_directory
91 my ($shipinstalldir, $languagestringref, $current_install_number_ref) = @_;
93 my $installdir = "";
95 my $languageref = $languagestringref;
97 $installdir = installer::systemactions::create_directories("install", $languageref);
98 installer::logger::print_message( "... creating installation set in $installdir ...\n" );
99 remove_old_installation_sets($installdir);
100 my $inprogressinstalldir = $installdir . "_inprogress";
101 installer::systemactions::rename_directory($installdir, $inprogressinstalldir);
102 $installdir = $inprogressinstalldir;
104 $installer::globals::saveinstalldir = $installdir; # saving directory globally, in case of exiting
106 return $installdir;
109 ###############################################################
110 # Analyzing and creating the log file
111 ###############################################################
113 sub analyze_and_save_logfile
115 my ($loggingdir, $installdir, $installlogdir, $allsettingsarrayref, $languagestringref, $current_install_number) = @_;
117 my $is_success = 1;
118 my $finalinstalldir = "";
120 installer::logger::print_message( "... checking log file " . $loggingdir . $installer::globals::logfilename . "\n" );
122 my $contains_error = installer::control::check_logfile(\@installer::globals::logfileinfo);
124 # Dependent from the success, the installation directory can be renamed.
126 if ( $contains_error )
128 my $errordir = installer::systemactions::rename_string_in_directory($installdir, "_inprogress", "_witherror");
129 # Error output to STDERR
130 for ( my $j = 0; $j <= $#installer::globals::errorlogfileinfo; $j++ )
132 my $line = $installer::globals::errorlogfileinfo[$j];
133 $line =~ s/\s*$//g;
134 installer::logger::print_error( $line );
136 $is_success = 0;
138 $finalinstalldir = $errordir;
140 else
142 my $destdir = "";
144 $destdir = installer::systemactions::rename_string_in_directory($installdir, "_inprogress", "");
146 $finalinstalldir = $destdir;
149 # Saving the logfile in the log file directory and additionally in a log directory in the install directory
151 my $numberedlogfilename = $installer::globals::logfilename;
152 installer::logger::print_message( "... creating log file $numberedlogfilename \n" );
153 installer::files::save_file($loggingdir . $numberedlogfilename, \@installer::globals::logfileinfo);
154 installer::files::save_file($installlogdir . $installer::globals::separator . $numberedlogfilename, \@installer::globals::logfileinfo);
156 # Saving the list of patchfiles in a patchlist directory in the install directory
157 if ( $installer::globals::creating_windows_installer_patch ) { _save_patchlist_file($installlogdir, $numberedlogfilename); }
159 if ( $installer::globals::creating_windows_installer_patch ) { $installer::globals::creating_windows_installer_patch = 0; }
161 # Exiting the packaging process, if an error occurred.
162 # This is important, to get an error code "-1", if an error was found in the log file,
163 # that did not break the packaging process
165 if ( ! $is_success) { installer::exiter::exit_program("ERROR: Found an error in the logfile " . $loggingdir . $installer::globals::logfilename . ". Packaging failed.", "analyze_and_save_logfile"); }
167 return ($is_success, $finalinstalldir);
170 ###############################################################
171 # Removing all directories that are saved in the
172 # global directory @installer::globals::removedirs
173 ###############################################################
175 sub clean_output_tree
177 installer::logger::print_message( "... cleaning the output tree ...\n" );
179 for ( my $i = 0; $i <= $#installer::globals::removedirs; $i++ )
181 if ( -d $installer::globals::removedirs[$i] )
183 installer::logger::print_message( "... removing directory $installer::globals::removedirs[$i] ...\n" );
184 installer::systemactions::remove_complete_directory($installer::globals::removedirs[$i], 1);
188 # Last try to remove the ship test directory
190 if ( $installer::globals::shiptestdirectory )
192 if ( -d $installer::globals::shiptestdirectory )
194 my $infoline = "Last try to remove $installer::globals::shiptestdirectory . \n";
195 push(@installer::globals::logfileinfo, $infoline);
196 my $systemcall = "rmdir $installer::globals::shiptestdirectory";
197 my $returnvalue = system($systemcall);
202 ###########################################################
203 # Setting one language in the language independent
204 # array of include paths with $(LANG)
205 ###########################################################
207 sub get_language_specific_include_paths
209 my ( $patharrayref, $onelanguage ) = @_;
211 my @patharray = ();
213 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
215 my $line = ${$patharrayref}[$i];
216 $line =~ s/\$\(LANG\)/$onelanguage/g;
217 push(@patharray ,$line);
220 return \@patharray;
223 ##############################################################
224 # Collecting all items with a defined flag
225 ##############################################################
227 sub collect_all_items_with_special_flag
229 my ($itemsref, $flag) = @_;
231 my @allitems = ();
233 for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
235 my $oneitem = ${$itemsref}[$i];
236 my $styles = "";
237 if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'} };
239 if ( $styles =~ /\b$flag\b/ )
241 push( @allitems, $oneitem );
245 return \@allitems;
248 ##############################################################
249 # Removing all items with a defined flag from collector
250 ##############################################################
252 sub remove_all_items_with_special_flag
254 my ($itemsref, $flag) = @_;
256 my @allitems = ();
258 for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
260 my $oneitem = ${$itemsref}[$i];
261 my $styles = "";
262 if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'} };
263 if ( $styles =~ /\b$flag\b/ )
265 my $infoline = "Attention: Removing from collector: $oneitem->{'Name'} !\n";
266 push( @installer::globals::logfileinfo, $infoline);
267 if ( $flag eq "BINARYTABLE_ONLY" ) { push(@installer::globals::binarytableonlyfiles, $oneitem); }
268 next;
270 push( @allitems, $oneitem );
273 return \@allitems;
276 ###########################################################
277 # Mechanism for simple installation without packing
278 ###########################################################
280 sub install_simple ($$$$$$)
282 my ($packagename, $languagestring, $directoriesarray, $filesarray, $linksarray, $unixlinksarray) = @_;
284 installer::logger::print_message( "... installing module $packagename ...\n" );
286 my $destdir = $installer::globals::destdir;
287 my @lines = ();
289 installer::logger::print_message( "DestDir: $destdir \n" );
290 installer::logger::print_message( "Rootpath: $installer::globals::rootpath \n" );
292 `mkdir -p $destdir` if $destdir ne "";
293 `mkdir -p $destdir$installer::globals::rootpath`;
295 # Create Directories
296 for ( my $i = 0; $i <= $#{$directoriesarray}; $i++ )
298 my $onedir = ${$directoriesarray}[$i];
299 my $dir = "";
301 if ( $onedir->{'Dir'} ) { $dir = $onedir->{'Dir'}; }
303 if ((!($dir =~ /\bPREDEFINED_/ )) || ( $dir =~ /\bPREDEFINED_PROGDIR\b/ ))
305 my $hostname = $onedir->{'HostName'};
307 # ignore '.' subdirectories
308 next if ( $hostname =~ m/\.$/ );
309 # remove './' from the path
310 $hostname =~ s/\.\///g;
312 # printf "mkdir $destdir$hostname\n";
313 mkdir $destdir . $hostname;
314 push @lines, "%dir " . $hostname . "\n";
318 for ( my $i = 0; $i <= $#{$filesarray}; $i++ )
320 my $onefile = ${$filesarray}[$i];
321 my $unixrights = $onefile->{'UnixRights'};
322 my $destination = $onefile->{'destination'};
323 my $sourcepath = $onefile->{'sourcepath'};
325 # This is necessary to install SDK that includes files with $ in its name
326 # Otherwise, the following shell commands does not work and the file list
327 # is not correct
328 $destination =~ s/\$\$/\$/;
329 $sourcepath =~ s/\$\$/\$/;
331 # remove './' from the path
332 $sourcepath =~ s/\.\///g;
333 $destination =~ s/\.\///g;
335 push @lines, "$destination\n";
336 if(-d "$destdir$destination"){
337 rmtree("$destdir$destination");
339 if(-e "$destdir$destination") {
340 unlink "$destdir$destination";
343 if ( -l "$sourcepath" ) {
344 symlink (readlink ("$sourcepath"), "$destdir$destination") || die "Can't symlink $destdir$destination -> " . readlink ("$sourcepath") . "$!";
346 elsif ( -d $sourcepath ) {
347 `mkdir -p "$destdir$destination"`;
349 else {
350 copy ("$sourcepath", "$destdir$destination") || die "Can't copy file: $sourcepath -> $destdir$destination $!";
351 my $sourcestat = stat($sourcepath);
352 utime ($sourcestat->atime, $sourcestat->mtime, "$destdir$destination");
353 chmod (oct($unixrights), "$destdir$destination") || die "Can't change permissions: $!";
355 push @lines, "$destination\n";
358 for ( my $i = 0; $i <= $#{$linksarray}; $i++ )
360 my $onelink = ${$linksarray}[$i];
361 my $destination = $onelink->{'destination'};
362 my $destinationfile = $onelink->{'destinationfile'};
364 if(-e "$destdir$destination") {
365 unlink "$destdir$destination";
367 symlink ("$destinationfile", "$destdir$destination") || die "Can't create symlink: $!";
368 push @lines, "$destination\n";
371 for ( my $i = 0; $i <= $#{$unixlinksarray}; $i++ )
373 my $onelink = ${$unixlinksarray}[$i];
374 my $target = $onelink->{'Target'};
375 my $destination = $onelink->{'destination'};
376 my $cmd = "mkdir -p '" . dirname($destdir . $destination) . "'";
377 system($cmd) && die "Failed to execute \"$cmd\"";
378 $cmd = "ln -sf '$target' '$destdir$destination'";
380 system($cmd) && die "Failed \"$cmd\"";
381 push @lines, "$destination\n";
384 if ( $destdir ne "" )
386 my $filelist;
387 my $fname = $installer::globals::destdir . "/$packagename";
388 open ($filelist, ">$fname") || die "Can't open $fname: $!";
389 print $filelist @lines;
390 close ($filelist);
395 ###########################################################
396 # Selecting langpack items
397 ###########################################################
399 sub select_langpack_items
401 my ( $itemsref, $itemname ) = @_;
403 installer::logger::include_header_into_logfile("Selecting RegistryItems for Language Packs");
405 my @itemsarray = ();
407 for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
409 my $oneitem = ${$itemsref}[$i];
411 # Items with style "LANGUAGEPACK" have to be included into the patch
412 my $styles = "";
413 if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; }
414 if (( $styles =~ /\bLANGUAGEPACK\b/ ) || ( $styles =~ /\bFORCELANGUAGEPACK\b/ )) { push(@itemsarray, $oneitem); }
417 return \@itemsarray;
420 ###########################################################
421 # Selecting helppack items
422 ###########################################################
424 sub select_helppack_items
426 my ( $itemsref, $itemname ) = @_;
428 installer::logger::include_header_into_logfile("Selecting RegistryItems for Help Packs");
430 my @itemsarray = ();
432 for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
434 my $oneitem = ${$itemsref}[$i];
436 # Items with style "HELPPACK" have to be included into the patch
437 my $styles = "";
438 if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; }
439 if (( $styles =~ /\bHELPPACK\b/ ) || ( $styles =~ /\bFORCEHELPPACK\b/ )) { push(@itemsarray, $oneitem); }
442 return \@itemsarray;
445 ###########################################################
446 # Replacing %-variables with the content
447 # of $allvariableshashref
448 ###########################################################
450 sub replace_variables_in_string
452 my ( $string, $variableshashref ) = @_;
454 if ( $string =~ /^.*\%\w+.*$/ )
456 my $key;
458 # we want to substitute FOO_BR before FOO to avoid floating _BR suffixes
459 foreach $key (sort { length ($b) <=> length ($a) } keys %{$variableshashref})
461 my $value = $variableshashref->{$key};
462 $key = "\%" . $key;
463 $string =~ s/\Q$key\E/$value/g;
467 return $string;
470 #################################################################
471 # Copying the files defined as ScpActions into the
472 # installation set.
473 #################################################################
475 sub put_scpactions_into_installset
477 my ($installdir) = @_;
479 installer::logger::include_header_into_logfile("Start: Copying scp action files into installation set");
481 for ( my $i = 0; $i <= $#installer::globals::allscpactions; $i++ )
483 my $onescpaction = $installer::globals::allscpactions[$i];
485 my $subdir = "";
486 if ( $onescpaction->{'Subdir'} ) { $subdir = $onescpaction->{'Subdir'}; }
488 if ( $onescpaction->{'Name'} eq "loader.exe" ) { next; } # do not copy this ScpAction loader
490 my $destdir = $installdir;
491 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
492 if ( $subdir ) { $destdir = $destdir . $installer::globals::separator . $subdir; }
494 my $sourcefile = $onescpaction->{'sourcepath'};
495 my $destfile = $destdir . $installer::globals::separator . $onescpaction->{'DestinationName'};
497 if (( $subdir =~ /\// ) || ( $subdir =~ /\\/ ))
499 installer::systemactions::create_directory_structure($destdir);
501 else
503 installer::systemactions::create_directory($destdir);
506 installer::systemactions::copy_one_file($sourcefile, $destfile);
508 if ( $onescpaction->{'UnixRights'} )
510 chmod oct($onescpaction->{'UnixRights'}), $destfile;
515 installer::logger::include_header_into_logfile("End: Copying scp action files into installation set");
519 #################################################################
520 # Collecting scp actions for all languages
521 #################################################################
523 sub collect_scpactions
525 my ($allscpactions) = @_;
527 for ( my $i = 0; $i <= $#{$allscpactions}; $i++ )
529 push(@installer::globals::allscpactions, ${$allscpactions}[$i]);
533 ###########################################################
534 # Adding additional variables into the variableshashref,
535 # that are defined in include files in the source tree. The
536 # names of the include files are stored in
537 # ADD_INCLUDE_FILES (comma separated list).
538 ###########################################################
540 sub add_variables_from_inc_to_hashref
542 my ($allvariables, $includepatharrayref) = @_;
544 my $infoline = "";
545 my $includefilelist = $allvariables->{'ADD_INCLUDE_FILES'} || "";
547 for my $includefilename (split /,\s*/, $includefilelist)
549 $includefilename =~ s/^\s*//;
550 $includefilename =~ s/\s*$//;
551 $includefilenameref = $ENV{'SRCDIR'} . "/" . $includefilename;
552 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"); }
554 $infoline = "Including inc file: $includefilenameref \n";
555 push( @installer::globals::globallogfileinfo, $infoline);
557 my $includefile = installer::files::read_file($includefilenameref);
559 for ( my $j = 0; $j <= $#{$includefile}; $j++ )
561 # Analyzing all "key=value" lines
562 my $oneline = ${$includefile}[$j];
564 if ( $oneline =~ /^\s*(\S+)\s*\=\s*(.*?)\s*$/ ) # no white space allowed in key
566 my $key = $1;
567 my $value = $2;
568 $allvariables->{$key} = $value;
569 $infoline = "Setting of variable: $key = $value\n";
570 push( @installer::globals::globallogfileinfo, $infoline);
576 ##############################################
577 # Collecting all files from include paths
578 ##############################################
580 sub collect_all_files_from_includepaths
582 my ($patharrayref) = @_;
584 installer::logger::globallog("Reading all directories: Start");
585 installer::logger::print_message( "... reading include paths ...\n" );
586 # empty the global
588 @installer::globals::allincludepaths =();
589 my $infoline;
591 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
593 $includepath = ${$patharrayref}[$i];
594 installer::remover::remove_leading_and_ending_whitespaces(\$includepath);
596 if ( ! -d $includepath )
598 $infoline = "$includepath does not exist. (Can be removed from include path list?)\n";
599 push( @installer::globals::globallogfileinfo, $infoline);
600 next;
603 my @sourcefiles = ();
604 my $pathstring = "";
605 installer::systemactions::read_full_directory($includepath, $pathstring, \@sourcefiles);
607 if ( ! ( $#sourcefiles > -1 ))
609 $infoline = "$includepath is empty. (Can be removed from include path list?)\n";
610 push( @installer::globals::globallogfileinfo, $infoline);
612 else
614 my $number = $#sourcefiles + 1;
615 $infoline = "Directory $includepath contains $number files (including subdirs)\n";
616 push( @installer::globals::globallogfileinfo, $infoline);
618 my %allfileshash = ();
619 $allfileshash{'includepath'} = $includepath;
621 for ( my $j = 0; $j <= $#sourcefiles; $j++ )
623 $allfileshash{$sourcefiles[$j]} = 1;
626 push(@installer::globals::allincludepaths, \%allfileshash);
630 $installer::globals::include_paths_read = 1;
632 installer::logger::globallog("Reading all directories: End");
633 push( @installer::globals::globallogfileinfo, "\n");
636 ##############################################
637 # Searching for a file with the gid
638 ##############################################
640 sub find_file_by_id
642 my ( $filesref, $gid ) = @_;
644 my $foundfile = 0;
645 my $onefile;
647 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
649 $onefile = ${$filesref}[$i];
650 my $filegid = $onefile->{'gid'};
652 if ( $filegid eq $gid )
654 $foundfile = 1;
655 last;
659 if (! $foundfile ) { $onefile = ""; }
661 return $onefile;
664 #################################################
665 # Generating paths for cygwin (second version)
666 # This function generates smaller files for
667 #################################################
669 sub generate_cygwin_paths
671 my ($filesref) = @_;
673 installer::logger::include_timestamp_into_logfile("Starting generating cygwin paths");
675 my $infoline = "Generating cygwin paths (generate_cygwin_paths)\n";
676 push( @installer::globals::logfileinfo, $infoline);
678 my $max = 5000; # number of paths in one file
680 my @pathcollector = ();
681 my $startnumber = 0;
682 my $counter = 0;
684 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
686 my $line = ${$filesref}[$i]->{'sourcepath'} . "\n";
687 push(@pathcollector, $line);
688 $counter++;
690 if (( $i == $#{$filesref} ) || ((( $counter % $max ) == 0 ) && ( $i > 0 )))
692 my $tmpfilename = "cygwinhelper_" . $i . ".txt";
693 my $temppath = $installer::globals::temppath;
694 $temppath =~ s/\Q$installer::globals::separator\E\s*$//;
695 $tmpfilename = $temppath . $installer::globals::separator . $tmpfilename;
696 $infoline = "Creating temporary file for cygwin conversion: $tmpfilename (contains $counter paths)\n";
697 push( @installer::globals::logfileinfo, $infoline);
698 if ( -f $tmpfilename ) { unlink $tmpfilename; }
700 installer::files::save_file($tmpfilename, \@pathcollector);
702 my $success = 0;
703 my @cyg_sourcepathlist = qx{cygpath -w -f "$tmpfilename"};
704 chomp @cyg_sourcepathlist;
706 # Validating the array, it has to contain the correct number of values
707 my $new_paths = $#cyg_sourcepathlist + 1;
708 if ( $new_paths == $counter ) { $success = 1; }
710 if ($success)
712 $infoline = "Success: Successfully converted to cygwin paths!\n";
713 push( @installer::globals::logfileinfo, $infoline);
715 else
717 $infoline = "ERROR: Failed to convert to cygwin paths!\n";
718 push( @installer::globals::logfileinfo, $infoline);
719 installer::exiter::exit_program("ERROR: Failed to convert to cygwin paths!", "generate_cygwin_paths");
722 for ( my $j = 0; $j <= $#cyg_sourcepathlist; $j++ )
724 my $number = $startnumber + $j;
725 ${$filesref}[$number]->{'cyg_sourcepath'} = $cyg_sourcepathlist[$j];
728 if ( -f $tmpfilename ) { unlink $tmpfilename; }
730 @pathcollector = ();
731 $startnumber = $startnumber + $max;
732 $counter = 0;
736 # Checking existence of cyg_sourcepath for every file
737 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
739 if (( ! exists(${$filesref}[$i]->{'cyg_sourcepath'}) ) || ( ${$filesref}[$i]->{'cyg_sourcepath'} eq "" ))
741 $infoline = "ERROR: No cygwin sourcepath defined for file ${$filesref}[$i]->{'sourcepath'}\n";
742 push( @installer::globals::logfileinfo, $infoline);
743 installer::exiter::exit_program("ERROR: No cygwin sourcepath defined for file ${$filesref}[$i]->{'sourcepath'}!", "generate_cygwin_paths");
747 installer::logger::include_timestamp_into_logfile("Ending generating cygwin paths");
750 ######################################################
751 # Getting the first entry from a list of languages
752 ######################################################
754 sub get_first_from_list
756 my ( $list ) = @_;
758 my $first = $list;
760 if ( $list =~ /^\s*(.+?),(.+)\s*$/) # "?" for minimal matching
762 $first = $1;
765 return $first;
768 ################################################
769 # Setting all spellchecker languages
770 ################################################
772 sub set_spellcheckerlanguages
774 my ( $productlanguagesarrayref, $allvariables ) = @_;
776 my %productlanguages = ();
777 for ( my $i = 0; $i <= $#{$productlanguagesarrayref}; $i++ ) { $productlanguages{${$productlanguagesarrayref}[$i]} = 1; }
779 my $spellcheckfilename = $allvariables->{'SPELLCHECKERFILE'};
781 my $spellcheckfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$spellcheckfilename, "", 1);
783 if ($$spellcheckfileref eq "") { installer::exiter::exit_program("ERROR: Could not find $spellcheckfilename!", "set_spellcheckerlanguages"); }
785 my $infoline = "Using spellchecker file: $$spellcheckfileref \n";
786 push( @installer::globals::globallogfileinfo, $infoline);
788 my $spellcheckfile = installer::files::read_file($$spellcheckfileref);
789 my %spellcheckhash = ();
791 for ( my $j = 0; $j <= $#{$spellcheckfile}; $j++ )
793 # Analyzing all "key=value" lines
794 my $oneline = ${$spellcheckfile}[$j];
796 if ( $oneline =~ /^\s*(\S+)\s*\=\s*\"(.*?)\"\s*$/ ) # no white space allowed in key
798 my $onelang = $1;
799 my $languagelist = $2;
801 # Special handling for language packs. Only include the first language of the language list.
802 # If no spellchecker shall be included, the keyword "EMPTY" can be used.
804 if ( $installer::globals::languagepack )
806 my $first = get_first_from_list($languagelist);
808 if ( $first eq "EMPTY" ) # no spellchecker into language pack
810 $languagelist = "";
812 else
814 $languagelist = $first;
817 else # no language pack, so EMPTY is not required
819 $languagelist =~ s/^\s*EMPTY\s*,//; # removing the entry EMPTY
822 $spellcheckhash{$onelang} = $languagelist;
826 # Collecting all required languages in %installer::globals::spellcheckerlanguagehash
828 foreach my $lang (keys %productlanguages)
830 my $languagelist = "";
831 if ( exists($spellcheckhash{$lang}) ) { $languagelist = $spellcheckhash{$lang}; }
832 else { $languagelist = ""; } # no dictionary unless defined in SPELLCHECKERFILE
834 my $langlisthash = installer::converter::convert_stringlist_into_hash(\$languagelist, ",");
835 foreach my $onelang ( keys %{$langlisthash} ) { $installer::globals::spellcheckerlanguagehash{$onelang} = 1; }
838 $installer::globals::analyze_spellcheckerlanguage = 1;
840 # Logging
842 my $langstring = "";
843 foreach my $lang (sort keys %installer::globals::spellcheckerlanguagehash) { $langstring = $langstring . "," . $lang }
844 $langstring =~ s/^\s*,//;
846 $infoline = "Collected spellchecker languages for spellchecker: $langstring \n";
847 push( @installer::globals::globallogfileinfo, $infoline);
850 ################################################
851 # Including a license text into setup script
852 ################################################
854 sub put_license_into_setup
856 my ($installdir, $includepatharrayref) = @_;
858 # find and read the license file
859 my $licenselanguage = "en-US"; # always english !
860 my $licensefilename = "license";
861 # my $licensefilename = "LICENSE" . ".txt";
862 my $licenseincludepatharrayref = get_language_specific_include_paths($includepatharrayref, $licenselanguage);
864 my $licenseref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $licenseincludepatharrayref, 0);
865 if ($$licenseref eq "") { installer::exiter::exit_program("ERROR: Could not find License file $licensefilename!", "put_license_into_setup"); }
866 my $licensefile = installer::files::read_file($$licenseref);
868 # Read setup
869 my $setupfilename = $installdir . $installer::globals::separator . "setup";
870 my $setupfile = installer::files::read_file($setupfilename);
872 # Replacement
873 my $infoline = "Adding licensefile into setup script\n";
874 push( @installer::globals::logfileinfo, $infoline);
876 my $includestring = "";
877 for ( my $i = 0; $i <= $#{$licensefile}; $i++ ) { $includestring = $includestring . ${$licensefile}[$i]; }
878 for ( my $i = 0; $i <= $#{$setupfile}; $i++ ) { ${$setupfile}[$i] =~ s/LICENSEFILEPLACEHOLDER/$includestring/; }
880 # Write setup
881 installer::files::save_file($setupfilename, $setupfile);
884 #########################################################
885 # Collecting all pkgmap files from an installation set
886 #########################################################
888 sub collectpackagemaps
890 my ( $installdir, $languagestringref, $allvariables ) = @_;
892 installer::logger::include_header_into_logfile("Collecting all packagemaps (pkgmap):");
894 my $pkgmapdir = installer::systemactions::create_directories("pkgmap", $languagestringref);
895 my $subdirname = $allvariables->{'UNIXPRODUCTNAME'} . "_pkgmaps";
896 my $pkgmapsubdir = $pkgmapdir . $installer::globals::separator . $subdirname;
897 if ( -d $pkgmapsubdir ) { installer::systemactions::remove_complete_directory($pkgmapsubdir); }
898 if ( ! -d $pkgmapsubdir ) { installer::systemactions::create_directory($pkgmapsubdir); }
900 $installdir =~ s/\/\s*$//;
901 # Collecting all packages in $installdir and its sub package ("packages")
902 my $searchdir = $installdir . $installer::globals::separator . $installer::globals::epmoutpath;
904 my $allpackages = installer::systemactions::get_all_directories_without_path($searchdir);
906 for ( my $i = 0; $i <= $#{$allpackages}; $i++ )
908 my $pkgmapfile = $searchdir . $installer::globals::separator . ${$allpackages}[$i] . $installer::globals::separator . "pkgmap";
909 my $destfilename = $pkgmapsubdir . $installer::globals::separator . ${$allpackages}[$i] . "_pkgmap";
910 installer::systemactions::copy_one_file($pkgmapfile, $destfilename);
913 # Create a tar gz file with all package maps
914 my $tarfilename = $subdirname . ".tar";
915 my $targzname = $tarfilename . ".gz";
916 $systemcall = "cd $pkgmapdir; tar -cf - $subdirname | $installer::globals::packertool > $targzname";
917 installer::systemactions::make_systemcall($systemcall);
918 installer::systemactions::remove_complete_directory($pkgmapsubdir, 1);