1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: remover.pm,v $
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
::downloadsigner
;
34 use installer
::exiter
;
36 use installer
::globals
;
37 use installer
::logger
;
38 use installer
::pathanalyzer
;
40 ############################################
41 # Parameter Operations
42 ############################################
47 --------------------------------------------------------------------------------
49 The following parameter are needed:
50 -d: Full path to the file containing the follow-me info or to a directory
51 containing the follow-me info files. In the latter case, all follow-me
52 info files are evaluated. If a directory is used, the successfully used
53 follow-me info files are renamed using a string "success". Files with
54 this string are ignored in repeated processes using "-d" with a
57 The following parameter are optional:
58 -nodownload: Only signing, no creation of download sets (Windows only)
59 -useminor: Important for installation sets, created without minor set
60 -writetotemp: Necessary, if you do not want to write into solver
61 This can be caused by missing privileges (Windows only)
62 -internalcabinet: Not only the cabinet files are signed, but also all
63 files included in the cabinet files (Windows only).
65 -sign: Uses signing mechanism to sign installation sets
66 If \"-sign\" is set, the following two parameter are required:
67 -pfx: Full path to the pfx file
68 -pw: Full path to the file, containing the pfx password.
72 Specifying an installation set (with "-d"):
74 perl make_download.pl -d <followmeinfofilename>
76 perl make_download.pl -d <followmeinfofilename>
79 -pw <passwordfilename>
81 or without specifying an installation set:
83 perl make_download.pl -d <followmedirectory>
86 -pw <passwordfilename>
87 --------------------------------------------------------------------------------
92 #####################################
94 #####################################
98 # installer::logger::print_message("Checking parameter");
100 while ( $#ARGV >= 0 )
102 my $param = shift(@ARGV);
104 if ($param eq "-d") { $installer::globals
::followmeinfofilename
= shift(@ARGV); }
105 elsif ($param eq "-pw") { $installer::globals
::pwfile
= shift(@ARGV); }
106 elsif ($param eq "-pfx") { $installer::globals
::pfxfile
= shift(@ARGV); }
107 elsif ($param eq "-sign") { $installer::globals
::dosign
= 1; }
108 elsif ($param eq "-nodownload") { $installer::globals
::nodownload
= 1; }
109 elsif ($param eq "-writetotemp") { $installer::globals
::writetotemp
= 1; }
110 elsif ($param eq "-useminor") { $installer::globals
::useminor
= 1; }
111 elsif ($param eq "-internalcabinet") { $installer::globals
::internal_cabinet_signing
= 1; }
114 installer
::logger
::print_error
( "unknown parameter: $param" );
121 #####################################
122 # Controlling required parameter
123 #####################################
127 if ( $installer::globals
::followmeinfofilename
eq "" )
129 installer
::logger
::print_error
( "Error: Required parameter is missing: -d\n" );
134 if ( $installer::globals
::dosign
)
136 # -pfx and -pw have to be set
137 if ( $installer::globals
::pfxfile
eq "" )
139 installer
::logger
::print_error
( "Error: If \"-sign\" is set, a pfx file has to be specified: -pfx\n" );
144 # -pfx and -pw have to be set
145 if ( $installer::globals
::pwfile
eq "" )
147 installer
::logger
::print_error
( "Error: If \"-sign\" is set, a password file has to be specified: -pw\n" );
152 # and both files have to exist
153 if ( ! -f
$installer::globals
::pfxfile
)
155 installer
::logger
::print_error
( "Error: pfx file \"$installer::globals::pfxfile\" does not exist.\n" );
160 if ( ! -f
$installer::globals
::pwfile
)
162 installer
::logger
::print_error
( "Error: Password file \"$installer::globals::pwfile\" does not exist (-pw).\n" );
169 #############################################
170 # Setting the temporary path for the download
171 # and signing process
172 #############################################
177 my $pid = $$; # process id
178 my $time = time(); # time
179 my $helperdir = "unpackdir_" . $pid . $time;
181 if (( $ENV{'TMP'} ) || ( $ENV{'TEMP'} ))
183 if ( $ENV{'TMP'} ) { $temppath = $ENV{'TMP'}; }
184 elsif ( $ENV{'TEMP'} ) { $temppath = $ENV{'TEMP'}; }
185 $temppath =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
186 $temppath = $temppath . $installer::globals
::separator
. $helperdir;
188 if( $^O
=~ /cygwin/i )
190 $temppath = qx{cygpath
-w
"$temppath"};
191 $temppath =~ s/\\/\//g
;
192 $temppath =~ s/\s*$//g;
195 installer
::systemactions
::create_directory_structure
($temppath);
199 installer
::logger
::print_error
( "Error: TMP and TEMP not defined. This is required for this process.\n" );
204 installer
::logger
::print_message
( "\n... using output path: $temppath ...\n" );
206 push(@installer::globals
::removedirs
, $temppath);
211 #############################################
212 # Setting output pathes to temp directory
214 # unpackpath and the loggingdir
215 #############################################
217 sub set_output_pathes_to_temp
219 my ($followmeinfohash, $temppath) = @_;
221 $followmeinfohash->{'loggingdir'} = $temppath . $installer::globals
::separator
;
222 $installer::globals
::unpackpath
= $temppath;
225 #############################################
226 # Setting the minor into the pathes. This is
227 # required, if the original installation set
228 # was created without minor
229 # Value is always saved in
230 # $installer::globals::lastminor
231 # which is saved in the follow_me file
232 #############################################
234 sub set_minor_into_pathes
236 my ($followmeinfohash, $temppath) = @_;
238 installer
::logger
::print_message
( "\n... forcing into minor: $installer::globals::lastminor ...\n" );
240 my @pathnames = ("bin", "doc", "inc", "lib", "pck", "res", "xml");
241 my $sourcename = "src";
242 my $srcpath = $installer::globals
::separator
. $sourcename . $installer::globals
::separator
;
244 if ( $installer::globals
::minor
ne "" )
246 installer
::logger
::print_message
( "\n... already defined minor: $installer::globals::minor -> ignoring parameter \"-useminor\" ...\n" );
251 # $contenthash{'installlogdir'}
252 # $contenthash{'includepatharray'}
253 # $installer::globals::unpackpath
254 # $installer::globals::idttemplatepath
255 # $installer::globals::idtlanguagepath
257 installer
::logger
::include_header_into_logfile
("Changing saved pathes to add the minor");
258 my $infoline = "Old pathes:\n";
259 push( @installer::globals
::logfileinfo
, $infoline);
260 $infoline = "\$followmeinfohash->{'installlogdir'}: $followmeinfohash->{'installlogdir'}\n";
261 push( @installer::globals
::logfileinfo
, $infoline);
262 $infoline = "\$installer::globals::unpackpath: $installer::globals::unpackpath\n";
263 push( @installer::globals
::logfileinfo
, $infoline);
264 $infoline = "\$installer::globals::idttemplatepath: $installer::globals::idttemplatepath\n";
265 push( @installer::globals
::logfileinfo
, $infoline);
266 $infoline = "\$installer::globals::idtlanguagepath: $installer::globals::idtlanguagepath\n";
267 push( @installer::globals
::logfileinfo
, $infoline);
268 $infoline = "Include pathes:\n";
269 push( @installer::globals
::logfileinfo
, $infoline);
270 foreach my $path ( @
{$followmeinfohash->{'includepatharray'}} ) { push( @installer::globals
::logfileinfo
, $path); }
272 foreach $onepath ( @pathnames )
274 my $oldvalue = $installer::globals
::separator
. $onepath . $installer::globals
::separator
;
275 my $newvalue = $installer::globals
::separator
. $onepath . "\." . $installer::globals
::lastminor
. $installer::globals
::separator
;
277 if (( $followmeinfohash->{'installlogdir'} =~ /\Q$oldvalue\E/ ) && ( ! ( $followmeinfohash->{'installlogdir'} =~ /\Q$srcpath\E/ ))) { $followmeinfohash->{'installlogdir'} =~ s/\Q$oldvalue\E/$newvalue/; }
278 if (( $installer::globals
::unpackpath
=~ /\Q$oldvalue\E/ ) && ( ! ( $installer::globals
::unpackpath
=~ /\Q$srcpath\E/ ))) { $installer::globals
::unpackpath
=~ s/\Q$oldvalue\E/$newvalue/; }
279 if (( $installer::globals
::idttemplatepath
=~ /\Q$oldvalue\E/ ) && ( ! ( $installer::globals
::idttemplatepath
=~ /\Q$srcpath\E/ ))) { $installer::globals
::idttemplatepath
=~ s/\Q$oldvalue\E/$newvalue/; }
280 if (( $installer::globals
::idtlanguagepath
=~ /\Q$oldvalue\E/ ) && ( ! ( $installer::globals
::idtlanguagepath
=~ /\Q$srcpath\E/ ))) { $installer::globals
::idtlanguagepath
=~ s/\Q$oldvalue\E/$newvalue/; }
281 foreach my $path ( @
{$followmeinfohash->{'includepatharray'}} ) { if (( $path =~ /\Q$oldvalue\E/ ) && ( ! ( $path =~ /\Q$srcpath\E/ ))) { $path =~ s/\Q$oldvalue\E/$newvalue/; } }
283 # Checking for the end of the path
284 $oldvalue = $installer::globals
::separator
. $onepath;
285 $newvalue = $installer::globals
::separator
. $onepath . "\." . $installer::globals
::lastminor
;
287 if (( $followmeinfohash->{'installlogdir'} =~ /\Q$oldvalue\E\s*$/ ) && ( ! ( $followmeinfohash->{'installlogdir'} =~ /\Q$srcpath\E/ ))) { $followmeinfohash->{'installlogdir'} =~ s/\Q$oldvalue\E\s*$/$newvalue/; }
288 if (( $installer::globals
::unpackpath
=~ /\Q$oldvalue\E\s*$/ ) && ( ! ( $installer::globals
::unpackpath
=~ /\Q$srcpath\E/ ))) { $installer::globals
::unpackpath
=~ s/\Q$oldvalue\E\s*$/$newvalue/; }
289 if (( $installer::globals
::idttemplatepath
=~ /\Q$oldvalue\E\s*$/ ) && ( ! ( $installer::globals
::idttemplatepath
=~ /\Q$srcpath\E/ ))) { $installer::globals
::idttemplatepath
=~ s/\Q$oldvalue\E\s*$/$newvalue/; }
290 if (( $installer::globals
::idtlanguagepath
=~ /\Q$oldvalue\E\s*$/ ) && ( ! ( $installer::globals
::idtlanguagepath
=~ /\Q$srcpath\E/ ))) { $installer::globals
::idtlanguagepath
=~ s/\Q$oldvalue\E\s*$/$newvalue/; }
291 foreach my $path ( @
{$followmeinfohash->{'includepatharray'}} )
293 if (( $path =~ /\Q$oldvalue\E\s*$/ ) && ( ! ( $path =~ /\Q$srcpath\E/ )))
295 $path =~ s/\Q$oldvalue\E\s*$/$newvalue/;
296 $path = $path . "\n";
301 # And now can follow the replacement for the source path "src". Subdirs like "bin" in the source tree
302 # must not get the minor. This is instead "src.m9/instsetoo_native/common.pro/bin/..."
303 # Directory "src" can never be the end of the path
305 my $newsrcpath = $installer::globals
::separator
. $sourcename . "\." . $installer::globals
::lastminor
. $installer::globals
::separator
;
307 if ( $followmeinfohash->{'installlogdir'} =~ /\Q$srcpath\E/ ) { $followmeinfohash->{'installlogdir'} =~ s/\Q$srcpath\E/$newsrcpath/; }
308 if ( $installer::globals
::unpackpath
=~ /\Q$srcpath\E/ ) { $installer::globals
::unpackpath
=~ s/\Q$srcpath\E/$newsrcpath/; }
309 if ( $installer::globals
::idttemplatepath
=~ /\Q$srcpath\E/ ) { $installer::globals
::idttemplatepath
=~ s/\Q$srcpath\E/$newsrcpath/; }
310 if ( $installer::globals
::idtlanguagepath
=~ /\Q$srcpath\E/ ) { $installer::globals
::idtlanguagepath
=~ s/\Q$srcpath\E/$newsrcpath/; }
311 foreach my $path ( @
{$followmeinfohash->{'includepatharray'}} ) { if ( $path =~ /\Q$srcpath\E/ ) { $path =~ s/\Q$srcpath\E/$newsrcpath/; } }
313 $infoline = "\nNew pathes:\n";
314 push( @installer::globals
::logfileinfo
, $infoline);
315 $infoline = "\$followmeinfohash->{'installlogdir'}: $followmeinfohash->{'installlogdir'}\n";
316 push( @installer::globals
::logfileinfo
, $infoline);
317 $infoline = "\$installer::globals::unpackpath: $installer::globals::unpackpath\n";
318 push( @installer::globals
::logfileinfo
, $infoline);
319 $infoline = "\$installer::globals::idttemplatepath: $installer::globals::idttemplatepath\n";
320 push( @installer::globals
::logfileinfo
, $infoline);
321 $infoline = "\$installer::globals::idtlanguagepath: $installer::globals::idtlanguagepath\n";
322 push( @installer::globals
::logfileinfo
, $infoline);
323 $infoline = "Include pathes:\n";
324 push( @installer::globals
::logfileinfo
, $infoline);
325 foreach my $path ( @
{$followmeinfohash->{'includepatharray'}} ) { push( @installer::globals
::logfileinfo
, $path); }
328 #############################################
329 # Setting the name of the log file
330 #############################################
334 if ( $installer::globals
::dosign
) { $installer::globals
::logfilename
= "sign_and_download_" . $installer::globals
::logfilename
; }
335 else { $installer::globals
::logfilename
= "download_" . $installer::globals
::logfilename
; }
337 @installer::globals
::logfileinfo
= ();
340 #########################################################
341 # Checking, if this is a task in a cws or
342 # on the master. Simple check of naming schema:
343 # CWS: follow_me_DEV300_m40_de.log
344 # Master: follow_me_4_DEV300_m40_en-US.log
345 #########################################################
349 my ( $filename ) = @_;
353 if ( $filename =~ /follow_me_\d+_/ ) { $iscws = 0; }
354 # if ( $filename =~ /log_\d+_/ ) { $iscws = 0; }
359 #########################################################
360 # Reading a specific key from a follow-me file
361 #########################################################
363 sub get_property_from_file
365 my ($followmefile, $key) = @_;
369 my $filecontent = installer
::files
::read_file
($followmefile);
371 for ( my $i = 0; $i <= $#{$filecontent}; $i++ )
373 if ( ${$filecontent}[$i] =~ /^\s*\Q$key\E\s*\:\s*(.*?)\s*$/ )
383 #########################################################
384 # Publishing the content of the product list
385 #########################################################
387 sub publishproductlist
389 my ($infofilelist) = @_;
391 installer
::logger
::print_message
( "\n... found products: ...\n" );
393 for ( my $i = 0; $i <= $#{$infofilelist}; $i++ )
395 my $onefile = ${$infofilelist}[$i];
396 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$onefile);
397 installer
::logger
::print_message
( "...... $onefile ...\n" );
400 installer
::logger
::print_message
( "\n" );
403 #########################################################
404 # Filtering all files, that have correct minor
406 # Master: follow_me_4_DEV300_m40_en-US.log
407 #########################################################
409 sub filter_all_files_with_correct_settings
411 my ($allfollowmefiles) = @_;
420 if ( $ENV{'WORK_STAMP'} ) { $workstamp = $ENV{'WORK_STAMP'}; }
421 if ( $ENV{'UPDMINOR'} ) { $minor = $ENV{'UPDMINOR'}; }
423 if ( $minor eq "" ) { installer
::exiter
::exit_program
("ERROR: Environment variable \"UPDMINOR\" not set!", "filter_all_files_with_correct_settings"); }
424 if ( $workstamp eq "" ) { installer
::exiter
::exit_program
("ERROR: Environment variable \"WORK_STAMP\" not set!", "filter_all_files_with_correct_settings"); }
426 foreach my $onefile ( @
{$allfollowmefiles} )
428 if (( $onefile =~ /_\Q$minor\E_/i ) && ( $onefile =~ /_\Q$workstamp\E_/i ))
430 push(@allfiles, $onefile);
432 # also collecting maximum hash
434 if ( $onefile =~ /follow_me_(\d+)_\Q$workstamp\E_\Q$minor\E_([-\w]+)\.log\s*$/i )
439 if (( ! exists($maxhash{$lang})) || ( $maxhash{$lang} < $sequence )) { $maxhash{$lang} = $sequence; }
444 # second run, because of sequence numbers
446 foreach my $onefile ( @allfiles )
448 if ( $onefile =~ /follow_me_(\d+)_\Q$workstamp\E_\Q$minor\E_([-\w]+)\.log\s*$/i )
453 if ( $sequence == $maxhash{$lang} ) { push(@allfiles2, $onefile); }
457 return ( \
@allfiles2 );
460 #########################################################
461 # Creating a list of products, that need to be signed
462 # or for which download sets need to be created.
463 #########################################################
465 sub createproductlist
467 # If "-d" specifies an installation set, there is only one product
469 my @infofilelist = ();
470 my @infofilelist2 = ();
472 if ( -f
$installer::globals
::followmeinfofilename
)
474 push(@infofilelist, $installer::globals
::followmeinfofilename
);
475 # Saving info, that this is a file
476 $installer::globals
::followme_from_directory
= 0;
478 elsif ( -d
$installer::globals
::followmeinfofilename
)
480 installer
::logger
::print_message
( "\n... reading directory: $installer::globals::followmeinfofilename ...\n" );
481 $installer::globals
::followmeinfofilename
=~ s/$installer::globals::separator\s*$//;
482 my $allfollowmefiles = installer
::systemactions
::find_file_with_file_extension
("log", $installer::globals
::followmeinfofilename
);
484 if ( ! ( $#{$allfollowmefiles} > -1 ))
486 installer
::logger
::print_error
( "Error: Nothing to do! No follow-me file in directory \"$installer::globals::followmeinfofilename\"!.\n" );
491 # Saving info, that this is a directory
492 $installer::globals
::followme_from_directory
= 1;
494 # Collect all possible installation sets
495 # CWS: All installation sets
496 # Master: All installation sets with same major, minor and buildid. Additionally using the highest number.
498 my $iscws = check_cws_build
(${$allfollowmefiles}[0]);
502 # Simply read all follow-me files and check existence of installation sets
503 foreach my $onefile ( @
{$allfollowmefiles} )
505 my $fullfilename = $installer::globals
::followmeinfofilename
. $installer::globals
::separator
. $onefile;
506 my $installdir = get_property_from_file
($fullfilename, "finalinstalldir");
507 if (( $installdir ne "" ) && ( -d
$installdir )) { push(@infofilelist2, $fullfilename); }
512 $allfollowmefiles = filter_all_files_with_correct_settings
($allfollowmefiles);
514 foreach my $onefile ( @
{$allfollowmefiles} )
516 my $fullfilename = $installer::globals
::followmeinfofilename
. $installer::globals
::separator
. $onefile;
517 # Check, if installation set still exists
518 my $installdir = get_property_from_file
($fullfilename, "finalinstalldir");
519 if (( $installdir ne "" ) && ( -d
$installdir )) { push(@infofilelist2, $fullfilename); }
523 # Removing all files, starting with "follow_me_success_" in their names. This have already been used successfully.
525 foreach my $onefile ( @infofilelist2 )
527 if ( $onefile =~ /follow_me_success_/ ) { next; }
528 push(@infofilelist, $onefile);
531 # Checking, if there is content in the list
532 if ( ! ( $#infofilelist > -1 ))
534 installer
::logger
::print_error
( "Error: Nothing to do! No installation set found for follow-me files in directory \"$installer::globals::followmeinfofilename\"!.\n" );
541 installer
::logger
::print_error
( "Error: Nothing to do! \"$installer::globals::followmeinfofilename\" is no file and no directory (-d).\n" );
546 return \
@infofilelist;
549 #############################################
550 # Logging the content of the download hash
551 #############################################
553 sub logfollowmeinfohash
555 my ( $followmehash ) = @_;
557 print "\n*****************************************\n";
558 print "Content of follow-me info file:\n";
559 print "finalinstalldir: $followmehash->{'finalinstalldir'}\n";
560 print "downloadname: $followmehash->{'downloadname'}\n";
561 print "languagestring: $followmehash->{'languagestring'}\n";
562 foreach my $lang ( @
{$followmehash->{'languagesarray'}} ) { print "languagesarray: $lang\n"; }
563 foreach my $path ( @
{$followmehash->{'includepatharray'}} ) { print "includepatharray: $path"; }
564 foreach my $key ( sort keys %{$followmehash->{'allvariableshash'}} ) { print "allvariableshash: $key : $followmehash->{'allvariableshash'}->{$key}\n"; }
567 ########################################################################
568 # Renaming the follow me info file, if it was successfully used.
569 # This can only be done, if the parameter "-d" was used with a
570 # directory, not a name. In this case the repeated use of parameter
571 # "-d" with this directory has to ignore this already successfully
573 ########################################################################
575 sub rename_followme_infofile
577 my ( $filename ) = @_;
579 my $newfilename = $filename;
580 $newfilename =~ s/follow_me_/follow_me_success_/; # including "_success" after "follow_me"
582 if ( $filename ne $newfilename )
584 my $returnvalue = rename($filename, $newfilename);
585 if ( $returnvalue ) { installer
::logger
::print_message
( "\n... renamed file \"$filename\" to \"$newfilename\" ...\n" ); }