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