1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
|
#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# This file is part of OpenOffice.org.
#
# OpenOffice.org is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# only, as published by the Free Software Foundation.
#
# OpenOffice.org is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License version 3 for more details
# (a copy is included in the LICENSE file that accompanied this code).
#
# You should have received a copy of the GNU Lesser General Public License
# version 3 along with OpenOffice.org. If not, see
# <http://www.openoffice.org/license.html>
# for a copy of the LGPLv3 License.
#
#*************************************************************************
package installer::downloadsigner;
use installer::exiter;
use installer::files;
use installer::globals;
use installer::logger;
use installer::pathanalyzer;
############################################
# Parameter Operations
############################################
sub usage
{
print <<Ende;
--------------------------------------------------------------------------------
make_download V1.0
The following parameter are needed:
-d: Full path to the file containing the follow-me info or to a directory
containing the follow-me info files. In the latter case, all follow-me
info files are evaluated. If a directory is used, the successfully used
follow-me info files are renamed using a string "success". Files with
this string are ignored in repeated processes using "-d" with a
directory.
The following parameter are optional:
-nodownload: Only signing, no creation of download sets (Windows only)
-useminor: Important for installation sets, created without minor set
-writetotemp: Necessary, if you do not want to write into solver
This can be caused by missing privileges (Windows only)
-internalcabinet: Not only the cabinet files are signed, but also all
files included in the cabinet files (Windows only).
-sign: Uses signing mechanism to sign installation sets
If \"-sign\" is set, the following two parameter are required:
-pfx: Full path to the pfx file
-pw: Full path to the file, containing the pfx password.
Examples:
Specifying an installation set (with "-d"):
perl make_download.pl -d <followmeinfofilename>
perl make_download.pl -d <followmeinfofilename>
-sign
-pfx <pfxfilename>
-pw <passwordfilename>
or without specifying an installation set:
perl make_download.pl -d <followmedirectory>
-sign
-pfx <pfxfilename>
-pw <passwordfilename>
--------------------------------------------------------------------------------
Ende
exit(-1);
}
#####################################
# Reading parameter
#####################################
sub getparameter
{
while ( $#ARGV >= 0 )
{
my $param = shift(@ARGV);
if ($param eq "-d") { $installer::globals::followmeinfofilename = shift(@ARGV); }
elsif ($param eq "-pw") { $installer::globals::pwfile = shift(@ARGV); }
elsif ($param eq "-pfx") { $installer::globals::pfxfile = shift(@ARGV); }
elsif ($param eq "-sign") { $installer::globals::dosign = 1; }
elsif ($param eq "-nodownload") { $installer::globals::nodownload = 1; }
elsif ($param eq "-writetotemp") { $installer::globals::writetotemp = 1; }
elsif ($param eq "-useminor") { $installer::globals::useminor = 1; }
elsif ($param eq "-internalcabinet") { $installer::globals::internal_cabinet_signing = 1; }
else
{
installer::logger::print_error( "unknown parameter: $param" );
usage();
exit(-1);
}
}
}
#####################################
# Controlling required parameter
#####################################
sub checkparameter
{
if ( $installer::globals::followmeinfofilename eq "" )
{
installer::logger::print_error( "Error: Required parameter is missing: -d\n" );
usage();
exit(-1);
}
if ( $installer::globals::dosign )
{
# -pfx and -pw have to be set
if ( $installer::globals::pfxfile eq "" )
{
installer::logger::print_error( "Error: If \"-sign\" is set, a pfx file has to be specified: -pfx\n" );
usage();
exit(-1);
}
# -pfx and -pw have to be set
if ( $installer::globals::pwfile eq "" )
{
installer::logger::print_error( "Error: If \"-sign\" is set, a password file has to be specified: -pw\n" );
usage();
exit(-1);
}
# and both files have to exist
if ( ! -f $installer::globals::pfxfile )
{
installer::logger::print_error( "Error: pfx file \"$installer::globals::pfxfile\" does not exist.\n" );
usage();
exit(-1);
}
if ( ! -f $installer::globals::pwfile )
{
installer::logger::print_error( "Error: Password file \"$installer::globals::pwfile\" does not exist (-pw).\n" );
usage();
exit(-1);
}
}
}
#############################################
# Setting the temporary path for the download
# and signing process
#############################################
sub set_temp_path
{
my $temppath = "";
my $pid = $$; # process id
my $time = time(); # time
my $helperdir = "unpackdir_" . $pid . $time;
if (( $ENV{'TMP'} ) || ( $ENV{'TEMP'} ))
{
if ( $ENV{'TMP'} ) { $temppath = $ENV{'TMP'}; }
elsif ( $ENV{'TEMP'} ) { $temppath = $ENV{'TEMP'}; }
$temppath =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
$temppath = $temppath . $installer::globals::separator . $helperdir;
if( $^O =~ /cygwin/i )
{
$temppath = qx{cygpath -w "$temppath"};
$temppath =~ s/\\/\//g;
$temppath =~ s/\s*$//g;
}
installer::systemactions::create_directory_structure($temppath);
}
else
{
installer::logger::print_error( "Error: TMP and TEMP not defined. This is required for this process.\n" );
usage();
exit(-1);
}
installer::logger::print_message( "\n... using output path: $temppath ...\n" );
push(@installer::globals::removedirs, $temppath);
return $temppath;
}
#############################################
# Setting output pathes to temp directory
# This are the:
# unpackpath and the loggingdir
#############################################
sub set_output_pathes_to_temp
{
my ($followmeinfohash, $temppath) = @_;
$followmeinfohash->{'loggingdir'} = $temppath . $installer::globals::separator;
$installer::globals::unpackpath = $temppath;
}
#############################################
# Setting the minor into the pathes. This is
# required, if the original installation set
# was created without minor
# Value is always saved in
# $installer::globals::lastminor
# which is saved in the follow_me file
#############################################
sub set_minor_into_pathes
{
my ($followmeinfohash, $temppath) = @_;
installer::logger::print_message( "\n... forcing into minor: $installer::globals::lastminor ...\n" );
my @pathnames = ("bin", "doc", "inc", "lib", "pck", "res", "xml");
my $sourcename = "src";
my $srcpath = $installer::globals::separator . $sourcename . $installer::globals::separator;
if ( $installer::globals::minor ne "" )
{
installer::logger::print_message( "\n... already defined minor: $installer::globals::minor -> ignoring parameter \"-useminor\" ...\n" );
return;
}
# Affected pathes:
# $contenthash{'installlogdir'}
# $contenthash{'includepatharray'}
# $installer::globals::unpackpath
# $installer::globals::idttemplatepath
# $installer::globals::idtlanguagepath
installer::logger::include_header_into_logfile("Changing saved pathes to add the minor");
my $infoline = "Old pathes:\n";
push( @installer::globals::logfileinfo, $infoline);
$infoline = "\$followmeinfohash->{'installlogdir'}: $followmeinfohash->{'installlogdir'}\n";
push( @installer::globals::logfileinfo, $infoline);
$infoline = "\$installer::globals::unpackpath: $installer::globals::unpackpath\n";
push( @installer::globals::logfileinfo, $infoline);
$infoline = "\$installer::globals::idttemplatepath: $installer::globals::idttemplatepath\n";
push( @installer::globals::logfileinfo, $infoline);
$infoline = "\$installer::globals::idtlanguagepath: $installer::globals::idtlanguagepath\n";
push( @installer::globals::logfileinfo, $infoline);
$infoline = "Include pathes:\n";
push( @installer::globals::logfileinfo, $infoline);
foreach my $path ( @{$followmeinfohash->{'includepatharray'}} ) { push( @installer::globals::logfileinfo, $path); }
foreach $onepath ( @pathnames )
{
my $oldvalue = $installer::globals::separator . $onepath . $installer::globals::separator;
my $newvalue = $installer::globals::separator . $onepath . "\." . $installer::globals::lastminor . $installer::globals::separator;
if (( $followmeinfohash->{'installlogdir'} =~ /\Q$oldvalue\E/ ) && ( ! ( $followmeinfohash->{'installlogdir'} =~ /\Q$srcpath\E/ ))) { $followmeinfohash->{'installlogdir'} =~ s/\Q$oldvalue\E/$newvalue/; }
if (( $installer::globals::unpackpath =~ /\Q$oldvalue\E/ ) && ( ! ( $installer::globals::unpackpath =~ /\Q$srcpath\E/ ))) { $installer::globals::unpackpath =~ s/\Q$oldvalue\E/$newvalue/; }
if (( $installer::globals::idttemplatepath =~ /\Q$oldvalue\E/ ) && ( ! ( $installer::globals::idttemplatepath =~ /\Q$srcpath\E/ ))) { $installer::globals::idttemplatepath =~ s/\Q$oldvalue\E/$newvalue/; }
if (( $installer::globals::idtlanguagepath =~ /\Q$oldvalue\E/ ) && ( ! ( $installer::globals::idtlanguagepath =~ /\Q$srcpath\E/ ))) { $installer::globals::idtlanguagepath =~ s/\Q$oldvalue\E/$newvalue/; }
foreach my $path ( @{$followmeinfohash->{'includepatharray'}} ) { if (( $path =~ /\Q$oldvalue\E/ ) && ( ! ( $path =~ /\Q$srcpath\E/ ))) { $path =~ s/\Q$oldvalue\E/$newvalue/; } }
# Checking for the end of the path
$oldvalue = $installer::globals::separator . $onepath;
$newvalue = $installer::globals::separator . $onepath . "\." . $installer::globals::lastminor;
if (( $followmeinfohash->{'installlogdir'} =~ /\Q$oldvalue\E\s*$/ ) && ( ! ( $followmeinfohash->{'installlogdir'} =~ /\Q$srcpath\E/ ))) { $followmeinfohash->{'installlogdir'} =~ s/\Q$oldvalue\E\s*$/$newvalue/; }
if (( $installer::globals::unpackpath =~ /\Q$oldvalue\E\s*$/ ) && ( ! ( $installer::globals::unpackpath =~ /\Q$srcpath\E/ ))) { $installer::globals::unpackpath =~ s/\Q$oldvalue\E\s*$/$newvalue/; }
if (( $installer::globals::idttemplatepath =~ /\Q$oldvalue\E\s*$/ ) && ( ! ( $installer::globals::idttemplatepath =~ /\Q$srcpath\E/ ))) { $installer::globals::idttemplatepath =~ s/\Q$oldvalue\E\s*$/$newvalue/; }
if (( $installer::globals::idtlanguagepath =~ /\Q$oldvalue\E\s*$/ ) && ( ! ( $installer::globals::idtlanguagepath =~ /\Q$srcpath\E/ ))) { $installer::globals::idtlanguagepath =~ s/\Q$oldvalue\E\s*$/$newvalue/; }
foreach my $path ( @{$followmeinfohash->{'includepatharray'}} )
{
if (( $path =~ /\Q$oldvalue\E\s*$/ ) && ( ! ( $path =~ /\Q$srcpath\E/ )))
{
$path =~ s/\Q$oldvalue\E\s*$/$newvalue/;
$path = $path . "\n";
}
}
}
# And now can follow the replacement for the source path "src". Subdirs like "bin" in the source tree
# must not get the minor. This is instead "src.m9/instsetoo_native/common.pro/bin/..."
# Directory "src" can never be the end of the path
my $newsrcpath = $installer::globals::separator . $sourcename . "\." . $installer::globals::lastminor . $installer::globals::separator;
if ( $followmeinfohash->{'installlogdir'} =~ /\Q$srcpath\E/ ) { $followmeinfohash->{'installlogdir'} =~ s/\Q$srcpath\E/$newsrcpath/; }
if ( $installer::globals::unpackpath =~ /\Q$srcpath\E/ ) { $installer::globals::unpackpath =~ s/\Q$srcpath\E/$newsrcpath/; }
if ( $installer::globals::idttemplatepath =~ /\Q$srcpath\E/ ) { $installer::globals::idttemplatepath =~ s/\Q$srcpath\E/$newsrcpath/; }
if ( $installer::globals::idtlanguagepath =~ /\Q$srcpath\E/ ) { $installer::globals::idtlanguagepath =~ s/\Q$srcpath\E/$newsrcpath/; }
foreach my $path ( @{$followmeinfohash->{'includepatharray'}} ) { if ( $path =~ /\Q$srcpath\E/ ) { $path =~ s/\Q$srcpath\E/$newsrcpath/; } }
$infoline = "\nNew pathes:\n";
push( @installer::globals::logfileinfo, $infoline);
$infoline = "\$followmeinfohash->{'installlogdir'}: $followmeinfohash->{'installlogdir'}\n";
push( @installer::globals::logfileinfo, $infoline);
$infoline = "\$installer::globals::unpackpath: $installer::globals::unpackpath\n";
push( @installer::globals::logfileinfo, $infoline);
$infoline = "\$installer::globals::idttemplatepath: $installer::globals::idttemplatepath\n";
push( @installer::globals::logfileinfo, $infoline);
$infoline = "\$installer::globals::idtlanguagepath: $installer::globals::idtlanguagepath\n";
push( @installer::globals::logfileinfo, $infoline);
$infoline = "Include pathes:\n";
push( @installer::globals::logfileinfo, $infoline);
foreach my $path ( @{$followmeinfohash->{'includepatharray'}} ) { push( @installer::globals::logfileinfo, $path); }
}
#############################################
# Setting the name of the log file
#############################################
sub setlogfilename
{
if ( $installer::globals::dosign ) { $installer::globals::logfilename = "sign_and_download_" . $installer::globals::logfilename; }
else { $installer::globals::logfilename = "download_" . $installer::globals::logfilename; }
# reset the log file
@installer::globals::logfileinfo = ();
}
#########################################################
# Checking, if this is a task in a cws or
# on the master. Simple check of naming schema:
# CWS: follow_me_DEV300_m40_de.log
# Master: follow_me_4_DEV300_m40_en-US.log
#########################################################
sub check_cws_build
{
my ( $filename ) = @_;
my $iscws = 1;
if ( $filename =~ /follow_me_\d+_/ ) { $iscws = 0; }
return $iscws;
}
#########################################################
# Reading a specific key from a follow-me file
#########################################################
sub get_property_from_file
{
my ($followmefile, $key) = @_;
my $value = "";
my $filecontent = installer::files::read_file($followmefile);
for ( my $i = 0; $i <= $#{$filecontent}; $i++ )
{
if ( ${$filecontent}[$i] =~ /^\s*\Q$key\E\s*\:\s*(.*?)\s*$/ )
{
$value = $1;
last;
}
}
return $value;
}
#########################################################
# Publishing the content of the product list
#########################################################
sub publishproductlist
{
my ($infofilelist) = @_;
installer::logger::print_message( "\n... found products: ...\n" );
for ( my $i = 0; $i <= $#{$infofilelist}; $i++ )
{
my $onefile = ${$infofilelist}[$i];
installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$onefile);
installer::logger::print_message( "...... $onefile ...\n" );
}
installer::logger::print_message( "\n" );
}
#########################################################
# Filtering all files, that have correct minor
# and work stamp.
# Master: follow_me_4_DEV300_m40_en-US.log
#########################################################
sub filter_all_files_with_correct_settings
{
my ($allfollowmefiles) = @_;
my @allfiles = ();
my @allfiles2 = ();
my $maxhash = ();
my $minor = "";
my $workstamp = "";
if ( $ENV{'WORK_STAMP'} ) { $workstamp = $ENV{'WORK_STAMP'}; }
# This is broken, we don't want to support any UPDMINOR
# complexities in LibreOffice. (Or do we?) This needs updating if
# we want to actually use this file for signing.
if ( $ENV{'UPDMINOR'} ) { $minor = $ENV{'UPDMINOR'}; }
if ( $minor eq "" ) { installer::exiter::exit_program("ERROR: Environment variable \"UPDMINOR\" not set!", "filter_all_files_with_correct_settings"); }
if ( $workstamp eq "" ) { installer::exiter::exit_program("ERROR: Environment variable \"WORK_STAMP\" not set!", "filter_all_files_with_correct_settings"); }
foreach my $onefile ( @{$allfollowmefiles} )
{
if (( $onefile =~ /_\Q$minor\E_/i ) && ( $onefile =~ /_\Q$workstamp\E_/i ))
{
push(@allfiles, $onefile);
# also collecting maximum hash
if ( $onefile =~ /follow_me_(\d+)_\Q$workstamp\E_\Q$minor\E_([-\w]+)\.log\s*$/i )
{
my $sequence = $1;
my $lang = $2;
if (( ! exists($maxhash{$lang})) || ( $maxhash{$lang} < $sequence )) { $maxhash{$lang} = $sequence; }
}
}
}
# second run, because of sequence numbers
foreach my $onefile ( @allfiles )
{
if ( $onefile =~ /follow_me_(\d+)_\Q$workstamp\E_\Q$minor\E_([-\w]+)\.log\s*$/i )
{
my $sequence = $1;
my $lang = $2;
if ( $sequence == $maxhash{$lang} ) { push(@allfiles2, $onefile); }
}
}
return ( \@allfiles2 );
}
#########################################################
# Creating a list of products, that need to be signed
# or for which download sets need to be created.
#########################################################
sub createproductlist
{
# If "-d" specifies an installation set, there is only one product
my @infofilelist = ();
my @infofilelist2 = ();
if ( -f $installer::globals::followmeinfofilename )
{
push(@infofilelist, $installer::globals::followmeinfofilename);
# Saving info, that this is a file
$installer::globals::followme_from_directory = 0;
}
elsif ( -d $installer::globals::followmeinfofilename )
{
installer::logger::print_message( "\n... reading directory: $installer::globals::followmeinfofilename ...\n" );
$installer::globals::followmeinfofilename =~ s/$installer::globals::separator\s*$//;
my $allfollowmefiles = installer::systemactions::find_file_with_file_extension("log", $installer::globals::followmeinfofilename);
if ( ! ( $#{$allfollowmefiles} > -1 ))
{
installer::logger::print_error( "Error: Nothing to do! No follow-me file in directory \"$installer::globals::followmeinfofilename\"!.\n" );
usage();
exit(-1);
}
# Saving info, that this is a directory
$installer::globals::followme_from_directory = 1;
# Collect all possible installation sets
# CWS: All installation sets
# Master: All installation sets with same major, minor and buildid. Additionally using the highest number.
my $iscws = check_cws_build(${$allfollowmefiles}[0]);
if ( $iscws )
{
# Simply read all follow-me files and check existence of installation sets
foreach my $onefile ( @{$allfollowmefiles} )
{
my $fullfilename = $installer::globals::followmeinfofilename . $installer::globals::separator . $onefile;
my $installdir = get_property_from_file($fullfilename, "finalinstalldir");
if (( $installdir ne "" ) && ( -d $installdir )) { push(@infofilelist2, $fullfilename); }
}
}
else
{
$allfollowmefiles = filter_all_files_with_correct_settings($allfollowmefiles);
foreach my $onefile ( @{$allfollowmefiles} )
{
my $fullfilename = $installer::globals::followmeinfofilename . $installer::globals::separator . $onefile;
# Check, if installation set still exists
my $installdir = get_property_from_file($fullfilename, "finalinstalldir");
if (( $installdir ne "" ) && ( -d $installdir )) { push(@infofilelist2, $fullfilename); }
}
}
# Removing all files, starting with "follow_me_success_" in their names. This have already been used successfully.
foreach my $onefile ( @infofilelist2 )
{
if ( $onefile =~ /follow_me_success_/ ) { next; }
push(@infofilelist, $onefile);
}
# Checking, if there is content in the list
if ( ! ( $#infofilelist > -1 ))
{
installer::logger::print_error( "Error: Nothing to do! No installation set found for follow-me files in directory \"$installer::globals::followmeinfofilename\"!.\n" );
usage();
exit(-1);
}
}
else
{
installer::logger::print_error( "Error: Nothing to do! \"$installer::globals::followmeinfofilename\" is no file and no directory (-d).\n" );
usage();
exit(-1);
}
return \@infofilelist;
}
########################################################################
# Renaming the follow me info file, if it was successfully used.
# This can only be done, if the parameter "-d" was used with a
# directory, not a name. In this case the repeated use of parameter
# "-d" with this directory has to ignore this already successfully
# used file.
########################################################################
sub rename_followme_infofile
{
my ( $filename ) = @_;
my $newfilename = $filename;
$newfilename =~ s/follow_me_/follow_me_success_/; # including "_success" after "follow_me"
if ( $filename ne $newfilename )
{
my $returnvalue = rename($filename, $newfilename);
if ( $returnvalue ) { installer::logger::print_message( "\n... renamed file \"$filename\" to \"$newfilename\" ...\n" ); }
}
}
1;
|