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