update dev300-m58
[ooovba.git] / solenv / bin / modules / installer / control.pm
blobf9891333d2ea871b4923bb96517d738242d9db3b
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: control.pm,v $
11 # $Revision: 1.42 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer::control;
34 use Cwd;
35 use installer::converter;
36 use installer::exiter;
37 use installer::files;
38 use installer::globals;
39 use installer::pathanalyzer;
40 use installer::scriptitems;
41 use installer::systemactions;
43 #########################################################
44 # Function that can be used for additional controls.
45 # Search happens in $installer::globals::patharray.
46 #########################################################
48 sub check_needed_files_in_path
50 my ( $filesref ) = @_;
52 foreach $onefile ( @{$filesref} )
54 installer::logger::print_message( "...... searching $onefile ..." );
56 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$onefile, $installer::globals::patharray , 0);
58 if ( $$fileref eq "" )
60 $error = 1;
61 installer::logger::print_error( "$onefile not found\n" );
63 else
65 installer::logger::print_message( "\tFound: $$fileref\n" );
69 if ( $error )
71 installer::exiter::exit_program("ERROR: Could not find all needed files in path!", "check_needed_files_in_path");
75 #########################################################
76 # Checking the local system
77 # Checking existence of needed files in include path
78 #########################################################
80 sub check_system_path
82 # The following files have to be found in the environment variable PATH
83 # All platforms: zip
84 # Windows only: msvcp70.dll, msvcr70.dll for regcomp.exe
85 # Windows only: "msiinfo.exe", "msidb.exe", "uuidgen.exe", "makecab.exe", "msitran.exe", "expand.exe" for msi database and packaging
87 my $onefile;
88 my $error = 0;
89 my $pathvariable = $ENV{'PATH'};
90 my $local_pathseparator = $installer::globals::pathseparator;
92 if( $^O =~ /cygwin/i )
93 { # When using cygwin's perl the PATH variable is POSIX style and ...
94 my $temparrayref = installer::converter::convert_stringlist_into_array_without_newline(\$pathvariable, $local_pathseparator);
95 foreach $i (0..$#$temparrayref) {
96 $$temparrayref[$i] = qx{cygpath -m "$$temparrayref[$i]"};
97 chomp($$temparrayref[$i]);
99 # has to be converted to DOS style for further use.
100 $local_pathseparator = ';';
101 $pathvariable = join($local_pathseparator, @$temparrayref);
103 my $patharrayref = installer::converter::convert_stringlist_into_array(\$pathvariable, $local_pathseparator);
105 $installer::globals::patharray = $patharrayref;
107 my @needed_files_in_path = ();
109 if (($installer::globals::iswin) && ($installer::globals::iswindowsbuild))
111 @needed_files_in_path = ("zip.exe", "msiinfo.exe", "msidb.exe", "uuidgen.exe", "makecab.exe", "msitran.exe", "expand.exe");
113 if ( $installer::globals::compiler eq "wntmsci8" )
115 push(@needed_files_in_path, "msvcp70.dll");
116 push(@needed_files_in_path, "msvcr70.dll");
119 if ( $installer::globals::compiler eq "wntmsci10" )
121 push(@needed_files_in_path, "msvcp71.dll");
122 push(@needed_files_in_path, "msvcr71.dll");
126 elsif ($installer::globals::iswin)
128 @needed_files_in_path = ("zip.exe");
130 else
132 @needed_files_in_path = ("zip");
135 foreach $onefile ( @needed_files_in_path )
137 installer::logger::print_message( "...... searching $onefile ..." );
139 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$onefile, $patharrayref , 0);
141 if ( $$fileref eq "" )
143 $error = 1;
144 installer::logger::print_error( "$onefile not found\n" );
146 else
148 installer::logger::print_message( "\tFound: $$fileref\n" );
149 # Saving the absolut path for msitran.exe. This is required for the determination of the checksum.
150 if ( $onefile eq "msitran.exe" ) { $installer::globals::msitranpath = $$fileref; }
154 if ( $error )
156 installer::exiter::exit_program("ERROR: Could not find all needed files in path!", "check_system_path");
159 # checking for epm, which has to be in the path or in the solver
161 if (( $installer::globals::call_epm ) && (!($installer::globals::iswindowsbuild)))
163 my $onefile = "epm";
164 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$onefile, $patharrayref , 0);
165 if (!( $$fileref eq "" ))
167 $installer::globals::epm_in_path = 1;
169 if ( $$fileref =~ /^\s*\.\/epm\s*$/ )
171 my $currentdir = cwd();
172 $$fileref =~ s/\./$currentdir/;
175 $installer::globals::epm_path = $$fileref;
179 # checking, if upx can be found in path
181 if ( $installer::globals::iswindowsbuild ) { $installer::globals::upxfile = "upx.exe"; }
182 else { $installer::globals::upxfile = "upx"; }
184 my $upxfilename = $installer::globals::upxfile;
185 my $upxfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$upxfilename, $patharrayref , 0);
187 if (!( $$upxfileref eq "" ))
189 $installer::globals::upx_in_path = 1;
190 $installer::globals::upxfile = $$upxfileref;
191 installer::logger::print_message( "\tFound: $$upxfileref\n" );
196 ######################################################################
197 # Determining the version of file makecab.exe
198 ######################################################################
200 sub get_makecab_version
202 my $makecabversion = -1;
204 my $systemcall = "makecab.exe |";
205 my @makecaboutput = ();
207 open (CAB, $systemcall);
208 while (<CAB>) { push(@makecaboutput, $_); }
209 close (CAB);
211 my $returnvalue = $?; # $? contains the return value of the systemcall
213 if ($returnvalue)
215 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
216 push( @installer::globals::globallogfileinfo, $infoline);
218 else
220 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
221 push( @installer::globals::globallogfileinfo, $infoline);
223 my $versionline = "";
225 for ( my $i = 0; $i <= $#makecaboutput; $i++ )
227 if ( $makecaboutput[$i] =~ /\bVersion\b/i )
229 $versionline = $makecaboutput[$i];
230 last;
234 $infoline = $versionline;
235 push( @installer::globals::globallogfileinfo, $infoline);
237 if ( $versionline =~ /\bVersion\b\s+(\d+[\d\.]+\d+)\s+/ )
239 $makecabversion = $1;
242 # Only using the first number
244 if ( $makecabversion =~ /^\s*(\d+?)\D*/ )
246 $makecabversion = $1;
249 $infoline = "Using version: " . $makecabversion . "\n";
250 push( @installer::globals::globallogfileinfo, $infoline);
253 return $makecabversion;
256 ######################################################################
257 # Checking the version of file makecab.exe
258 ######################################################################
260 sub check_makecab_version
262 # checking version of makecab.exe
263 # Now it is guaranteed, that makecab.exe is in the path
265 my $do_check = 1;
267 my $makecabversion = get_makecab_version();
269 my $infoline = "Tested version: " . $installer::globals::controlledmakecabversion . "\n";
270 push( @installer::globals::globallogfileinfo, $infoline);
272 if ( $makecabversion < 0 ) { $do_check = 0; } # version could not be determined
274 if ( $do_check )
276 if ( $makecabversion < $installer::globals::controlledmakecabversion )
278 # warning for OOo, error for inhouse products
279 if ( $installer::globals::isopensourceproduct )
281 installer::logger::print_warning("Old version of makecab.exe. Found version: \"$makecabversion\", tested version: \"$installer::globals::controlledmakecabversion\"!\n");
283 else
285 installer::exiter::exit_program("makecab.exe too old. Found version: \"$makecabversion\", required version: \"$installer::globals::controlledmakecabversion\"!", "check_makecab_version");
289 else
291 $infoline = "Warning: No version check of makecab.exe\n";
292 push( @installer::globals::globallogfileinfo, $infoline);
296 ######################################################################
297 # Reading the environment variables for the pathes in ziplist.
298 # solarpath, solarenvpath, solarcommonpath, os, osdef, pmiscpath
299 ######################################################################
301 sub check_system_environment
303 my %variables = ();
304 my $key;
305 my $error = 0;
307 foreach $key ( @installer::globals::environmentvariables )
309 my $value = "";
310 if ( $ENV{$key} ) { $value = $ENV{$key}; }
311 $variables{$key} = $value;
313 if ( $value eq "" )
315 installer::logger::print_error( "$key not set in environment\n" );
316 $error = 1;
320 if ( $error )
322 installer::exiter::exit_program("ERROR: Environment variable not set!", "check_system_environment");
325 return \%variables;
328 #############################################################
329 # Controlling the log file at the end of the
330 # packaging process
331 #############################################################
333 sub check_logfile
335 my ($logfile) = @_;
337 my @errors = ();
338 my @output = ();
339 my $contains_error = 0;
341 for ( my $i = 0; $i <= $#{$logfile}; $i++ )
343 my $line = ${$logfile}[$i];
345 # Errors are all errors, but not the Windows installer table "Error.idt"
347 my $compareline = $line;
348 $compareline =~ s/Error\.idt//g; # removing all occurences of "Error.idt"
349 $compareline =~ s/Error\.mlf//g; # removing all occurences of "Error.mlf"
350 $compareline =~ s/Error\.ulf//g; # removing all occurences of "Error.ulf"
351 $compareline =~ s/Error\.idl//g; # removing all occurences of "Error.idl"
352 $compareline =~ s/Error\.html//g; # removing all occurences of "Error.html"
354 if ( $compareline =~ /\bError\b/i )
356 $contains_error = 1;
357 push(@errors, $line);
361 if ($contains_error)
363 my $line = "\n*********************************************************************\n";
364 push(@output, $line);
365 $line = "ERROR: The following errors occured in packaging process:\n\n";
366 push(@output, $line);
368 for ( my $i = 0; $i <= $#errors; $i++ )
370 $line = "$errors[$i]";
371 push(@output, $line);
374 $line = "*********************************************************************\n";
375 push(@output, $line);
376 # exit(-1);
378 else
380 my $line = "\n***********************************************************\n";
381 push(@output, $line);
382 $line = "Successful packaging process!\n";
383 push(@output, $line);
384 $line = "***********************************************************\n";
385 push(@output, $line);
388 # printing the output file and adding it to the logfile
390 installer::logger::include_header_into_logfile("Summary:");
392 my $force = 1; # print this message even in 'quiet' mode
393 for ( my $i = 0; $i <= $#output; $i++ )
395 my $line = "$output[$i]";
396 installer::logger::print_message( "$line", $force );
397 push( @installer::globals::logfileinfo, $line);
398 push( @installer::globals::errorlogfileinfo, $line);
401 return $contains_error;
404 #############################################################
405 # Determining the ship installation directory
406 #############################################################
408 sub determine_ship_directory
410 my ($languagesref) = @_;
412 if (!( $ENV{'SHIPDRIVE'} )) { installer::exiter::exit_program("ERROR: SHIPDRIVE must be set for updater!", "determine_ship_directory"); }
414 my $shipdrive = $ENV{'SHIPDRIVE'};
416 my $languagestring = $$languagesref;
417 my $productstring = $installer::globals::product;
418 my $productsubdir = "";
420 if ( $productstring =~ /^\s*(.+?)\_\_(.+?)\s*$/ )
422 $productstring = $1;
423 $productsubdir = $2;
426 if ( $installer::globals::languagepack ) { $productstring = $productstring . "_languagepack"; }
427 if ( $installer::globals::patch ) { $productstring = $productstring . "_patch"; }
429 my $destdir = $shipdrive . $installer::globals::separator . $installer::globals::compiler .
430 $installer::globals::productextension . $installer::globals::separator .
431 $productstring . $installer::globals::separator;
433 if ( $productsubdir ) { $destdir = $destdir . $productsubdir . $installer::globals::separator; }
435 $destdir = $destdir . $installer::globals::installertypedir . $installer::globals::separator .
436 $installer::globals::build . "_" . $installer::globals::lastminor . "_" .
437 "native_inprogress-number_" . $languagestring . "\." . $installer::globals::buildid;
439 my $infoline = "\nSetting ship directory: $destdir\n";
440 push(@installer::globals::globallogfileinfo, $infoline);
442 return $destdir;
445 #############################################################
446 # Controlling if this is an official RE pack process
447 #############################################################
449 sub check_updatepack
451 my $shipdrive = "";
452 my $filename = "";
453 my $infoline = "";
455 if ( $ENV{'UPDATER'} ) # the environment variable UPDATER has to be set
457 $infoline = "\nEnvironment variable UPDATER set\n";
458 push(@installer::globals::globallogfileinfo, $infoline);
460 if ( ! $ENV{'CWS_WORK_STAMP'} ) # the environment variable CWS_WORK_STAMP must not be set (set only in CWS)
462 $infoline = "Environment variable CWS_WORK_STAMP not set\n";
463 push(@installer::globals::globallogfileinfo, $infoline);
465 if ( $ENV{'SHIPDRIVE'} ) # the environment variable SHIPDRIVE must be set
467 $shipdrive = $ENV{'SHIPDRIVE'};
468 $infoline = "Ship drive defined: $shipdrive\n";
469 push(@installer::globals::globallogfileinfo, $infoline);
471 if ( -d $shipdrive ) # SHIPDRIVE must be a directory
473 $infoline = "Ship drive exists\n";
474 push(@installer::globals::globallogfileinfo, $infoline);
476 # try to write into $shipdrive
478 $directory = $installer::globals::product . "_" . $installer::globals::compiler . "_" . $installer::globals::buildid . "_" . $installer::globals::languageproducts[0] . "_test_$$";
479 $directory =~ s/\,/\_/g; # for the list of languages
480 $directory =~ s/\-/\_/g; # for en-US, pt-BR, ...
481 $directory = $shipdrive . $installer::globals::separator . $directory;
483 $infoline = "Try to create directory: $directory\n";
484 push(@installer::globals::globallogfileinfo, $infoline);
486 # saving this directory for later removal
487 $installer::globals::shiptestdirectory = $directory;
489 if ( installer::systemactions::try_to_create_directory($directory))
491 $infoline = "Write access on Ship drive\n";
492 push(@installer::globals::globallogfileinfo, $infoline);
493 $infoline = "Ship test directory $installer::globals::shiptestdirectory was successfully created\n";
494 push(@installer::globals::globallogfileinfo, $infoline);
495 my $systemcall = "rmdir $directory";
496 my $returnvalue = system($systemcall);
498 # 5th condition: No local build environment.
499 # In this case the content of SOLARENV starts with the content of SOL_TMP
501 my $solarenv = "";
502 my $sol_tmp;
503 if ( $ENV{'SOLARENV'} ) { $solarenv = $ENV{'SOLARENV'}; }
505 $infoline = "Environment variable SOLARENV: $solarenv\n";
506 push(@installer::globals::globallogfileinfo, $infoline);
508 if ( $ENV{'SOL_TMP'} )
510 $sol_tmp = $ENV{'SOL_TMP'};
511 $infoline = "Environment variable SOL_TMP: $sol_tmp\n";
512 } else {
513 $infoline = "Environment variable SOL_TMP not set\n";
515 push(@installer::globals::globallogfileinfo, $infoline);
517 if ( defined $sol_tmp && ( $solarenv =~ /^\s*\Q$sol_tmp\E/ ))
519 $infoline = "Content of SOLARENV starts with the content of SOL_TMP\: Local environment -\> No Updatepack\n";
520 push(@installer::globals::globallogfileinfo, $infoline);
522 else
524 $infoline = "Content of SOLARENV does not start with the content of SOL_TMP: No local environment\n";
525 push(@installer::globals::globallogfileinfo, $infoline);
527 $installer::globals::updatepack = 1; # That's it
530 # Additional logging information for the temporary ship directory
532 if ( -d $installer::globals::shiptestdirectory )
534 $infoline = "Ship test directory $installer::globals::shiptestdirectory still exists. Trying removal later again.\n";
535 push(@installer::globals::globallogfileinfo, $infoline);
537 else
539 $infoline = "Ship test directory $installer::globals::shiptestdirectory was successfully removed.\n";
540 push(@installer::globals::globallogfileinfo, $infoline);
543 else
545 $infoline = "No write access on Ship drive\n";
546 push(@installer::globals::globallogfileinfo, $infoline);
547 $infoline = "Failed to create directory $directory\n";
548 push(@installer::globals::globallogfileinfo, $infoline);
549 if ( defined $ENV{'BSCLIENT'} && ( uc $ENV{'BSCLIENT'} eq 'TRUE' ) ) {
550 installer::exiter::exit_program("ERROR: No write access to SHIPDRIVE allthough BSCLIENT is set.", "check_updatepack");
554 else
556 $infoline = "Ship drive not found: No updatepack\n";
557 push(@installer::globals::globallogfileinfo, $infoline);
560 else
562 $infoline = "Environment variable SHIPDRIVE not set: No updatepack\n";
563 push(@installer::globals::globallogfileinfo, $infoline);
566 else
568 $infoline = "Environment variable CWS_WORK_STAMP defined: No updatepack\n";
569 push(@installer::globals::globallogfileinfo, $infoline);
573 if ( $installer::globals::updatepack ) { $infoline = "Setting updatepack true\n\n"; }
574 else { $infoline = "\nNo updatepack\n"; }
575 push(@installer::globals::globallogfileinfo, $infoline);
579 #############################################################
580 # Reading the Windows list file for language encodings
581 #############################################################
583 sub read_encodinglist
585 my ($patharrayref) = @_;
587 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$installer::globals::encodinglistname, $patharrayref , 0);
589 if ( $$fileref eq "" ) { installer::exiter::exit_program("ERROR: Did not find Windows encoding list $installer::globals::encodinglistname!", "read_encodinglist"); }
591 my $infoline = "Found encoding file: $$fileref\n";
592 push(@installer::globals::globallogfileinfo, $infoline);
594 my $encodinglist = installer::files::read_file($$fileref);
596 my %msiencoding = ();
597 my %msilanguage = ();
599 # Controlling the encoding list
601 for ( my $i = 0; $i <= $#{$encodinglist}; $i++ )
603 my $line = ${$encodinglist}[$i];
605 if ( $line =~ /^\s*\#/ ) { next; } # this is a comment line
607 if ( $line =~ /^(.*?)(\#.*)$/ ) { $line = $1; } # removing comments after "#"
609 if ( $line =~ /^\s*([\w-]+)\s*(\d+)\s*(\d+)\s*$/ )
611 my $onelanguage = $1;
612 my $codepage = $2;
613 my $windowslanguage = $3;
615 $msiencoding{$onelanguage} = $codepage;
616 $msilanguage{$onelanguage} = $windowslanguage;
618 else
620 installer::exiter::exit_program("ERROR: Wrong syntax in Windows encoding list $installer::globals::encodinglistname : en-US 1252 1033 !", "read_encodinglist");
624 $installer::globals::msiencoding = \%msiencoding;
625 $installer::globals::msilanguage = \%msilanguage;
627 # my $key;
628 # foreach $key (keys %{$installer::globals::msiencoding}) { print "A Key: $key : Value: $installer::globals::msiencoding->{$key}\n"; }
629 # foreach $key (keys %{$installer::globals::msilanguage}) { print "B Key: $key : Value: $installer::globals::msilanguage->{$key}\n"; }
633 #############################################################
634 # Only for Windows and Linux (RPM)there is currently
635 # a reliable mechanism to register extensions during
636 # installation process. Therefore it is for all other
637 # platforms forbidden to install oxt files into that
638 # directory, in which they are searched for registration.
639 #############################################################
641 sub check_oxtfiles
643 my ( $filesarray ) = @_;
645 for ( my $i = 0; $i <= $#{$filesarray}; $i++ )
647 my $onefile = ${$filesarray}[$i];
649 if (( $onefile->{'Name'} ) && ( $onefile->{'Dir'} ))
651 if (( $onefile->{'Name'} =~ /\.oxt\s*$/ ) && ( $onefile->{'Dir'} eq $installer::globals::extensioninstalldir ))
653 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 WNT\" and \"\#ifdef LINUX\" in scp.", "check_oxtfiles");
659 #############################################################
660 # Check if Java is available to create xpd installer
661 #############################################################
663 sub check_java_for_xpd
665 my ( $allvariables ) = @_;
667 if ( ! $installer::globals::solarjavaset ) { $allvariables->{'XPDINSTALLER'} = 0; }
670 ####################################################################
671 # Setting global variable "$installer::globals::addchildprojects"
672 ####################################################################
674 sub set_addchildprojects
676 my ($allvariables) = @_;
678 if (( $allvariables->{'JAVAPRODUCT'} ) ||
679 ( $allvariables->{'ADAPRODUCT'} ) ||
680 ( $allvariables->{'UREPRODUCT'} ) ||
681 ( $allvariables->{'ADDREQUIREDPACKAGES'} )) { $installer::globals::addchildprojects = 1; }
683 if ( $installer::globals::patch )
685 $installer::globals::addchildprojects = 0; # no child projects for patches
688 my $infoline = "Value of \$installer::globals::addchildprojects: $installer::globals::addchildprojects\n";
689 push( @installer::globals::globallogfileinfo, $infoline);
692 ####################################################################
693 # Setting global variable "$installer::globals::addjavainstaller"
694 ####################################################################
696 sub set_addjavainstaller
698 my ($allvariables) = @_;
700 if ( $allvariables->{'JAVAINSTALLER'} ) { $installer::globals::addjavainstaller = 1; }
702 if ( $installer::globals::patch ) { $installer::globals::addjavainstaller = 0; }
703 if ( $installer::globals::languagepack ) { $installer::globals::addjavainstaller = 0; }
704 if ( $allvariableshashref->{'XPDINSTALLER'} ) { $installer::globals::addjavainstaller = 0; }
706 my $infoline = "Value of \$installer::globals::addjavainstaller: $installer::globals::addjavainstaller\n";
707 push( @installer::globals::globallogfileinfo, $infoline);
710 #######################################################################
711 # Setting global variable "$installer::globals::addsystemintegration"
712 #######################################################################
714 sub set_addsystemintegration
716 my ($allvariables) = @_;
718 if ( $allvariables->{'ADDSYSTEMINTEGRATION'} ) { $installer::globals::addsystemintegration = 1; }
720 if ( $installer::globals::patch ) { $installer::globals::addsystemintegration = 0; }
721 if ( $installer::globals::languagepack ) { $installer::globals::addsystemintegration = 0; }
722 if ( $installer::globals::packageformat eq "native" ) { $installer::globals::addsystemintegration = 0; }
724 my $infoline = "Value of \$installer::globals::addsystemintegration: $installer::globals::addsystemintegration\n";
725 push( @installer::globals::globallogfileinfo, $infoline);