Subversion Repositories DevTools

Rev

Rev 1594 | Rev 1598 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1544 dpurdie 1
########################################################################
2
# Copyright (C) 2006 ERG Limited, All rights reserved
1530 dpurdie 3
#
4
# Program Name        : deploylib.pm
5
#
6
# Program Type        : Perl Module (.pm)
7
#
8
# Original Author(s)  : V.Chatzimichail(vasilic)
9
#
10
# Description / Purpose:
11
#      Deploylib is a set of high-level functions written in Perl (for portability) 
12
#      that allow a user to quickly setup a deployment configuration and produce a 
13
#      deliverable package.
14
#
1544 dpurdie 15
# Description:
16
#
17
#
18
#......................................................................#
1530 dpurdie 19
 
1544 dpurdie 20
require 5.6.1;
1530 dpurdie 21
 
22
#------------------------------------------------------------------------------
23
# Package definition
24
#------------------------------------------------------------------------------
25
package deploylib;
26
 
27
#------------------------------------------------------------------------------
28
# Pragmas
29
#------------------------------------------------------------------------------
30
use strict;
31
use Getopt::Std;
32
use File::Copy;
33
use File::Find;
34
use File::Basename;
35
use File::Path;
36
use Cwd;
37
use Carp;
38
use DBI;
39
use DeployUtils::RmPkgInfo;
1532 dpurdie 40
use BuildConfig;
1530 dpurdie 41
use Exporter();
1534 dpurdie 42
 
1530 dpurdie 43
use ArrayHashUtils;
1592 dpurdie 44
use JatsEnv;
1534 dpurdie 45
use JatsError;
46
use JatsSystem;
1530 dpurdie 47
 
1538 dpurdie 48
#
49
#   The LWP is a part of the Active State Perl, but not the solaris perl
50
#   If the user has not read the installation doco that insists we use
51
#   ActiveState perl...
52
#
53
my $UserAgentAvailable = eval "require LWP::UserAgent";
54
 
55
 
1530 dpurdie 56
#-------------------------------------------------------------------------------
57
#   Export variables and function into the users name space
58
#-------------------------------------------------------------------------------
59
our @ISA    = qw(Exporter);
60
our @EXPORT = qw(
61
                    &Init
62
                    &setPkgDescription
63
                    &setPkgName
64
                    &setErgAfcBaseDir
65
                    &setPkgOverview
66
                    &addInstallshieldFiles
67
                    &installAllDpkgArchivePkgFiles
68
                    &installAllDpkgArchivePkgFiles2
69
                    &installAllDpkgArchiveDevcdFiles
70
                    &installAllDpkgArchiveJspFiles
71
                    &installAllDpkgArchiveFiles
72
                    &installAllDpkgArchiveAcHtmlFiles
73
                    &installAllDpkgArchiveInfoFilesFiles
74
                    &installAllDpkgArchiveSqlFiles
75
                    &installAllDpkgArchiveWarFiles
76
                    &installAllDpkgArchiveJarFiles
77
                    &installAllDpkgArchiveEtcFiles
78
                    &installAllDpkgArchiveScriptsFiles
79
                    &installAllDpkgArchiveIncludeFiles
80
                    &installAllDpkgArchiveDocFiles
81
                    &installDpkgArchiveFile
82
                    &installDpkgArchiveAcHtmlFile
83
                    &installDpkgArchiveRptFile
84
                    &installDpkgArchiveRoxFile
85
                    &installDpkgArchiveDatFile
86
                    &installDpkgArchiveThxFile
87
                    &installDpkgArchiveMugFile
88
                    &installDpkgArchiveInfoFilesFile
89
                    &installDpkgArchiveSqlFile
90
                    &installDpkgArchiveWarFile
91
                    &installDpkgArchiveJarFile
92
                    &installDpkgArchiveSarFile
93
                    &installDpkgArchiveEtcFile
94
                    &installDpkgArchiveScriptsFile
95
                    &installDpkgArchiveIncludeFile
96
                    &installDpkgArchiveDocFile
97
                    &installDpkgArchiveBinFile
98
                    &installDpkgArchiveLibFile
99
                    &installPkgAddConfigFile
100
                    &installPkgAddSystemClassFile
1540 dpurdie 101
                    &installDpkgArchivePkgRaw
1530 dpurdie 102
                    &updatePrototypeFileAddItem
103
                    &updatePrototypeFileAddItem2
104
                    &addPath2Prototype
105
                    &createAfcRcScriptLink
106
                    &createAfcRcScriptLink2
107
                    &installAllDpkgArchiveBinFiles
108
                    &CreateTargetDirStructure
109
                    &createPatch
110
                    &createPackage
111
                    &createPrototypeFile
112
                    &addPatchInfo2ProtoTypeFile
113
                    &addPkgInfoClasses
114
                    &addPkgInfoField
115
                    &updatePrototypeFileItemClass
116
                    &useReplaceClass
117
                    &setReplaceClassFiles
118
                    &createPkginfoFile
119
                    &updatePrototypeFileItemOwner
1592 dpurdie 120
                    &setPermissions
1530 dpurdie 121
                    &chmod
122
                    &chmodRecursive
123
                    &chmodDir
124
                    &chmodFile
125
                    &createSymbolicLink
126
                    &createPrototypeFile2
127
                    &installDeployFile
128
                    &createDpkgArchive
129
                    &generateHtmlReleaseNote
130
                    &generateIShieldIncludeFile
131
                    &createPerlSvcWin32
132
                    &createPerlAppWin32
133
                    &convertFile
134
 
135
                    &getErgAfcBaseDir
136
                    &getGenericNameNoVersionForLib
137
                    &getGenericNameForLib
1534 dpurdie 138
                    &createZip
1544 dpurdie 139
                    &generateXmlDependancy
1530 dpurdie 140
 
141
                    %TargetDstDirStructure
142
                    %LocalSrcDirStructure
143
                    %BuildPkgArchive
144
                    $MachType
145
                    $TargetHomeDir
146
                    $TargetBaseDir
147
 
148
                    $PkgName
1540 dpurdie 149
                    $PkgVersionUser
150
                    $PkgVersion
1530 dpurdie 151
 
152
                );
153
 
154
#------------------------------------------------------------------------------
155
# Constants global/local to this package
156
#------------------------------------------------------------------------------
157
use vars qw ( $opt_n $opt_v $opt_r $opt_t $opt_m $opt_d $opt_p $opt_o $opt_k $opt_g );
158
 
159
my ($VENDOR_DESC)            = "ERG Transit Systems Ltd";
160
my ($CATEGORY_DESC)          = "application";
161
my ($ERGAFC_BASEDIR)         = "/afc";
162
my ($MAXINST)                = "1000";
163
my ($PKG_OVERVIEW)           = "To Be Defined.";
164
 
165
my (@PATCH_INFO_FILES) = qw (
166
    checkinstall 
167
    copyright 
168
    patch_checkinstall 
169
    patch_postinstall 
170
    i.none 
171
    postinstall 
172
    preinstall 
173
) ;
174
 
175
my (@PATCH_UTIL_FILES) = qw ( backoutpatch installpatch );
176
 
177
my (@PKG_UTIL_FILES) = qw ( requestlib.sh );
178
 
179
my (@PKG_ISHIELD_FILES)   = qw ( ishieldlib.rul ishieldlib.h );
180
 
181
my (@PKG_ISHIELD_IMG_FILES) = qw ( 
182
   islib_pane.bmp
183
   islib_splash.bmp
184
   islib_topicon.bmp
185
);
186
 
187
 
188
my (@PATCH_ISHIELD_FILES) = qw ( 
189
    postinstall.rul
190
    preinstall.rul 
191
    postremove.rul 
192
    preremove.rul 
193
);
194
 
195
my ($PKG_ISHIELD_DEF_FILE) = "pkgdef.h";
196
my ($PKG_ISHIELD_DIR)      = "";
197
 
198
my ($PKG_UTIL_DIR)   = "";
199
my ($PATCH_UTIL_DIR) = "";
200
 
201
 
202
my ($m_UID)  = "";
203
my ($m_GID)  = "";
204
my ($m_MASK) = "";
1550 dpurdie 205
my ($m_KEEP_MASK) = "";
1530 dpurdie 206
 
207
 
208
#------------------------------------------------------------------------------
209
# Variables global/local to this package
210
#------------------------------------------------------------------------------
211
our $InterfaceDir       = "";
212
 
213
our $DpkgBinDir         = "";
214
our %DpkgBinDirList     = ();
215
our $DpkgLibDir         = "";
216
our %DpkgLibDirList     = ();
217
our $DpkgScriptsDir     = "";
218
our $DpkgEtcDir         = "";
219
our $DpkgJarDir         = "";
220
our $DpkgSarDir         = "";
221
our $DpkgWarDir         = "";
222
our $DpkgSqlDir         = "";
223
our $DpkgInfoFilesDir   = "";
224
our $DpkgPkgDir         = "";
225
our $DpkgJspDir         = "";
226
our $DpkgRoxDir         = "";
227
our $DpkgRptDir         = "";
228
our $DpkgAcHtmlDir      = "";
229
our $DpkgIncludeDir     = "";
230
our $DpkgDevcdDir       = "";
231
our $DpkgDatDir         = "";
232
our $DpkgThxDir         = "";
233
our $DpkgMugDir         = "";
234
our $DpkgDocDir         = "";
235
 
236
our @LibCheckList       = ();
237
 
238
our $CurrentDir         = "";
239
our $RootDir            = "";
240
our $BuildType          = "";
241
our $MachType           = "";
242
our $Platform           = "";
243
our $Product            = "";
244
our $Target             = "";
245
our $SrcDir             = "";
246
our $PkgDir             = "";
247
our $ReleaseDir         = "";
248
our $Username           = "";
249
 
250
our $PkgBaseDir         = "";
251
our $PkgInfoFileName    = "pkginfo";
252
our $PkgInfoFile        = "";
253
our $ProtoTypeFileName  = "prototype";
254
our $ProtoTypeFile      = "";
255
 
256
our $PkgPatchName       = "";
257
our $PkgPatchID         = "";
258
our $PkgPatchNum        = "";
259
our $PkgPatchReadme     = "";
260
our $PkgPatchTmpDir     = "";
261
 
262
our $PkgVersion         = "";
263
our $PkgVersionStr      = "";
264
our $PkgVersionUser     = "";
265
our $PkgName            = "";
266
our $PkgBuildNum        = "";
267
our $PkgOutputFile      = "";
268
our $PkgReleaseNote     = "";
269
our $PkgLabel           = "";
270
our $PkgDesc            = "";
271
our $PkgNameLong        = "";
272
our $PkgInfoClasses     = "none";
273
 
274
our $PkgPreviousVersionStr = "";
275
our $TargetBaseDir      = "";
276
our $TargetHomeDir      = "";
277
 
278
our $SandBoxName        = "";
279
our $ProjectAcronym     = "";
280
 
281
our $TmpGlobalVariable  = ""; # used to pass variables into PERL find functions
282
 
283
our %TargetDstDirStructure = ();
284
our %LocalSrcDirStructure  = ();
285
 
286
our $BuildFileInfo       = "";
287
# This was removed to add the use of the Buildfile.pm module, but this hash is needed 
288
# because the deployfiles use it for library version numbers in the file lists.
289
# So it is left here and is a simply copy of the hash from buildfile pm
290
our %BuildPkgArchive     = ();
291
 
292
our $RmPkgDetails        = undef;
293
our $RmPvPkgDetails      = undef;
294
 
1532 dpurdie 295
my  $autobuild = $ENV{'GBE_ABT'} || 0;
1530 dpurdie 296
 
1532 dpurdie 297
 
1530 dpurdie 298
#------------------------------------------------------------------------------
299
# Initialization actions
300
#------------------------------------------------------------------------------
301
 
1534 dpurdie 302
#
303
#   Init the error and message subsystem
304
#
305
ErrorConfig( 'name'    => 'DEPLOYLIB' ,
306
             'debug'   => $ENV{GBE_DEBUG},
307
             'verbose' => $ENV{GBE_VERBOSE},
308
             );
1530 dpurdie 309
 
1534 dpurdie 310
 
1530 dpurdie 311
#------------------------------------------------------------------------------
312
# Package Interface Subroutines
313
#
314
# The following functions are used by the Makefile.pl scripts.  Programmers
315
# call the following functions to set up the basic requirements that the
316
# automated make system requires.
317
#------------------------------------------------------------------------------
318
 
319
 
320
#------------------------------------------------------------------------------
321
sub Init
322
#
323
# Description:
324
#       Tests Environment Variables, it also checks the required command line 
325
#       variables.
326
#
327
# Inputs:
328
#       Command line.
329
#
330
# Returns:
331
#  1
332
#
333
# Globals:
334
#  $makelib::RootDir
335
#
336
# Notes:
337
#  -
338
#
339
# Todo:
340
#  -
341
#------------------------------------------------------------------------------
342
{
343
 
344
    # first we deal with the command line values we expect, these include:
345
    #  	GBE_ROOT                                                       (-r)
346
    #  	Package Name                                                   (-n)
347
    #  	Package Home Directory (relative to the ERGAFC_BASEDIR)        (-d)
348
    #  	Package Version                                                (-v)
349
    #  	Build Type                                                     (-t)
350
    #  	Patch Number                                                   (-p)
351
    #  	Previous (old) version number                                  (-o)
352
    #  	Platform                                                       (-m)
353
    # 	Product (optional)                                             (-k)
354
    #  	Machine Type (optional)                                        (-g)
355
 
356
    $CurrentDir = cwd;
357
 
358
    my ($i);
359
    Getopt::Std::getopts ('v:n:r:t:m:d:p:o:k:g:');
360
    if ( $opt_n )
361
    {
362
        $PkgName      = $opt_n;
363
    }
364
    else
365
    {
1534 dpurdie 366
        Error("Package Name not supplied!");
1530 dpurdie 367
    }
368
 
369
    if ( $opt_r )
370
    {
371
        # lets change to root dir and get fully qualified path from cwd and return back
372
        chdir($opt_r);
373
        $RootDir = cwd;
374
        chdir($CurrentDir);
375
 
376
        $SandBoxName      = File::Basename::basename($RootDir);
377
    }
378
    else
379
    {
1534 dpurdie 380
        Error("GBE_ROOT not supplied!");
1530 dpurdie 381
    }
382
 
383
    if ( $opt_t )
384
    {
385
        $BuildType = $opt_t;
386
    }
387
    else
388
    {
1534 dpurdie 389
        Error("GBE_TYPE not supplied!");
1530 dpurdie 390
    }
391
 
392
    #
393
    #   Target machine type ( Underlying machine type in a Product Family)
394
    #   If not provided, the assume that its the same as the platform (compat)
395
    #
396
    $opt_g = $opt_m unless ( $opt_g );
397
    if ( $opt_g )
398
    {
399
        $Target = $opt_g;
400
        if ( $Target =~ /^SOLARIS/ )
401
        {
402
            $MachType = 'sparc';
403
        }
404
        elsif ( $Target =~ /^WCE/ )
405
        {
406
            $MachType = 'WinCE';
407
        }
408
        elsif ( $Target =~ /^WIN32/ )
409
        {
410
            $MachType = 'win32';
411
        }
412
        else
413
        {
1534 dpurdie 414
            Error("Unknown target [$opt_g] supplied!");
1530 dpurdie 415
        }
416
    }
417
 
418
    #
419
    #   Platform
420
    #   This is the full product name in a product family.
421
    #
422
    if ( $opt_m )
423
    {
424
        $Platform = $opt_m;
425
    }
426
    else
427
    {
1534 dpurdie 428
        Error("Platform not supplied!");
1530 dpurdie 429
    }
430
 
431
    #
432
    #   Setup Product
433
    #   If not defined then use the platform
434
    #
435
    $Product = $opt_k ? $opt_k : $Platform;
436
 
437
    if ( $opt_d )
438
    {
439
        $TargetBaseDir = $opt_d;
440
    }
441
    else
442
    {
1534 dpurdie 443
        Error("Package base directory not supplied!");
1530 dpurdie 444
    }
445
 
446
    if ( $opt_p )
447
    {
448
        my $pNum = sprintf("%02s", $opt_p);
449
        if ( "$pNum" =~ m/^[0-9][0-9]$/ )
450
        {
451
            $PkgPatchNum = $pNum;
452
        }
453
        else
454
        {
1534 dpurdie 455
            Error("-p command line arg [$opt_p] has invalid format",
456
                     "Required format is an integer value.");
1530 dpurdie 457
        }
458
    }
459
 
460
    if ($opt_v)
461
    {
1554 dpurdie 462
        if( "$opt_v" =~ m/^(\d*)\.(\d*)\.(\d*)-(\d*)\.([a-z]{2,3})$/ ) # N.N.N-N.ppp
1530 dpurdie 463
        {
1554 dpurdie 464
            my ($s1, $s2, $s3, $s4, $s5) = ($1, $2, $3, $4, $5);
1530 dpurdie 465
 
1554 dpurdie 466
            $PkgVersionStr = sprintf("%02s%02s%02s", $s1,$s2,$s3);
467
            $PkgVersion  = "$s1\.$s2\.$s3";
468
            $PkgBuildNum = $s4;
469
            $ProjectAcronym   = $s5;
1530 dpurdie 470
        }
1554 dpurdie 471
        elsif( "$opt_v" =~ m/^(\d*)\.(\d*)\.(\d*)\.([a-z]{2,3})$/ ) # N.N.N.ppp
1530 dpurdie 472
        {
1554 dpurdie 473
            my ($s1, $s2, $s3, $s4) = ($1, $2, $3, $4);
1530 dpurdie 474
 
475
            $PkgVersionStr = sprintf("%02s%02s%02s", $s1,$s2,$s3);
476
            $PkgVersion  = "$s1\.$s2\.$s3";
477
            $PkgBuildNum = "1";
1554 dpurdie 478
            $ProjectAcronym   = $s4;
1530 dpurdie 479
        }
480
        else
481
        {
1534 dpurdie 482
            Error("-v command line arg [$opt_v] has invalid format",
483
                  "Allowed formats are N.N.N-B.ppp and N.N.N.ppp where:",
484
                  "    N is an integer",
485
                  "    B is an integer",
486
                  "    ppp is the project acronym",
487
                  "Check propject acronym.");
488
 
1530 dpurdie 489
        }
490
        $PkgVersionUser  = $opt_v;
491
    }
492
    else
493
    {
1534 dpurdie 494
        Error("Package Version not supplied!");
1530 dpurdie 495
    }
496
 
497
 
498
    # lets check to see if we have a previous version 
499
    if ($opt_o)
500
    {
501
        $PkgPreviousVersionStr = $opt_o;
502
    }
503
 
1532 dpurdie 504
    # Load the JATS-parsed information from the build.pl file
505
    #
506
    $BuildFileInfo = DeployUtils::BuildConfig->new($RootDir, $Platform);
1530 dpurdie 507
 
1532 dpurdie 508
    # Load all our build dependencies
509
    #
510
    %BuildPkgArchive = $BuildFileInfo->getDpkgArchiveHash();
511
 
1530 dpurdie 512
    # lets define where we get our stuff from
513
    #
514
    if ( $ERGAFC_BASEDIR =~ m|/$| )
515
    {
516
        $TargetHomeDir= "$ERGAFC_BASEDIR$TargetBaseDir"; 
517
    }
518
    else
519
    {
520
        $TargetHomeDir= "$ERGAFC_BASEDIR/$TargetBaseDir"; 
521
    }
522
    $PkgDir       = "$RootDir/pkg";
523
    $SrcDir       = "$RootDir/src"; 
524
    $InterfaceDir = "$RootDir/interface";
525
    $ReleaseDir   = "$RootDir/build/deploy";
526
 
527
    $PKG_UTIL_DIR   = "$InterfaceDir/deployfiles";
528
    $PATCH_UTIL_DIR = $PKG_UTIL_DIR;
529
    #
530
    #   InstallShield files are provided via a package
531
    #   Ensure that a suitable package has been provided
532
    #
533
    if ( ! -d  $PKG_UTIL_DIR )
534
    {
1534 dpurdie 535
        Error("No deployment support files found",
536
              "These MUST be provided by a dependant package in build.pl");
1530 dpurdie 537
    }
538
 
1532 dpurdie 539
 
1530 dpurdie 540
    $Username     = getlogin || getpwuid($<);
541
 
542
    if ( "$BuildType" eq "D" )
543
    {
544
        $PkgBaseDir = "$PkgDir/debug"; 
545
    }
546
    else
547
    {
548
        $PkgBaseDir = "$PkgDir/prod"; 
549
    }
550
 
551
    $PkgInfoFile   = "$PkgBaseDir/$PkgInfoFileName";
552
    $ProtoTypeFile = "$PkgBaseDir/$ProtoTypeFileName";
553
 
554
    $DpkgScriptsDir = "$InterfaceDir/scripts";
555
 
556
 
557
    $DpkgEtcDir     = "$InterfaceDir/etc";
558
    $DpkgJarDir     = "$InterfaceDir/jar";
559
    $DpkgSarDir     = "$InterfaceDir/sar";
560
    $DpkgWarDir     = "$InterfaceDir/war";
561
    $DpkgSqlDir     = "$InterfaceDir/sql";
562
 
563
    $DpkgInfoFilesDir = "$InterfaceDir/infofiles";
564
    $DpkgPkgDir       = "$InterfaceDir/pkg";
565
    $DpkgJspDir       = "$InterfaceDir/jsp";
566
    $DpkgRoxDir       = "$InterfaceDir/rox";
567
    $DpkgRptDir       = "$InterfaceDir/rpt";
568
    $DpkgAcHtmlDir    = "$InterfaceDir/achtml";
569
    $DpkgIncludeDir   = "$InterfaceDir/include";
570
    $DpkgDevcdDir     = "$InterfaceDir/devcd";
571
    $DpkgDatDir       = "$InterfaceDir/dat";
572
    $DpkgThxDir       = "$InterfaceDir/thx";
573
    $DpkgMugDir       = "$InterfaceDir/mug";
574
    $DpkgDocDir       = "$InterfaceDir/doc";
575
 
576
 
577
    $DpkgLibDir     = "$InterfaceDir";
578
    $DpkgBinDir     = "$InterfaceDir";
579
 
580
 
581
    #   Define where we might find our artifacts
1532 dpurdie 582
    #   The search order is: Platform, Product, --Uses extensions,Target, MachineType
583
    #   Much of this list, and its described in the build.pl file, use the JATS
584
    #   generated information to extract the correct information
1530 dpurdie 585
    #
586
    #   Only add the directory to the list if it actually exists
587
    #   This will speed up searching later.
588
    #
589
    #   Create multiple search paths
590
    #       One for an exaustive search
591
    #       Others for selective searchs
592
    #
593
    #
1532 dpurdie 594
    foreach my $part ( $BuildFileInfo->getPlatformParts($Platform), $MachType )
1530 dpurdie 595
    {
596
        next unless ( $part );
597
        foreach my $subdir ( "lib." . "$part",
598
                             "lib." . "$part" . "$BuildType",
599
                             "lib/lib." . "$part" . "$BuildType",
600
                             "lib/$part" . "$BuildType",
601
                             "lib/$part" )
602
        {
603
            if ( -d "$DpkgLibDir/$subdir" )
604
            {
605
                UniquePush( \@{$DpkgLibDirList{_ALL_}}, $subdir);
606
                UniquePush( \@{$DpkgLibDirList{$part}}, $subdir);
607
            }
608
        }
609
    }
610
 
1532 dpurdie 611
    foreach my $part ( $BuildFileInfo->getPlatformParts($Platform), $MachType )
1530 dpurdie 612
    {
613
        next unless ( $part );
614
        foreach my $subdir ( "bin." . "$part" . "$BuildType",
615
                             "bin." . "$part",
616
                             "bin/bin." . "$part" . "$BuildType",
617
                             "bin/" . "$part" . "$BuildType",
618
                             "bin/" . uc($part) . "$BuildType",
619
                             "bin/$part",
620
 
621
                             "bin." . "$part" . "P",
622
                             "bin/bin." . "$part" . "P",
623
                             "bin/" . "$part" . "P",
624
                             "bin/" . uc($part) . "P" )
625
        {
626
            if ( -d "$DpkgBinDir/$subdir" )
627
            {
628
                UniquePush( \@{$DpkgBinDirList{_ALL_}}, $subdir);
629
                UniquePush( \@{$DpkgBinDirList{$part}}, $subdir);
630
            }
631
        }
632
 
633
    }
634
 
1534 dpurdie 635
    Information("------------------------------------------------------------");
1530 dpurdie 636
 
637
 
638
    # lets generate the patch id if we are building a patch
639
    #
640
    if ( "x$PkgPatchNum" ne "x" )
641
    {
1534 dpurdie 642
        Information("This is a PATCH build...");
1530 dpurdie 643
 
644
        $PkgPatchName = uc ($PkgName);
645
 
646
 
647
        my ($_tmpStr) = sprintf("%s%s", $PkgPatchName, 
648
                                        $PkgVersionStr);
649
 
650
 
651
        $PkgPatchID     = "$_tmpStr" . "-" . "$PkgPatchNum"; 
652
        $PkgPatchReadme = "$PkgBaseDir" . "/README." . "$PkgPatchID"; 
653
        $PkgPatchTmpDir = "$PkgBaseDir/tmp";
654
 
1532 dpurdie 655
        $PkgReleaseNote = "$ReleaseDir" . "/$PkgPatchName" .
1530 dpurdie 656
                                                                "$PkgVersionStr\_" . 
657
                                                                "$PkgPatchNum\_" . 
658
                                                                "$ProjectAcronym\_" . 
659
                                                                "$Platform"; 
660
 
661
        $PkgLabel = uc ($ProjectAcronym) . "_" .
662
                               $PkgPatchName . "_" .
663
                               $PkgVersionStr . 
664
                               "_P" . $PkgPatchNum;  
665
 
666
 
667
        # lets define what our output package name shall be
668
        #
669
        $PkgOutputFile = "na"; 
670
    }
671
    else
672
    {
1534 dpurdie 673
        Information("This is a normal RELEASE build...");
1532 dpurdie 674
        $PkgReleaseNote = "$ReleaseDir" . "/" .
1530 dpurdie 675
                                                                "$PkgName" . "-" . 
676
                                                                "$PkgVersion" . "." .
677
                                                                "$ProjectAcronym" . "-" .
678
                                                                "$Platform";
679
 
680
        $PkgLabel = uc ($ProjectAcronym) . "_" .
681
                               uc ($PkgName) . "_" .
682
                               "R_" .
683
                               "$PkgVersionStr";  
684
 
685
 
686
        # lets define what our output package name shall be
687
        #
688
        $PkgOutputFile = "$PkgName" . "-" . 
689
                         "$PkgVersion" . "." .
690
                         "$ProjectAcronym" . "-" .
691
                         "$Platform" . "-" .
692
                         "$BuildType\.pkg";
693
    }
694
 
1534 dpurdie 695
    Information("------------------------------------------------------------");
1530 dpurdie 696
 
697
 
698
    # lets just show what we have determined.
699
    #
1534 dpurdie 700
    Information("Current environment definitions (Increase Verbose Level to see all definitions)...");
1530 dpurdie 701
 
1534 dpurdie 702
    Verbose("DeployFiles      =[$PKG_UTIL_DIR]");
1530 dpurdie 703
 
1534 dpurdie 704
    Information("PkgName          =[$PkgName]");
705
    Information("PkgVersionUser   =[$PkgVersionUser]");
1530 dpurdie 706
 
1534 dpurdie 707
    Information("PkgVersion       =[$PkgVersion]");
708
    Information("PkgVersionStr    =[$PkgVersionStr]");
1530 dpurdie 709
 
1534 dpurdie 710
    Information("PkgBuildNum      =[$PkgBuildNum]");
1530 dpurdie 711
 
712
    if ( "x$PkgPatchID" ne "x" )
713
    {
1534 dpurdie 714
        Information("PkgPatchName     =[$PkgPatchName]");
715
        Information("PkgPatchNum      =[$PkgPatchNum]");
716
        Information("PkgPatchID       =[$PkgPatchID]");
717
        Information("PkgPatchTmpDir   =[$PkgPatchTmpDir]");
1530 dpurdie 718
    }
719
 
1534 dpurdie 720
    Information("PkgReleaseNote   =[$PkgReleaseNote]") unless ($autobuild);
721
    Information("PkgReleaseNote   =[Generated later by ABT]") if ($autobuild);
722
    Information("PkgLabel         =[$PkgLabel]");
1530 dpurdie 723
 
1534 dpurdie 724
    Information("PkgPreviousVersionStr=[$PkgPreviousVersionStr]");
1530 dpurdie 725
 
1534 dpurdie 726
    Information("ProjectAcronym   =[$ProjectAcronym]");
727
    Information("BuildType        =[$BuildType]");
728
    Information("MachType         =[$MachType]");
729
    Information("Platform         =[$Platform]");
730
    Information("Product          =[$Product]");
731
    Information("Target           =[$Target]");
732
    Verbose("BuildParts       =[" . join(',',$BuildFileInfo->getPlatformParts($Platform)) . "]");
1530 dpurdie 733
 
1534 dpurdie 734
    Information("CurrentDir       =[$CurrentDir]");
735
    Information("RootDir          =[$RootDir]");
736
    Information("SandBoxName      =[$SandBoxName]");
737
    Information("Username         =[$Username]");
1530 dpurdie 738
 
1534 dpurdie 739
    Information("TargetBaseDir    =[$TargetBaseDir]");
740
    Information("TargetHomeDir    =[$TargetHomeDir]");
1530 dpurdie 741
 
1534 dpurdie 742
    Information("PkgBaseDir       =[$PkgBaseDir]");
743
    Information("SrcDir           =[$SrcDir]");
744
    Information("PkgDir           =[$PkgDir]");
745
    Information("ReleaseDir       =[$ReleaseDir]");
1530 dpurdie 746
 
1534 dpurdie 747
    Verbose("InterfaceDir     =[$InterfaceDir]");
748
    Verbose("DpkgScriptsDir   =[$DpkgScriptsDir]");
749
    Verbose("DpkgBinDir(s)    =[");
1530 dpurdie 750
    foreach $i (@{$DpkgBinDirList{'_ALL_'}})
751
    {
1534 dpurdie 752
        Verbose("                   $DpkgBinDir/$i");
1530 dpurdie 753
    }
1534 dpurdie 754
    Verbose("                  ]");
1530 dpurdie 755
 
756
 
1534 dpurdie 757
    Verbose("DpkgLibDir(s)    =[");
1530 dpurdie 758
    foreach $i (@{$DpkgLibDirList{'_ALL_'}})
759
    {
1534 dpurdie 760
        Verbose("                   $DpkgLibDir/$i");
1530 dpurdie 761
    }
1534 dpurdie 762
    Verbose("                  ]");
1530 dpurdie 763
 
764
 
1534 dpurdie 765
    Verbose("DpkgEtcDir       =[$DpkgEtcDir]");
766
    Verbose("DpkgJarDir       =[$DpkgJarDir]");
767
    Verbose("DpkgSarDir       =[$DpkgSarDir]");
768
    Verbose("DpkgWarDir       =[$DpkgWarDir]");
769
    Verbose("DpkgSqlDir       =[$DpkgSqlDir]");
770
    Verbose("DpkgJspDir       =[$DpkgJspDir]");
771
    Verbose("DpkgRoxDir       =[$DpkgRoxDir]");
772
    Verbose("DpkgRptDir       =[$DpkgRptDir]");
773
    Verbose("DpkgAcHtmlDir    =[$DpkgAcHtmlDir]");
774
    Verbose("DpkgIncludeDir   =[$DpkgIncludeDir]");
775
    Verbose("DpkgDevcdDir     =[$DpkgDevcdDir]");
776
    Verbose("DpkgDatDir       =[$DpkgDatDir]");
777
    Verbose("DpkgThxDir       =[$DpkgThxDir]");
778
    Verbose("DpkgMugDir       =[$DpkgMugDir]");
779
    Verbose("DpkgDocDir       =[$DpkgDocDir]");
1530 dpurdie 780
 
1534 dpurdie 781
    Verbose("DpkgInfoFilesDir =[$DpkgInfoFilesDir]");
782
    Verbose("DpkgPkgDir       =[$DpkgPkgDir]");
1530 dpurdie 783
 
1534 dpurdie 784
    Verbose("PkgInfoFile      =[$PkgInfoFile]");
785
    Verbose("ProtoTypeFile    =[$ProtoTypeFile]");
1530 dpurdie 786
 
787
    foreach $i ( $BuildFileInfo->getDpkgArchiveList() )
788
    {
789
        my $moduleInfo = $BuildFileInfo->getDpkgArchiveInfo($i);
790
 
1534 dpurdie 791
        Verbose(  "Build Dependency =" .
1530 dpurdie 792
                  "[$moduleInfo->{type}] " .
793
                  "[$i] " .
794
                  "[$moduleInfo->{version}] " .
795
                  "[$moduleInfo->{proj}]");
796
    }
797
 
798
    if ( "$MachType" eq "sparc" )
799
    {
1534 dpurdie 800
        Information("PkgOutputFile    =[$PkgOutputFile]");
1530 dpurdie 801
    }
802
 
1534 dpurdie 803
    Information("PkgOverview      =[$PKG_OVERVIEW]");
1530 dpurdie 804
 
805
 
806
    # Lets evaluate TargetDstDirStructure to expand any vars
807
    foreach $i ( keys %TargetDstDirStructure )
808
    {
809
        if ( $TargetDstDirStructure{$i} =~ /\$/ )
810
        {
1534 dpurdie 811
            Debug("-n", "Expanding TargetDstDirStructure [$TargetDstDirStructure{$i}] to ");
1530 dpurdie 812
            $TargetDstDirStructure{$i} = eval "sprintf " . qq/"$TargetDstDirStructure{$i}"/;
1540 dpurdie 813
            Information("TargetDstDir $i =[$TargetDstDirStructure{$i}]");
1530 dpurdie 814
        }
815
    }
816
 
817
    # lets check waht we can before proceeding.
818
    #
819
    ValidateLocalSrcDirStructure();
820
 
821
    # Everything went ok lets begin by creating some dirs...
822
    #
823
    CreateTargetDirStructure();
824
 
825
    # lets get some details for our package
826
    getRmDetails();
827
 
828
    # done
829
    return 1;
830
}
831
 
832
 
833
#------------------------------------------------------------------------------
834
sub setPkgDescription
835
#
836
# Description:
837
#       This sub-routine is used to set the Package DESC field
838
#       from within the deployfile.
839
#
840
#------------------------------------------------------------------------------
841
{
842
    # correct number of parameters?
843
    if ( ($#_+1) != 1 )
844
    {
1534 dpurdie 845
        Error("Incorrect number of params passed to setPkgDescription() function.",
846
              "Check deploy config.");
1530 dpurdie 847
    }
848
    my ($lpkgDesc) = shift;
849
 
850
    # we use what was defined in deployfile if
851
    # the RM details are not available
852
    if ( ! defined($RmPkgDetails) )
853
    {
854
        $PkgDesc = $lpkgDesc;
855
    }
856
    else
857
    {
858
        # let's use the details if we have them
859
        if ( $RmPkgDetails->foundDetails() )
860
        {
861
            # we have RM details, we will only use them
862
            # if nothing is locally defined,
863
            # (ie locally defined details takes precedence)
864
            if ( "x$lpkgDesc" eq "x" )
865
            {
866
                $PkgDesc = $RmPkgDetails->pv_description();
867
            }
868
            else
869
            {
870
                $PkgDesc = $lpkgDesc;
871
            }
872
        }
873
        else
874
        {
875
            $PkgDesc = $lpkgDesc;
876
        }
877
    }
878
 
879
    # done
880
    return 1;
881
}
882
 
883
#------------------------------------------------------------------------------
884
sub setPkgName
885
#
886
# Description:
887
#       This sub-routine is used to set the Package NAME field
888
#       from within the deployfile.
889
#
890
#------------------------------------------------------------------------------
891
{
892
    # correct number of parameters?
893
    if ( ($#_+1) != 1 )
894
    {
1534 dpurdie 895
        Error("Incorrect number of params passed to " .
896
                  "setPkgName() function. ",
1530 dpurdie 897
                  "Check deploy config.");
898
    }
899
    $PkgNameLong = shift;
900
 
901
    # done
902
    return 1;
903
}
904
 
905
 
906
#------------------------------------------------------------------------------
907
sub setErgAfcBaseDir
908
#
909
# Description:
910
#       This sub-routine is used to reset the ERG AFC base dir global variable
911
#       from within the deployfile.
912
#
913
#------------------------------------------------------------------------------
914
{
915
    # if TargetBaseDir is empty then init has not been called yet so we can set 
916
    # base dir, if however it is not null then init has been called and setting
917
    # base dir after init causes problems in some cases.
918
    if ( $TargetBaseDir ne "" )
919
    {
1534 dpurdie 920
        Error("setErgAfcBaseDir() cannot be called after Init(), place before Init() in deployfile.pl");
1530 dpurdie 921
    }
922
 
923
    # correct number of parameters?
924
    if ( ($#_+1) != 1 )
925
    {
1534 dpurdie 926
        Error("Incorrect number of params passed to " .
927
                  "setErgBaseDir() function. ",
1530 dpurdie 928
                  "Check deploy config.");
929
    }
930
 
931
    my ($newDir) = @_;
932
    $ERGAFC_BASEDIR = "$newDir";
933
 
934
    return 1;
935
}
936
 
937
 
938
 
939
#------------------------------------------------------------------------------
940
sub getErgAfcBaseDir
941
#
942
# Description:
943
#       This sub-routine is used to get the ERG AFC base dir global variable
944
#       to be used within the deployfile.
945
#
946
#------------------------------------------------------------------------------
947
{
948
    # correct number of parameters?
949
    if ( ($#_+1) != 0 )
950
    {
1534 dpurdie 951
        Error("Incorrect number of params passed to " .
952
                  "getErgBaseDir() function. ",
1530 dpurdie 953
                  "Check deploy config.");
954
    }
955
 
956
    return "$ERGAFC_BASEDIR";
957
}
958
 
959
 
960
#------------------------------------------------------------------------------
961
sub setPkgOverview
962
#
963
# Description:
964
#       This sub-routine is used to reset the package overview that
965
#       is used to build the package from within the deployfile.
966
#
967
#------------------------------------------------------------------------------
968
{
969
    # correct number of parameters?
970
    if ( ($#_+1) != 1 )
971
    {
1534 dpurdie 972
        Error("Incorrect number of params passed to " .
973
                  "setPkgOverview() function. ",
1530 dpurdie 974
                  "Check deploy config.");
975
    }
976
 
977
    my ($mStr) = @_;
978
    $PKG_OVERVIEW = "$mStr";
979
 
980
    return 1;
981
}
982
 
983
 
984
#------------------------------------------------------------------------------
985
sub getPkgOverview
986
#
987
# Description:
988
#       This sub-routine is used to get the package overview string global variable
989
#       to be used within the deployfile.
990
#
991
#------------------------------------------------------------------------------
992
{
993
    # correct number of parameters?
994
    if ( ($#_+1) != 0 )
995
    {
1534 dpurdie 996
        Error("Incorrect number of params passed to " .
997
                  "getPkgOverview() function. ",
1530 dpurdie 998
                  "Check deploy config.");
999
    }
1000
 
1001
    return "$PKG_OVERVIEW";
1002
}
1003
 
1004
 
1005
 
1006
#------------------------------------------------------------------------------
1007
sub addInstallshieldFiles
1008
#
1009
#    Description:
1010
#        This is called to add extra installshield files to the PKG_ISHIELD_FILES array.
1011
#        For each parameter it checks for the existense of arg.* in the PKG_UTIL_DIR
1012
#        and adds all found files to the array
1013
#        This must be called before init() is called.
1014
#
1015
#    INPUT:
1016
#        files to add
1017
#
1018
#    RETURN:
1019
#        nothing
1020
#
1021
#------------------------------------------------------------------------------
1022
{
1023
    my @files;
1024
 
1025
    # lets just check to see if we can execute this function on this machine.
1026
    if ( "$MachType" eq "sparc" )
1027
    {
1534 dpurdie 1028
        Warning("addInstallshieldFiles() not supported on this machine type.");
1530 dpurdie 1029
        return 1;
1030
    }
1031
 
1032
    foreach my $i ( @_ )
1033
    {
1034
        @files = glob("$PKG_UTIL_DIR/$i.*");
1035
        foreach my $j ( @files )
1036
        {
1037
            $j = basename($j);
1534 dpurdie 1038
            Verbose("Adding Installshield file $j");
1530 dpurdie 1039
            push(@PKG_ISHIELD_FILES, $j);
1040
        }
1041
    }
1042
    return 1;
1043
}   # addInstallshieldFiles
1044
 
1045
 
1046
 
1047
#------------------------------------------------------------------------------
1048
sub removeBuildTypeFromItemName
1049
#
1050
#    Description:
1051
#        This sub-routine is used to remove the buildtype from the item name.
1052
#        i.e. debug files will be tagged with *D.* 
1053
#             prod  file will be tagged with *P.*
1054
#
1055
#    INPUT:
1056
#        item name
1057
#
1058
#    RETURN:
1059
#        new item name.
1060
#
1061
#------------------------------------------------------------------------------
1062
{
1063
    my ($file) = @_;
1064
 
1065
    my ($nfile) = $file;
1066
    $nfile =~ s/D\.|P\./\./;
1067
    return "$nfile";
1068
}
1069
 
1070
 
1071
 
1072
#------------------------------------------------------------------------------
1073
sub installAllDpkgArchivePkgFiles
1074
#
1075
# Description:
1076
#       This sub-routine is used to install all infofiles files from the
1077
#       dpkg_archive into the defined install area.
1078
#
1079
#       It assumes based on the build type where the src files will be located.
1080
#
1081
#       If it has any problems it will log an error and stop processing.
1082
#
1083
#       Source directory: $DpkgPkgDir       (interface/pkg)
1084
#       Target directory: $PkgBaseDir       (output/pkg/[debug|prod]
1085
#
1086
#------------------------------------------------------------------------------
1087
{
1088
    #
1089
    #   Use the (now) more general function installAllDpkgArchivePkgFiles2
1090
    #   with spacial parameters to mimic the original function
1091
    #
1092
    #   Copy all from the 'pkg' directory to the PkgBaseDir
1093
    #
1094
    installAllDpkgArchivePkgFiles2 ( "--Dstdir=$PkgBaseDir", '--Srcdir=pkg', @_ );
1095
    return 1;
1096
}
1097
 
1098
 
1099
#------------------------------------------------------------------------------
1100
sub installAllDpkgArchivePkgFiles2
1101
#
1102
# Description:
1103
#       This sub-routine is used to install all pkg files from the
1104
#       dpkg_archive into the defined install area.
1105
#
1106
#       Simlar to installAllDpkgArchivePkgFiles, but the target directory
1107
#       is specified by the user.
1108
#
1109
#       It assumes based on the build type where the src files will be located.
1110
#
1111
#       If it has any problems it will log an error and stop processing.
1112
#
1113
# Inputs          : targetTag       - Target directory      [Mandatory]
1114
#                   options         - Optional options
1115
#                                       --Srcdir=path       [default=pkg]
1116
#                                       --Dstdir=abs_path   [internal use]
1117
#                                       --NoRecurse
1118
#                                       --Recurse           [default]
1119
#                                       --Flatten
1120
#                                       --NoFlatten         [default]
1121
#                                       --FilterIn=xx
1122
#                                       --FilterInRE=xx     [default=.*]
1123
#                                       --FilterOut=xx
1124
#                                       --FilterOutRE=xx
1125
#
1126
# Notes:    --FilterIn=xxxx, --FilterOut=xxx
1127
#           xxx is a simple Shell style filter where:
1128
#               * means one or more charters        '*.EXE'
1129
#               ? means a single character          '*.?'
1130
#               [abc] means either a or b or c      'file.[ch]'
1131
#
1132
#           --FilterInRE=xxx, --FilterOutRE=xxx
1133
#           xxx is a Regular Expression. There are harder to use but very
1134
#           powerful. ie '.*\.EXE$'
1135
#
1136
#           The 'In' filters are applied before the 'Out' filters.
1137
#
1138
#           If no 'In' filters are specified then all files will be included.
1139
#
1140
#           The filter rules are applied to the path below the Srcdir, and, for
1141
#           the purposes of the filter the path starts with a '/'.
1142
#
1143
#------------------------------------------------------------------------------
1144
{
1145
    my $src_base_dir;
1146
    my $flatten = 0;
1147
    my $dstDir;
1552 dpurdie 1148
    my $search =  LocateFiles->new(recurse => 1);
1530 dpurdie 1149
 
1534 dpurdie 1150
    Information("Installing all Prepared pkg files...");
1530 dpurdie 1151
 
1152
    #
1153
    #   Process the arguments and extract parameters and options
1154
    #
1155
    foreach ( @_ )
1156
    {
1157
        if ( m/^--Srcdir=(.*)/ ) {
1534 dpurdie 1158
            Error("installAllDpkgArchivePkgFiles2: Multiple --Srcdir not allowed")
1530 dpurdie 1159
                if ( $src_base_dir );
1160
            $src_base_dir = "$InterfaceDir/$1";
1534 dpurdie 1161
            $src_base_dir =~ s~/\.$~~;
1162
            $src_base_dir =~ s~/$~~;
1530 dpurdie 1163
 
1164
        } elsif ( /^--Dstdir=(.*)/ ) {
1534 dpurdie 1165
            Error("installAllDpkgArchivePkgFiles2: Multiple target directories not allowed")
1530 dpurdie 1166
                if ( $dstDir );
1167
            $dstDir = $1;
1168
 
1169
        } elsif ( m/^--NoRecurse/ ) {
1552 dpurdie 1170
            $search->recurse(0);
1530 dpurdie 1171
 
1172
        } elsif ( m/^--Recurse/ ) {
1552 dpurdie 1173
            $search->recurse(1);
1530 dpurdie 1174
 
1175
        } elsif ( /^--FilterOut=(.*)/ ) {
1552 dpurdie 1176
            $search->filter_out( $1 );
1530 dpurdie 1177
 
1178
        } elsif ( /^--FilterOutRE=(.*)/ ) {
1552 dpurdie 1179
            $search->filter_out_re( $1 );
1530 dpurdie 1180
 
1181
        } elsif ( /^--FilterIn=(.*)/ ) {
1552 dpurdie 1182
            $search->filter_in( $1 );
1530 dpurdie 1183
 
1184
        } elsif ( /^--FilterInRE=(.*)/ ) {
1552 dpurdie 1185
            $search->filter_in_re( $1 );
1530 dpurdie 1186
 
1187
        } elsif ( /^--Flatten/ ) {
1188
            $flatten = 1;
1189
 
1190
        } elsif ( /^--NoFlatten/ ) {
1191
            $flatten = 0;
1192
 
1193
        } elsif ( m/^--/ ) {
1534 dpurdie 1194
            Error("installAllDpkgArchivePkgFiles2: Unknown option: $_")
1530 dpurdie 1195
 
1196
        } else {
1534 dpurdie 1197
            Error("installAllDpkgArchivePkgFiles2: Multiple target directories not allowed")
1530 dpurdie 1198
                if ( $dstDir );
1199
 
1200
            #   Convert the symbolic target directory name into a real path
1201
 
1202
            $dstDir = getTargetDstDirValue($_, "A");
1203
        }
1204
    }
1205
 
1206
    #
1207
    #   Ensure that we have a valid source directory
1208
    #   Data taken from the 'pkg' directory unless otherwise specified by the user
1209
    #
1210
    $src_base_dir = $DpkgPkgDir unless $src_base_dir;
1534 dpurdie 1211
    Error("installAllDpkgArchivePkgFiles2: Package directory not found: $src_base_dir")
1530 dpurdie 1212
        unless ( -d $src_base_dir );
1213
 
1214
    #
1215
    #   Ensure that the user has specified a target directory
1216
    #
1534 dpurdie 1217
    Error("installAllDpkgArchivePkgFiles2: No target directories specified")
1530 dpurdie 1218
        unless ( $dstDir );
1219
 
1220
    #
1221
    #   Build up a list of files to copy
1222
    #   Creating a list allows:
1223
    #       Simplified coding
1224
    #       Flattening and testing of the flattening
1225
    #
1552 dpurdie 1226
    my @elements = $search->search( $src_base_dir);
1592 dpurdie 1227
    Warning("installAllDpkgArchivePkgFiles2: No files found") unless ( @elements );
1530 dpurdie 1228
 
1229
    #
1230
    #   Perform the file copy
1231
    #   This copy will NOT create empty directories, but it will create needed
1232
    #   directories on the fly.
1233
    #
1234
    foreach  my $sfile ( @elements )
1235
    {
1236
 
1237
        #
1238
        #   Split into directory and file as we may need to make the directory
1239
        #   since the copy operation will not
1240
        #
1241
        my $dir;                                # Target directory
1242
        my $tfile;                              # Target path
1534 dpurdie 1243
       (my $fname = $sfile )=~ s~^.*/+~~;       # Filename(only)
1530 dpurdie 1244
 
1245
        unless ( $flatten )
1246
        {
1247
            $sfile =~ m~^(.*/)~;
1248
            $dir = "$dstDir/$1";
1249
            $tfile = $sfile;
1250
        }
1251
        else
1252
        {
1253
            $dir = $dstDir;
1254
            $tfile = $fname;
1255
        }
1256
 
1257
        #
1258
        #   Ensure the target directory is present
1259
        #
1534 dpurdie 1260
        make_directory ( $dir, 0775 );
1530 dpurdie 1261
 
1262
        #
1263
        #   Copy the file
1264
        #   Ensure that the target file does not already exist
1265
        #   This is most likely to occur when flattening the directory structure
1266
        #
1267
        my $m_sfile = "$src_base_dir$sfile";
1268
        my $m_tfile = "$dstDir/$tfile";
1269
 
1270
        if ( -f $m_tfile  )
1271
        {
1534 dpurdie 1272
            Error("Failed to copy file [$m_sfile] to [$m_tfile]: File already exists");
1530 dpurdie 1273
        }
1274
 
1275
        if( File::Copy::copy("$m_sfile", "$m_tfile") )
1276
        {
1534 dpurdie 1277
            Verbose("Copied [$fname] to [$m_tfile] ...");
1530 dpurdie 1278
        }
1279
        else
1280
        {
1534 dpurdie 1281
            Error("Failed to copy file [$m_sfile] to [$m_tfile]: $!");
1530 dpurdie 1282
        }
1283
    }
1284
 
1285
    return 1;
1286
}
1287
 
1288
#------------------------------------------------------------------------------
1540 dpurdie 1289
sub installDpkgArchivePkgRaw
1290
#
1291
# Description:
1292
#       This sub-routine is used to install all pkg files from the named package
1293
#       in dpkg_archive into the defined install area.
1294
#
1295
#       If it has any problems it will log an error and stop processing.
1296
#
1297
# Inputs          : targetTag       - Target directory      [Mandatory]
1298
#                   package         - Source Package        [Mandatory]
1299
#                   options         - Optional options
1300
#                                       --NoRecurse
1301
#                                       --Recurse           [default]
1302
#                                       --Flatten
1303
#                                       --NoFlatten         [default]
1304
#                                       --FilterIn=xx
1305
#                                       --FilterInRE=xx     [default=.*]
1306
#                                       --FilterOut=xx
1307
#                                       --FilterOutRE=xx
1308
#                                       --Warn              [ default]
1309
#                                       --NoWarn
1310
#
1311
# Notes:    --FilterIn=xxxx, --FilterOut=xxx
1312
#           xxx is a simple Shell style filter where:
1313
#               * means one or more charters        '*.EXE'
1314
#               ? means a single character          '*.?'
1315
#               [abc] means either a or b or c      'file.[ch]'
1316
#
1317
#           --FilterInRE=xxx, --FilterOutRE=xxx
1318
#           xxx is a Regular Expression. There are harder to use but very
1319
#           powerful. ie '.*\.EXE$'
1320
#
1321
#           The 'In' filters are applied before the 'Out' filters.
1322
#
1323
#           If no 'In' filters are specified then all files will be included.
1324
#
1325
#           The filter rules are applied to the path below the Srcdir, and, for
1326
#           the purposes of the filter the path starts with a '/'.
1327
#
1328
#
1329
#       --NoWarn
1330
#           Supresses the warning message generated if no files are transferred
1331
#
1332
#------------------------------------------------------------------------------
1333
{
1334
    my $flatten = 0;
1335
    my $dstDir;
1336
    my @args;
1337
    my $src_base_dir;
1338
    my $warning = 1;
1552 dpurdie 1339
    my $search =  LocateFiles->new(recurse => 1);
1540 dpurdie 1340
 
1341
    #
1342
    #   Process the arguments and extract parameters and options
1343
    #
1344
    foreach ( @_ )
1345
    {
1346
        if ( m/^--NoRecurse/ ) {
1552 dpurdie 1347
            $search->recurse(0);
1540 dpurdie 1348
 
1349
        } elsif ( m/^--Recurse/ ) {
1552 dpurdie 1350
            $search->recurse(1);
1540 dpurdie 1351
 
1352
        } elsif ( /^--FilterOut=(.*)/ ) {
1552 dpurdie 1353
            $search->filter_out( $1 );
1540 dpurdie 1354
 
1355
        } elsif ( /^--FilterOutRE=(.*)/ ) {
1552 dpurdie 1356
            $search->filter_out_re( $1 );
1540 dpurdie 1357
 
1358
        } elsif ( /^--FilterIn=(.*)/ ) {
1552 dpurdie 1359
            $search->filter_in( $1 );
1540 dpurdie 1360
 
1361
        } elsif ( /^--FilterInRE=(.*)/ ) {
1552 dpurdie 1362
            $search->filter_in_re( $1 );
1540 dpurdie 1363
 
1364
        } elsif ( /^--Flatten/ ) {
1365
            $flatten = 1;
1366
 
1367
        } elsif ( /^--NoFlatten/ ) {
1368
            $flatten = 0;
1369
 
1370
        } elsif ( /^--NoWarn/ ) {
1371
            $warning = 0;
1372
 
1373
        } elsif ( /^--Warn/ ) {
1374
            $warning = 1;
1375
 
1376
        } elsif ( m/^--/ ) {
1377
            Error("installDpkgArchivePkgRaw: Unknown option: $_")
1378
 
1379
        } else {
1380
            push @args, $_;
1381
 
1382
        }
1383
    }
1384
 
1385
    #
1386
    #   Have removed all the options
1387
    #   Must have two parameters left
1388
    #
1389
    if ( $#args != 1 )
1390
    {
1391
        Error("Incorrect number of params passed to installDpkgArchivePkgRaw() function.",
1392
              "Check deploy config.");
1393
    }
1394
 
1395
    my ( $dstDirTag, $pkgName ) = @args;
1396
 
1397
    #
1398
    #   Ensure that the user has specified a target directory
1399
    #   Convert the symbolic target directory to a real path
1400
    #
1401
    Error("installDpkgArchivePkgRaw: No target directories specified")
1402
        unless ( $dstDirTag );
1403
    $dstDir = getTargetDstDirValue($dstDirTag, "A");
1404
 
1405
    #
1406
    #   Convert the package name into a real path name to the package as
1407
    #   held in dpkg_archive. Do not use the copy in the 'interface' directory
1408
    #
1546 dpurdie 1409
    $src_base_dir = LocatePackageBase ( "installDpkgArchivePkgRaw", $pkgName );
1540 dpurdie 1410
 
1411
    #
1412
    #   Build up a list of files to copy
1413
    #   Creating a list allows:
1414
    #       Simplified coding
1415
    #       Flattening and testing of the flattening
1416
    #
1552 dpurdie 1417
    my @elements = $search->search( $src_base_dir );
1540 dpurdie 1418
    Information("Installing Raw Pkg files: $pkgName") if @elements;
1419
 
1420
    #
1421
    #   Perform the file copy
1422
    #   This copy will NOT create empty directories, but it will create needed
1423
    #   directories on the fly.
1424
    #
1425
    foreach  my $sfile ( @elements )
1426
    {
1427
 
1428
        #
1429
        #   Split into directory and file as we may need to make the directory
1430
        #   since the copy operation will not
1431
        #
1432
        my $dir;                                # Target directory
1433
        my $tfile;                              # Target path
1434
       (my $fname = $sfile )=~ s~^.*/+~~;       # Filename(only)
1435
 
1436
        unless ( $flatten )
1437
        {
1438
            $sfile =~ m~^(.*/)~;
1439
            $dir = "$dstDir/$1";
1440
            $tfile = $sfile;
1441
        }
1442
        else
1443
        {
1444
            $dir = $dstDir;
1445
            $tfile = $fname;
1446
        }
1447
 
1448
        #
1449
        #   Ensure the target directory is present
1450
        #
1451
        make_directory ( $dir, 0775 );
1452
 
1453
        #
1454
        #   Copy the file
1455
        #   Ensure that the target file does not already exist
1456
        #   This is most likely to occur when flattening the directory structure
1457
        #
1458
        my $m_sfile = "$src_base_dir$sfile";
1459
        my $m_tfile = "$dstDir/$tfile";
1460
 
1461
        if ( -f $m_tfile  )
1462
        {
1463
            Error("Failed to copy file [$m_sfile] to [$m_tfile]: File already exists");
1464
        }
1465
 
1466
        if( File::Copy::copy("$m_sfile", "$m_tfile") )
1467
        {
1468
            Verbose("Copied [$fname] to [$m_tfile] ...");
1469
        }
1470
        else
1471
        {
1472
            Error("Failed to copy file [$m_sfile] to [$m_tfile]: $!");
1473
        }
1474
    }
1475
 
1476
    #
1477
    #   Return the number of files transferred
1478
    #
1479
    my $nfiles = $#elements + 1;
1480
    Warning("Installing Raw Pkg files: $pkgName - No files transferred") if ( $warning && ! $nfiles ) ;
1481
 
1482
    return $nfiles;
1483
}
1484
 
1485
 
1486
#------------------------------------------------------------------------------
1530 dpurdie 1487
sub installAllDpkgArchiveDevcdFiles
1488
#
1489
# Description:
1490
#       This sub-routine is used to install all devcd files from the
1491
#       dpkg_archive into the defined install area.
1492
#
1493
#       It assumes based on the build type where the src files will be located.
1494
#
1495
#       If it has any problems it will log an error and stop processing.
1496
#
1497
#       Source directory: $DpkgDevcdDir       (interface/devcd)
1498
#       Target directory: Symbolic Directory
1499
#
1500
# Inputs: None
1501
#
1502
#------------------------------------------------------------------------------
1503
{
1504
    # correct number of parameters?
1505
    if ( ($#_+1) != 1 )
1506
    {
1534 dpurdie 1507
        Error("Incorrect number of params passed to " .
1508
              "installAllDpkgArchiveDevcdFiles() function. ",
1509
              "Check deploy config.");
1530 dpurdie 1510
    }
1511
 
1534 dpurdie 1512
    Information("Installing all Prepared Day 0 devcd files...");
1530 dpurdie 1513
 
1514
 
1515
    my ($targetTag) = @_;
1516
 
1517
    # lets check to see if the target tag exists
1518
    # if does not the process with log an error.
1519
    #
1520
    my ($targetValue) = getTargetDstDirValue($targetTag, "R");
1521
 
1522
 
1523
    # ok we have a valid dst value we now need to get a hold of all the 
1524
    # lib scripts files.
1525
    #
1526
    if ( "$MachType" eq "win32" || "$MachType" eq "WinCE" )
1527
    {
1528
        $TmpGlobalVariable = $targetValue; 
1529
        File::Find::find( \&pkgFindDevcd, "$DpkgDevcdDir");
1530
    }
1531
    else
1532
    {
1533
        my ($i);
1534
        my(@FindRes) = `find $DpkgDevcdDir -follow`;
1535
        my ($m_sfile);
1536
        my ($tmp_DstDir) = "$PkgBaseDir/$targetValue";
1537
        my ($tmp_SrcDir) = "$DpkgDevcdDir";
1538
        foreach $i (@FindRes)
1539
        {
1540
 
1541
            chomp($i);
1542
            my($base)= File::Basename::basename($i);
1543
 
1544
            if ( $base eq "devcd" )
1545
            {
1546
                next;
1547
            }
1548
 
1549
            my ($tmp_dItem) = $i;
1550
            $tmp_dItem =~ s/$tmp_SrcDir/$tmp_DstDir/;
1551
 
1534 dpurdie 1552
            if ( -d $i )
1530 dpurdie 1553
            {
1534 dpurdie 1554
                make_directory ( $tmp_dItem, 0775 );
1530 dpurdie 1555
            }
1556
            else
1557
            {
1534 dpurdie 1558
                if(File::Copy::copy( $i , $tmp_dItem ))
1530 dpurdie 1559
                {
1534 dpurdie 1560
                    Verbose("Copied [$base] to [$tmp_dItem] ...");
1530 dpurdie 1561
                }
1562
                else
1563
                {
1534 dpurdie 1564
                    Error("Failed to copy pkg file [$tmp_dItem] to [$i]: $!");
1530 dpurdie 1565
                }
1566
            }
1567
        }
1568
    }
1569
 
1570
    return 1;
1571
}
1572
 
1573
 
1574
#------------------------------------------------------------------------------
1575
sub pkgFindDevcd
1576
#
1577
#    Description:
1578
#        This subroutine is used to locate all associated devcd files in 
1579
#        a pre-defined dpkg_archive.
1580
#
1581
#   Trick: Will not copy a file/directory called 'devcd'
1582
#          Not too sure why. May be an attempt to prevent empty devcd directories
1583
#          If you know better, then correct this comment.
1584
#------------------------------------------------------------------------------
1585
{
1586
    my($item)= "$File::Find::name";
1587
    my($base)= File::Basename::basename($item);
1588
 
1589
    if ( $base eq "devcd" )
1590
    {
1591
        return 1;
1592
    }
1593
 
1594
    my ($tmp_dItem) = $item;
1595
    my ($tmp_DstDir) = "$PkgBaseDir/$TmpGlobalVariable";
1596
    my ($tmp_SrcDir) = "$DpkgDevcdDir";
1597
    $tmp_dItem =~ s/$tmp_SrcDir/$tmp_DstDir/;
1598
 
1599
    # we need to determine what type of item we are dealing with file we are dealing with
1600
    if ( -d "$item")
1601
    {
1534 dpurdie 1602
        make_directory( $tmp_dItem, 0775 );
1530 dpurdie 1603
    }
1604
    else
1605
    {
1606
        if(File::Copy::copy("$item", "$tmp_dItem"))
1607
        {
1534 dpurdie 1608
            Verbose("Copied [$base] to [$tmp_dItem] ...");
1530 dpurdie 1609
        }
1610
        else
1611
        {
1534 dpurdie 1612
            Error("Failed to copy pkg file [$tmp_dItem] to [$item]: $!"); 
1530 dpurdie 1613
        }
1614
    }
1615
}
1616
 
1617
#------------------------------------------------------------------------------
1618
sub installAllDpkgArchiveFiles
1619
#
1620
# Description:
1621
#       This sub-routine is used to install all files from the
1622
#       dpkg_archive into the defined install area.
1623
#
1624
#       It assumes based on the build type where the src files will be located.
1625
#
1626
#       If it has any problems it will log an error and stop processing.
1627
#
1628
# Inputs:   $targetType         - Internal tag to specify source file
1629
#           $targetTag          - Users tag for destination
1630
#
1631
#
1632
#------------------------------------------------------------------------------
1633
{
1634
    # correct number of parameters?
1635
    if ( ($#_+1) != 2 )
1636
    {
1534 dpurdie 1637
        Error("Incorrect number of params passed to " .
1638
              "installAllDpkgArchiveFiles() function. ",
1639
              "Check deploy config.");
1530 dpurdie 1640
    }
1641
 
1642
    my ($targetType, $targetTag) = @_;
1643
 
1644
    # lets check to see if the target tag exists
1645
    # if does not the process with log an error.
1646
    #
1647
    my $targetValue;
1648
    if ( $targetTag eq "--NoTag" )
1649
    {
1650
        $targetValue = "$PkgBaseDir/$TargetBaseDir";
1651
    }
1652
    else
1653
    {
1654
       $targetValue = getTargetDstDirValue($targetTag, "A");
1655
    }
1656
 
1657
    # ok we have a valid dst value we now need to get a hold of all the 
1658
    # lib scripts files.
1659
    #
1660
    local *DIR;
1661
    my $src_dir;
1662
 
1663
    if    ( "$targetType" eq "jar" )        { $src_dir = $DpkgJarDir; }
1664
    elsif ( "$targetType" eq "sar" )        { $src_dir = $DpkgSarDir; }
1665
    elsif ( "$targetType" eq "include" )    { $src_dir = $DpkgIncludeDir; }
1666
    elsif ( "$targetType" eq "war" )        { $src_dir = $DpkgWarDir; }
1667
    elsif ( "$targetType" eq "infofiles" )  { $src_dir = $DpkgInfoFilesDir; }
1668
    elsif ( "$targetType" eq "sql" )        { $src_dir = $DpkgSqlDir; }
1669
    elsif ( "$targetType" eq "etc" )        { $src_dir = $DpkgEtcDir; }
1670
    elsif ( "$targetType" eq "scripts" )    { $src_dir = $DpkgScriptsDir; }
1671
    elsif ( "$targetType" eq "rox" )        { $src_dir = $DpkgRoxDir; }
1672
    elsif ( "$targetType" eq "rpt" )        { $src_dir = $DpkgRptDir; }
1673
    elsif ( "$targetType" eq "doc" )        { $src_dir = $DpkgDocDir; }
1674
    elsif ( "$targetType" eq "jsp" )        { $src_dir = $DpkgJspDir; }
1675
#    elsif ( "$targetType" eq "achtml" )     { $src_dir = $DpkgAcHtmlDir; }
1676
    else  {
1534 dpurdie 1677
        Error("installAllDpkgArchiveFiles() passed unknown target type [$targetType].");
1530 dpurdie 1678
    }
1679
 
1680
    opendir(DIR, $src_dir) or
1534 dpurdie 1681
            Error("Can't opendir $src_dir: $!");
1530 dpurdie 1682
 
1683
 
1684
    # lets process what we have found
1685
    #
1686
    my ($file);
1687
    while (defined($file = readdir(DIR))) 
1688
    {
1689
        if ( $file !~ /^.$/  && 
1690
             $file !~ /^..$/ ) 
1691
        {
1692
            my ($m_fLoc) = "$src_dir/$file";
1693
 
1694
            if(File::Copy::copy("$m_fLoc", "$targetValue"))
1695
            {
1534 dpurdie 1696
                Verbose("Copied [$targetType] item [$file] to [$targetValue] ...");
1530 dpurdie 1697
            }
1698
            else
1699
            {
1534 dpurdie 1700
                Error("Failed to copy [$targetType] item [$m_fLoc]: $!"); 
1530 dpurdie 1701
            }
1702
        }
1703
    }
1704
 
1705
    closedir(DIR);
1706
    return 1;
1707
}
1708
 
1709
 
1710
#------------------------------------------------------------------------------
1711
sub installAllDpkgArchiveAcHtmlFiles
1712
#
1713
# Description:
1714
#       This sub-routine is used to install all achtml files from the
1715
#       dpkg_archive into the defined install area.
1716
#
1717
#       It assumes based on the build type where the src files will be located.
1718
#
1719
#       If it has any problems it will log an error and stop processing.
1720
#
1721
#
1722
# Ugly trick:
1723
#       This function tags a $$targetType argument which is used in constructing
1724
#       the source directory path. ie: InterfaceDir/achtml/$targetType
1725
#
1726
#       Could provide as an option to installAllDpkgArchiveFiles and re-use that
1727
#       function
1728
#
1729
#------------------------------------------------------------------------------
1730
{
1731
    # correct number of parameters?
1732
    if ( ($#_+1) != 2 )
1733
    {
1534 dpurdie 1734
        Error("Incorrect number of params passed to " .
1735
              "installAllDpkgArchiveAcHtmlFiles() function. ",
1736
              "Check deploy config.");
1530 dpurdie 1737
    }
1738
    my ($targetType, $targetTag) = @_;
1739
 
1740
    # lets check to see if the target tag exists
1741
    # if does not the process with log an error.
1742
    #
1743
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
1744
 
1745
    # lets check to see if the source type dir actually exists
1746
    #
1747
    my($m_sDirLoc)  = "$DpkgAcHtmlDir/$targetType";
1748
    if( ! -d "$m_sDirLoc" )
1749
    {
1534 dpurdie 1750
        Error("Failed to locate [$targetType] AcHtml dir [$m_sDirLoc].");
1530 dpurdie 1751
    }
1752
 
1753
    # know everything exists so lets do the biz.
1754
    #
1755
    # now we need to copy all the files.
1756
    #
1757
    local *DIR;
1758
    opendir(DIR, $m_sDirLoc) or 
1534 dpurdie 1759
        Error("Can't opendir $m_sDirLoc: $!");
1530 dpurdie 1760
 
1761
    my ($m_fLoc) = "";
1762
    my ($file) = "";
1763
    while (defined($file = readdir(DIR)))
1764
    {
1765
        if ( $file !~ /^.$/  &&
1766
             $file !~ /^..$/ )
1767
        {
1768
            $m_fLoc = "$m_sDirLoc/$file";
1769
            if(File::Copy::copy("$m_fLoc", "$targetValue"))
1770
            {
1534 dpurdie 1771
                Verbose("Copied AcHtml [$targetType] item [$file] to [$targetValue] ...");
1530 dpurdie 1772
            }
1773
            else
1774
            {
1534 dpurdie 1775
                Error("Failed to copy AcHtml [$targetType] item [$m_fLoc]: $!");
1530 dpurdie 1776
            }
1777
        }
1778
    }
1779
 
1780
    closedir(DIR);
1781
    return 1;
1782
}
1783
 
1784
 
1785
#------------------------------------------------------------------------------
1786
sub installAllDpkgArchiveInfoFilesFiles
1787
#
1788
# Description:
1789
#       This sub-routine is used to install all infofiles files from the
1790
#       dpkg_archive into the defined install area.
1791
#
1792
#       It assumes based on the build type where the src files will be located.
1793
#
1794
#       If it has any problems it will log an error and stop processing.
1795
#
1796
#------------------------------------------------------------------------------
1797
{
1798
    # correct number of parameters?
1799
    if ( ($#_+1) != 1 )
1800
    {
1534 dpurdie 1801
        Error("Incorrect number of params passed to " .
1802
              "installAllDpkgArchiveInfoFilesFiles() function. ",
1803
              "Check deploy config.");
1530 dpurdie 1804
    }
1805
 
1806
    my ($targetTag) = @_;
1807
 
1808
    # lets check to see if the target tag exists
1809
    # if does not the process with log an error.
1810
    #
1811
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
1812
 
1813
 
1814
    # for now lets call the generic funtion to move all items
1815
    # in the associated dpkg_archive dir.
1816
    #
1817
    installAllDpkgArchiveFiles("infofiles", $targetTag);
1818
 
1819
    return 1;
1820
}
1821
 
1822
 
1823
 
1824
#------------------------------------------------------------------------------
1825
sub installAllDpkgArchiveSqlFiles
1826
#
1827
# Description:
1828
#       This sub-routine is used to install all sql files from the
1829
#       dpkg_archive into the defined install area.
1830
#
1831
#       It assumes based on the build type where the src files will be located.
1832
#
1833
#       If it has any problems it will log an error and stop processing.
1834
#
1835
#------------------------------------------------------------------------------
1836
{
1837
    # correct number of parameters?
1838
    if ( ($#_+1) != 1 )
1839
    {
1534 dpurdie 1840
        Error("Incorrect number of params passed to " .
1841
              "installAllDpkgArchiveSqlFiles() function. ",
1842
              "Check deploy config.");
1530 dpurdie 1843
    }
1844
 
1845
    my ($targetTag) = @_;
1846
 
1847
    # lets check to see if the target tag exists
1848
    # if does not the process with log an error.
1849
    #
1850
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
1851
 
1852
 
1853
    # for now lets call the generic funtion to move all items
1854
    # in the associated dpkg_archive dir.
1855
    #
1856
    installAllDpkgArchiveFiles("sql", $targetTag);
1857
 
1858
    return 1;
1859
}
1860
 
1861
 
1862
#------------------------------------------------------------------------------
1863
sub installAllDpkgArchiveWarFiles
1864
#
1865
# Description:
1866
#       This sub-routine is used to install all war files from the
1867
#       dpkg_archive into the defined install area.
1868
#
1869
#       It assumes based on the build type where the src files will be located.
1870
#
1871
#       If it has any problems it will log an error and stop processing.
1872
#
1873
#------------------------------------------------------------------------------
1874
{
1875
    # correct number of parameters?
1876
    if ( ($#_+1) != 1 )
1877
    {
1534 dpurdie 1878
        Error("Incorrect number of params passed to " .
1879
              "installAllDpkgArchiveWarFiles() function. " ,
1880
              "Check deploy config.");
1530 dpurdie 1881
    }
1882
 
1883
    my ($targetTag) = @_;
1884
 
1885
    # lets check to see if the target tag exists
1886
    # if does not the process with log an error.
1887
    #
1888
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
1889
 
1890
 
1891
    # for now lets call the generic funtion to move all items
1892
    # in the associated dpkg_archive dir.
1893
    #
1894
    installAllDpkgArchiveFiles("war", $targetTag);
1895
 
1896
    return 1;
1897
}
1898
 
1899
 
1900
#------------------------------------------------------------------------------
1901
sub installAllDpkgArchiveJarFiles
1902
#
1903
# Description:
1904
#       This sub-routine is used to install all jar files from the
1905
#       dpkg_archive into the defined install area.
1906
#
1907
#       It assumes based on the build type where the src files will be located.
1908
#
1909
#       If it has any problems it will log an error and stop processing.
1910
#
1911
#------------------------------------------------------------------------------
1912
{
1913
    # correct number of parameters?
1914
    if ( ($#_+1) != 1 )
1915
    {
1534 dpurdie 1916
        Error("Incorrect number of params passed to " .
1917
              "installAllDpkgArchiveJarFiles() function. " ,
1918
              "Check deploy config.");
1530 dpurdie 1919
    }
1920
 
1921
    my ($targetTag) = @_;
1922
 
1923
    # lets check to see if the target tag exists
1924
    # if does not the process with log an error.
1925
    #
1926
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
1927
 
1928
 
1929
    # for now lets call the generic funtion to move all items
1930
    # in the associated dpkg_archive dir.
1931
    #
1932
    installAllDpkgArchiveFiles("jar", $targetTag);
1933
 
1934
    return 1;
1935
}
1936
 
1937
 
1938
#------------------------------------------------------------------------------
1939
sub installAllDpkgArchiveEtcFiles
1940
#
1941
# Description:
1942
#       This sub-routine is used to install all etc files from the
1943
#       dpkg_archive into the defined install area.
1944
#
1945
#       It assumes based on the build type where the src files will be located.
1946
#
1947
#       If it has any problems it will log an error and stop processing.
1948
#
1949
#------------------------------------------------------------------------------
1950
{
1951
    # correct number of parameters?
1952
    if ( ($#_+1) != 1 )
1953
    {
1534 dpurdie 1954
        Error("Incorrect number of params passed to " .
1955
              "installAllDpkgArchiveEtcFiles() function. " ,
1956
              "Check deploy config.");
1530 dpurdie 1957
    }
1958
 
1959
    my ($targetTag) = @_;
1960
 
1961
    # lets check to see if the target tag exists
1962
    # if does not the process with log an error.
1963
    #
1964
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
1965
 
1966
 
1967
    # for now lets call the generic funtion to move all items
1968
    # in the associated dpkg_archive dir.
1969
    #
1970
    installAllDpkgArchiveFiles("etc", $targetTag);
1971
 
1972
    return 1;
1973
}
1974
 
1975
 
1976
#------------------------------------------------------------------------------
1977
sub installAllDpkgArchiveScriptsFiles
1978
#
1979
# Description:
1980
#       This sub-routine is used to install all scripts files from the
1981
#       dpkg_archive into the defined install area.
1982
#
1983
#       It assumes based on the build type where the src files will be located.
1984
#
1985
#       If it has any problems it will log an error and stop processing.
1986
#
1987
#------------------------------------------------------------------------------
1988
{
1989
    # correct number of parameters?
1990
    if ( ($#_+1) != 1 )
1991
    {
1534 dpurdie 1992
        Error("Incorrect number of params passed to " .
1993
              "installAllDpkgArchiveScriptsFiles() function. " ,
1994
              "Check deploy config.");
1530 dpurdie 1995
    }
1996
 
1997
    my ($targetTag) = @_;
1998
 
1999
    # lets check to see if the target tag exists
2000
    # if does not the process with log an error.
2001
    #
2002
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2003
 
2004
 
2005
    # for now lets call the generic funtion to move all items
2006
    # in the associated dpkg_archive dir.
2007
    #
2008
    installAllDpkgArchiveFiles("scripts", $targetTag);
2009
 
2010
    return 1;
2011
}
2012
 
2013
 
2014
#------------------------------------------------------------------------------
2015
sub installAllDpkgArchiveIncludeFiles
2016
#
2017
# Description:
2018
#       This sub-routine is used to install all include files from the
2019
#       dpkg_archive into the defined install area.
2020
#
2021
#       It assumes based on the build type where the src files will be located.
2022
#
2023
#       If it has any problems it will log an error and stop processing.
2024
#
2025
#------------------------------------------------------------------------------
2026
{
2027
    # correct number of parameters?
2028
    if ( ($#_+1) != 1 )
2029
    {
1534 dpurdie 2030
        Error("Incorrect number of params passed to " .
2031
              "installAllDpkgArchiveIncludeFiles() function. " ,
2032
              "Check deploy config.");
1530 dpurdie 2033
    }
2034
 
2035
    my ($targetTag) = @_;
2036
 
2037
    # lets check to see if the target tag exists
2038
    # if does not the process with log an error.
2039
    #
2040
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2041
 
2042
 
2043
    # for now lets call the generic funtion to move all items
2044
    # in the associated dpkg_archive dir.
2045
    #
2046
    installAllDpkgArchiveFiles("include", $targetTag);
2047
 
2048
    return 1;
2049
}
2050
 
2051
 
2052
#------------------------------------------------------------------------------
2053
sub installAllDpkgArchiveDocFiles
2054
#
2055
# Description:
2056
#       This sub-routine is used to install all include files from the
2057
#       dpkg_archive into the defined install area.
2058
#
2059
#       It assumes based on the build type where the src files will be located.
2060
#
2061
#       If it has any problems it will log an error and stop processing.
2062
#
2063
#------------------------------------------------------------------------------
2064
{
2065
    # correct number of parameters?
2066
    if ( ($#_+1) != 1 )
2067
    {
1534 dpurdie 2068
        Error("Incorrect number of params passed to " .
2069
              "installAllDpkgArchiveIncludeFiles() function. " ,
2070
              "Check deploy config.");
1530 dpurdie 2071
    }
2072
 
2073
    my ($targetTag) = @_;
2074
 
2075
    # lets check to see if the target tag exists
2076
    # if does not the process with log an error.
2077
    #
2078
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2079
 
2080
 
2081
    # for now lets call the generic funtion to move all items
2082
    # in the associated dpkg_archive dir.
2083
    #
2084
    installAllDpkgArchiveFiles("doc", $targetTag);
2085
 
2086
    return 1;
2087
}
2088
 
2089
#------------------------------------------------------------------------------
2090
sub installAllDpkgArchiveJspFiles
2091
#
2092
# Description:
2093
#       This sub-routine is used to install all jsp associated files from the
2094
#       dpkg_archive into the defined install area.
2095
#
2096
#       It assumes based on the build type where the src files will be located.
2097
#
2098
#       If it has any problems it will log an error and stop processing.
2099
#
2100
#   Source directory: $DpkgJspDir
2101
#   Target directory: $TargetBaseDir
2102
#
2103
#------------------------------------------------------------------------------
2104
{
2105
    # correct number of parameters?
2106
    if ( ($#_+1) != 0 )
2107
    {
1534 dpurdie 2108
        Error("Incorrect number of params passed to " .
2109
              "installAllDpkgArchiveJspFiles() function. " ,
2110
              "Check deploy config.");
1530 dpurdie 2111
    }
2112
 
2113
    return installAllDpkgArchiveFiles ('jsp', '--NoTag');
2114
}
2115
 
2116
 
2117
#------------------------------------------------------------------------------
2118
sub installDpkgArchiveFile
2119
#
2120
# Description:
2121
#       This sub-routine is used to install a file of a particular type
2122
#       from the dpkg_archive into the supplied install dir. 
2123
#
2124
#       It assumes based on the build type where the file will be located.
2125
#
2126
#       If it fails to find the file it will report an error and terminates
2127
#       processing.
2128
#
2129
# Inputs:   $targetType         - Type of target ( provides source directory)
2130
#           $sfile              - Source file name, within source directory
2131
#           $targetTag          - Symbolic target dir
2132
#
2133
#
2134
# Note: This function will copy a single file
2135
#
2136
#------------------------------------------------------------------------------
2137
{
2138
    # correct number of parameters?
2139
    if ( ($#_+1) != 3 )
2140
    {
1534 dpurdie 2141
        Error("Incorrect number of params passed to " .
2142
              "installDpkgArchiveFile() function. " ,
2143
              "Check deploy config.");
1530 dpurdie 2144
    }
2145
 
2146
    my ($targetType, $sfile, $targetTag) = @_;
2147
 
2148
    # lets check to see if the target tag exists
2149
    # if does not the process with log an error.
2150
    #
2151
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2152
 
2153
 
2154
    # lets define the absolute location of the file
2155
    #
2156
    my ($m_dstFileLocation) = "$targetValue/$sfile";
2157
    my ($m_srcFileLocation) = "";
2158
 
2159
    if    ( "$targetType" eq "jar" )        { $m_srcFileLocation = "$DpkgJarDir/$sfile"; }
2160
    elsif ( "$targetType" eq "sar" )        { $m_srcFileLocation = "$DpkgSarDir/$sfile"; }
2161
    elsif ( "$targetType" eq "include" )    { $m_srcFileLocation = "$DpkgIncludeDir/$sfile"; }
2162
    elsif ( "$targetType" eq "war" )        { $m_srcFileLocation = "$DpkgWarDir/$sfile"; }
2163
    elsif ( "$targetType" eq "infofiles" )  { $m_srcFileLocation = "$DpkgInfoFilesDir/$sfile"; }
2164
    elsif ( "$targetType" eq "sql" )        { $m_srcFileLocation = "$DpkgSqlDir/$sfile"; }
2165
    elsif ( "$targetType" eq "etc" )        { $m_srcFileLocation = "$DpkgEtcDir/$sfile"; }
2166
    elsif ( "$targetType" eq "scripts" )    { $m_srcFileLocation = "$DpkgScriptsDir/$sfile";  }
2167
    elsif ( "$targetType" eq "rox" )        { $m_srcFileLocation = "$DpkgRoxDir/$sfile";  }
2168
    elsif ( "$targetType" eq "dat" )        { $m_srcFileLocation = "$DpkgDatDir/$sfile";  }
2169
    elsif ( "$targetType" eq "thx" )        { $m_srcFileLocation = "$DpkgThxDir/$sfile";  }
2170
    elsif ( "$targetType" eq "mug" )        { $m_srcFileLocation = "$DpkgMugDir/$sfile";  }
2171
    elsif ( "$targetType" eq "rpt" )        { $m_srcFileLocation = "$DpkgRptDir/$sfile";  }
2172
    elsif ( "$targetType" eq "doc" )        { $m_srcFileLocation = "$DpkgDocDir/$sfile";  }
2173
    else  {
1534 dpurdie 2174
        Error("installDpkgArchiveFile() passed unknown target type [$targetType].");
1530 dpurdie 2175
    }
2176
 
2177
 
2178
    # we will check to see if the file exists.
2179
    #
2180
    if ( -f "$m_srcFileLocation" )
2181
    {
2182
        # now we need to copy the file. 
2183
        if(File::Copy::copy("$m_srcFileLocation", "$m_dstFileLocation"))
2184
        {
1534 dpurdie 2185
            Verbose("Copied [$targetType] item [$sfile] to [$m_dstFileLocation] ...");
1530 dpurdie 2186
        }
2187
        else
2188
        {
1534 dpurdie 2189
            Error("Failed to copy [$targetType] item [$sfile]: $!"); 
1530 dpurdie 2190
        }
2191
    }
2192
    else
2193
    {
1534 dpurdie 2194
        Error("Dpkg_archive [$targetType] item [$sfile] does not exist.");
1530 dpurdie 2195
    }
2196
 
2197
    return 1;
2198
}
2199
 
2200
 
2201
#------------------------------------------------------------------------------
2202
sub installDpkgArchiveAcHtmlFile
2203
#
2204
# Description:
2205
#       This sub-routine is used to install a achtml file from the
2206
#       dpkg_archive into the supplied install dir. 
2207
#
2208
#       It assumes based on the build type where the file will be located.
2209
#
2210
#       If it fails to find the file it will report an error and terminates
2211
#       processing.
2212
#
2213
# Ugly trick:
2214
#       This function tags a $$targetType argument which is used in constructing
2215
#       the source directory path. ie: InterfaceDir/achtml/$targetType
2216
#
2217
#       Could provide as an option to installDpkgArchiveFile and re-use that
2218
#       function
2219
#------------------------------------------------------------------------------
2220
{
2221
    # correct number of parameters?
2222
    if ( ($#_+1) != 3 )
2223
    {
1534 dpurdie 2224
        Error("Incorrect number of params passed to " .
2225
              "installDpkgArchiveAcHtmlFile() function. " ,
2226
              "Check deploy config.");
1530 dpurdie 2227
    }
2228
    my ($targetType, $sfile, $targetTag) = @_;
2229
 
2230
    # lets check to see if the source type and file actually exist
2231
    #
2232
    my($m_sDirLoc)  = "$DpkgAcHtmlDir/$targetType";
2233
    if( ! -d "$m_sDirLoc" )
2234
    {
1534 dpurdie 2235
        Error("Failed to locate [$targetType] AcHtml dir [$m_sDirLoc].");
1530 dpurdie 2236
    }
2237
 
2238
    # lets check to see if the file exists
2239
    #
2240
    my($m_sFileLoc) = "$DpkgAcHtmlDir/$targetType/$sfile";
2241
    if( ! -f "$m_sFileLoc" )
2242
    {
1534 dpurdie 2243
        Error("Failed to locate [$targetType] AcHtml file [$m_sFileLoc].");
1530 dpurdie 2244
    }
2245
 
2246
    # lets check to see if the target tag exists
2247
    # if does not the process with log an error.
2248
    #
2249
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2250
 
2251
    # know everything exists so lets do the biz.
2252
    #
2253
    # now we need to copy the file.
2254
    if(File::Copy::copy("$m_sFileLoc", "$targetValue"))
2255
    {
1534 dpurdie 2256
        Verbose("Copied [$targetType] AcHtml item [$sfile] to [$targetValue] ...");
1530 dpurdie 2257
    }
2258
    else
2259
    {
1534 dpurdie 2260
        Error("Failed to copy [$targetType] AcHtml item [$sfile]: $!");
1530 dpurdie 2261
    }
2262
 
2263
    return 1;
2264
}
2265
 
2266
 
2267
#------------------------------------------------------------------------------
2268
sub installDpkgArchiveRptFile
2269
#
2270
# Description:
2271
#       This sub-routine is used to install a rpt file from the
2272
#       dpkg_archive into the supplied install dir. 
2273
#
2274
#       It assumes based on the build type where the file will be located.
2275
#
2276
#       If it fails to find the file it will report an error and terminates
2277
#       processing.
2278
#
2279
#------------------------------------------------------------------------------
2280
{
2281
    # correct number of parameters?
2282
    if ( ($#_+1) != 2 )
2283
    {
1534 dpurdie 2284
        Error("Incorrect number of params passed to " .
2285
              "installDpkgArchiveRptFile() function. " ,
2286
              "Check deploy config.");
1530 dpurdie 2287
    }
2288
 
2289
    my ($sfile, $targetTag) = @_;
2290
 
2291
    # lets check to see if the target tag exists
2292
    # if does not the process with log an error.
2293
    #
2294
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2295
 
2296
 
2297
    # for now lets call the generic funtion to move all items
2298
    # in the associated dpkg_archive dir.
2299
    #
2300
    installDpkgArchiveFile("rpt", $sfile, $targetTag);
2301
 
2302
    return 1;
2303
}
2304
 
2305
 
2306
#------------------------------------------------------------------------------
2307
sub installDpkgArchiveRoxFile
2308
#
2309
# Description:
2310
#       This sub-routine is used to install a rox file from the
2311
#       dpkg_archive into the supplied install dir. 
2312
#
2313
#       It assumes based on the build type where the file will be located.
2314
#
2315
#       If it fails to find the file it will report an error and terminates
2316
#       processing.
2317
#
2318
#------------------------------------------------------------------------------
2319
{
2320
    # correct number of parameters?
2321
    if ( ($#_+1) != 2 )
2322
    {
1534 dpurdie 2323
        Error("Incorrect number of params passed to " .
2324
              "installDpkgArchiveRoxFile() function. " ,
2325
              "Check deploy config.");
1530 dpurdie 2326
    }
2327
 
2328
    my ($sfile, $targetTag) = @_;
2329
 
2330
    # lets check to see if the target tag exists
2331
    # if does not the process with log an error.
2332
    #
2333
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2334
 
2335
 
2336
    # for now lets call the generic funtion to move all items
2337
    # in the associated dpkg_archive dir.
2338
    #
2339
    installDpkgArchiveFile("rox", $sfile, $targetTag);
2340
 
2341
    return 1;
2342
}
2343
 
2344
 
2345
#------------------------------------------------------------------------------
2346
sub installDpkgArchiveDatFile
2347
#
2348
# Description:
2349
#       This sub-routine is used to install a dat file from the
2350
#       dpkg_archive into the supplied install dir. 
2351
#
2352
#       It assumes based on the build type where the file will be located.
2353
#
2354
#       If it fails to find the file it will report an error and terminates
2355
#       processing.
2356
#
2357
#------------------------------------------------------------------------------
2358
{
2359
    # correct number of parameters?
2360
    if ( ($#_+1) != 2 )
2361
    {
1534 dpurdie 2362
        Error("Incorrect number of params passed to " .
2363
              "installDpkgArchiveDatFile() function. " ,
2364
              "Check deploy config.");
1530 dpurdie 2365
    }
2366
 
2367
    my ($sfile, $targetTag) = @_;
2368
 
2369
    # lets check to see if the target tag exists
2370
    # if does not the process with log an error.
2371
    #
2372
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2373
 
2374
 
2375
    # for now lets call the generic funtion to move all items
2376
    # in the associated dpkg_archive dir.
2377
    #
2378
    installDpkgArchiveFile("dat", $sfile, $targetTag);
2379
 
2380
    return 1;
2381
}
2382
 
2383
 
2384
#------------------------------------------------------------------------------
2385
sub installDpkgArchiveThxFile
2386
#
2387
# Description:
2388
#       This sub-routine is used to install a thx file from the
2389
#       dpkg_archive into the supplied install dir. 
2390
#
2391
#       It assumes based on the build type where the file will be located.
2392
#
2393
#       If it fails to find the file it will report an error and terminates
2394
#       processing.
2395
#
2396
#------------------------------------------------------------------------------
2397
{
2398
    # correct number of parameters?
2399
    if ( ($#_+1) != 2 )
2400
    {
1534 dpurdie 2401
        Error("Incorrect number of params passed to " .
2402
              "installDpkgArchiveThxFile() function. " ,
2403
              "Check deploy config.");
1530 dpurdie 2404
    }
2405
 
2406
    my ($sfile, $targetTag) = @_;
2407
 
2408
    # lets check to see if the target tag exists
2409
    # if does not the process with log an error.
2410
    #
2411
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2412
 
2413
 
2414
    # for now lets call the generic funtion to move all items
2415
    # in the associated dpkg_archive dir.
2416
    #
2417
    installDpkgArchiveFile("thx", $sfile, $targetTag);
2418
 
2419
    return 1;
2420
}
2421
 
2422
 
2423
#------------------------------------------------------------------------------
2424
sub installDpkgArchiveMugFile
2425
#
2426
# Description:
2427
#       This sub-routine is used to install a mug file from the
2428
#       dpkg_archive into the supplied install dir. 
2429
#
2430
#       It assumes based on the build type where the file will be located.
2431
#
2432
#       If it fails to find the file it will report an error and terminates
2433
#       processing.
2434
#
2435
#------------------------------------------------------------------------------
2436
{
2437
    # correct number of parameters?
2438
    if ( ($#_+1) != 2 )
2439
    {
1534 dpurdie 2440
        Error("Incorrect number of params passed to " .
2441
              "installDpkgArchiveMugFile() function. " ,
2442
              "Check deploy config.");
1530 dpurdie 2443
    }
2444
 
2445
    my ($sfile, $targetTag) = @_;
2446
 
2447
    # lets check to see if the target tag exists
2448
    # if does not the process with log an error.
2449
    #
2450
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2451
 
2452
 
2453
    # for now lets call the generic funtion to move all items
2454
    # in the associated dpkg_archive dir.
2455
    #
2456
    installDpkgArchiveFile("mug", $sfile, $targetTag);
2457
 
2458
    return 1;
2459
}
2460
 
2461
 
2462
#------------------------------------------------------------------------------
2463
sub installDpkgArchiveInfoFilesFile
2464
#
2465
# Description:
2466
#       This sub-routine is used to install a infofiles file from the
2467
#       dpkg_archive into the supplied install dir. 
2468
#
2469
#       It assumes based on the build type where the file will be located.
2470
#
2471
#       If it fails to find the file it will report an error and terminates
2472
#       processing.
2473
#
2474
#------------------------------------------------------------------------------
2475
{
2476
    # correct number of parameters?
2477
    if ( ($#_+1) != 2 )
2478
    {
1534 dpurdie 2479
        Error("Incorrect number of params passed to " .
2480
              "installDpkgArchiveInfoFilesFile() function. " ,
2481
              "Check deploy config.");
1530 dpurdie 2482
    }
2483
 
2484
    my ($sfile, $targetTag) = @_;
2485
 
2486
    # lets check to see if the target tag exists
2487
    # if does not the process with log an error.
2488
    #
2489
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2490
 
2491
 
2492
    # for now lets call the generic funtion to move all items
2493
    # in the associated dpkg_archive dir.
2494
    #
2495
    installDpkgArchiveFile("infofiles", $sfile, $targetTag);
2496
 
2497
    return 1;
2498
}
2499
 
2500
 
2501
#------------------------------------------------------------------------------
2502
sub installDpkgArchiveSqlFile
2503
#
2504
# Description:
2505
#       This sub-routine is used to install a sql file from the
2506
#       dpkg_archive into the supplied install dir. 
2507
#
2508
#       It assumes based on the build type where the file will be located.
2509
#
2510
#       If it fails to find the file it will report an error and terminates
2511
#       processing.
2512
#
2513
#------------------------------------------------------------------------------
2514
{
2515
    # correct number of parameters?
2516
    if ( ($#_+1) != 2 )
2517
    {
1534 dpurdie 2518
        Error("Incorrect number of params passed to " .
2519
              "installDpkgArchiveSqlFile() function. " ,
2520
              "Check deploy config.");
1530 dpurdie 2521
    }
2522
 
2523
    my ($sfile, $targetTag) = @_;
2524
 
2525
    # lets check to see if the target tag exists
2526
    # if does not the process with log an error.
2527
    #
2528
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2529
 
2530
 
2531
    # for now lets call the generic funtion to move all items
2532
    # in the associated dpkg_archive dir.
2533
    #
2534
    installDpkgArchiveFile("sql", $sfile, $targetTag);
2535
 
2536
    return 1;
2537
}
2538
 
2539
 
2540
#------------------------------------------------------------------------------
2541
sub installDpkgArchiveWarFile
2542
#
2543
# Description:
2544
#       This sub-routine is used to install a war file from the
2545
#       dpkg_archive into the supplied install dir. 
2546
#
2547
#       It assumes based on the build type where the file will be located.
2548
#
2549
#       If it fails to find the file it will report an error and terminates
2550
#       processing.
2551
#
2552
#------------------------------------------------------------------------------
2553
{
2554
    # correct number of parameters?
2555
    if ( ($#_+1) != 2 )
2556
    {
1534 dpurdie 2557
        Error("Incorrect number of params passed to " .
2558
              "installDpkgArchiveWarFile() function. " ,
2559
              "Check deploy config.");
1530 dpurdie 2560
    }
2561
 
2562
    my ($sfile, $targetTag) = @_;
2563
 
2564
    # lets check to see if the target tag exists
2565
    # if does not the process with log an error.
2566
    #
2567
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2568
 
2569
 
2570
    # for now lets call the generic funtion to move all items
2571
    # in the associated dpkg_archive dir.
2572
    #
2573
    installDpkgArchiveFile("war", $sfile, $targetTag);
2574
 
2575
    return 1;
2576
}
2577
 
2578
 
2579
 
2580
#------------------------------------------------------------------------------
2581
sub installDpkgArchiveJarFile
2582
#
2583
# Description:
2584
#       This sub-routine is used to install a jar file from the
2585
#       dpkg_archive into the supplied install dir. 
2586
#
2587
#       It assumes based on the build type where the file will be located.
2588
#
2589
#       If it fails to find the file it will report an error and terminates
2590
#       processing.
2591
#
2592
#------------------------------------------------------------------------------
2593
{
2594
    # correct number of parameters?
2595
    if ( ($#_+1) != 2 )
2596
    {
1534 dpurdie 2597
        Error("Incorrect number of params passed to " .
2598
              "installDpkgArchiveJarFile() function. " ,
2599
              "Check deploy config.");
1530 dpurdie 2600
    }
2601
 
2602
    my ($sfile, $targetTag) = @_;
2603
 
2604
    # lets check to see if the target tag exists
2605
    # if does not the process with log an error.
2606
    #
2607
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2608
 
2609
 
2610
    # for now lets call the generic funtion to move all items
2611
    # in the associated dpkg_archive dir.
2612
    #
2613
    installDpkgArchiveFile("jar", $sfile, $targetTag);
2614
 
2615
    return 1;
2616
}
2617
 
2618
 
2619
 
2620
#------------------------------------------------------------------------------
2621
sub installDpkgArchiveSarFile
2622
#
2623
# Description:
2624
#       This sub-routine is used to install a sar file from the
2625
#       dpkg_archive into the supplied install dir. 
2626
#
2627
#       It assumes based on the build type where the file will be located.
2628
#
2629
#       If it fails to find the file it will report an error and terminates
2630
#       processing.
2631
#
2632
#------------------------------------------------------------------------------
2633
{
2634
    # correct number of parameters?
2635
    if ( ($#_+1) != 2 )
2636
    {
1534 dpurdie 2637
        Error("Incorrect number of params passed to " .
2638
              "installDpkgArchiveSarFile() function. " ,
2639
              "Check deploy config.");
1530 dpurdie 2640
    }
2641
 
2642
    my ($sfile, $targetTag) = @_;
2643
 
2644
    # lets check to see if the target tag exists
2645
    # if does not the process with log an error.
2646
    #
2647
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2648
 
2649
 
2650
    # for now lets call the generic funtion to move all items
2651
    # in the associated dpkg_archive dir.
2652
    #
2653
    installDpkgArchiveFile("sar", $sfile, $targetTag);
2654
 
2655
    return 1;
2656
}
2657
 
2658
 
2659
 
2660
 
2661
 
2662
#------------------------------------------------------------------------------
2663
sub installDpkgArchiveEtcFile
2664
#
2665
# Description:
2666
#       This sub-routine is used to install an etc file from the
2667
#       dpkg_archive into the supplied install dir. 
2668
#
2669
#       It assumes based on the build type where the file will be located.
2670
#
2671
#       If it fails to find the file it will report an error and terminates
2672
#       processing.
2673
#
2674
#------------------------------------------------------------------------------
2675
{
2676
    # correct number of parameters?
2677
    if ( ($#_+1) != 2 )
2678
    {
1534 dpurdie 2679
        Error("Incorrect number of params passed to " .
2680
              "installDpkgArchiveEtcFile() function. " ,
2681
              "Check deploy config.");
1530 dpurdie 2682
    }
2683
 
2684
    my ($sfile, $targetTag) = @_;
2685
 
2686
    # lets check to see if the target tag exists
2687
    # if does not the process with log an error.
2688
    #
2689
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2690
 
2691
 
2692
    # for now lets call the generic funtion to move all items
2693
    # in the associated dpkg_archive dir.
2694
    #
2695
    installDpkgArchiveFile("etc", $sfile, $targetTag);
2696
 
2697
    return 1;
2698
}
2699
 
2700
 
2701
#------------------------------------------------------------------------------
2702
sub installDpkgArchiveScriptsFile
2703
#
2704
# Description:
2705
#       This sub-routine is used to install a scripts file from the
2706
#       dpkg_archive into the supplied install dir. 
2707
#
2708
#       It assumes based on the build type where the file will be located.
2709
#
2710
#       If it fails to find the file it will report an error and terminates
2711
#       processing.
2712
#
2713
#------------------------------------------------------------------------------
2714
{
2715
    # correct number of parameters?
2716
    if ( ($#_+1) != 2 )
2717
    {
1534 dpurdie 2718
        Error("Incorrect number of params passed to " .
2719
              "installDpkgArchiveScriptsFile() function. " ,
2720
              "Check deploy config.");
1530 dpurdie 2721
    }
2722
 
2723
   my ($sfile, $targetTag) = @_;
2724
 
2725
    # lets check to see if the target tag exists
2726
    # if does not the process with log an error.
2727
    #
2728
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2729
 
2730
 
2731
    # for now lets call the generic funtion to move all items
2732
    # in the associated dpkg_archive dir.
2733
    #
2734
    installDpkgArchiveFile("scripts", $sfile, $targetTag);
2735
 
2736
    return 1;
2737
}
2738
 
2739
 
2740
 
2741
#------------------------------------------------------------------------------
2742
sub installDpkgArchiveIncludeFile
2743
#
2744
# Description:
2745
#       This sub-routine is used to install a include file from the
2746
#       dpkg_archive into the supplied install dir. 
2747
#
2748
#       It assumes based on the build type where the file will be located.
2749
#
2750
#       If it fails to find the file it will report an error and terminates
2751
#       processing.
2752
#
2753
#------------------------------------------------------------------------------
2754
{
2755
    # correct number of parameters?
2756
    if ( ($#_+1) != 2 )
2757
    {
1534 dpurdie 2758
        Error("Incorrect number of params passed to " .
2759
              "installDpkgArchiveIncludeFile() function. " ,
2760
              "Check deploy config.");
1530 dpurdie 2761
    }
2762
 
2763
   my ($sfile, $targetTag) = @_;
2764
 
2765
    # lets check to see if the target tag exists
2766
    # if does not the process with log an error.
2767
    #
2768
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2769
 
2770
 
2771
    # for now lets call the generic funtion to move all items
2772
    # in the associated dpkg_archive dir.
2773
    #
2774
    installDpkgArchiveFile("include", $sfile, $targetTag);
2775
 
2776
    return 1;
2777
}
2778
 
2779
 
2780
 
2781
#------------------------------------------------------------------------------
2782
sub installDpkgArchiveDocFile
2783
#
2784
# Description:
2785
#       This sub-routine is used to install a include file from the
2786
#       dpkg_archive into the supplied install dir. 
2787
#
2788
#       It assumes based on the build type where the file will be located.
2789
#
2790
#       If it fails to find the file it will report an error and terminates
2791
#       processing.
2792
#
2793
#------------------------------------------------------------------------------
2794
{
2795
    # correct number of parameters?
2796
    if ( ($#_+1) != 2 )
2797
    {
1534 dpurdie 2798
        Error("Incorrect number of params passed to " .
2799
              "installDpkgArchiveDocFile() function. " ,
2800
              "Check deploy config.");
1530 dpurdie 2801
    }
2802
 
2803
   my ($sfile, $targetTag) = @_;
2804
 
2805
    # lets check to see if the target tag exists
2806
    # if does not the process with log an error.
2807
    #
2808
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2809
 
2810
 
2811
    # for now lets call the generic funtion to move all items
2812
    # in the associated dpkg_archive dir.
2813
    #
2814
    installDpkgArchiveFile("doc", $sfile, $targetTag);
2815
 
2816
    return 1;
2817
}
2818
 
2819
 
2820
#------------------------------------------------------------------------------
2821
sub installDpkgArchiveBinFile
2822
#
2823
# Description:
2824
#       This sub-routine is used to install a binary file from the
2825
#       dpkg_archive into the supplied install dir. 
2826
#
2827
#       It assumes based on the build type where the file will be located.
2828
#
2829
#       If it fails to find the file it will report an error and terminates
2830
#       processing.
2831
#
2832
# Inputs          :     $sfile              - Name of source file
2833
#                                             or a reference to a list of files
2834
#                       $targetTag          - Symbolic name of target
2835
#                       Options             - Optional options
2836
#
2837
# Options:
1546 dpurdie 2838
#                   --SelectFrom=xxxx       - Limits file source selection
1530 dpurdie 2839
#                                             By default all LIB sources are searched.
2840
#                                             The selector should be a Platform, Product
2841
#                                             ,Target or MachineType
2842
#
2843
#
2844
# Returns         :     Nothing of use
2845
#                       Will not return if the file is not found
2846
#
2847
#------------------------------------------------------------------------------
2848
{
2849
    my @args;
2850
    my $select = '_ALL_';
2851
 
2852
    #
2853
    #   Process parameters and extract options
2854
    #
2855
    foreach  ( @_ )
2856
    {
2857
        if ( m/^--SelectFrom=(.*)/ ) {
2858
            $select = $1;
1534 dpurdie 2859
            Error("installDpkgArchiveBinFile: Selector not known: $_")
1530 dpurdie 2860
                unless ( defined $DpkgLibDirList{$select} );
2861
 
2862
        } elsif ( m/^--/ ) {
1534 dpurdie 2863
            Warning ("installDpkgArchiveBinFile: Unknown option ignored: $_")
1530 dpurdie 2864
 
2865
        } else {
2866
            push @args, $_;
2867
        }
2868
    }
2869
 
2870
 
2871
    # correct number of parameters?
2872
    my ($fref, $targetTag) = @_;
2873
    if ( $#args != 1 )
2874
    {
1534 dpurdie 2875
        Error("Incorrect number of params passed to " .
2876
              "installDpkgArchiveBinFile() function. " ,
2877
              "Check deploy config.");
1530 dpurdie 2878
    }
2879
 
2880
    # lets check to see if the target tag exists
2881
    # if does not the process with log an error.
2882
    #
2883
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
2884
 
2885
    #
2886
    #   Process the file name
2887
    #   This will either be a scalar name, or a reference to an array of names
2888
    #   If the user has provided an array of names then expand the list
2889
    #
2890
    #   Convert $fref into an reference to a list
2891
    #
2892
    my @one_file;
2893
    unless ( ref ( $fref ) eq 'ARRAY' )
2894
    {
2895
        push @one_file, $fref;
2896
        $fref = \@one_file;
2897
    }
2898
 
2899
    foreach my $sfile ( @$fref )
2900
    {
2901
 
2902
        if ( "$MachType" eq "win32" )
2903
        {
2904
            # if the item does not have an .exe extention
2905
            # we shall add one for convience.
2906
            #
2907
            if ( $sfile !~ m/\.exe$/  &&
2908
                 $sfile !~ m/\.dll$/ )
2909
            {
2910
                $sfile = $sfile . ".exe";
2911
            }
2912
        }
2913
 
2914
 
2915
        my ($i);
2916
        my ($foundFileFlag) = "false";
2917
        my ($m_DpkgBinDir)  = "";
2918
        my ($m_srcFileLocation) = "";
2919
        my ($m_dstFileLocation) = "";
2920
        foreach $i (@{$DpkgBinDirList{$select}})
2921
        {
2922
            $m_DpkgBinDir = "$DpkgBinDir" . "/$i";
2923
            if ( ! -d "$m_DpkgBinDir" )
2924
            {
1534 dpurdie 2925
                Debug("Directory [$m_DpkgBinDir] not found.");
1530 dpurdie 2926
                next;
2927
            }
2928
 
2929
            # lets define the absolute location of the file
2930
            $m_srcFileLocation = "$m_DpkgBinDir/$sfile";
2931
            $m_dstFileLocation = "$targetValue/$sfile";
2932
 
2933
            # we will check to see if the file exists.
2934
            #
2935
            if ( -f "$m_srcFileLocation" )
2936
            {
2937
                # now we need to copy the file.
2938
                if(File::Copy::copy("$m_srcFileLocation", "$m_dstFileLocation"))
2939
                {
1534 dpurdie 2940
                    Verbose("Copied Bin [$sfile] to [$m_dstFileLocation] ...");
1530 dpurdie 2941
                    $foundFileFlag = "true";
2942
 
2943
                    # no need to go further, we have found the file.
2944
                    #
2945
                    last;
2946
                }
2947
                else
2948
                {
1534 dpurdie 2949
                    Error("Failed to copy binary [$sfile]: $!");
1530 dpurdie 2950
                }
2951
            }
2952
            # else we have not found the file yet!
2953
        }
2954
 
2955
        # if we do not find the file at all we need to inform
2956
        # the user.
2957
        #
2958
        if ( "$foundFileFlag" eq "false" )
2959
        {
1534 dpurdie 2960
            Error("Dpkg_archive bin file [$sfile] does not exist or is not in correct directory structure.");
1530 dpurdie 2961
        }
2962
    }
2963
 
2964
    return 1;
2965
}
2966
 
2967
 
2968
#------------------------------------------------------------------------------
2969
sub installDpkgArchiveLibFile
2970
#
2971
# Description:
2972
#       This sub-routine is used to install a binary file from the
2973
#       dpkg_archive into the supplied install location dir.
2974
#
2975
#       It assumes based on the build type where the file will be located.
2976
#
2977
#       If it fails to find the file it will report an error and terminates
2978
#       processing.
2979
#
2980
#       Added optional 3rd parameter & if set to NoLinks then no generic named
2981
#       libs will be created
2982
#
1534 dpurdie 2983
# Inputs          :     $sfile              - Name of source file OR
2984
#                                             A --Filter specification ( below)
2985
#                                             A reference to a list of files OR
1530 dpurdie 2986
#                       $targetTag          - Symbolic name of target
2987
#                       $links              - Optional. 'nolinks' will supress generic named libs
2988
#                       Options             - Optional options
2989
#
2990
# Options:
1534 dpurdie 2991
#                   --NoLink                - same as 3rd arg == nolinks
1530 dpurdie 2992
#                   --Link                  - Default
1546 dpurdie 2993
#                   --SelectFrom=xxxx       - Limits file source selection
1530 dpurdie 2994
#                                             By default all LIB sources are searched.
2995
#                                             The selector should be a Platform, Product
2996
#                                             ,Target or MachineType
2997
#
1534 dpurdie 2998
# SourceFile options:
2999
#                   Source files may be a filter rule which will expand to
3000
#                   one or more files.
3001
#                       --FilterIn=xx
3002
#                       --FilterInRE=xx
3003
#                       --FilterOut=xx
3004
#                       --FilterOutRE=xx
1530 dpurdie 3005
#
1534 dpurdie 3006
#                     Notes:    --FilterIn=xxxx, --FilterOut=xxx
3007
#                               xxx is a simple Shell style filter where:
3008
#                                   * means one or more charters        '*.EXE'
3009
#                                   ? means a single character          '*.?'
3010
#                                   [abc] means either a or b or c      'file.[ch]'
3011
#
3012
#                               --FilterInRE=xxx, --FilterOutRE=xxx
3013
#                               xxx is a Regular Expression. There are harder to use but very
3014
#                               powerful. ie '.*\.EXE$'
3015
#
3016
#                               The 'In' filters are applied before the 'Out' filters.
3017
#
3018
#                               Multiple options may be joined with a comma.
3019
#
1530 dpurdie 3020
# Returns         :     Nothing of use
3021
#                       Will not return if the file is not found
3022
#
3023
#------------------------------------------------------------------------------
3024
{
3025
    my @args;
3026
    my $links = 1;
3027
    my $select = '_ALL_';
3028
 
3029
    #
3030
    #   Process parameters and extract options
3031
    #
3032
    foreach  ( @_ )
3033
    {
3034
        if ( m/^--NoLink/ ) {
3035
            $links = 0;
3036
 
3037
        } elsif ( m/^--Link/ ) {
3038
            $links = 1;
3039
 
3040
        } elsif ( m/^--SelectFrom=(.*)/ ) {
3041
            $select = $1;
1534 dpurdie 3042
            Error("installDpkgArchiveLibFile: Selector not known: $_")
1530 dpurdie 3043
                unless ( defined $DpkgLibDirList{$select} );
3044
 
1534 dpurdie 3045
        } elsif ( m/^--Filter.*=/ ) {
3046
            push @args, $_;
3047
 
1530 dpurdie 3048
        } elsif ( m/^--/ ) {
1534 dpurdie 3049
            Warning ("installDpkgArchiveLibFile: Unknown option ignored: $_")
1530 dpurdie 3050
 
3051
        } else {
3052
            push @args, $_;
3053
        }
3054
    }
3055
 
3056
    #
3057
    #   Handle the optional 3rd argument
3058
    #
3059
    if ( $args[2] )
3060
    {
3061
        $links = $args[2] !~ m/nolink/i;
3062
        delete $args[2];
3063
    }
3064
 
3065
    # correct number of parameters?
3066
    my ($fref, $targetTag) = @_;
3067
    if ( $#args != 1 )
3068
    {
1534 dpurdie 3069
        Error("Incorrect number of params passed to " .
3070
              "installDpkgArchiveLibFile() function. " ,
3071
              "Check deploy config.");
1530 dpurdie 3072
    }
3073
 
3074
    #
3075
    # Check to see if the target tag exists
3076
    # If does not the process with log an error.
3077
    #
3078
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
3079
 
3080
    #
3081
    #   Process the file name
3082
    #   This will either be a scalar name, or a reference to an array of names
3083
    #   If the user has provided an array of names then expand the list
3084
    #
3085
    #   Convert $fref into an reference to a list
3086
    #
3087
    my @one_file;
3088
    unless ( ref ( $fref ) eq 'ARRAY' )
3089
    {
3090
        push @one_file, $fref;
3091
        $fref = \@one_file;
3092
    }
3093
 
1534 dpurdie 3094
    #
3095
    #   If the source file contains a pattern, then expand the pattern
3096
    #   This may result in multiple files.
3097
    #   Note: Allow for a single entry of the form
3098
    #           --Filterin=xxx,---FilterOut=yyy
3099
    #
1552 dpurdie 3100
    my $search =  LocateFiles->new(recurse => 0);
1534 dpurdie 3101
    my @flist;
3102
    foreach my $element ( @$fref )
1530 dpurdie 3103
    {
1534 dpurdie 3104
        foreach  ( split /,/ , $element )
3105
        {
3106
            if ( /^--FilterOut=(.*)/ ) {
1552 dpurdie 3107
                $search->filter_out( $1 );
1530 dpurdie 3108
 
1534 dpurdie 3109
            } elsif ( /^--FilterOutRE=(.*)/ ) {
1552 dpurdie 3110
                $search->filter_out_re( $1 );
1530 dpurdie 3111
 
1534 dpurdie 3112
            } elsif ( /^--FilterIn=(.*)/ ) {
1552 dpurdie 3113
                $search->filter_in( $1 );
1534 dpurdie 3114
 
3115
            } elsif ( /^--FilterInRE=(.*)/ ) {
1552 dpurdie 3116
                $search->filter_in_re( $1 );
1534 dpurdie 3117
 
3118
            } elsif ( m/^--/ ) {
3119
                Warning( "installDpkgArchiveLibFile: Unknown Filter option ignored: $_");
3120
 
3121
            } else {
3122
                push @flist, $_;
3123
            }
3124
        }
3125
    }
3126
 
3127
    #
3128
    #   If any patterns have been found, then expand them
3129
    #
1552 dpurdie 3130
    if ( $search->has_filter() )
1534 dpurdie 3131
    {
3132
        foreach my $i (@{$DpkgLibDirList{$select}})
3133
        {
1552 dpurdie 3134
            my @elements = $search->search( "$DpkgLibDir/$i" );
1534 dpurdie 3135
 
3136
            #
3137
            #   Clean off any leading / from each filename then add to a list
3138
            #   Remove any duplicates that were found
3139
            #
3140
            map { $_ =~ s~^/~~ } @elements;
3141
            UniquePush \@flist, @elements;
3142
        }
3143
    }
3144
 
3145
 
3146
    #
3147
    #   Process each file
3148
    #
3149
    foreach my $sfile ( @flist )
3150
    {
3151
 
1530 dpurdie 3152
        # we exclude .dll files if this is a sparc build
3153
        #
3154
        if ( "$MachType" eq "sparc"  &&
3155
             $sfile =~ m/\.dll/
3156
           )
3157
        {
1534 dpurdie 3158
            Verbose("Excluding item [$sfile] from build, as we do not deliver dlls for this machine type [$MachType].");
1530 dpurdie 3159
            return 1;
3160
        }
3161
 
3162
        # we exclude .so files if this is a win32 build
3163
        #
3164
        if ( "$MachType" eq "win32"  &&
3165
             $sfile =~ m/\.so/
3166
           )
3167
        {
1534 dpurdie 3168
            Verbose("Excluding item [$sfile] from build, as we do not deliver sosss for this machine type [$MachType].");
1530 dpurdie 3169
            return 1;
3170
        }
3171
 
3172
        my ($libName) = $sfile;
3173
        if ( "$MachType" eq "sparc" )
3174
        {
3175
            $libName =~ s/\.so.*$//;
3176
        }
3177
 
3178
        # lets define the absolute location of the file
3179
        my ($m_srcFileLocation) = "";
3180
        my ($m_dstFileLocation) = "";
3181
        my ($m_DpkgLibDir) = "";
3182
 
3183
        my ($i);
3184
        my ($j);
3185
        my ($count);
3186
        my ($foundFileFlag) = "false";
3187
        my ($ExcludedFlag) = "false";
3188
 
3189
        #
3190
        #   Search all the 'lib' locations, or a specified subset
3191
        #
3192
        foreach $i (@{$DpkgLibDirList{$select}})
3193
        {
3194
 
3195
            $m_DpkgLibDir = "$DpkgLibDir" . "/$i";
3196
            if ( ! -d "$m_DpkgLibDir" )
3197
            {
1534 dpurdie 3198
                Debug("Directory [$m_DpkgLibDir] not found.");
1530 dpurdie 3199
                next;
3200
            }
3201
 
1534 dpurdie 3202
 
1530 dpurdie 3203
            $m_srcFileLocation = "$m_DpkgLibDir/$sfile";
3204
            $m_dstFileLocation = "$targetValue/$sfile";
3205
 
3206
 
3207
            # we only want debug items in a debug build
3208
            #
3209
            if(excludeItemFromBuild($sfile))
3210
            {
1534 dpurdie 3211
                Verbose("Excluding item [$sfile] from build as not compatible with build type [$BuildType].");
1530 dpurdie 3212
                $ExcludedFlag = "true";
3213
            }
3214
            else
3215
            {
3216
                # we need to ensure that only a single version/entry of the lib exists in the lib list
3217
                #
3218
                $count = 1;
3219
                foreach $j (@LibCheckList)
3220
                {
3221
                    if ( $j =~ m/^$libName$/ )
3222
                    {
3223
                        $count++;
3224
                    }
3225
 
3226
                    if ( $count > 1 )
3227
                    {
1534 dpurdie 3228
                        Error("Detected multiple references of lib [$libName] in lib list, check item [$sfile].");
1530 dpurdie 3229
                    }
3230
                }
3231
 
3232
                # we will check to see if the file exists.
3233
                #
3234
                if ( -f "$m_srcFileLocation" )
3235
                {
3236
                    # now we need to copy the file.
3237
 
3238
                    # we also want to create a generically named copy
1534 dpurdie 3239
                    # of the library. ie:
3240
                    #       libraryP.nn.nn.nn.dll -> library.dll, libraryP.dll
3241
                    #       libraryP.so.nn.nn.nn  -> library.so, libraryP.so
1530 dpurdie 3242
                    #
3243
                    my ($gName)    = $sfile;
3244
                    my ($nVerName) = $sfile;
3245
                    $gName = removeBuildTypeFromItemName($sfile);
3246
                    $gName = removeVersionNumberFromItemName($gName);
3247
                    $nVerName = removeVersionNumberFromItemName($sfile);
3248
 
3249
                    if(File::Copy::copy("$m_srcFileLocation", "$m_dstFileLocation"))
3250
                    {
1534 dpurdie 3251
                        Verbose("Copied Lib [$sfile] to [$m_dstFileLocation] ...");
1530 dpurdie 3252
                        $foundFileFlag = "true";
3253
 
3254
                        if ( $links && ( "x$PkgPatchID" eq "x" || "$MachType" eq "win32") )
3255
                        {
3256
                            # normal build or if we are building win32 we want generic names
3257
 
3258
                            # we want to create a copy of our target using
3259
                            # the generic name
3260
                            if ( $sfile ne $nVerName )
3261
                            {
3262
                                createGenericCopy("$sfile", "$m_srcFileLocation", "$nVerName", "$targetValue");
3263
                            }
3264
                            if ( $sfile ne $gName )
3265
                            {
3266
                                createGenericCopy("$sfile", "$m_srcFileLocation", "$gName",    "$targetValue");
3267
                            }
3268
                        }
3269
 
3270
 
3271
                        # lets add this lib to our check list for next time.
3272
                        #
3273
                        push @LibCheckList, $libName;
3274
 
3275
                        # no need to go further, implies we found the file!
3276
                        #
3277
                        last;
3278
                    }
3279
                    else
3280
                    {
3281
                        # here found the file but we had some trouble
3282
                        #
1534 dpurdie 3283
                        Error("Failed to copy lib [$m_srcFileLocation]: $!");
1530 dpurdie 3284
                    }
3285
 
3286
                }
3287
                # else have not found the file yet!
3288
            }
3289
        }
3290
 
3291
        # if we do not find the file at all we need to inform
3292
        # the user.
3293
        #
3294
        if ( "$foundFileFlag" eq "false" && $ExcludedFlag eq "false" )
3295
        {
1534 dpurdie 3296
            Error("Dpkg_archive lib file [$sfile] does not exist or is not in correct directory structure.");
1530 dpurdie 3297
        }
3298
    }
3299
 
3300
    return 1;
3301
}
3302
 
3303
 
3304
#------------------------------------------------------------------------------
3305
sub installPkgAddConfigFile
3306
#
3307
# Description:
3308
#       This sub-routine is used to install a package config file from a supplied
3309
#       source location to a predefined destination location that is based on
3310
#       the build type.
3311
#
3312
#       The sub routine also updates to the prototype file with an appropriate
3313
#       entry for the associated file.
1546 dpurdie 3314
# Inputs:
3315
#       sDirTag                 - Source directory tag
1554 dpurdie 3316
#                                 Or --Package=name,subdir
3317
#                                 Or --Interface=subdir
1546 dpurdie 3318
#       sfile                   - Source File Name [Mandatory]
3319
#       tfile                   - Not sure. Used in the prototype file.
3320
#                                 Suggest using the same name as sfile
1530 dpurdie 3321
#
3322
#       If it has any problems it will log an error and stop processing.
3323
#
3324
#------------------------------------------------------------------------------
3325
{
3326
    # correct number of parameters?
3327
    if ( ($#_+1) != 3 )
3328
    {
1534 dpurdie 3329
        Error("Incorrect number of params passed to " .
3330
              "installPkgAddConfigFile() function. " ,
3331
              "Check deploy config.");
1530 dpurdie 3332
    }
3333
 
3334
    # lets just check to see if we can execute this function on
3335
    # this machine.
3336
    #
3337
    if ( "$MachType" ne "sparc" )
3338
    {
1534 dpurdie 3339
        Verbose("installPkgAddConfigFile() not supported on this machine type.");
1530 dpurdie 3340
        return 1;
3341
    }
3342
 
3343
 
3344
    my ($sDirTag, $sfile, $tfile) = @_;
3345
 
3346
 
3347
    # we must have a filename.
3348
    #
1546 dpurdie 3349
    unless ( $sfile )
1530 dpurdie 3350
    {
1534 dpurdie 3351
        Error("Source filename not supplied. Check deploy config.");
1530 dpurdie 3352
    }
3353
 
3354
    # lets check to see if the local src dir tag exists
3355
    # if does not the process with log an error.
3356
    #
3357
    my ($sDirValue) = getLocalDirValue("$sDirTag", "A");
3358
 
3359
 
3360
    # lets check to see if the source file exists
3361
    #
3362
    if ( ! -f "$sDirValue/$sfile" )
3363
    {
1534 dpurdie 3364
        Error("Failed to find local source file [$sDirValue/$sfile].");
1530 dpurdie 3365
    }
3366
 
3367
    if ( ! -f "$ProtoTypeFile" )
3368
    {
1534 dpurdie 3369
        Error("Prototype file [$ProtoTypeFile] does not exist.",
3370
              "Ensure createPrototypeFile() function has been called before executing installPkgAddConfigFile() function.",
3371
              "Check deploy config.");
1530 dpurdie 3372
    }
3373
 
3374
 
3375
    # lets determine which prototype file we are going to
3376
    # use
3377
    my ($dFileName);
3378
    $dFileName     = "$PkgBaseDir/$sfile";
3379
 
3380
    # lets copy the file
3381
    #
3382
    if(File::Copy::copy("$sDirValue/$sfile", "$dFileName"))
3383
    {
1534 dpurdie 3384
        Verbose("Copied [$sfile] to [$dFileName] ...");
1530 dpurdie 3385
    }
3386
    else
3387
    {
1534 dpurdie 3388
        Error("Failed to copy local source file [$sDirValue/$sfile]: $!"); 
1530 dpurdie 3389
    }
3390
 
3391
 
3392
    # now we need to update the prototype file
3393
    #
3394
    local *FILE;
3395
    open ( FILE, ">> $ProtoTypeFile") or
1534 dpurdie 3396
        Error("Failed to open file [$ProtoTypeFile].");
1530 dpurdie 3397
    printf FILE ("i $tfile=$sfile\n");
3398
    close (FILE);
3399
 
3400
 
3401
    return 1;
3402
}
3403
 
3404
 
3405
#------------------------------------------------------------------------------
3406
sub installPkgAddSystemClassFile
3407
#
3408
# Description:
3409
#       This sub-routine is used to install a package system class file from a supplied
3410
#       source location to a predefined destination location the class type is also 
3411
#       supplied and must be sed, awk, build or preserve
3412
#
3413
#       The sub routine also updates to the prototype file with an appropriate
3414
#       entry for the associated file.
3415
#
3416
#       If it has any problems it will log an error and stop processing.
3417
#
1554 dpurdie 3418
# Inputs:
3419
#       sDirTag                 - Source directory tag
3420
#                                 Or --Package=name,subdir
3421
#                                 Or --Interface=subdir
3422
#       sfile                   - Source File Name [Mandatory]
3423
#       tfile                   - Not sure. Used in the prototype file.
3424
#                                 Suggest using the same name as sfile
3425
#       class                   - Class Name
1530 dpurdie 3426
#------------------------------------------------------------------------------
3427
{
3428
    # correct number of parameters?
3429
    if ( ($#_+1) != 4 )
3430
    {
1534 dpurdie 3431
        Error("Incorrect number of params passed to " .
3432
              "installPkgAddConfigFile() function. " ,
3433
              "Check deploy config.");
1530 dpurdie 3434
    }
3435
 
3436
    # lets just check to see if we can execute this function on
3437
    # this machine.
3438
    #
3439
    if ( "$MachType" ne "sparc" )
3440
    {
1534 dpurdie 3441
        Verbose("installPkgAddConfigFile() not supported on this machine type.");
1530 dpurdie 3442
        return 1;
3443
    }
3444
 
3445
 
3446
    my ($sDirTag, $sfile, $tfile, $class) = @_;
3447
 
3448
    if ( $class ne "sed" && $class ne "build" && $class ne "awk" && $class ne "preserve" )
3449
    {
1534 dpurdie 3450
        Error("Class Name for System Class File can only be one of sed, build, awk or preserve");
1530 dpurdie 3451
    }
3452
 
3453
    # we must have a filename.
3454
    #
3455
    if ( "x$sfile" eq "x" )
3456
    {
1534 dpurdie 3457
        Error("Source filename not supplied. Check deploy config.");
1530 dpurdie 3458
    }
3459
 
3460
 
3461
    # lets check to see if the local src dir tag exists
3462
    # if does not the process with log an error.
3463
    #
3464
    my ($sDirValue) = getLocalDirValue("$sDirTag", "A");
3465
 
3466
 
3467
    # lets check to see if the source file exists
3468
    #
3469
    if ( ! -f "$sDirValue/$sfile" )
3470
    {
1534 dpurdie 3471
        Error("Failed to find local source file [$sDirValue/$sfile].");
1530 dpurdie 3472
    }
3473
 
3474
    if ( ! -f "$ProtoTypeFile" )
3475
    {
1534 dpurdie 3476
        Error("Prototype file [$ProtoTypeFile] does not exist.",
3477
              "Ensure createPrototypeFile() function has been called before executing installPkgAddConfigFile() function.",
3478
              "Check deploy config.");
1530 dpurdie 3479
    }
3480
 
3481
 
3482
    # lets determine which prototype file we are going to
3483
    # use
3484
    my ($dFileName);
3485
    $dFileName     = "$PkgBaseDir/$sfile";
3486
 
3487
    # lets copy the file
3488
    #
3489
    if(File::Copy::copy("$sDirValue/$sfile", "$dFileName"))
3490
    {
1534 dpurdie 3491
        Verbose("Copied [$sfile] to [$dFileName] ...");
1530 dpurdie 3492
    }
3493
    else
3494
    {
1534 dpurdie 3495
        Error("Failed to copy local source file [$sDirValue/$sfile]: $!"); 
1530 dpurdie 3496
    }
3497
 
3498
 
3499
    # now we need to update the prototype file
3500
    #
3501
    local *FILE;
3502
    open ( FILE, ">> $ProtoTypeFile") or
1534 dpurdie 3503
        Error("Failed to open file [$ProtoTypeFile].");
1530 dpurdie 3504
    printf FILE ("e $class $tfile=$sfile ? ? ?\n");
3505
    close (FILE);
3506
 
3507
 
3508
    return 1;
3509
}
3510
 
3511
 
3512
 
3513
#------------------------------------------------------------------------------
3514
sub updatePrototypeFileAddItem
3515
#
3516
# Description:
3517
#       This sub-routine is used to update the prototype file with an
3518
#       extra package add item. Here we pre-pend the ERGAFC_BASEDIR to the
3519
#       destination item.
3520
#
3521
#       The only item type we support at this stage are "s" and "f" types.
3522
#
3523
#       You also need to supply the source tag, destination tag, user id, group id 
3524
#       and permissions associated to this item.
3525
#
3526
#       If it has any problems it will log an error and stop processing.
3527
#
3528
#------------------------------------------------------------------------------
3529
{
3530
    # correct number of parameters?
3531
    if ( ($#_+1) != 6 )
3532
    {
1534 dpurdie 3533
        Error("Incorrect number of params passed to " .
3534
              "updatePrototypeFileAddItem() function. " ,
3535
              "Check deploy config.");
1530 dpurdie 3536
    }
3537
 
3538
 
3539
    # lets just check to see if we can execute this function on
3540
    # this machine.
3541
    #
3542
    if ( "$MachType" ne "sparc" )
3543
    {
1534 dpurdie 3544
        Verbose("updatePrototypeFileAddItem() not supported on this machine type.");
1530 dpurdie 3545
        return 1;
3546
    }
3547
 
3548
    my ($sTag, $dTag, $perms, $uid, $gid, $type) = @_;
3549
 
3550
    # lets determine which prototype file we are going to
3551
    # use
3552
    my ($protoTypeFile);
3553
    $protoTypeFile = "$ProtoTypeFile";
3554
 
3555
 
3556
    # lets check the valid types
3557
    $type = uc($type);
3558
    if ( "$type" !~ /S/ )
3559
    {
1534 dpurdie 3560
        Error("Invalid type field supplied in updatePrototypeFileAddItem(). Check deploy config.");
1530 dpurdie 3561
    }
3562
 
3563
    # now we need to update the prototype file
3564
    #
3565
    local *FILE;
3566
    open ( FILE, ">> $protoTypeFile") or
1534 dpurdie 3567
        Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 3568
 
3569
    my($m_Str)=""; 
3570
    if ( "$type" eq "S" )
3571
    {
3572
        $m_Str = "s none $sTag=$ERGAFC_BASEDIR/$dTag $perms $uid $gid";
1534 dpurdie 3573
        Verbose("Updated prototype file with entry [$m_Str]");
1530 dpurdie 3574
    }
3575
    else
3576
    {
3577
        $m_Str = "f none $sTag=$ERGAFC_BASEDIR/$dTag $perms $uid $gid";
1534 dpurdie 3578
        Verbose("Updated prototype file with entry [$m_Str]");
1530 dpurdie 3579
    }
3580
    printf FILE ("$m_Str\n");
3581
    close (FILE);
3582
 
3583
    return 1;
3584
}
3585
 
3586
 
3587
#------------------------------------------------------------------------------
3588
sub updatePrototypeFileAddItem2
3589
#
3590
# Description:
3591
#       This sub-routine is used to update the prototype file with an
3592
#       extra package add item. Here we do not pre-append the 
3593
#       ERGAFC_BASEDIR to the destination item.
3594
#
3595
#       The only item type we support at this stage are "s", "i" and "e" types.
3596
#
3597
#       You also need to supply the source tag, destination tag, user id, group id 
3598
#       and permissions associated to this item.
3599
#
3600
#       If it has any problems it will log an error and stop processing.
3601
#
3602
#------------------------------------------------------------------------------
3603
{
3604
    # correct number of parameters?
3605
    if ( ($#_+1) != 6 && ($#_+1) != 7 )
3606
    {
1534 dpurdie 3607
        Error("Incorrect number of params passed to " .
3608
              "updatePrototypeFileAddItem2() function. " ,
3609
              "Check deploy config.");
1530 dpurdie 3610
    }
3611
 
3612
 
3613
    # lets just check to see if we can execute this function on
3614
    # this machine.
3615
    #
3616
    if ( "$MachType" ne "sparc" )
3617
    {
1534 dpurdie 3618
        Verbose("updatePrototypeFileAddItem2() not supported on this machine type.");
1530 dpurdie 3619
        return 1;
3620
    }
3621
 
3622
    # class must be last as it is optional
3623
    my ($sTag, $dTag, $perms, $uid, $gid, $type, $class) = @_;
3624
 
3625
    $class = "none" if ( ($#_+1) == 6 );
3626
 
3627
    # lets determine which prototype file we are going to
3628
    # use
3629
    my ($protoTypeFile);
3630
    $protoTypeFile = "$ProtoTypeFile";
3631
 
3632
    # lets check the valid types
3633
    $type = uc($type);
3634
    if ( "$type" !~ /S/ && "$type" !~ /I/ && "$type" !~ /E/ )
3635
    {
1534 dpurdie 3636
        Error("Invalid type field supplied in updatePrototypeFileAddItem2(). Check deploy config.");
1530 dpurdie 3637
    }
3638
 
3639
    # now we need to update the prototype file
3640
    #
3641
    local *FILE;
3642
    open ( FILE, ">> $protoTypeFile") or
1534 dpurdie 3643
        Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 3644
 
3645
    my($m_Str)="";
3646
    if ( "$type" eq "S" )
3647
    {
3648
        $m_Str = "s $class $sTag=$dTag $perms $uid $gid";
1534 dpurdie 3649
        Verbose("Updated prototype file with entry [$m_Str]");
1530 dpurdie 3650
    }
3651
    elsif ( "$type" eq "E" )
3652
    {
3653
        $m_Str = "e $class $sTag=$dTag $perms $uid $gid";
1534 dpurdie 3654
        Verbose("Updated prototype file with entry [$m_Str]");
1530 dpurdie 3655
    }
3656
    else
3657
    {
3658
        $m_Str = "i $sTag=$dTag";
1534 dpurdie 3659
        Verbose("Updated prototype file with entry [$m_Str]");
1530 dpurdie 3660
    }
3661
    printf FILE ("$m_Str\n");
3662
    close (FILE);
3663
 
3664
    return 1;
3665
}
3666
 
3667
 
3668
#------------------------------------------------------------------------------
3669
sub addPath2Prototype
3670
#
3671
# Description:
3672
#       This sub-routine is used to add directory entries to the prototype file
3673
#   to make sure the supplied path exists in the prototype file
3674
#
3675
#------------------------------------------------------------------------------
3676
{
3677
    # lets just check to see if we can execute this function on
3678
    # this machine.
3679
    #
3680
    if ( "$MachType" ne "sparc" )
3681
    {
1534 dpurdie 3682
        Verbose("addPath2Prototype() not supported on this machine type.");
1530 dpurdie 3683
        return 1;
3684
    }
3685
 
3686
    # class must be last as it is optional
3687
    my ($path, $perms, $uid, $gid, $class) = @_;
3688
 
3689
    # set defaults if not supplied
3690
    $perms  = "?"       if ( ($#_+1) < 2 );
3691
    $uid    = "?"       if ( ($#_+1) < 3 );
3692
    $gid    = "?"       if ( ($#_+1) < 4 );
3693
    $class  = "none"    if ( ($#_+1) < 5 );
3694
 
1534 dpurdie 3695
    Information("addPathToPrototype adding path [$path $perms $uid $gid $class]");
1530 dpurdie 3696
 
3697
    # lets determine which prototype file we are going to
3698
    # use
3699
    my ($protoTypeFile);
3700
    $protoTypeFile = "$ProtoTypeFile";
3701
 
3702
    # now we need to update the prototype file
3703
    #
3704
    local *FILE;
1534 dpurdie 3705
    open ( FILE, "+<$protoTypeFile") or Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 3706
 
3707
    # set up has of all paths to be added
3708
    my ( %pathDirs );
3709
    my ( $workPath );
3710
    my ( $i );
3711
 
3712
    $workPath = "/" if ( $path =~ s|^/|| );
3713
    foreach $i ( split("/" , $path) )
3714
    {
3715
        $workPath .= $i;
3716
        $pathDirs{$workPath} = 1;
3717
        $workPath .= "/";
3718
    }
3719
 
3720
    while ( <FILE> )
3721
    {
3722
        # lets get all the current dir entries and check for duplicates
3723
        #        class   path    mode    owner   group
3724
        if ( /^d ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)/ )
3725
        {
3726
            # if this dir entry is defined in our paths to add we need to remove the entry
3727
            if ( defined($pathDirs{$2}) )
3728
            {
1534 dpurdie 3729
                Warning("addPath2Prototype: Path [$2] already exists in prototype file");
1530 dpurdie 3730
                delete($pathDirs{$2});
3731
            }
3732
        }
3733
    }
3734
 
3735
    my $protoLine;
3736
    # now we write the remaining dirs in the hash 
3737
    foreach $i ( sort keys(%pathDirs) )
3738
    {
3739
        $protoLine = sprintf("d %s %s %s %s %s", $class, $i, $perms, $uid, $gid);
1534 dpurdie 3740
        Verbose("addPath2Prototype: Adding Dir entry [$protoLine]");
1530 dpurdie 3741
        printf FILE "$protoLine\n"; 
3742
    }
3743
 
3744
    close FILE;
3745
    return 1;
3746
}
3747
 
3748
 
3749
#------------------------------------------------------------------------------
3750
sub createAfcRcScriptLink
3751
#
3752
#    Description:
3753
#        This sub-routine is used to create links into /afc/rc.d for start & stop 
3754
#         scripts.
3755
#
3756
#    INPUT:
3757
#        Start prefix number (2 digit number)
3758
#        Stop prefix Number (2 digit Number)
3759
#        Full path to script to create link to.
3760
#
3761
#------------------------------------------------------------------------------
3762
{
3763
    # correct number of parameters?
3764
    if ( ($#_+1) != 3 )
3765
    {
1534 dpurdie 3766
        Error("Incorrect number of params passed to " .
3767
              "createAfcRcScriptLink() function. " ,
3768
              "Check deploy config.");
1530 dpurdie 3769
    }
3770
 
3771
 
3772
    # lets just check to see if we can execute this function on
3773
    # this machine.
3774
    #
3775
    if ( "$MachType" ne "sparc" )
3776
    {
1534 dpurdie 3777
        Verbose("createAfcRcScriptLink() not supported on this machine type.");
1530 dpurdie 3778
        return 1;
3779
    }
3780
 
3781
    my ($startPrefix, $stopPrefix, $scriptPath) = @_;
3782
 
3783
    if ( $startPrefix ne "" )
3784
    {
3785
        updatePrototypeFileAddItem2(sprintf("/afc/rc.d/S%02d%s", $startPrefix, $PkgName), 
3786
                                    $scriptPath, "0755", "root", "other", "S");
3787
    }
3788
    if ( $stopPrefix ne "" )
3789
    {
3790
        updatePrototypeFileAddItem2(sprintf("/afc/rc.d/K%02d%s", $stopPrefix, $PkgName), 
3791
                                    $scriptPath, "0755", "root", "other", "S");        
3792
    }
3793
}
3794
 
3795
 
3796
#------------------------------------------------------------------------------
3797
sub createAfcRcScriptLink2
3798
#
3799
#    Description:
3800
#        This sub-routine is used to create links into the afc rc.d for start & stop 
3801
#        scripts.  It differs from the original in that you pass a TargetDirType
3802
#        parameter and the filename instead of a full path.  It then creates a relative
3803
#        link from $BASEDIR/rc.d to TargetBaseDir
3804
#
3805
#    INPUT:
3806
#        Start prefix number (2 digit number)
3807
#        Stop prefix Number (2 digit Number)
3808
#        Full path to script to create link to.
3809
#
3810
#------------------------------------------------------------------------------
3811
{
3812
    # correct number of parameters?
3813
    if ( ($#_+1) != 4 )
3814
    {
1534 dpurdie 3815
        Error("Incorrect number of params passed to " .
3816
              "createAfcRcScriptLink() function. " ,
3817
              "Check deploy config.");
1530 dpurdie 3818
    }
3819
 
3820
 
3821
    # lets just check to see if we can execute this function on
3822
    # this machine.
3823
    #
3824
    if ( "$MachType" ne "sparc" )
3825
    {
1534 dpurdie 3826
        Verbose("createAfcRcScriptLink() not supported on this machine type.");
1530 dpurdie 3827
        return 1;
3828
    }
3829
 
3830
    my ($startPrefix, $stopPrefix, $targetTag, $scriptPath) = @_;
3831
 
3832
    # lets check to see if the target tag exists if does not the process with log an error.
3833
    my ($targetValue) = getTargetDstDirValue($targetTag, "R");
3834
 
3835
    if ( $startPrefix ne "" )
3836
    {
3837
        updatePrototypeFileAddItem2(sprintf("rc.d/S%02d%s", $startPrefix, $PkgName), 
3838
                                    "../$targetValue/$scriptPath", "0755", "root", "other", "S");
3839
    }
3840
    if ( $stopPrefix ne "" )
3841
    {
3842
        updatePrototypeFileAddItem2(sprintf("rc.d/K%02d%s", $stopPrefix, $PkgName), 
3843
                                    "../$targetValue/$scriptPath", "0755", "root", "other", "S");        
3844
    }
3845
}
3846
 
3847
 
3848
#------------------------------------------------------------------------------
3849
sub createGenericCopy
3850
#
3851
#    Description:
3852
#        This sub-routine is used to create a generic copy of a specific item.
3853
#
3854
#        On sparc this will be a link, but on win32 it will be a file based on the
3855
#        buildType.
3856
#
3857
#    INPUT:
3858
#        src item name
3859
#        generic item name
3860
#        target dir
3861
#
3862
#    RETURN:
3863
#         1
3864
#
3865
#------------------------------------------------------------------------------
3866
{
3867
    my ($sName, $sLoc, $gName, $tDir) = @_;
3868
 
3869
    my ($cmd);
3870
    my ($retVal);
3871
    if ( "$MachType" eq "sparc" )
3872
    {
3873
        # I want to cd into the tDir and then create the link.
3874
        # only if an item of the same name does not already exist
3875
        #
3876
        if ( ! -f "$tDir/$gName" )
3877
        {
3878
            $cmd = "cd $tDir; ln -s $sName $gName";
3879
            $retVal = system("$cmd");
3880
            if ( $retVal != 0 )
3881
            {
1534 dpurdie 3882
                Error("Failed to create generic link [$gName] to [$tDir/$sName]: $retVal");
1530 dpurdie 3883
            }
3884
            else
3885
            {
1534 dpurdie 3886
                Verbose("Created generic link [$gName] to [$tDir/$sName] ...");
1530 dpurdie 3887
            }
3888
        }
3889
    }
3890
    else
3891
    {
3892
 
3893
        # we only create a generic copy of the an item that matches
3894
        # our build type.  (i.e. if we are building a debug package then
3895
        # only the debug items shall be considered.
3896
        #
3897
        if ( "$BuildType" eq "D" )
3898
        {
3899
            if ( $sName !~ /D\./ )
3900
            {
3901
                # this item is not a debug one.
3902
                return 1;
3903
            }
3904
        }
3905
        else
3906
        {
3907
            # this is prod build
3908
            if ( $sName !~ /P\./ )
3909
            {
3910
                # this item is not a prod one.
3911
                return 1;
3912
            }
3913
        }
3914
 
3915
 
3916
        # we have a match, lets create the copy.
3917
        #
3918
        if(File::Copy::copy("$sLoc", "$tDir/$gName"))
3919
        {
1534 dpurdie 3920
            Verbose("Created generic lib copy [$tDir/$gName]...");
1530 dpurdie 3921
        }
3922
        else
3923
        {
1534 dpurdie 3924
            Error("Failed to create generic lib copy [$gName] from [$sLoc]: $!");
1530 dpurdie 3925
        }
3926
    }
3927
 
3928
    return 1;
3929
}
3930
 
3931
 
3932
 
3933
#------------------------------------------------------------------------------
3934
sub removeVersionNumberFromItemName
3935
#
3936
#    Description:
3937
#        This sub-routine is used to remove the version number from the item name.
3938
#        i.e.  myFile.so.1.2.3 ==> myFile.so
3939
#
3940
#    INPUT:
3941
#        item name
3942
#
3943
#    RETURN:
3944
#        new item name.
3945
#
3946
#------------------------------------------------------------------------------
3947
{
3948
    my ($file) = @_;
3949
 
3950
    my ($nfile) = $file;
3951
 
3952
    if ( "$MachType" eq "sparc" )
3953
    {
3954
        $nfile =~ s/\.so.*$/\.so/;
3955
    }
3956
    else
3957
    {
3958
        $nfile =~ s/\.[0-9]+\.[0-9]+.*dll$/\.dll/;
3959
    }
3960
    return "$nfile";
3961
}
3962
 
3963
 
3964
#------------------------------------------------------------------------------
3965
sub excludeItemFromBuild
3966
#
3967
#    Description:
3968
#        This sub-routine is used to determine is a item is to be included in
3969
#        a build based on the current build type and the extension 
3970
#        it SHOULD HAVE!.
3971
#
3972
#        i.e. debug files will be tagged with *D.* 
3973
#             prod  file will be tagged with *P.*
3974
#
3975
#        if the item does not have a *D.* or a *P.* we included it by default.
3976
#
3977
#        INPUT:
3978
#              filename
3979
#
3980
#        RETURN: 
3981
#              1  - exclude 
3982
#              0  - include 
3983
#
3984
#------------------------------------------------------------------------------
3985
{
3986
    my ($file) = @_;
3987
 
3988
    # we only want to deliver
3989
    if ( "$MachType" eq "win32" )
3990
    {
3991
        # we have to include it by default.
3992
        return 0;
3993
    }
3994
 
3995
 
3996
    #######################################################
3997
    #######################################################
3998
    #######################################################
3999
    # Third party packages do not adhere to the *D.* *P.*
4000
    # conventions of debug and production builds.
4001
    #
4002
    # Hopefully we won't have to many of these, only found 
4003
    # one so far.
4004
    # 
4005
    #######################################################
4006
    #######################################################
4007
    #######################################################
4008
    if ( $file =~ /libTAO_BiDirGIOP\.so/ )
4009
    {
4010
        return 0;
4011
    } 
4012
 
4013
    if ( $file !~ /D\./ &&
4014
         $file !~ /P\./
4015
       )
4016
    {
4017
        # we have to include it by default. 
4018
        return 0;
4019
    }
4020
 
4021
 
4022
    # we only want to deliver 
4023
    if ( "$BuildType" eq "D" )
4024
    { 
4025
        if ( $file !~ /D\./ )
4026
        {
4027
            # we do not want this file for this build type.
4028
            return 1;
4029
        }
4030
        else
4031
        {
4032
            return 0;
4033
        }
4034
    }
4035
    else
4036
    {
4037
        if ( $file !~ /P\./ )
4038
        {
4039
            # we do not want this file for this build type.
4040
            return 1;
4041
        }
4042
        else
4043
        {
4044
            return 0;
4045
        }
4046
    }
4047
 
4048
    return 1;
4049
}
4050
 
4051
 
4052
#------------------------------------------------------------------------------
4053
sub installAllDpkgArchiveBinFiles
4054
#
4055
# Description:
4056
#       This sub-routine is used to install all bin files from the
4057
#       dpkg_archive into the defined install area.
4058
#
4059
#       It assumes based on the build type where the src files will be located.
4060
#
4061
#       If it has any problems it will log an error and stop processing.
4062
#
4063
#------------------------------------------------------------------------------
4064
{
4065
    # correct number of parameters?
4066
    if ( ($#_+1) != 1 )
4067
    {
1534 dpurdie 4068
        Error("Incorrect number of params passed to " .
4069
              "installAllDpkgArchiveBinFiles() function. " ,
4070
              "Check deploy config.");
1530 dpurdie 4071
    }
4072
 
4073
    my ($targetTag) = @_;
4074
 
4075
    # lets check to see if the target tag exists
4076
    # if does not the process with log an error.
4077
    #
4078
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
4079
 
4080
 
4081
    # ok we have a valid dst value we now need to get a hold of all the 
4082
    # lib files for this buildtype
4083
    #
4084
    my ($i);
4085
    my ($m_DpkgBinDir);
4086
    foreach $i (@{$DpkgBinDirList{'_ALL_'}})
4087
    {
1534 dpurdie 4088
        $m_DpkgBinDir = "$DpkgBinDir/$i";
4089
        if ( ! -d $m_DpkgBinDir )
1530 dpurdie 4090
        {
1534 dpurdie 4091
            Verbose("Directory [$m_DpkgBinDir] not found.");
1530 dpurdie 4092
            next;
4093
        }
4094
 
4095
        local *DIR;
4096
        opendir(DIR, $m_DpkgBinDir) or 
1534 dpurdie 4097
            Error("can't opendir $m_DpkgBinDir : $!");
1530 dpurdie 4098
 
4099
        my ($file);
4100
        while (defined($file = readdir(DIR))) 
4101
        {
4102
            if ( $file !~ /^\.$/  &&     # we do not want the . and .. entries.
4103
                 $file !~ /^\.\.$/ &&
4104
                 $file !~ /\.pdb$/ )
4105
            {
4106
                my ($m_fLoc) = "$m_DpkgBinDir/$file"; 
4107
                if(File::Copy::copy("$m_fLoc", "$targetValue"))
4108
                {
1534 dpurdie 4109
                    Verbose("Copied [$file] to [$targetValue] ...");
1530 dpurdie 4110
                }
4111
                else
4112
                {
1534 dpurdie 4113
                    Error("Failed to copy bin [$m_fLoc]: $!"); 
1530 dpurdie 4114
                }
4115
            }
4116
        }
4117
        closedir(DIR);
4118
    }
4119
 
4120
    return 1;
4121
}
4122
 
4123
 
4124
#------------------------------------------------------------------------------
4125
sub rmDirectory
4126
#
4127
# Description:
4128
#       This sub-routine is used to remove an entire directory tree.
4129
#
4130
#       It recurses from a starting point removing each item and if it
4131
#       finds a dir it recurses into that dir cleaning it as well.
4132
#
4133
#------------------------------------------------------------------------------
4134
{
4135
    # correct number of parameters?
4136
    if ( ($#_+1) != 1  )
4137
    {
1534 dpurdie 4138
        Error("Incorrect number of params passed to rmDirectory() function.");
1530 dpurdie 4139
    }
4140
 
4141
    my ($startingPoint) = @_;
1548 dpurdie 4142
    return 0 unless ( -d $startingPoint );
1534 dpurdie 4143
    Verbose("Recursively removing Directory tree [$startingPoint]");
1530 dpurdie 4144
 
4145
    #
1542 dpurdie 4146
    #   Use the rmtree function
4147
    #   It works better than glob when given a filepath with spaces
4148
    #
4149
    rmtree($startingPoint, IsVerbose(1), 1);
4150
    Error("Failed to remove dir [$startingPoint] : $!") if (-d $startingPoint);
4151
 
1530 dpurdie 4152
    return 1;
4153
}
4154
 
4155
#------------------------------------------------------------------------------
4156
sub CreateTargetDirStructure
4157
#
4158
# Description:
4159
#       This sub-routine create the target stucture based on what the user has
4160
#       previously defined in the %TargetDstDirStructure hash array
4161
#
4162
#       It will also clean the contents of this location prior to creation.
4163
#
4164
#       In this function we also check to see if all the LocalSrcDirStructure
4165
#       directories exist. We warn if they do not.
4166
#
4167
#------------------------------------------------------------------------------
4168
{
1534 dpurdie 4169
    Information("Cleaning any previous target file items...");
1530 dpurdie 4170
 
4171
    my ($i);
4172
 
1554 dpurdie 4173
    #   Clean out PkgBaseDir
4174
    #   This is the directory in which the final package image will be assembled
4175
    #   Recreate the directory. Ensure that it does not have setgid on the directory
4176
    #   as this will affect all the subdirectories that are created and will
4177
    #   propergate into the target package.
1530 dpurdie 4178
    #
1554 dpurdie 4179
    rmDirectory( $PkgBaseDir );
4180
    make_directory( $PkgDir, 0777, "Create target base dir");
1530 dpurdie 4181
 
4182
    # lets create.
4183
    #
1534 dpurdie 4184
    Information ("Creating target directory structure...");
4185
    make_directory( "$PkgBaseDir/$TargetBaseDir", 0777, "Create target dir");
1530 dpurdie 4186
    foreach $i ( sort {$a cmp $b} values %TargetDstDirStructure )
4187
    {
1534 dpurdie 4188
        make_directory("$PkgBaseDir/$TargetBaseDir/$i", 0777);
1530 dpurdie 4189
    }
4190
 
4191
 
4192
    # lets determine if we have a InstallShield config dir
4193
    #
4194
    if ( "$MachType" eq "win32" || "$MachType" eq "WinCE" )
4195
    {
4196
 
4197
        # if this is a patch build i expect to find a "p" in the front of the
4198
        # file names. we use this as a simple visual differentiation.
4199
        #
4200
        my ($m_ishieldDir);    
4201
        my ($m_ishieldProjFile);
4202
        if ( "x$PkgPatchNum" ne "x" )
4203
        {
4204
            # patch build.
4205
            $m_ishieldDir      = "$RootDir/" . "p$PkgName";
4206
            $m_ishieldProjFile = "$RootDir/" . "p$PkgName" . ".ism";
4207
        }
4208
        else
4209
        {
4210
            # normal build.
4211
            $m_ishieldDir      = "$RootDir/" . "$PkgName";
4212
            $m_ishieldProjFile = "$RootDir/" . "$PkgName" . ".ism";
4213
        }
4214
 
4215
        # here i can set the location of my IShield project dir
4216
        # so i can use it later if required.
4217
        $PKG_ISHIELD_DIR = $m_ishieldDir;
4218
 
4219
 
4220
        # we check for an ism file based on the pkg name
4221
        # if we find one we need to deal with the dir and
4222
        # the isheildlib files.
4223
        #
4224
        if ( -f "$m_ishieldProjFile" )
4225
        {
4226
            if ( ! -d "$m_ishieldDir" )
4227
            {
1534 dpurdie 4228
                Error ("Local InstallShield config dir [$m_ishieldDir] does not exist.",
4229
                       "Please create before continuing.");
1530 dpurdie 4230
            }
4231
            else
4232
            {
4233
                # we populate the ishield config dir with the ishieldlib files
4234
                #
4235
                my ($i);
1534 dpurdie 4236
                Verbose("Installing Standard ishieldlib files from [$PKG_UTIL_DIR] to [$m_ishieldDir]");
1530 dpurdie 4237
                foreach $i ( @PKG_ISHIELD_FILES )
4238
                {
4239
                    # first we remove the file (as previously it install read-only).
4240
                    unlink("$m_ishieldDir/$i");
4241
                    if( File::Copy::copy("$PKG_UTIL_DIR/$i", "$m_ishieldDir") )
4242
                    {
1534 dpurdie 4243
                        Verbose("Copied [$PKG_UTIL_DIR/$i] to [$m_ishieldDir] ...");
1530 dpurdie 4244
                    }
4245
                    else
4246
                    {
1534 dpurdie 4247
                        Error("Failed to copy info file [$PKG_UTIL_DIR/$i] to [$m_ishieldDir] : $!");
1530 dpurdie 4248
                    }
4249
                }
4250
 
4251
 
4252
                # we also want to deliver the patch rule files
4253
                # if this build is a patch build.
4254
                #
4255
                if ( "x$PkgPatchNum" ne "x" )
4256
                {
1534 dpurdie 4257
                    Verbose("Installing Patch ishieldlib files from [$PKG_UTIL_DIR] to [$m_ishieldDir]");
1530 dpurdie 4258
                    foreach $i ( @PATCH_ISHIELD_FILES )
4259
                    {
4260
                        # first we remove the file (as previously it install read-only).
4261
                        unlink("$m_ishieldDir/$i");
4262
                        if( File::Copy::copy("$PKG_UTIL_DIR/$i", "$m_ishieldDir") )
4263
                        {
1534 dpurdie 4264
                            Verbose("Copied [$PKG_UTIL_DIR/$i] to [$m_ishieldDir] ...");
1530 dpurdie 4265
                        }
4266
                        else
4267
                        {
1534 dpurdie 4268
                            Error("Failed to copy info file [$PKG_UTIL_DIR/$i] to [$m_ishieldDir] : $!");
1530 dpurdie 4269
                        }
4270
                    }
4271
                }
4272
 
4273
 
4274
                # we also want to deliver the islib imgages to be
4275
                # used by this project, we assume the image has a project
4276
                # acronym prefix, and if not found we just WARN the user
4277
                #
4278
                # we assume our source dir is the interface/etc dir and our
4279
                # dst dir is the PkgBaseDir
4280
                #
4281
                my ($m_islibImgFile) = "";
1534 dpurdie 4282
                Verbose("Installing ishield image files from [$DpkgEtcDir] to [$m_ishieldDir]");
1530 dpurdie 4283
                foreach $i ( @PKG_ISHIELD_IMG_FILES )
4284
                {
4285
                    $m_islibImgFile = "$DpkgEtcDir/$ProjectAcronym" . "_" . $i;
4286
                    if ( -f "$m_islibImgFile" )
4287
                    {
4288
                        if( File::Copy::copy("$m_islibImgFile", "$PkgBaseDir") )
4289
                        {
1534 dpurdie 4290
                            Verbose("Copied [$m_islibImgFile] to [$PkgBaseDir] ...");
1530 dpurdie 4291
                        }
4292
                        else
4293
                        {
1534 dpurdie 4294
                            Error("Failed to copy info file [$m_islibImgFile] to " .
1530 dpurdie 4295
                                     "[$PkgBaseDir] : $!");
4296
                        }
4297
                    }
4298
                    else
4299
                    {
4300
                        # we shall check for the MASS items, if the exist we copy them
4301
                        # over. Here we assume the 'mas' acronymn is correct.
4302
                        #
4303
                        $m_islibImgFile = "$DpkgEtcDir/mas" . "_" . $i;
4304
                        if ( -f "$m_islibImgFile" )
4305
                        {
4306
                            if( File::Copy::copy("$m_islibImgFile", "$PkgBaseDir") )
4307
                            {
1534 dpurdie 4308
                                Verbose("Copied [$m_islibImgFile] to [$PkgBaseDir] ...");
1530 dpurdie 4309
                            }
4310
                            else
4311
                            {
1534 dpurdie 4312
                                Error("Failed to copy info file [$m_islibImgFile] to " .
1530 dpurdie 4313
                                         "[$PkgBaseDir] : $!");
4314
                            } 
4315
                        } 
4316
                        else
4317
                        {
1534 dpurdie 4318
                            Warning("Failed to locate ishieldlib image [xxx_$i], no image copied, " .
1530 dpurdie 4319
                                    "check depolylib config.");
4320
                        }
4321
                    }
4322
                }
4323
 
4324
            }
4325
        }
4326
        else
4327
        {
1534 dpurdie 4328
            Warning("Did not detect InstallShield project file [$m_ishieldProjFile]");
4329
            Warning("Not installing InstallShield library files.");
1530 dpurdie 4330
        }
4331
    }
4332
 
4333
    # done.
4334
    return 1;
4335
}
4336
 
4337
#------------------------------------------------------------------------------
4338
sub generateIShieldIncludeFile ()
4339
#
4340
# Description:
4341
#     This subroutine is used to generate a definition include file 
4342
#     that is used during IShield builds.
4343
#
4344
#     The output location of the file is the IShieldProjDir.
4345
#    
4346
#------------------------------------------------------------------------------
4347
{
4348
    my ($outFile) = "$PKG_ISHIELD_DIR/$PKG_ISHIELD_DEF_FILE";
4349
 
4350
    # this is only relavent for win32 builds.
4351
    if ( "$MachType" eq "sparc" )
4352
    {
4353
        return 1;
4354
    }
4355
 
4356
    # lets open the file.
4357
    #
4358
    local *FILE;
4359
    open ( FILE, "> $outFile") or
1534 dpurdie 4360
        Error("Failed to open file [$outFile].");
1530 dpurdie 4361
 
4362
    # lets populate the pkgdef file.
4363
 
4364
    printf FILE ("// This is an automatically generated include file.\n");
4365
    printf FILE ("// Please do not modify, and please do not check into ClearCase.\n");
4366
    printf FILE ("//\n");
4367
    printf FILE ("#define PKG_NAME         \"$PkgName\"\n");
4368
    printf FILE ("#define PKG_NAMELONG     \"$PkgNameLong\"\n");
4369
    printf FILE ("#define PKG_VERSION      \"$PkgVersion\"\n");
4370
    printf FILE ("#define PKG_BUILDNUM     \"$PkgBuildNum\"\n");
4371
    printf FILE ("#define PKG_PROJACRONYM  \"$ProjectAcronym\"\n");
4372
    printf FILE ("#define PKG_DESC         \"$PkgDesc\"\n");
4373
 
4374
    # if this build is a patch build.
4375
    #
4376
    if ( "x$PkgPatchNum" ne "x" )
4377
    {
4378
        printf FILE ("#define PATCH_NAME       \"$PkgPatchName\"\n");
4379
        printf FILE ("#define PATCH_NUM        \"$PkgPatchNum\"\n");
4380
        printf FILE ("#define PATCH_ID         \"$PkgPatchID\"\n");
4381
    }
4382
    else
4383
    {
4384
        printf FILE ("#define PATCH_NAME       \"\"\n");
4385
        printf FILE ("#define PATCH_NUM        \"\"\n");
4386
        printf FILE ("#define PATCH_ID         \"\"\n");
4387
    }
4388
 
4389
    # lets close the file
4390
    close FILE;
4391
 
4392
    # done.
4393
    return 1;
4394
}
4395
 
4396
 
4397
#------------------------------------------------------------------------------
4398
sub ValidateLocalSrcDirStructure
4399
#
4400
# Description:
4401
#       This sub-routine is used to check the existence the local dir 
4402
#       configuration items, these are stored in 
4403
#       %LocalSrcDirStructure.
4404
#
4405
#------------------------------------------------------------------------------
4406
{
4407
    # lets check the configured local direcotry structure
4408
    #
4409
    my ($i);
4410
    foreach $i ( values %LocalSrcDirStructure )
4411
    {
4412
        my ($m_Dir) = "$SrcDir/$i";
4413
        if ( ! -d "$m_Dir" )
4414
        {
1534 dpurdie 4415
            Warning ("Local src dir [$m_Dir] does not exist.");
1530 dpurdie 4416
        }
4417
    }
4418
 
4419
    return 1;
4420
}
4421
 
4422
 
4423
#------------------------------------------------------------------------------
4424
sub getLocalDirValue
4425
#
4426
# Description:
4427
#       This sub-routine is used to return the local dir value from
4428
#       %LocalSrcDirStructure based on providing the 
4429
#       associated key.
4430
#
1546 dpurdie 4431
#
4432
# Input:
4433
#       m_key               - A symbolic directory name to be found in the
4434
#                             LocalSrcDirStructure
4435
#
4436
#                             A Package Name of the form
4437
#                             --Package=PackageName,subdir
4438
#
4439
#                             A directory within the interface directory
4440
#                             --Interface=subdir
4441
#
4442
#                             This form is only valid for an ABS address
4443
#
4444
#       m_type              - "A"   Absolute address
4445
#                             else  Relative address
4446
#
1530 dpurdie 4447
#       If the value does not exist then it will return an error
4448
#       and terminate processing.
4449
#
4450
#------------------------------------------------------------------------------
4451
{
4452
    # correct number of parameters?
4453
    if ( ($#_+1) != 2 ) 
4454
    {
1534 dpurdie 4455
        Error("Incorrect number of params passed to " .
1530 dpurdie 4456
                  "getLocalDirValue() function.");
4457
    }
4458
 
4459
    my ($m_key, $m_type) = @_;
1546 dpurdie 4460
 
4461
    #
4462
    #   Determine the type of lookup
4463
    #
4464
    if ( $m_key =~ m~^--Interface=(.*)~ )
1530 dpurdie 4465
    {
1546 dpurdie 4466
        Error("Locating Interface directory must be used in conjunction with an Absolute path")
4467
            unless ( $m_type eq 'A' );
4468
 
4469
        my $SubDir = $1;
4470
        my $Dir = "$InterfaceDir/$SubDir";
4471
        Error ("Interface subdirectory not found: $SubDir" )
4472
            unless ( -d $Dir );
4473
        return $Dir;
4474
    }
4475
 
4476
    if ( $m_key =~ m~^--Package=(.*)~ )
4477
    {
4478
        Error("Locating local source directory must be used in conjunction with an Absolute path")
4479
            unless ( $m_type eq 'A' );
4480
 
4481
        #
4482
        #   Locate directory within a package
4483
        #
4484
        my ($PkgName, $PkgSubDir) = split /[\/,]/, $1, 2;
4485
        Error ("--Package requres a package name and a subdirectory") unless ( $PkgName && $PkgSubDir );
4486
        my $PkgDir = LocatePackageBase( "getLocalDirValue", $PkgName, $PkgSubDir );
4487
        return $PkgDir;
4488
    }
4489
 
4490
    #
4491
    #   Locate the directory within the LocalSrcDirStructure
4492
    #   This is a symbolic reference to a local directory
4493
    #
4494
    if (exists  $LocalSrcDirStructure{$m_key} )
4495
    {
1530 dpurdie 4496
        if ( "$m_type" eq "A" )
4497
        {
1546 dpurdie 4498
            return "$SrcDir/$LocalSrcDirStructure{$m_key}";
1530 dpurdie 4499
        }
4500
        else
4501
        {
4502
            return "$LocalSrcDirStructure{$m_key}";
4503
        }
4504
    }
4505
    else
4506
    {
1534 dpurdie 4507
        Error("Local src tag [$m_key] does not exist in " .
4508
             "LocalSrcDirStructure. " ,
4509
             "Check deploy configuration.");
1530 dpurdie 4510
    }
4511
 
4512
    return 1;
4513
}
4514
 
4515
 
4516
#------------------------------------------------------------------------------
4517
sub getTargetDstDirValue
4518
#
4519
# Description:
4520
#       This sub-routine is used to return the target dest dir value from
4521
#       %TargetDstDirStructure based on providing the 
4522
#       associated key.
4523
#
4524
#       If the value does not exist then it will return an error
4525
#       and terminate processing.
4526
#
1532 dpurdie 4527
# Inputs:   $m_key          Symbolic name for target directory
4528
#           $m_type         Type : A    - Absolute
4529
#                                  R    - Relative
4530
#
1530 dpurdie 4531
#------------------------------------------------------------------------------
4532
{
4533
    # correct number of parameters?
4534
    if ( ($#_+1) != 2 ) 
4535
    {
1534 dpurdie 4536
        Error("Incorrect number of params passed to " .
1530 dpurdie 4537
                  "getTargetDstDirValue() function.");
4538
    }
4539
 
4540
    my ($m_key, $m_type) = @_;
1532 dpurdie 4541
    my $tdir;
4542
 
4543
    #
4544
    #   Look up the users tag conversion hash
4545
    #
4546
    if ( exists $TargetDstDirStructure{$m_key} )
1530 dpurdie 4547
    {
1532 dpurdie 4548
        $tdir = $TargetBaseDir . '/' . $TargetDstDirStructure{$m_key};
1530 dpurdie 4549
    }
4550
    else
4551
    {
1534 dpurdie 4552
        Error("Target destination dir tag [$m_key] does not exist in " .
4553
             "TargetDstDirStructure. " ,
4554
             "Check deploy configuration.");
1530 dpurdie 4555
    }
4556
 
1532 dpurdie 4557
 
4558
    #
4559
    #   If an absolute path is required than add the PkgBaseDir
4560
    #   otherwise the user must be requesting a relative path.
4561
    #
4562
    if ( "$m_type" eq "A" ) {
4563
        $tdir = "$PkgBaseDir/$tdir";
4564
    } elsif ( "$m_type" eq "R" )  {
4565
    } else {
1534 dpurdie 4566
        Error("getTargetDstDirValue: Bad call. Unknown type: $m_type");
1532 dpurdie 4567
    }
4568
 
4569
    return $tdir;
1530 dpurdie 4570
}
4571
 
4572
 
4573
#------------------------------------------------------------------------------
4574
sub createPatch
4575
#
4576
# Description:
4577
#       This sub-routine is used to create a solaris patch.
4578
#
4579
#------------------------------------------------------------------------------
4580
{
4581
    # correct number of parameters?
4582
    if ( ($#_+1) != 0 )
4583
    {
1534 dpurdie 4584
        Error("Incorrect number of params passed to " .
4585
              "createPatch() function.",
4586
              "Check deploy config.");
1530 dpurdie 4587
    }
4588
 
4589
    # lets just check to see if we can execute this function on
4590
    # this machine.
4591
    #
4592
    if ( "$MachType" ne "sparc" )
4593
    {
1534 dpurdie 4594
        Verbose("createPatch() not supported on this machine type.");
1530 dpurdie 4595
        return 1;
4596
    }
4597
 
4598
    # lets just check to see if we can execute this function on
4599
    # for  this build.
4600
    #
4601
    if ( "x$PkgPatchNum" eq "x" )
4602
    {
1534 dpurdie 4603
        Warning("createPatch() can only be called during a PATCH build.");
1530 dpurdie 4604
        return 1;
4605
    }
4606
 
4607
    # we need to create the patch directory that contains
4608
    #
1534 dpurdie 4609
    Information("Creating patch ...");
1530 dpurdie 4610
 
4611
    my ( $m_pkgmkCmd );
4612
    my ( $m_pkgtransCmd );
4613
    $m_pkgmkCmd = "pkgmk -o " .
4614
                  "-f $PkgBaseDir/prototype " .
4615
                  "-d $PkgBaseDir";
4616
 
4617
    # lets execute the package commands.
4618
    my ($retVal);
4619
    $retVal = system("$m_pkgmkCmd");
4620
    if ( $retVal != 0 )
4621
    {
1534 dpurdie 4622
        Error("Failed to complete command [$m_pkgmkCmd].");
1530 dpurdie 4623
    }
4624
 
4625
    # we need to generate a README file to help during installation
4626
    #
4627
    generatePatchREADME();
4628
 
4629
 
4630
    my ($m_Cmd)    = ""; 
4631
    my ($m_tmpDir) = "$PkgPatchTmpDir/$PkgPatchID";
4632
 
1534 dpurdie 4633
    Information("Creating staging area of patch...");
1530 dpurdie 4634
    $m_Cmd = "cd $PkgBaseDir && mkdir -p $m_tmpDir;";
4635
    system($m_Cmd);
4636
 
1534 dpurdie 4637
    Information("Copying patch contents to staging area of patch...");
1530 dpurdie 4638
    $m_Cmd = "cd $PkgBaseDir && cp -r $PkgName $m_tmpDir;";
4639
    system($m_Cmd);
4640
 
4641
    # we need to copy the patch install utility files from
4642
    # their resting place.
4643
    #
4644
    my ($i);
4645
    foreach $i ( @PATCH_UTIL_FILES )
4646
    {
4647
        if( File::Copy::copy("$PATCH_UTIL_DIR/$i", "$PkgPatchTmpDir") )
4648
        {
1534 dpurdie 4649
            Verbose("Copied [$PATCH_UTIL_DIR/$i] to [$PkgPatchTmpDir] ...");
1530 dpurdie 4650
            system("chmod 0755 $PkgPatchTmpDir/$i");
4651
        }
4652
        else
4653
        {
1534 dpurdie 4654
            Error("Failed to copy info file [$PATCH_UTIL_DIR/$i] to [$PkgPatchTmpDir] : $!");
1530 dpurdie 4655
        }
4656
    }
4657
 
4658
    # Lets put the readme in place
4659
    #
4660
    if( File::Copy::copy("$PkgPatchReadme", "$PkgPatchTmpDir") )
4661
    {
1534 dpurdie 4662
        Verbose("Copied [$PkgPatchReadme] to [$PkgPatchTmpDir] ...");
1530 dpurdie 4663
    }
4664
    else
4665
    {
1534 dpurdie 4666
        Error("Failed to copy info file [$PkgPatchReadme] to [$PkgPatchTmpDir] : $!");
1530 dpurdie 4667
    }
4668
 
1534 dpurdie 4669
    Information("Copying patch contents to staging area of patch...");
1530 dpurdie 4670
    $m_Cmd = "cd $PkgBaseDir && cp -r $PkgName $m_tmpDir;";
4671
    system($m_Cmd);
4672
 
4673
    my ($m_oFile) = "$PkgPatchID-$ProjectAcronym\.tgz";
1534 dpurdie 4674
    Information("Creating a gzip'd compressed tar (.tgz) output file [$m_oFile]...");
1530 dpurdie 4675
    my ($base) = File::Basename::basename($PkgPatchTmpDir);
4676
    $m_Cmd = "cd $PkgBaseDir && tar cvf - $base | gzip > $m_oFile";
4677
    system($m_Cmd);
4678
 
4679
    return 1;
4680
}
4681
 
4682
 
4683
 
4684
#------------------------------------------------------------------------------
4685
sub generatePatchREADME
4686
#
4687
#   This function is used to generate a README text file to help the user
4688
#   duing the patch installation.
4689
#
4690
#------------------------------------------------------------------------------
4691
{
4692
    local *FILE;
4693
    open ( FILE, "> $PkgPatchReadme") or
1534 dpurdie 4694
        Error("Failed to open file [$PkgPatchReadme].");
1530 dpurdie 4695
 
4696
    printf FILE ("This is a patch for $PkgName $PkgVersion\n");
4697
    printf FILE ("---------------------------------------------------------------\n");
4698
    printf FILE ("\n");
4699
    printf FILE ("Installing patch (as the 'root' user) :\n");
4700
    printf FILE ("---------------------------------------------------------------\n");
4701
    printf FILE ("./installpatch $PkgPatchID\n");
4702
    printf FILE ("\n");
4703
    printf FILE ("Backing Out patch:\n");
4704
    printf FILE ("---------------------------------------------------------------\n");
4705
    printf FILE ("./backoutpatch $PkgPatchID\n");
4706
    printf FILE ("\n");
4707
 
4708
    printf FILE ("Patch contents of $PkgPatchID\n");
4709
    printf FILE ("---------------------------------------------------------------\n");
4710
    close FILE;
4711
 
4712
    # now we need to get the contents of the patch we are creating.
4713
    #
4714
    File::Find::find(\&getPatchContents, "$PkgBaseDir/$TargetBaseDir");
4715
 
4716
    return 1;
4717
}
4718
 
4719
 
4720
#------------------------------------------------------------------------------
4721
sub getPatchContents
4722
#
4723
#   This sub-routine adds an entry into the readme file for each
4724
#   item in the patch delivery tree.
4725
#
4726
#------------------------------------------------------------------------------
4727
{
4728
    my($file)= "$File::Find::name";
4729
    my($base)= File::Basename::basename($file);
4730
 
4731
    # we get the absolute path from the find, but we only require
4732
    # a relative path from the starting dir.
4733
    # so our start dir.
4734
 
4735
    my ($m_sfile) = $file;
4736
    $file =~ s/$PkgBaseDir//;
4737
 
4738
    open ( FILE, ">> $PkgPatchReadme") or
1534 dpurdie 4739
         Error("Failed to open file [$deplylib::PkgPatchReadme].");
1530 dpurdie 4740
 
4741
    # lets populate the prototype file.
4742
    printf FILE ("* $file\n");
4743
 
4744
    close (FILE);
4745
}
4746
 
4747
 
4748
#------------------------------------------------------------------------------
4749
sub createPackage
4750
#
4751
# Description:
1532 dpurdie 4752
#       This sub-routine is used to create a package.
4753
#       The type of package is machine specific. The subroutine will invoke a
4754
#       machine specfic function to do the real work.
1530 dpurdie 4755
#
4756
#------------------------------------------------------------------------------
4757
{
1534 dpurdie 4758
    Information("createPackage");
1530 dpurdie 4759
 
4760
    # lets just check to see if we can execute this function on
4761
    # this machine.
4762
    #
1532 dpurdie 4763
    my $createRoutine = 'createPackage_' . $MachType;
4764
    if ( exists &$createRoutine )
1530 dpurdie 4765
    {
1532 dpurdie 4766
        # lets just check to see if we can execute this function on
4767
        # for  this build.
4768
        #
4769
        if ( $PkgPatchNum )
4770
        {
1534 dpurdie 4771
            Warning("createPackage() can only be called during a RELEASE build.");
1532 dpurdie 4772
            return 1;
4773
        }
4774
 
4775
        #
4776
        #   Ensure the Release directory is present
4777
        #
1534 dpurdie 4778
        make_directory( $ReleaseDir, 0777 );
1532 dpurdie 4779
 
4780
        # Ensure that the package descriptor is transferred
4781
        #
4782
        my ($m_copydesc) = "cp $SrcDir/descpkg $ReleaseDir";
4783
        system($m_copydesc);
4784
 
4785
        # Invoke the machine specific package builder by name
4786
        # Need to relax strictness. Yes we do know what we are doing here
4787
        #
4788
        no strict "refs";
1534 dpurdie 4789
        &$createRoutine( @_ ) || Error("Unspecified error building package");
1532 dpurdie 4790
        use strict "refs";
1530 dpurdie 4791
    }
1532 dpurdie 4792
    else
1530 dpurdie 4793
    {
1534 dpurdie 4794
        Verbose("createPackage() not supported on this machine type: $MachType.");
1530 dpurdie 4795
    }
1532 dpurdie 4796
    return 1;
4797
}
1530 dpurdie 4798
 
4799
 
1532 dpurdie 4800
#------------------------------------------------------------------------------
4801
sub createPackage_sparc
4802
#
4803
# Description:
4804
#       This sub-routine is used to create a package.
4805
#       The type of package is machine specific. The subroutine will invoke a
4806
#       machine specfic function to do the real work.
4807
#
4808
#------------------------------------------------------------------------------
4809
{
1534 dpurdie 4810
    Verbose("createPackage_sparc");
1532 dpurdie 4811
 
1530 dpurdie 4812
    # we need to copy the package utility files from
4813
    # their resting place.
4814
    #
1532 dpurdie 4815
    foreach my $i ( @PKG_UTIL_FILES )
1530 dpurdie 4816
    {
4817
        if( File::Copy::copy("$PKG_UTIL_DIR/$i", "$PkgBaseDir") )
4818
        {
1534 dpurdie 4819
            Verbose("Copied [$PKG_UTIL_DIR/$i] to [$PkgBaseDir] ...");
1530 dpurdie 4820
            updatePrototypeFileAddItem2("$i", "$i", "", "", "", "I");
4821
            system("chmod 0755 $PkgBaseDir/$i");
4822
        }
4823
        else
4824
        {
1534 dpurdie 4825
            Error("Failed to copy info file [$PKG_UTIL_DIR/$i] to [$PkgBaseDir] : $!");
1530 dpurdie 4826
        }
4827
    }
4828
 
1596 dpurdie 4829
    #
4830
    #   Scan the install 'image' looking for files and directories that have a 'space' in the name
4831
    #   These are not handled by the pkgmk utility, so it is best to create a nice error message now.
4832
    #
4833
    my $search = LocateFiles->new( recurse => 1, dirs_too => 1 );
4834
    $search->filter_in_re('\s');                                  
4835
    my @m_nfiles = $search->search($PkgBaseDir);                                  
4836
    if ( @m_nfiles )
4837
    {
4838
        Error ("Pathnames containing a space cannot be packaged under Solaris",
4839
               "The following paths contain a space",
4840
               @m_nfiles );
4841
    }
4842
 
1530 dpurdie 4843
    my ( $m_pkgmkCmd );
4844
    my ( $m_pkgtransCmd );
4845
    $m_pkgmkCmd = "pkgmk -o " .
4846
                  "-f $PkgBaseDir/prototype " .
4847
                  "-d $PkgBaseDir";
4848
 
4849
 
4850
    $m_pkgtransCmd = "pkgtrans -o " .
4851
                     "-s $PkgBaseDir " .
4852
                     "$PkgOutputFile " .
4853
                     "$PkgName";
4854
 
4855
    # lets execute the package commands.
4856
    my ($retVal);
4857
    $retVal = system("$m_pkgmkCmd");
4858
    if ( $retVal != 0 )
4859
    {
1534 dpurdie 4860
        Error("Failed to complete command [$m_pkgmkCmd].");
1530 dpurdie 4861
    }
4862
 
4863
    $retVal = system("$m_pkgtransCmd");
4864
    system("$m_pkgtransCmd");
4865
    if ( $retVal != 0 )
4866
    {
1534 dpurdie 4867
        Error("Failed to complete command [$m_pkgtransCmd].");
1530 dpurdie 4868
    }
4869
 
4870
    # lets compress the output to save some space.
4871
    #
1534 dpurdie 4872
    Information("Compressing $PkgOutputFile");
1532 dpurdie 4873
    my ($m_compressCmd) = "cd $PkgBaseDir; gzip $PkgOutputFile; mv ${PkgOutputFile}.gz $ReleaseDir";
1530 dpurdie 4874
    system($m_compressCmd);
4875
 
4876
    return 1;
4877
}
4878
 
1532 dpurdie 4879
#------------------------------------------------------------------------------
4880
sub createPackage_WinCE
4881
#
4882
# Description:
4883
#       This sub-routine is used to create a package.
4884
#       Really a win32 machine type, but for some reason, the MachType gets
4885
#       stuffed around. Don't know why.
4886
#
4887
#       Do have the option of creating a WinCE specific packager
4888
#
4889
#------------------------------------------------------------------------------
4890
{
1534 dpurdie 4891
    Verbose("createPackage_WinCE");
1532 dpurdie 4892
    createPackage_win32(@_);
4893
}
1530 dpurdie 4894
 
4895
#------------------------------------------------------------------------------
1532 dpurdie 4896
sub createPackage_win32
4897
#
4898
# Description:
4899
#       This sub-routine is used to create a package.
4900
#       Invoke the isbuild.pl utility to build the install shield project
4901
#
4902
#------------------------------------------------------------------------------
4903
{
1534 dpurdie 4904
    Verbose("createPackage_win32");
1538 dpurdie 4905
 
1532 dpurdie 4906
    #
1538 dpurdie 4907
    #   Process any options that may be present
4908
    #   Don't complain about args we don't understand. They may apply to other
4909
    #   platforms
4910
    #
4911
    my @user_options = ();
4912
    foreach my $arg ( @_ )
4913
    {
4914
        if ( $arg =~ m/^-nonameversion/ || $arg =~ m/^-nameversion/   ) {
4915
            push @user_options, $arg;
4916
 
4917
        } elsif ( $arg =~ m/^-nocode/ || $arg =~ m/^-code/   ) {
4918
            push @user_options, $arg;
4919
 
4920
        } else {
4921
            Message ( "createPackage_win32: Unknown option: $_");
4922
        }
4923
    }
4924
 
4925
    #
1532 dpurdie 4926
    #   Locate MergeModules in external packages
4927
    #   These will be used by the InstallShield compiler
4928
    #
4929
    my @mm_dirs;
4930
    my @mm_tld;
4931
    my $tdir;
4932
 
4933
    #
4934
    #   Check for Merge Modules in the local directory
4935
    #   This must be a flat directory structure. ie: all files in the
4936
    #   subdirectory called MergeModule.
4937
    #
4938
    $tdir = "$RootDir/MergeModules";
4939
    push @mm_dirs, $tdir if ( -d $tdir );
1534 dpurdie 4940
    Verbose ("Discovered MergeModules in: $tdir") if ( -d $tdir );
1532 dpurdie 4941
 
4942
    #
4943
    #   Check for Merge Modules in the Interface directory
4944
    #   This will be pulled in via a BuildPkgArchive
4945
    #
4946
    $tdir = "$InterfaceDir/MergeModules";
4947
    push @mm_tld, $tdir if ( -d $tdir );
1534 dpurdie 4948
    Verbose ("Discovered MergeModules in: $tdir") if ( -d $tdir );
1532 dpurdie 4949
 
4950
    #
4951
    #   Check in LinkPkgArchive locations too
4952
    for my $entry ( $BuildFileInfo->getBuildPkgRules() )
4953
    {
4954
        next unless ( $entry->{'TYPE'} eq 'link' );
4955
        $tdir = $entry->{'ROOT'} . '/MergeModules';
4956
        push @mm_tld, $tdir if ( -d $tdir );
1534 dpurdie 4957
        Verbose ("Discovered MergeModules in: $tdir") if ( -d $tdir );
1532 dpurdie 4958
    }
4959
 
4960
    #
4961
    #   Expand the merge module subdirectory tree into
4962
    #   suitable paths:
4963
    #       Modules/i386
4964
    #       Modules/i386/<language>
4965
    #       Objects
4966
    #       Merge Modules
4967
    #
4968
    foreach my $dir ( @mm_tld )
4969
    {
4970
        $tdir = $dir . '/Modules/i386';
4971
        if ( -d $tdir )
4972
        {
4973
            push @mm_dirs, $tdir;
4974
            foreach my $file ( glob( "$tdir/*" ))
4975
            {
4976
                next unless ( -d $file );
4977
                push @mm_dirs, $file;
4978
            }
4979
        }
4980
 
4981
        $tdir = $dir . '/Objects';
4982
        push @mm_dirs, $tdir if ( -d $tdir );
4983
 
4984
        $tdir = $dir . '/Merge Modules';
4985
        push @mm_dirs, $tdir if ( -d $tdir );
4986
    }
4987
 
4988
 
4989
    #
4990
    #   Locate the program
4991
    #   It will be in a location addressed by the @INC path
4992
    #
4993
    my $prog_found;
4994
    my $prog;
4995
    foreach my $dir ( @INC )
4996
    {
4997
        $prog = $dir . '/isbuild.pl';
4998
        next unless ( -f $prog );
4999
        $prog_found = 1;
5000
        last;
5001
    }
5002
 
1534 dpurdie 5003
    Error("isbuild.pl not found") unless $prog_found;
5004
    Verbose("isbuild: $prog");
1532 dpurdie 5005
    my $rv = system ( $ENV{GBE_PERL}, $prog,
5006
                            "-project=../$PkgName.ism",
5007
                            "-version=$PkgVersionUser",
5008
                            "-out=$ReleaseDir",
5009
                            "-workdir=$InterfaceDir",
1538 dpurdie 5010
                            @user_options,
1532 dpurdie 5011
                            map { "-mergemodule=$_" } @mm_dirs
5012
                             );
1534 dpurdie 5013
    Error ("InstallShield Builder Error" ) if ( $rv );
1532 dpurdie 5014
    return 1;
5015
}
5016
 
5017
#------------------------------------------------------------------------------
1530 dpurdie 5018
sub createPrototypeFile
5019
#
5020
# Description:
1532 dpurdie 5021
#       This sub-routine is used to create the required package prototype file
1530 dpurdie 5022
#       from a known directory struture using the search path method.
5023
#
5024
#------------------------------------------------------------------------------
5025
{
5026
    # correct number of parameters?
5027
    if ( ($#_+1) != 2 )
5028
    {
1534 dpurdie 5029
        Error("Incorrect number of params passed to " .
5030
              "createPrototypeFile() function",
5031
              "Check deploy config.");
1530 dpurdie 5032
    }
5033
 
5034
    # lets just check to see if we can execute this function on
5035
    # this machine.
5036
    #
5037
    if ( "$MachType" ne "sparc" )
5038
    {
1534 dpurdie 5039
        Verbose("createPrototypeFile() not supported on this machine type.");
1530 dpurdie 5040
        return 1;
5041
    }
5042
 
5043
    # lets take the passed in args.
5044
    my ($uid, $gid) = @_;
5045
 
5046
 
5047
    # we need to determine whiich file we are dealing with
5048
    my ($protoTypeFile);
5049
    my ($targetBaseDir);
5050
    my ($pkgBaseDir);
5051
    $protoTypeFile = "$ProtoTypeFile"; 
5052
    $targetBaseDir = "$PkgBaseDir/$TargetBaseDir"; 
5053
    $pkgBaseDir    = "$PkgBaseDir"; 
5054
 
5055
 
5056
    # we need to locate the prototype file
5057
    if ( -f "$protoTypeFile" )
5058
    {
5059
        unlink("$protoTypeFile");
1534 dpurdie 5060
        Verbose("Removing prototype file [$protoTypeFile].");
1530 dpurdie 5061
    }
5062
 
5063
    # lets open the prototype file.
5064
    #    
5065
    local *FILE;
5066
    open ( FILE, "> $protoTypeFile") or
1534 dpurdie 5067
        Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 5068
 
5069
    # lets populate the prototype file.
5070
    printf FILE ("i pkginfo\n");
5071
 
5072
    if ( "x$TargetBaseDir" ne "x." )
5073
    {
5074
        printf FILE ("!search $TargetBaseDir");
5075
    }
5076
    else
5077
    {
5078
        printf FILE ("!search ");
5079
    }
5080
 
5081
    # now we need to add entries for each directory we will 
5082
    # be installing 
5083
    File::Find::find(\&prototypeFind, "$targetBaseDir");
5084
 
5085
    # lets populate the prototype file with a newline.
5086
    open ( FILE, ">> $protoTypeFile") or
1534 dpurdie 5087
        Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 5088
    printf FILE ("\n");
5089
    close (FILE);
5090
 
5091
 
5092
    # lets put the pre-deinfed generic entries into the 
5093
    # prototype file
5094
    #
5095
    if ( "x$PkgPatchNum" ne "x" )
5096
    {
5097
        addPatchInfo2ProtoTypeFile();
5098
    }
5099
 
5100
 
5101
    # we need to expand and complete the creation of the 
5102
    # prototype file
5103
    # if targetbasedir is "." the pkgproto will pick up the pkginfo and
5104
    # prototype files so we need to remove them
5105
    my ($m_cmd) = "pkgproto " .
5106
                  "$TargetBaseDir " .
5107
                  "| egrep -v \"($ProtoTypeFileName|$PkgInfoFileName)\"" .
5108
                  "| cut -f1-4 -d' ' | sed " . '"s/\$/ ' . "$uid $gid" . '/g"' . 
5109
                  " >> $protoTypeFile";
5110
 
5111
    my ($retVal) = system("cd $pkgBaseDir; $m_cmd");
5112
    if ( $retVal != 0 )
5113
    {
1534 dpurdie 5114
        Error("Failed to create prototype file [$protoTypeFile].");
1530 dpurdie 5115
    }
5116
 
1534 dpurdie 5117
    Information("Created prototype file [$protoTypeFile].");
1530 dpurdie 5118
 
5119
    return 1;
5120
}
5121
 
5122
#------------------------------------------------------------------------------
5123
sub prototypeFind
5124
#
5125
#    Description:
5126
#        This subroutine is used to locate all associated package dirs.
5127
#        It also adds an entry into the prototype file for each dir.
5128
#
5129
#------------------------------------------------------------------------------
5130
{
5131
    my($file)= "$File::Find::name";
5132
    my($base)= File::Basename::basename($file);
5133
 
5134
    # we get the absolute path from the find, but we only require
5135
    # a relative path from the starting dir.
5136
    # so our start dir.
5137
 
5138
    # we need to determine whiich file we are dealing with
5139
    my ($pfile);
5140
    my ($tDir);
5141
    $pfile = "$ProtoTypeFile"; 
5142
    $tDir = "$PkgBaseDir/$TargetBaseDir"; 
5143
    if ( "$file" ne "$tDir" )
5144
    {
5145
        if ( -d "$file" )  
5146
        {
5147
            my ($m_sfile) = $file;
5148
 
5149
            if ( "x$TargetBaseDir" eq "x." )
5150
            {
5151
                $tDir = $tDir . "/";
5152
                $file =~ s/$tDir//;
5153
            }
5154
            else
5155
            {
5156
                $file =~ s/$tDir/$TargetBaseDir/;
5157
            }
5158
 
5159
            open ( FILE, ">> $pfile") or
1534 dpurdie 5160
                 Error("Failed to open file [$pfile].");
1530 dpurdie 5161
 
5162
            # lets populate the prototype file.
5163
            printf FILE (" $file");
5164
            close (FILE);
5165
        }
5166
    }
5167
}
5168
 
5169
 
5170
#------------------------------------------------------------------------------
5171
sub addPatchInfo2ProtoTypeFile
5172
#
5173
# Description:
5174
#       This sub-routine is used to add additonal genericinformation
5175
#       used by the patch.
5176
#
5177
#------------------------------------------------------------------------------
5178
{
1534 dpurdie 5179
    Information("Adding patch information files to patch build...");
1530 dpurdie 5180
 
5181
    # we need to determine whiich file we are dealing with
5182
    my ($protoTypeFile);
5183
    $protoTypeFile = "$ProtoTypeFile";
5184
 
5185
    # lets open the prototype file.
5186
    #
5187
    local *FILE;
5188
    open ( FILE, ">> $protoTypeFile") or
1534 dpurdie 5189
        Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 5190
 
5191
 
5192
    # we need to copy the install informational files from
5193
    # their resting place.
5194
    my ($i);
5195
    foreach $i ( @PATCH_INFO_FILES )
5196
    {
5197
        if( File::Copy::copy("$PATCH_UTIL_DIR/$i", "$PkgBaseDir") )
5198
        {
1534 dpurdie 5199
            Verbose("Copied [$PATCH_UTIL_DIR/$i] to [$PkgBaseDir] ...");
1530 dpurdie 5200
            printf FILE ("i $i\n"); 
5201
        }
5202
        else
5203
        {
1534 dpurdie 5204
            Error("Failed to copy info file [$PATCH_UTIL_DIR/$i]: $!");
1530 dpurdie 5205
        }
5206
    }
5207
    close FILE;
5208
 
5209
    return 1;
5210
}
5211
 
5212
 
5213
#------------------------------------------------------------------------------
5214
sub useReplaceClass
5215
#
5216
# Description:
5217
#       This sub-routine is used to add replace class to the classes list and
5218
#       include the i.replace file in the PKG_INFO_FILES List
5219
#
5220
#------------------------------------------------------------------------------
5221
{
5222
 
1534 dpurdie 5223
    Information("useReplaceClass: Adding replace class to installer");
1530 dpurdie 5224
 
5225
    $PkgInfoClasses = $PkgInfoClasses . " " . "replace";
5226
    push(@PKG_UTIL_FILES, "i.replace");
5227
}
5228
 
5229
 
5230
#------------------------------------------------------------------------------
5231
sub addPkgInfoClasses
5232
#
5233
# Description:
5234
#       This sub-routine is used to add new classes to the pkginfo CLASSES variable.
5235
#
5236
#------------------------------------------------------------------------------
5237
{
5238
    # correct number of parameters?
5239
    if ( ($#_+1) == 0 )
5240
    {
1534 dpurdie 5241
        Error("Incorrect number of params passed to " .
5242
              "createPkginfoFile() function",
5243
              "Check deploy config.");
1530 dpurdie 5244
    }
5245
 
1534 dpurdie 5246
    Information("addPkgInfoClasses() Adding classes \"" . join(" ", @_) . "\" to CLASSES List");
1530 dpurdie 5247
 
5248
    $PkgInfoClasses = $PkgInfoClasses . " " . join(" ", @_);
5249
}
5250
 
5251
 
5252
#------------------------------------------------------------------------------
5253
sub addPkgInfoField
5254
#
5255
# Description:
5256
#       This sub-routine is used to add new fields to already created pkginfo file
5257
#       Acccepts any number of fields of format A=B as one string parameter.
5258
#------------------------------------------------------------------------------
5259
{
5260
    # lets just check to see if we can execute this function on this machine.
5261
    if ( "$MachType" ne "sparc" )
5262
    {
1534 dpurdie 5263
        Verbose("addPkgInfoField() not supported on this machine type.");
1530 dpurdie 5264
        return 1;
5265
    }
5266
    # lets open the pkginfo file.   
5267
    local *FILE;
1534 dpurdie 5268
    open ( FILE, ">> $PkgInfoFile") or Error("Failed to open file [$PkgInfoFile].");
1530 dpurdie 5269
 
5270
    foreach my $i ( @_ )
5271
    {
5272
        print FILE "$i\n";
5273
    }
5274
    close FILE;
5275
    return 1;
5276
}
5277
 
5278
#------------------------------------------------------------------------------
5279
sub updatePrototypeFileItemClass
5280
#
5281
# Description:
5282
#       This subroutine is used to change the class of a file already in the prototype file
5283
#
5284
#------------------------------------------------------------------------------
5285
{
5286
    # correct number of parameters?
5287
    if ( ($#_+1) != 2 )
5288
    {
1534 dpurdie 5289
        Error("Incorrect number of params passed to " .
1530 dpurdie 5290
                  "updatePrototypeFileItemClass() function. Check deploy config.");
5291
    }
5292
 
5293
 
5294
    # lets just check to see if we can execute this function on
5295
    # this machine.
5296
    #
5297
    if ( "$MachType" ne "sparc" )
5298
    {
1534 dpurdie 5299
        Verbose("updatePrototypeFileItemClass() not supported on this machine type.");
1530 dpurdie 5300
        return 1;
5301
    }
5302
 
5303
 
5304
    # lets setup the passed values.
5305
    my ($m_item, $class) = @_;
5306
 
5307
    my ($tmpProtoTypeFile) = "/tmp/xx_prototypefile.$$";
5308
 
5309
    # lets open the prototype file if it exists
5310
    #
5311
    open (PFILE, "< $ProtoTypeFile") or
1534 dpurdie 5312
        Error("Failed to open prototype file [$ProtoTypeFile].");
1530 dpurdie 5313
 
5314
    open (PFILETMP, "> $tmpProtoTypeFile") or
1534 dpurdie 5315
        Error("Failed to open tmp prototype file [$tmpProtoTypeFile].");
1530 dpurdie 5316
 
5317
    while ( <PFILE> )
5318
    {
5319
        chomp;
5320
        # The path section will normally contain "path [mode]" or path=path
5321
        # The passed arg can be full path or can skip top level dirs
5322
        # eg prototype can have line with path ergbpeod/etc/afcbp.ini
5323
        # arg to match can be ergbpeod/etc/afcbp.ini, etc/afcbp.ini or afcbp.ini
5324
        # therefore we need to match arg to the end of the path in line 
5325
        # so we append [= ] to arg
5326
        s/^(\s*[bcdefilpsvx]\s*)[^\s]*(.*$)/$1$class$2/ if ( /$m_item[ =]/ );
5327
        printf PFILETMP ("$_\n");
5328
    }
5329
    close PFILE;
5330
    close PFILETMP;
5331
 
5332
    # now we need to copy the file.
5333
    if(File::Copy::copy("$tmpProtoTypeFile", "$ProtoTypeFile"))
5334
    {
1534 dpurdie 5335
        Verbose("Updated file $m_item to class $class");
1530 dpurdie 5336
        unlink($tmpProtoTypeFile);
5337
    }
5338
    else
5339
    {
1534 dpurdie 5340
        Error("Failed to copy lib [$tmpProtoTypeFile]: $!");
1530 dpurdie 5341
    }
5342
 
5343
    return 1;
5344
 
5345
}
5346
 
5347
 
5348
 
5349
#------------------------------------------------------------------------------
5350
sub setReplaceClassFiles
5351
#
5352
# Description:
5353
#       This subroutine is used to change the class of a file already in the prototype file
5354
#
5355
#------------------------------------------------------------------------------
5356
{
5357
    # lets just check to see if we can execute this function on
5358
    # this machine.
5359
    #
5360
    if ( "$MachType" ne "sparc" )
5361
    {
1534 dpurdie 5362
        Verbose("updatePrototypeFileItemClass() not supported on this machine type.");
1530 dpurdie 5363
        return 1;
5364
    }
5365
 
1534 dpurdie 5366
    Error("Must call useReplaceClass() before calling setReplaceClassFiles()") if ( $PkgInfoClasses !~ /replace/ );
1530 dpurdie 5367
 
5368
    my ($tmpProtoTypeFile) = "/tmp/xx_prototypefile.$$";
5369
 
5370
    # lets open the prototype file if it exists
5371
    #
5372
    open (PFILE, "< $ProtoTypeFile") or
1534 dpurdie 5373
        Error("Failed to open prototype file [$ProtoTypeFile].");
1530 dpurdie 5374
 
5375
    open (PFILETMP, "> $tmpProtoTypeFile") or
1534 dpurdie 5376
        Error("Failed to open tmp prototype file [$tmpProtoTypeFile].");
1530 dpurdie 5377
 
5378
    my $line;
5379
    while ( $line = <PFILE> )
5380
    {
5381
        chomp $line;
5382
        # The path section will normally contain "path [mode]" or path=path
5383
        # The passed args can be full path or can skip top level dirs
5384
        # eg prototype can have line with path ergbpeod/etc/afcbp.ini
5385
        # args to match can be ergbpeod/etc/afcbp.ini, etc/afcbp.ini or afcbp.ini
5386
        # therefore we need to match each arg to the end of the path in line 
5387
        # so we append [= ] to end of each arg
5388
        $line =~ s/^(\s*[bcdefilpsvx]\s*)[^\s]*(.*$)/$1replace$2/ if ( scalar(grep { $line =~ /$_[ =]/ } @_) > 0 );
5389
        printf PFILETMP ("$line\n");
5390
    }
5391
    close PFILE;
5392
    close PFILETMP;
5393
 
5394
    # now we need to copy the file.
5395
    if(File::Copy::copy("$tmpProtoTypeFile", "$ProtoTypeFile"))
5396
    {
1534 dpurdie 5397
        Verbose("Updated prototype file entries to class replace");
1530 dpurdie 5398
        unlink($tmpProtoTypeFile);
5399
    }
5400
    else
5401
    {
1534 dpurdie 5402
        Error("Failed to copy lib [$tmpProtoTypeFile]: $!");
1530 dpurdie 5403
    }
5404
 
5405
    return 1;
5406
 
5407
}
5408
 
5409
 
5410
#------------------------------------------------------------------------------
5411
sub createPkginfoFile
5412
#
5413
# Description:
5414
#       This sub-routine is used to create the required package info.
5415
#       Accepts any number of parameters, with each parameter taken as a literal
5416
#       Field=Value string and inserted into the PkgInfo File
5417
#------------------------------------------------------------------------------
5418
{
5419
    # lets check to see if our description has been set
5420
    if ( $PkgDesc eq "" )
5421
    {
1534 dpurdie 5422
        Error("Package description not set. " .
1530 dpurdie 5423
                 "Use setPkgDescription('my package description') function.");
5424
    }
5425
 
5426
    # lets check to see if our long name has been set
5427
    if ( $PkgNameLong eq "" )
5428
    {
1534 dpurdie 5429
        Error("Package name not set. Use setPkgName('my package long name') function.");
1530 dpurdie 5430
    }
5431
 
5432
 
5433
    # lets just check to see if we can execute this function on
5434
    # this machine.
5435
    #
5436
    if ( "$MachType" ne "sparc" )
5437
    {
5438
        generateIShieldIncludeFile();
5439
        return 1;
5440
    }
5441
 
5442
    # we need to determine whiich file we are dealing with
5443
    my ($pkginfoFile) = "$PkgInfoFile"; 
5444
 
5445
    # we need to locate the pkginfo file
5446
    if ( -f "$pkginfoFile" )
5447
    {
5448
        unlink("$pkginfoFile");
1534 dpurdie 5449
        Verbose("Removing pkginfo file [$pkginfoFile].");
1530 dpurdie 5450
    }
5451
 
5452
    # lets open the pkginfo file.
5453
    #    
5454
    local *FILE;
5455
    open ( FILE, "> $pkginfoFile") or
1534 dpurdie 5456
        Error("Failed to open file [$pkginfoFile].");
1530 dpurdie 5457
 
5458
    # lets populate the pkginfo file.
5459
    printf FILE ("PKG=$PkgName\n");
5460
 
5461
 
5462
    # here we deal with the new version number format
5463
    #
5464
    printf FILE ("NAME=$PkgNameLong\n");
5465
    printf FILE ("VERSION=$PkgVersion.$ProjectAcronym\n");
5466
    printf FILE ("ARCH=$MachType\n");
5467
    printf FILE ("VENDOR=$VENDOR_DESC\n");
5468
    printf FILE ("DESC=$PkgDesc\n");
5469
    printf FILE ("CATEGORY=$CATEGORY_DESC\n");
5470
    printf FILE ("BASEDIR=$ERGAFC_BASEDIR\n");
5471
    printf FILE ("TARGETBASEDIR=$TargetBaseDir\n");
5472
    printf FILE ("CLASSES=$PkgInfoClasses\n");
5473
 
5474
    foreach my $param ( @_ )
5475
    {
5476
        printf FILE "$param\n";
5477
    }
5478
 
5479
    if ( "x$PkgPatchNum" ne "x" )
5480
    {
5481
        my ($count)=1;
5482
        my ($pRev)="";
5483
        printf FILE ("MAXINST=$MAXINST\n");
5484
        printf FILE ("SUNW_PATCHID=$PkgPatchID\n");
5485
        printf FILE ("SUNW_REQUIRES=\n");
5486
        printf FILE ("SUNW_INCOMPAT=\n");
5487
 
5488
        $count=1;
5489
        $pRev="";
5490
        printf FILE ("SUNW_OBSOLETES=");
5491
        while ( $count < $PkgPatchNum )
5492
        {
5493
            $pRev = sprintf ("%02s", $count); 
5494
            printf FILE ("$PkgPatchName" . 
5495
                         "$PkgVersionStr" . 
5496
                         "-" . 
5497
                         "$pRev ");
5498
            $count++;
5499
        }
5500
        printf FILE ("\n");
5501
 
5502
        $count=1;
5503
        $pRev="";
5504
        printf FILE ("PATCH_OBSOLETES=");
5505
        while ( $count < $PkgPatchNum )
5506
        {
5507
            $pRev = sprintf ("%02s", $count); 
5508
            printf FILE ("$PkgPatchName" . 
5509
                         "$PkgVersionStr" . 
5510
                         "-" . 
5511
                         "$pRev ");
5512
            $count++;
5513
        }
5514
        printf FILE ("\n");
5515
    }
5516
 
5517
 
5518
    # now we will list the build dependencies so
5519
    # we can refer to them online
5520
    #
5521
    my ($i);
5522
    my ($m_Str);
5523
    # printf FILE ("\n");
5524
    my ($count) = 1;
5525
    foreach $i ( $BuildFileInfo->getDpkgArchiveList() )
5526
    {
5527
         my $moduleInfo = $BuildFileInfo->getDpkgArchiveInfo($i);
5528
 
5529
         printf FILE ( "$moduleInfo->{type}\_$count=$i $moduleInfo->{version}");
5530
 
5531
         # we shall print the project bit if we have one
5532
         if ( $moduleInfo->{proj} ne "" )
5533
         {
5534
             printf FILE ( "\.$moduleInfo->{proj}\n");
5535
         }
5536
         else
5537
         {
5538
             printf FILE ("\n");
5539
         }
5540
         $count++;
5541
    }
5542
    close FILE;
5543
 
5544
 
5545
    # lets close the pkginfo file.
5546
    close (FILE);
1534 dpurdie 5547
    Information("Created pkginfo file [$pkginfoFile].");
1530 dpurdie 5548
 
5549
    return 1;
5550
}
5551
 
5552
 
5553
#------------------------------------------------------------------------------
5554
sub updatePrototypeFileItemOwner
5555
#
5556
# Description:
5557
#       This sub-routine is used to change the ownership of a file item
5558
#       in the prototype file.
5559
#
5560
#------------------------------------------------------------------------------
5561
{
5562
    # correct number of parameters?
5563
    if ( ($#_+1) != 4 )
5564
    {
1534 dpurdie 5565
        Error("Incorrect number of params passed to " .
1530 dpurdie 5566
                  "updatePrototypeFileItemOwner() function. Check deploy config.");
5567
    }
5568
 
5569
 
5570
    # lets just check to see if we can execute this function on
5571
    # this machine.
5572
    #
5573
    if ( "$MachType" ne "sparc" )
5574
    {
1534 dpurdie 5575
        Verbose("chmod() not supported on this machine type.");
1530 dpurdie 5576
        return 1;
5577
    }
5578
 
5579
 
5580
    # lets setup the passed values.
5581
    my ($m_item, $m_ownPerms, $m_ownUser, $m_ownGroup) = @_;
5582
 
5583
 
5584
    my ($tmpProtoTypeFile) = "/tmp/xx_prototypefile.$$";
5585
 
5586
 
5587
    # lets open the prototype file if it exists
5588
    #
5589
    open (PFILE, "< $ProtoTypeFile") or
1534 dpurdie 5590
        Error("Failed to open prototype file [$ProtoTypeFile].");
1530 dpurdie 5591
 
5592
    open (PFILETMP, "> $tmpProtoTypeFile") or
1534 dpurdie 5593
        Error("Failed to open tmp prototype file [$tmpProtoTypeFile].");
1530 dpurdie 5594
 
5595
    my ($inLine);
5596
    while ( <PFILE> )
5597
    {
5598
        $inLine = $_;
5599
        chomp($inLine);
5600
        if ( "$inLine" =~ /^f / && "$inLine" =~ /$m_item/ )
5601
        {
5602
            my ($b1, $b2, $b3, $b4, $b5, $b6) = split (/ /, $inLine); 
5603
            printf PFILETMP ("$b1 $b2 $b3 $m_ownPerms $m_ownUser $m_ownGroup\n");
5604
        }
5605
        else
5606
        {
5607
            printf PFILETMP ("$inLine\n");
5608
        }
5609
    }
5610
    close PFILE;
5611
    close PFILETMP;
5612
 
5613
    # now we need to copy the file.
5614
    if(File::Copy::copy("$tmpProtoTypeFile", "$ProtoTypeFile"))
5615
    {
1534 dpurdie 5616
        Verbose("Copied [$tmpProtoTypeFile] to [$ProtoTypeFile] ...");
1530 dpurdie 5617
        unlink($tmpProtoTypeFile);
5618
    }
5619
    else
5620
    {
1534 dpurdie 5621
        Error("Failed to copy lib [$tmpProtoTypeFile]: $!");
1530 dpurdie 5622
    }
5623
 
5624
    return 1;
5625
 
5626
}
5627
 
5628
 
5629
#------------------------------------------------------------------------------
1592 dpurdie 5630
sub setPermissions
5631
#   Called to set permissions of files/dirs in a directory structure.
5632
#       With no options sets DirTag and all files/dirs in it to perms
5633
#   
5634
#   Parameters:  
5635
#               DirTag:  The directory tag to start setting permissions on
5636
#       
5637
#   Required Options:
5638
#       One or both of
5639
#               --FilePerms=    Sets the permissions of files to this permission.
5640
#                               If not supplied then no files have their permissions changed
5641
#               --DirPerms=     Sets the permissions of directories to this permission
5642
#                               If not supplied then no directories have their permissions changed
5643
#       OR
5644
#               --Perms=        Sets the permissions of both files and directories to this permissions
5645
#                               Equivalent to supplying both --FilePerms=X && --DirPerms=X
5646
#               
5647
#   Options:
5648
#               --Recurse       Recurse the directory tree.  Does a deptth first recurse so that all 
5649
#                               dir entries are processed before the dir itself
5650
#               --NoRecurse     Dont recurse, default
5651
#               --DirTagOnly    Only sets the permissions on the DirTag directory, 
5652
#                               all other options ignored
5653
#               --SkipDirTag    Does not set permissions on the DirTag Directory, 
5654
#                               obviously mutually exlusive with --DirTagOnly
5655
#               --FilterIn=     Apply permissions to files/directories that matches this value.
5656
#               --FilterInRE=   Perl RE's can be used (Not Shell wildcards) and this option
5657
#                               can be supplied mulitple times
5658
#               --FilterOut=    Dont apply permissions to any files/directories matching this value
5659
#               --FilterOutRE=  Perl RE's can be used (Not Shell wildcards) and this option
5660
#                               can be supplied mulitple times
5661
#               
5662
#                               FilterIn is applied before FilterOut.  If Recurse is specified 
5663
#                               the directory will be recursed regardless of these filters, however
5664
#                               the filter will be applied when it comes time to chmod the dir 
1530 dpurdie 5665
#
5666
#------------------------------------------------------------------------------
5667
{
1592 dpurdie 5668
    my ( $dirTag, $filePerms, $dirPerms );
5669
    my ( $dirTagOnly, $skipDirTag ) = ( 0, 0 );
5670
 
5671
    my $search =  LocateFiles->new( recurse => 0, dirs_too =>1 );
5672
 
5673
    foreach ( @_ )
1530 dpurdie 5674
    {
1592 dpurdie 5675
        if ( m/^--Perms=(.*)/ ) {
5676
            $filePerms = $1;
5677
            $dirPerms = $1;
1530 dpurdie 5678
 
1592 dpurdie 5679
        } elsif ( m/^--FilePerms=(.*)/ )  {
5680
            $filePerms = $1;
1530 dpurdie 5681
 
1592 dpurdie 5682
        } elsif ( m/^--DirPerms=(.*)/ )  {
5683
            $dirPerms = $1;
1530 dpurdie 5684
 
1592 dpurdie 5685
        } elsif ( m/^--Recurse/ ) {
5686
            $search->recurse(1);
5687
        }
5688
        elsif ( m/^--NoRecurse/ ) {
5689
            $search->recurse(0);
1530 dpurdie 5690
 
1592 dpurdie 5691
        }  elsif ( m/^--DirTagOnly/ ) {
5692
            $dirTagOnly = 1;
5693
 
5694
        } elsif ( m/^--SkipDirTag/ )  {
5695
            $skipDirTag = 1;
5696
 
5697
        }  elsif ( m/^--FilterInRE=(.*)/ ) {
5698
            $search->filter_in_re($1);
5699
 
5700
        } elsif ( m/^--FilterIn=(.*)/ ) {
5701
            $search->filter_in($1);
5702
 
5703
        }  elsif ( m/^--FilterOutRE=(.*)/ ) {
5704
            $search->filter_out_re($1);
5705
 
5706
        }  elsif ( m/^--FilterOut=(.*)/ ) {
5707
            $search->filter_out($1);
5708
 
5709
        } else  {
5710
            Error("SetPermissions DirTag already set") if ( $dirTag );
5711
            $dirTag = $_;
5712
        }
5713
    }
5714
 
5715
    Error("SetPermissions called with out DirTag parameter") if ( !defined($dirTag) );
5716
    Error("SetPermissions called with out any Permission options") if ( !defined($filePerms) && !defined($dirPerms) );
5717
    Error("SetPermissions: Options --DirTagOnly & --SkipDirTag are mutually exclusive" ) if ( $dirTagOnly && $skipDirTag );
5718
 
5719
    #
1530 dpurdie 5720
    # lets just check to see if the perms are in correct format.
5721
    #
1592 dpurdie 5722
    if ( (defined($filePerms) && $filePerms !~ m/^\d{4}$/) || (defined($dirPerms) && $dirPerms !~ m/^\d{4}$/) )
1530 dpurdie 5723
    {
1592 dpurdie 5724
        Error("setPermissions called with invalid permissions format");
1530 dpurdie 5725
    }
5726
 
1592 dpurdie 5727
    #   Convert the symbolic target directory name into a real path
5728
    my ($topDir) = getTargetDstDirValue($dirTag, "A");
1530 dpurdie 5729
 
1592 dpurdie 5730
    #
5731
    #   Only set perms on the root directory
5732
    #   This is a trivial operation
5733
    #
5734
    if ( $dirTagOnly )
1530 dpurdie 5735
    {
1592 dpurdie 5736
        Error("SetPermissions:  --DirPerms or --Perms not supplied for setting perms with --DirTagOnly") 
5737
            if ( ! defined($dirPerms) );
5738
        Information("SetPermissions: Setting permissions on top level dir only [$topDir] to " . $dirPerms);
5739
        chmodFile($topDir, $dirPerms);
5740
        return;
1530 dpurdie 5741
    }
1592 dpurdie 5742
 
5743
    Information("SetPermissions: Called with options " . join(", ", @_));
5744
 
5745
 
5746
    #
5747
    #   Create a list of files/dirs to process
5748
    #
5749
    my @elements = $search->search( $topDir );
5750
    Warning ("setPermissions: No files located") unless ( @elements );
5751
 
5752
    foreach my $dirEntry ( @elements )
1530 dpurdie 5753
    {
1592 dpurdie 5754
        my $fullPath = "$topDir/$dirEntry";
5755
 
5756
        # A dir and we dont have dirperms, so skip
5757
        if ( -d $fullPath && !defined($dirPerms) )
5758
        {
5759
            Debug2("SetPermissions: Skipping dir $fullPath as we have no dir permissions");
5760
            next;
5761
        }
5762
 
5763
        # A file and we dont have fileperms, so skip
5764
        if ( -f $fullPath && !defined($filePerms) )
5765
        {
5766
            Debug2("SetPermissions: Skipping file $fullPath as we have no file permissions");
5767
            next;
5768
        }
5769
 
5770
        # a file or a dir and have the right permissions and we are not recursing
5771
        if ( -f $fullPath || -d $fullPath )
5772
        {
5773
            chmodFile($fullPath, ( -f $fullPath ) ? $filePerms : $dirPerms);
5774
        }
5775
        else
5776
        {
5777
            Warning("SetPermissions: Skipping $fullPath as its not a file or directory");
5778
        }
1530 dpurdie 5779
    }
5780
 
1592 dpurdie 5781
 
1530 dpurdie 5782
    #
1592 dpurdie 5783
    #   Process the topDir
5784
    #   May not be modified if --SkipDirTag has been requested
5785
    #
5786
    if ( !$skipDirTag && defined($dirPerms) )
1530 dpurdie 5787
    {
1592 dpurdie 5788
        chmodFile($topDir, $dirPerms);
1530 dpurdie 5789
    }
5790
 
1592 dpurdie 5791
}   # setPermissions
5792
 
5793
 
5794
#------------------------------------------------------------------------------
5795
sub chmod
5796
#
5797
# Description:
5798
#       This sub-routine is used to change the ownership of a file or
5799
#       directory structure.
5800
#
5801
#------------------------------------------------------------------------------
5802
{
5803
    # correct number of parameters?
5804
    Error("Incorrect number of params passed to chmod() function. Check deploy config.") if ( ($#_+1) != 3 );
5805
 
5806
    # lets setup the passed values.
5807
    my ($m_sDirTag, $m_sfile, $m_ownPerms) = @_;
5808
 
5809
    Warning("chmod has been deprecated by and now calls setPermissions, see deploylib.pm");
5810
 
5811
    # call setPermissions, if no File then do DirTagOnly, otherwise set FilterIn=File
5812
    setPermissions($m_sDirTag, "--NoRecurse", "--Perms=$m_ownPerms", 
5813
                    ($m_sfile eq "") ? "--DirTagOnly" : "--FilterIn=$m_sfile" );
5814
 
1530 dpurdie 5815
    return 1;
5816
}
5817
 
5818
 
5819
#------------------------------------------------------------------------------
5820
sub chmodRecursive
5821
#
5822
# Description:
5823
#       This sub-routine is used to change the permissions recursively in
5824
#       the target packgae.
5825
#
5826
#------------------------------------------------------------------------------
5827
{
5828
    # correct number of parameters?
1592 dpurdie 5829
    Error("Incorrect number of params passed to chmodRecursive() function. Check deploy config.") if ( ($#_+1) != 2 );
1530 dpurdie 5830
 
5831
    # lets setup the passed values.
5832
    my ($m_sDirTag, $m_ownPerms) = @_;
5833
 
1592 dpurdie 5834
    Warning("chmodRecursive has been deprecated by and now calls setPermissions, see deploylib.pm");
1530 dpurdie 5835
 
1592 dpurdie 5836
    # call setPermissions, if no File then do DirTagOnly, otherwise set FilterIn=File
5837
    setPermissions($m_sDirTag, "--Recurse", "--Perms=$m_ownPerms");
1530 dpurdie 5838
 
5839
    return 1;
5840
}
5841
 
5842
 
5843
 
5844
 
5845
#------------------------------------------------------------------------------
5846
sub chmodDir
5847
#
5848
# Description:
5849
#       This sub-routine is used to change the permissions an entire directory tree.
5850
#
5851
#       It recurses from a starting point chmod'ing each item and if it
5852
#       finds a dir it recurses into that dir chmod'ing it as well.
5853
#
5854
#------------------------------------------------------------------------------
5855
{
5856
    # correct number of parameters?
1592 dpurdie 5857
    Error("Incorrect number of params passed to chmodDir() function.") if ( ($#_+1) != 2 );
1530 dpurdie 5858
 
5859
    my ($startingPoint, $perms) = @_;
5860
 
1592 dpurdie 5861
    Warning("chmodDir has been deprecated by setPermissions, see deploylib.pm");
5862
 
1534 dpurdie 5863
    Verbose("chmodDir: Recursively setting permsision of [$startingPoint] to [$perms]");
1530 dpurdie 5864
 
5865
    local *DIR;
1592 dpurdie 5866
    opendir(DIR, $startingPoint) or Error("can't opendir $startingPoint: $!");
1530 dpurdie 5867
 
5868
    my ($item);
5869
    while (defined($item = readdir(DIR)))
5870
    {
1592 dpurdie 5871
        if ( "$item" !~ /^\.$/  && "$item" !~ /^\.\.$/ )
1530 dpurdie 5872
        {
5873
            if ( -d "$startingPoint/$item" )
5874
            {
5875
                chmodDir("$startingPoint/$item", $perms);
5876
            }
5877
            else
5878
            {
5879
                chmodFile("$startingPoint/$item", $perms);
5880
            }
5881
        }
5882
    }
5883
    close (DIR);
5884
 
5885
    # lets deal with starting dir
5886
    # 
5887
    chmodFile("$startingPoint", $perms);
5888
 
5889
    return 1;
5890
}
5891
 
5892
 
5893
 
5894
#------------------------------------------------------------------------------
5895
sub chmodFile
5896
#
5897
#    this function is used to chmod the perms od an item
5898
#    it is passed the absolute path to the item and the associated 
5899
#    perms.
5900
#
5901
#------------------------------------------------------------------------------
5902
{
5903
    my ($item, $perms) = @_;
5904
 
5905
    my ($noItems) = CORE::chmod oct($perms), $item;
5906
    if ( $noItems == 0 )
5907
    {
1592 dpurdie 5908
        Error("ERROR: Failed to chmod $item=$perms, retVal=[$noItems]");
1530 dpurdie 5909
    }
5910
    else
5911
    {
1592 dpurdie 5912
        Debug("Successfully chmod $item=$perms");
1530 dpurdie 5913
    }
5914
 
5915
    return 1;
5916
}
5917
 
5918
 
5919
 
5920
#------------------------------------------------------------------------------
5921
sub createSymbolicLink
5922
#
5923
# Description:
5924
#       This sub-routine is used to copy a local deployment file into
5925
#       the target destination dir. 
5926
#
5927
#
5928
#------------------------------------------------------------------------------
5929
{
5930
    # correct number of parameters?
5931
    if ( ($#_+1) != 3 )
5932
    {
1534 dpurdie 5933
        Error("Incorrect number of params passed to " .
1530 dpurdie 5934
                  "createSymbolicLink() function. Check deploy config.");
5935
    }
5936
 
5937
 
5938
    # lets just check to see if we can execute this function on
5939
    # this machine.
5940
    #
5941
    if ( "$MachType" ne "sparc" )
5942
    {
1534 dpurdie 5943
        Verbose("createSymbolicLink() not supported on this machine type.");
1530 dpurdie 5944
        return 1;
5945
    }
5946
 
5947
 
5948
    # lets setup the passed values.
5949
    my ($m_sDirTag, $m_srcStr, $m_linkStr) = @_;
5950
 
5951
    # lets get the absolute src dir value
5952
    my ($m_sDirAbsoluteValue) = getTargetDstDirValue($m_sDirTag, "A");
5953
 
5954
 
5955
    # lets see if the source item exists
5956
    #
5957
    if ( ! -f "$m_sDirAbsoluteValue/$m_srcStr" )
5958
    {
1534 dpurdie 5959
        Error("Failed to locate item [$m_sDirAbsoluteValue/$m_srcStr], link not created.");
1530 dpurdie 5960
    }
5961
 
5962
 
5963
 
5964
    my ($cmd) = "cd $m_sDirAbsoluteValue; ln -s $m_srcStr $m_linkStr";
5965
    system("$cmd");
5966
    if ( $? != 0 )
5967
    {
1534 dpurdie 5968
        Error("Failed to complete command: [$cmd]");
1530 dpurdie 5969
    }
5970
    else
5971
    {
1534 dpurdie 5972
        Verbose("Executed command: [$cmd]");
1530 dpurdie 5973
    }
5974
 
5975
    return 1;
5976
}
5977
 
5978
 
5979
#------------------------------------------------------------------------------
5980
sub createPrototypeFile2
5981
#
5982
# Description:
5983
#       This sub-routine is used to create the required package prototype file
5984
#       fom a known directory struture using the a=b format.
5985
#
5986
#------------------------------------------------------------------------------
5987
{
1550 dpurdie 5988
    my ($opt_keep_mask, @args);
5989
 
5990
    #
5991
    #   Process the arguments and extract parameters and options
5992
    #
5993
    foreach ( @_ )
5994
    {
5995
        if ( m/^--KeepMask/ ) {
5996
            $opt_keep_mask = 1;
5997
 
5998
        } elsif ( m/^--/ ) {
5999
            Error("createPrototypeFile2: Unknown option: $_")
6000
 
6001
        } else {
6002
            push @args, $_;
6003
 
6004
        }
6005
    }
6006
 
1530 dpurdie 6007
    # correct number of parameters?
1550 dpurdie 6008
    if ( ($#args + 1) != 3 )
1530 dpurdie 6009
    {
1534 dpurdie 6010
        Error("Incorrect number of params passed to " .
1530 dpurdie 6011
                  "createPrototypeFile2() function. Check deploy config.");
6012
    }
6013
 
6014
    # lets just check to see if we can execute this function on
6015
    # this machine.
6016
    #
6017
    if ( "$MachType" ne "sparc" )
6018
    {
1534 dpurdie 6019
        Verbose("createPrototypeFile2() not supported on this machine type.");
1530 dpurdie 6020
        return 1;
6021
    }
6022
 
6023
    # lets take the passed in args.
1550 dpurdie 6024
    my ($uid, $gid, $mask) = @args;
1530 dpurdie 6025
 
6026
 
6027
    # we need to determine whiich file we are dealing with
6028
    my ($protoTypeFile);
6029
    my ($targetBaseDir);
6030
    my ($pkgBaseDir);
6031
    $protoTypeFile = "$ProtoTypeFile"; 
6032
    $targetBaseDir = "$PkgBaseDir/$TargetBaseDir"; 
6033
    $pkgBaseDir    = "$PkgBaseDir"; 
6034
 
6035
 
6036
    # we need to locate the prototype file
6037
    if ( -f "$protoTypeFile" )
6038
    {
6039
        unlink("$protoTypeFile");
1534 dpurdie 6040
        Verbose("Removing prototype file [$protoTypeFile].");
1530 dpurdie 6041
    }
6042
 
6043
    # lets open the prototype file.
6044
    #    
6045
    local *FILE;
6046
    open ( FILE, "> $protoTypeFile") or
1534 dpurdie 6047
        Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 6048
    # lets populate the prototype file.
6049
    printf FILE ("!default $mask $uid $gid\n");
6050
    printf FILE ("i pkginfo\n");
6051
    close (FILE);
6052
 
6053
 
6054
    # lets put the pre-deinfed generic entries into the
6055
    # prototype file
6056
    #
6057
    if ( "x$PkgPatchNum" ne "x" )
6058
    {
6059
        addPatchInfo2ProtoTypeFile();
6060
    }
6061
 
6062
 
6063
    # lets set the associated uid, gid and mask
6064
    # for the bits in the prototype file.
6065
    #
6066
    $m_UID  = $uid;
6067
    $m_GID  = $gid;
6068
    $m_MASK = $mask;
1550 dpurdie 6069
    $m_KEEP_MASK = $opt_keep_mask;
1530 dpurdie 6070
 
6071
 
6072
    # now we need to add entries for each directory we will 
6073
    # be installing 
6074
    File::Find::find(\&prototype2Find, "$targetBaseDir");
6075
 
6076
 
6077
    # lets populate the prototype file with a newline.
6078
    open ( FILE, ">> $protoTypeFile") or
1534 dpurdie 6079
        Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 6080
    printf FILE ("\n");
6081
    close (FILE);
6082
 
6083
 
1534 dpurdie 6084
    Information("Created prototype file [$protoTypeFile].");
1530 dpurdie 6085
 
6086
    return 1;
6087
}
6088
 
1534 dpurdie 6089
#-------------------------------------------------------------------------------
6090
# Function        : createZip
6091
#
6092
# Description     : Create a ZIp file of a given directory
6093
#
6094
# Inputs          : --Recurse               - Recurse subdirs
6095
#                   --NoRecurse             - Done recurse subdirs
6096
#                   --Dirnames              - Record Dir names
6097
#                   --NoDirnames            - Don't record dirnames
6098
#                   --NoQuiet               - Display the operatios
6099
#                   --Dir=xxxx              - Symbolic Directory to zip
6100
#                   --ZipDir=ttt            - Symbolic target directory
6101
#                   --ZipFile=yyyy          - Zipfile to create
6102
#
6103
# Returns         : Will not return on error
6104
#                   Requires 'zip' to be provided by a 'package' such as InfoZip
6105
#
6106
sub createZip
6107
{
6108
    my $recurse = 1;
6109
    my $dirnames = 0;
6110
    my $quiet = 1;
6111
    my $sdir;
6112
    my $tdir;
6113
    my $tfile;
1530 dpurdie 6114
 
1534 dpurdie 6115
    #
6116
    #   Only on Windows at the moment.
6117
    #   Perhaps Unix should create a .gz file
6118
    #
6119
    Warning ("createZip not supported on $MachType. Operation skipped")
6120
        unless ( "$MachType" eq "win32" );
6121
 
6122
    #
6123
    #   Process user arguments
6124
    #
6125
    foreach ( @_ )
6126
    {
6127
        if ( m/^--Recurse/ ) {
6128
            $recurse = 1;
6129
 
6130
        } elsif ( m/^--NoRecurse/) {
6131
            $recurse = 0;
6132
 
6133
        } elsif ( m/^--Dirnames/ ) {
6134
            $dirnames = 1;
6135
 
6136
        } elsif ( m/^--NoDirnames/ ) {
6137
            $dirnames = 0;
6138
 
6139
        } elsif ( m/^--NoQuiets/ ) {
6140
            $quiet = 0;
6141
 
6142
        } elsif ( m/^--Dir=(.*)/ ) {
6143
            $sdir = $1;
6144
 
6145
        } elsif ( m/^--ZipDir=(.*)/ ) {
6146
            $tdir = $1;
6147
 
6148
        } elsif ( m/^--ZipFile=(.*)/ ) {
6149
            $tfile = $1;
6150
 
6151
        } else {
6152
            Warning("createZip: Unknown argument ignored: $_");
6153
 
6154
        }
6155
    }
6156
 
6157
    #
6158
    #   Convert the source directory TAG into a real directory
6159
    #
6160
    Error ("createZip: Source directory not specified") unless ( $sdir );
6161
    my $sdir_a = getTargetDstDirValue($sdir, "A");
6162
 
6163
    #
6164
    #   Convert the destination directory tag into a real directory
6165
    #
6166
    Error ("createZip: Target directory not specified") unless ( $tdir );
6167
    Error ("createZip: Target filename not specified") unless ( $tfile );
6168
    my $tdir_a = getTargetDstDirValue($tdir, "A");
6169
 
6170
    #
6171
    #   Locate the 'zip' uitilty
6172
    #
6173
    my $prog = LocateProgInPath( 'zip' );
6174
    Error ("createZip: Cannot locate ZIP executable",
6175
            "May need to use the 'infozip' package") unless ( $prog );
6176
 
6177
    #
6178
    #   Generate command file
6179
    #
6180
    my $args = '-9';
6181
    $args .= 'q' unless ( (! $quiet) || IsVerbose(1));
6182
    $args .= 'r' if ( $recurse );
6183
    $args .= 'j' unless ( $dirnames );
6184
 
6185
    #
6186
    #   Zip up the files
6187
    #
6188
    Information ("Create Zip File: [$tdir] $tfile");
6189
    chdir ( $sdir_a ) || Error ("Cannot cd to $sdir_a");
6190
    my $rv = System ($prog, $args, "$tdir_a/$tfile", "." );
6191
    chdir($CurrentDir) || Error ("Cannot cd to $CurrentDir");
6192
 
6193
    Error ("createZip: Zip file not created") if ( $rv );
6194
}
6195
 
6196
 
1530 dpurdie 6197
#------------------------------------------------------------------------------
6198
sub prototype2Find
6199
#
6200
#    Description:
6201
#        This subroutine is used to locate all associated package dirs.
6202
#        It also adds an entry into the prototype file for each dir.
6203
#
6204
#------------------------------------------------------------------------------
6205
{
1550 dpurdie 6206
    my $file = $File::Find::name;
6207
    my $fullfile = $file;
6208
    my $base = File::Basename::basename($file);
1530 dpurdie 6209
 
6210
    # we get the absolute path from the find, but we only require
6211
    # a relative path from the starting dir.
6212
    # so our start dir.
6213
 
6214
    # we need to determine which file we are dealing with
6215
    my ($pfile);
6216
    my ($tDir);
6217
    $pfile = "$ProtoTypeFile";
6218
    $tDir = "$PkgBaseDir/$TargetBaseDir";
6219
 
6220
    if ( "$file" ne "$tDir" )
6221
    {
6222
        my ($m_sfile) = $file;
6223
        if ( "x$TargetBaseDir" eq "x." )
6224
        {
6225
            $tDir = $tDir . "/";
6226
            $file =~ s/$tDir//;
6227
        }
6228
        else
6229
        {
6230
            $file =~ s/$tDir/$TargetBaseDir/;
6231
        }
6232
 
6233
        # if TargetBaseDir is "." then find will find the pkginfo & prototype 
6234
        # files so we need to exclude them
6235
        if ( "$file" ne "$ProtoTypeFileName" &&
6236
             "$file" ne "$PkgInfoFileName")
6237
        {
1550 dpurdie 6238
 
6239
            my $fmask = $m_MASK;
6240
            if ( $m_KEEP_MASK )
6241
            {
6242
                $fmask = sprintf "%lo", ( (stat($fullfile))[2]) & 07777;
6243
            }
6244
 
1530 dpurdie 6245
            open ( FILE, ">> $pfile") or
1534 dpurdie 6246
                Error("Failed to open file [$pfile].");
1530 dpurdie 6247
 
6248
            if ( -f "$m_sfile" )
6249
            {
1550 dpurdie 6250
                printf FILE ("f none $file=$file $fmask $m_UID $m_GID\n");
1530 dpurdie 6251
            }
6252
 
6253
            if ( -d "$m_sfile" )
6254
            {
1550 dpurdie 6255
                printf FILE ("d none $file $fmask $m_UID $m_GID\n");
1530 dpurdie 6256
            }
6257
 
6258
            close (FILE);
6259
        }
6260
    }
6261
}
6262
 
1552 dpurdie 6263
#-------------------------------------------------------------------------------
6264
# Function        : convertFile
1530 dpurdie 6265
#
1552 dpurdie 6266
# Description     : This sub-routine is used to remove all carrage return\line
6267
#                   feeds from a line and replace them with the platform
6268
#                   specific equivalent chars.
1530 dpurdie 6269
#
1552 dpurdie 6270
#                   We let PERL determine what characters are written to the
6271
#                   file base on the  platform you are running on.
1530 dpurdie 6272
#
1552 dpurdie 6273
#                   i.e. LF    for unix
6274
#                   CR\LF for win32
1530 dpurdie 6275
#
1552 dpurdie 6276
# Inputs          : m_targetDirTag          - Symbolic name of target directory
6277
#                   m_nfiles                - List of files in that directory
6278
#                   or
6279
#                   SearchOptions           - Search options to find files
6280
#                                           --Recurse
6281
#                                           --NoRecurse
6282
#                                           --FilterIn=xxx
6283
#                                           --FilterInRE=xxx
6284
#                                           --FilterOut=xxx
6285
#                                           --FilterOutRE=xxx
1530 dpurdie 6286
#
1552 dpurdie 6287
#
6288
# Returns         : 1
6289
#
6290
sub convertFile
1530 dpurdie 6291
{
1552 dpurdie 6292
    my @uargs;
6293
    my $search =  LocateFiles->new( recurse => 0 );
6294
 
6295
    #
6296
    #   Process user arguments extracting options
6297
    #
6298
    foreach  ( @_ )
1530 dpurdie 6299
    {
1552 dpurdie 6300
        if ( m~^--Recurse~ ) {
6301
            $search->recurse(1);
1530 dpurdie 6302
 
1552 dpurdie 6303
        } elsif ( m~^--NoRecurse~) {
6304
            $search->recurse(0);
1530 dpurdie 6305
 
1552 dpurdie 6306
        } elsif ( /^--FilterOut=(.*)/ ) {
6307
            $search->filter_out($1);
1530 dpurdie 6308
 
1552 dpurdie 6309
        } elsif ( /^--FilterOutRE=(.*)/ ) {
6310
            $search->filter_out_re($1);
1530 dpurdie 6311
 
1552 dpurdie 6312
        } elsif ( /^--FilterIn=(.*)/ ) {
6313
            $search->filter_in($1);
1530 dpurdie 6314
 
1552 dpurdie 6315
        } elsif ( /^--FilterInRE=(.*)/ ) {
6316
            $search->filter_in_re($1);
1530 dpurdie 6317
 
1552 dpurdie 6318
        } elsif ( m~^--~) {
6319
            Error ("convertFile: Unknown option: $_");
1530 dpurdie 6320
 
1552 dpurdie 6321
        } else {
6322
            push @uargs, $_;
1530 dpurdie 6323
        }
6324
    }
6325
 
1552 dpurdie 6326
    #
6327
    #   Process non-option arguments
6328
    #       - Base dir
6329
    #       - List of files
6330
    #
6331
    my ($m_targetDirTag, @m_nfiles) = @uargs;
6332
    Error ("convertFiles: Target Dir must be specified" ) unless ( $m_targetDirTag );
1530 dpurdie 6333
 
1552 dpurdie 6334
    #
6335
    # Convert symbolic dir tag to physical path
6336
    #
6337
    my ($m_targetDirValue) = getTargetDstDirValue($m_targetDirTag, "A");
1530 dpurdie 6338
 
6339
    #
1552 dpurdie 6340
    #   Need to determine if we are searching or simply using a file list
6341
    #   There are two forms of the functions. If any of the search options have
6342
    #   been used then we assume that we are searchine
6343
    #
6344
    if ( $search->has_filter() )
1530 dpurdie 6345
    {
1552 dpurdie 6346
        Error ("convertFiles: Cannot mix search options with named files") if ( @m_nfiles );
6347
        @m_nfiles = $search->search($m_targetDirValue);
1530 dpurdie 6348
    }
1552 dpurdie 6349
    Error ("convertFiles: No files specified") unless ( @m_nfiles );
6350
 
6351
    #
6352
    #   Process all named files
6353
    #
6354
    foreach my $m_nfile ( @m_nfiles )
1530 dpurdie 6355
    {
1552 dpurdie 6356
 
6357
        # this is our file that we want to clean.
6358
        my ($m_ifileLoc) = "$m_targetDirValue/$m_nfile";
6359
        my ($m_tfileLoc) = "$m_targetDirValue/$m_nfile\.tmp";
6360
 
6361
 
6362
        # we will check to see if the file exists.
6363
        #
6364
        local *IFILE;
6365
        local *TFILE;
6366
        if ( -f "$m_ifileLoc" )
6367
        {
6368
            open (IFILE, "< $m_ifileLoc" ) or
6369
                Error("Failed to open file [$m_ifileLoc] : $!");
6370
 
6371
            open (TFILE, "> $m_tfileLoc" ) or
6372
                Error("Failed to open file [$m_tfileLoc] : $!");
6373
 
6374
            while ( <IFILE> ) 
6375
            {
6376
                chomp;
6377
                print TFILE "$_\n";
6378
            }
6379
        }
6380
        else
6381
        {
6382
            Error("Deploy file [$m_ifileLoc] does not exist.");
6383
        }
6384
 
6385
        close IFILE;
6386
        close TFILE;
6387
 
6388
 
6389
        # lets replace our original file with the new one
6390
        #
6391
        if(File::Copy::move("$m_tfileLoc", "$m_ifileLoc"))
6392
        {
6393
            Information("Renamed [$m_tfileLoc] to [$m_ifileLoc] ...");
6394
        }
6395
        else
6396
        {
6397
            Error("Failed to rename file [$m_tfileLoc] to [$m_ifileLoc]: $!");
6398
        }
1530 dpurdie 6399
    }
6400
 
6401
    return 1;
6402
}
6403
 
1534 dpurdie 6404
#-------------------------------------------------------------------------------
6405
# Function        : installDeployFile
1530 dpurdie 6406
#
1534 dpurdie 6407
# Description     : This sub-routine is used to copy a local deployment file into
6408
#                   the target destination dir.
1530 dpurdie 6409
#
1534 dpurdie 6410
# Inputs          : m_srcDirTag             - Tag for Source Dir name
6411
#                                             Tag defined in %LocalSrcDirStructure
1554 dpurdie 6412
#                                             Or --Package=name,subdir
6413
#                                             Or --Interface=subdir
6414
#
1534 dpurdie 6415
#                   m_sfile                 - Name of the source file
6416
#                   m_targetDirTag          - Tag for the target directory
6417
#                                             Tag defined in %TargetDstDirStructure
6418
#                   m_nfile                 - Target filename
6419
#                                             Must be specified. If set to "", then
6420
#                                             the source filename will be used.
1530 dpurdie 6421
#
1534 dpurdie 6422
# Returns         : True
6423
#
1530 dpurdie 6424
#------------------------------------------------------------------------------
1534 dpurdie 6425
 
6426
sub installDeployFile
1530 dpurdie 6427
{
6428
    # correct number of parameters?
6429
    if ( ($#_+1) != 4 )
6430
    {
1534 dpurdie 6431
        Error("Incorrect number of params passed to " .
1530 dpurdie 6432
                  "installDeployFile() function. Check deploy config.");
6433
    }
6434
 
6435
    my ($m_srcDirTag, $m_sfile, $m_targetDirTag, $m_nfile) = @_;
6436
 
6437
    # lets get the src dir value
6438
    my ($m_targetDirValue) = getTargetDstDirValue($m_targetDirTag, "A");
6439
 
6440
    # lets get the target dir value
6441
    my ($m_srcDirValue) = getLocalDirValue($m_srcDirTag, "A");
6442
 
6443
 
6444
    # we know where we are getting this from and where we 
6445
    # going to put them.
6446
    my ($m_sfileLoc) = "$m_srcDirValue/$m_sfile";
6447
 
6448
    my ($m_nfileLoc) = "";
6449
    # lets determine what we are going to call the new file.
6450
    #
6451
    if ( "x$m_nfile" eq "x" )
6452
    {
6453
        $m_nfileLoc = "$m_targetDirValue/$m_sfile";
6454
    }
6455
    else
6456
    {
6457
        $m_nfileLoc = "$m_targetDirValue/$m_nfile";
6458
    }
6459
 
6460
 
6461
    # we will check to see if the file exists.
6462
    #
6463
    if ( -f "$m_sfileLoc" )
6464
    {
6465
        # now we need to copy the file. 
6466
        if(File::Copy::copy("$m_sfileLoc", "$m_nfileLoc"))
6467
        {
1534 dpurdie 6468
            Verbose("Copied [$m_sfile] to [$m_nfileLoc] ...");
1530 dpurdie 6469
 
6470
            # now we need to ensure the item is writable as it
6471
            # has come from our VOB that is by definition read-only
6472
            #
6473
            CORE::chmod oct("0755"), $m_nfileLoc;
6474
 
6475
        }
6476
        else
6477
        {
1534 dpurdie 6478
            Error("Failed to copy lib [$m_sfileLoc]: $!"); 
1530 dpurdie 6479
        }
6480
    }
6481
    else
6482
    {
1534 dpurdie 6483
        Error("Deploy file [$m_sfileLoc] does not exist.");
1530 dpurdie 6484
    }
6485
 
6486
    return 1;
6487
}
6488
 
6489
 
6490
#------------------------------------------------------------------------------
6491
sub getGenericNameForLib
6492
#
6493
# Description:
6494
#       This sub-routine is used to determine the generic name for
6495
#       a library. I.E remove the buildtype and version number.
6496
#
6497
#       It also checks if the name provided should be excluded from
6498
#       the build.
6499
#
6500
#------------------------------------------------------------------------------
6501
{
6502
   # correct number of parameters?
6503
    if ( ($#_+1) != 1 )
6504
    {
1534 dpurdie 6505
        Error("Incorrect number of params passed to " .
1530 dpurdie 6506
                  "getGenericNameForLib() function. Check deploy config.");
6507
    }
6508
 
6509
    # lets just check to see if we can execute this function on
6510
    # this machine.
6511
    #
6512
    if ( "$MachType" ne "sparc" )
6513
    {
1534 dpurdie 6514
        Verbose("getGenericNameForLib() not supported on this machine type.");
1530 dpurdie 6515
        return "";
6516
    }
6517
 
6518
 
6519
    my($itemName) = @_;
6520
 
6521
    # first we need to check to see if it belongs in this build
6522
    #
6523
    my ($gName) = "";
6524
    if(excludeItemFromBuild($itemName))
6525
    {
1534 dpurdie 6526
        Verbose("Excluding item [$itemName] from build as not compatible with build type " .
1530 dpurdie 6527
                "[$BuildType].");
6528
        return "";  # file should be excluded.
6529
    }
6530
    else
6531
    {
6532
        $gName = removeBuildTypeFromItemName($itemName);
6533
        $gName = removeVersionNumberFromItemName($gName);
6534
 
6535
        return "$gName";
6536
    }
6537
 
6538
    return 1;
6539
}
6540
 
6541
 
6542
#------------------------------------------------------------------------------
6543
sub getGenericNameNoVersionForLib
6544
#
6545
# Description:
6546
#       This sub-routine is used to determine the generic name for
6547
#       a library. I.E removes the version number.
6548
#
6549
#       It also checks if the name provided should be excluded from
6550
#       the build.
6551
#
6552
#------------------------------------------------------------------------------
6553
{
6554
   # correct number of parameters?
6555
    if ( ($#_+1) != 1 )
6556
    {
1534 dpurdie 6557
        Error("Incorrect number of params passed to " .
1530 dpurdie 6558
                  "getGenericNameNoVersionForLib() function. Check deploy config.");
6559
    }
6560
 
6561
    # lets just check to see if we can execute this function on
6562
    # this machine.
6563
    #
6564
    if ( "$MachType" ne "sparc" )
6565
    {
1534 dpurdie 6566
        Verbose("getGenericNameNoVersionForLib() not supported on this machine type.");
1530 dpurdie 6567
        return "";
6568
    }
6569
 
6570
 
6571
    my($itemName) = @_;
6572
 
6573
    # first we need to check to see if it belongs in this build
6574
    #
6575
    my ($gName) = "";
6576
    if(excludeItemFromBuild($itemName))
6577
    {
1534 dpurdie 6578
        Verbose("Excluding item [$itemName] from build as not compatible with build type " .
1530 dpurdie 6579
                "[$BuildType].");
6580
        return "";  # file should be excluded.
6581
    }
6582
    else
6583
    {
6584
        $gName = removeVersionNumberFromItemName($itemName);
6585
        return "$gName";
6586
    }
6587
 
6588
    return 1;
6589
}
6590
 
6591
 
6592
#------------------------------------------------------------------------------
6593
sub getGenericNameNoVersionForXML
6594
#
6595
# Description:
6596
#       This sub-routine is used to determine the generic name for
6597
#       an XML file. I.E removes the version number.
6598
#
6599
#------------------------------------------------------------------------------
6600
{
6601
   # correct number of parameters?
6602
    if ( ($#_+1) != 1 )
6603
    {
1534 dpurdie 6604
        Error("Incorrect number of params passed to " .
1530 dpurdie 6605
                  "getGenericNameNoVersionForXML() function. Check deploy config.");
6606
    }
6607
 
6608
    my($itemName) = @_;
6609
    my ($gName) = "";
6610
    $gName = removeVersionNumberFromXMLItemName($itemName);
6611
    return "$gName";
6612
 
6613
    return 1;
6614
}
6615
 
6616
 
6617
#------------------------------------------------------------------------------
6618
sub removeVersionNumberFromXMLItemName
6619
#
6620
#    Description:
6621
#        This sub-routine is used to remove the version number from the item name.
6622
#        i.e.  myFile_1_2_3.xml ==> myFile.xml
6623
#
6624
#    INPUT:
6625
#        item name
6626
#
6627
#    RETURN:
6628
#        new item name.
6629
#
6630
#------------------------------------------------------------------------------
6631
{
6632
    my ($file)  = @_;
6633
    my ($nfile) = $file;
6634
 
6635
    if ( $nfile =~ m/_[0-9]+_[0-9]+_[0-9]+\.xml$/ )
6636
    {
6637
        # if we match lets deal with it.
6638
        $nfile =~ s/_[0-9]+_[0-9]+_[0-9]+\.xml$/\.xml/;
6639
    }
6640
    else
6641
    {
1534 dpurdie 6642
        Warning("Filename [$nfile] does not contain required format [myfile_N_N_N.xml].");
1530 dpurdie 6643
    }
6644
    return "$nfile";
6645
}
6646
 
6647
 
6648
#------------------------------------------------------------------------------
6649
sub createDpkgArchive
6650
#
6651
# Description:
6652
#       This sub-routine is used to create a dpkg_archive directory
6653
#       structure.
6654
#
6655
#------------------------------------------------------------------------------
6656
{
6657
    # correct number of parameters?
6658
    if ( ($#_+1) != 1 )
6659
    {
1534 dpurdie 6660
        Error("Incorrect number of params passed to " .
1530 dpurdie 6661
                  "createDpkgArchive() function. Check deploy config.");
6662
    }
6663
 
6664
    my ($desc) = @_;
6665
 
6666
    # lets just check to see if we can execute this function on
6667
    # for  this build.
6668
    #
6669
    if ( "x$PkgPatchNum" ne "x" )
6670
    {
1534 dpurdie 6671
        Verbose("createDpkgArchive() can only be called during a RELEASE build.");
1530 dpurdie 6672
        return 1;
6673
    }
6674
 
6675
 
6676
    # 1. we create a dpkg_archive top level dir within the output directory
6677
    #
6678
    my ($m_tmpDir) = "$PkgBaseDir/dpkg_archive";
1534 dpurdie 6679
    make_directory( $m_tmpDir, 0777 );
6680
 
1530 dpurdie 6681
    # 2. we create a sub-directory with the package name
6682
    #
6683
    $m_tmpDir = "$PkgBaseDir/dpkg_archive/$TargetBaseDir";
1534 dpurdie 6684
    make_directory( $m_tmpDir, 0777 );
1530 dpurdie 6685
 
6686
    # 3. we create a sub-directory with the package version number
6687
    #
6688
    my ($m_tmpDir2) = "$PkgBaseDir/dpkg_archive/$TargetBaseDir/" .
6689
                      "$PkgVersion" .  "." . "$ProjectAcronym";
1534 dpurdie 6690
    make_directory( $m_tmpDir2, 0777 );
1530 dpurdie 6691
 
6692
 
6693
    # 4. we replacate the contents of the original outputdir/package name
6694
    #    to do this we shall execute a find starting within the original package target dir
6695
    #    any copy all items we find to the new location under the dpkg_archive/package/version dir.
6696
    #
6697
    File::Find::find( \&DpkgFind, "$PkgBaseDir/$TargetBaseDir");
6698
 
6699
 
6700
    # 5. we create a descpkg file, with the Package Name, Version and Desc
6701
    #
6702
    my ($m_DescPkgFile) = "$PkgBaseDir/dpkg_archive/$TargetBaseDir/$PkgVersion\.$ProjectAcronym/descpkg";
6703
 
6704
    # now we need to update the prototype file
6705
    #
6706
    local *FILE;
6707
    open ( FILE, ">> $m_DescPkgFile") or
1534 dpurdie 6708
        Error("Failed to open file [$m_DescPkgFile].");
1530 dpurdie 6709
    printf FILE ("$PkgName, $PkgVersion.$ProjectAcronym - $desc\n");
6710
    close (FILE);
6711
 
6712
 
6713
    # done.
1534 dpurdie 6714
    Information("createDpkgArchive() completed.");
1530 dpurdie 6715
 
6716
    return 1;
6717
}
6718
 
6719
 
6720
#------------------------------------------------------------------------------
6721
sub DpkgFind
6722
#
6723
#    Description:
6724
#        This subroutine is used to locate all associated items to
6725
#        create a new dpkg_archive directory structure. 
6726
#
6727
#------------------------------------------------------------------------------
6728
{
6729
    my($item)= "$File::Find::name";
6730
    my($base)= File::Basename::basename($item);
6731
 
6732
 
6733
    # we get the absolute path from the find, but we only require
6734
    # a relative path from the starting dir.
6735
 
6736
 
6737
    # we need to determine which file we are dealing with
6738
    if ( ! -d "$item")
6739
    {
6740
        my ($m_sfile) = $item;
6741
        $item =~ s/$PkgBaseDir\/$TargetBaseDir/$PkgBaseDir\/dpkg_archive\/$TargetBaseDir\/$PkgVersion\.$ProjectAcronym/;
6742
 
6743
        if(File::Copy::copy("$m_sfile", "$item"))
6744
        {
1534 dpurdie 6745
            Verbose("Copied [$base] to [$item] ...");
1530 dpurdie 6746
        }
6747
        else
6748
        {
1534 dpurdie 6749
            Error("Failed to copy pkg file [$m_sfile] to [$item]: $!");
1530 dpurdie 6750
        }
6751
    }
6752
    else
6753
    {
6754
        # we have found a dir
6755
        my ($m_sDir) = $item;
1534 dpurdie 6756
        $item =~ s~$PkgBaseDir/$TargetBaseDir~$PkgBaseDir/dpkg_archive/$TargetBaseDir/$PkgVersion\.$ProjectAcronym~;
6757
        make_directory( $item, 0777 );
1530 dpurdie 6758
    }
6759
}
6760
 
6761
 
6762
 
6763
 
6764
#------------------------------------------------------------------------------
6765
sub getRmDetails
6766
#
6767
#    Description:
6768
#        This is called to update the RM class objects with details from RM database
6769
#------------------------------------------------------------------------------
6770
{
1534 dpurdie 6771
    #
6772
    #   If this script is invoked by the AutoBuildTool, then we may not be able
6773
    #   to create a Release Note as the RM entry may not be available. More over
6774
    #   the ABT will create a release note as the package is made official
6775
    #
6776
    if ( $autobuild )
6777
    {
6778
        Debug('getRmDetails: AutoBuild Environment supresses function');
6779
        return;
6780
    }
6781
 
6782
 
1530 dpurdie 6783
    if ( ! defined($RmPkgDetails) )
6784
    {
6785
        # Set defaults for elements in RM if not found
6786
        DeployUtils::RmPkgInfo->DefaultDescription($PkgDesc);
6787
        DeployUtils::RmPkgInfo->DefaultLabel($PkgLabel);
6788
 
6789
        $RmPkgDetails = DeployUtils::RmPkgInfo->new( 
6790
                                    { PKG_NAME => $PkgName, 
6791
                                      PKG_VERSION => ( "$PkgPatchNum" ne "" ) ? $PkgPatchID : $PkgVersionUser } );
6792
 
6793
        # lets check to see if we got something
6794
        if ( $RmPkgDetails->foundPkg() )
6795
        {
6796
            $RmPvPkgDetails = DeployUtils::RmPkgInfo->new( { PKG_NAME => $PkgName, 
6797
                                                             PKG_VERSION => $PkgPreviousVersionStr } );
6798
            if ( $RmPvPkgDetails->foundDetails() )
6799
            {
1534 dpurdie 6800
                sub MultiLineVerb
6801
                {
6802
                    my ($prefix, $text ) = @_;
6803
                    my $zap = 0;
6804
 
6805
                    foreach my $line ( split /[\r\n]+/, $text  )
6806
                    {
6807
                        Verbose($prefix . "[" . $line . "]");
6808
                        unless ( $zap )
6809
                        {
6810
                            $prefix = ' ' x length($prefix);
6811
                            $zap = 1;
6812
                        }
6813
                    }
6814
                }
6815
 
6816
                Information("Retrieved Package Details from Release Manager");
6817
                if ( IsVerbose(1) )
6818
                {
6819
                    MultiLineVerb("RM pkg_name       = ",  $RmPkgDetails->pkg_name()       );
6820
                    MultiLineVerb("RM pkg_id         = ",  $RmPkgDetails->pkg_id()         );
6821
                    MultiLineVerb("RM pv_id          = ",  $RmPkgDetails->pv_id()          );
6822
                    MultiLineVerb("RM pv_description = ",  $RmPkgDetails->pv_description() );
6823
                    MultiLineVerb("RM pv_overview    = ",  $RmPkgDetails->pv_overview()    );
6824
                    MultiLineVerb("RM pv_reason      = ",  $RmPkgDetails->pv_reason()      );
6825
                    MultiLineVerb("RM pv_label       = ",  $RmPkgDetails->pv_label()       );
6826
                    MultiLineVerb("RM previousPv_id  = ",  $RmPvPkgDetails->pv_id()        );
6827
                    MultiLineVerb("RM pv_dlocked     = ",  $RmPvPkgDetails->pv_dlocked()   );
6828
                }
1530 dpurdie 6829
            }
6830
            else
6831
            {
6832
                # our package does not exist in release manager
1534 dpurdie 6833
                Warning("Could not retrieve package $PkgName $PkgVersionUser previous version " .
1530 dpurdie 6834
                        "details from Release Manager.")
6835
            }
6836
        }
6837
        else
6838
        {
6839
            # our package does not exist in release manager 
1534 dpurdie 6840
            Warning("Package $PkgName $PkgVersionUser does not exist in the Release Manager",
6841
                    "Please check configuration.")
1530 dpurdie 6842
        }
6843
    }
6844
}  
6845
 
6846
 
6847
 
6848
# This is now depricated
6849
sub generateReleaseNote
6850
{
1534 dpurdie 6851
    Error("generateReleaseNote is depricated please use generateHtmlReleaseNote");
1530 dpurdie 6852
    return 1;
6853
}
6854
 
6855
 
6856
 
6857
#------------------------------------------------------------------------------
6858
sub generateHtmlReleaseNote
6859
#
6860
#    Description:
6861
#
6862
#------------------------------------------------------------------------------
6863
{
1532 dpurdie 6864
 
1530 dpurdie 6865
    #
1532 dpurdie 6866
    #   If this script is invoked by the AutoBuildTool, then we may not be able
6867
    #   to create a Release Note as the RM entry may not be available. More over
6868
    #   the ABT will create a release note as the package is made official
6869
    #
6870
    if ( $autobuild )
6871
    {
1534 dpurdie 6872
        Warning('AutoBuild Environment. Release notes generated later');
1532 dpurdie 6873
        return;
6874
    }
6875
 
6876
    #
1530 dpurdie 6877
    #   Ensure the Release directory is present
6878
    #
1534 dpurdie 6879
    make_directory( $ReleaseDir, 0777 );
1530 dpurdie 6880
 
6881
    if ( ! getRmReleaseNote() )
6882
    {
1534 dpurdie 6883
        Error("No Release Manager details, release note not generated.");
1530 dpurdie 6884
    }
6885
}
6886
 
6887
 
6888
 
6889
#------------------------------------------------------------------------------
6890
sub getRmReleaseNote
6891
#
6892
#    Description:
6893
#
6894
#------------------------------------------------------------------------------
6895
{
6896
    # lets get some details for our package
6897
    getRmDetails();
6898
 
6899
 
6900
    # now we need to ensure that our local build file dependencies are
6901
    # the same as those we have entered in the Release Manager database.
6902
    checkDependencies();
6903
 
6904
 
6905
    # let's update the release contents now
6906
    #
6907
    generateProductContents();
6908
 
1538 dpurdie 6909
    #
6910
    #   Is the interface available
6911
    #
6912
    unless ( $UserAgentAvailable )
6913
    {
6914
        Warning("Unable to retrieve Release Manager Release Notes: LWP module missing");
6915
        return 0;
6916
    }
1530 dpurdie 6917
 
1554 dpurdie 6918
    our $GBE_RM_URL;
6919
    EnvImport('GBE_RM_URL');
6920
 
1534 dpurdie 6921
    Information("Retrieving Release Notes From Release Manager...Please wait...");
1530 dpurdie 6922
 
6923
    my $user_agent = LWP::UserAgent->new( timeout => 30 );
1554 dpurdie 6924
    my $response = $user_agent->get( $GBE_RM_URL . '/_adhoc_release_notes.asp?pv_id='. $RmPkgDetails->pv_id(),
1530 dpurdie 6925
                                    ':content_file' => "$PkgReleaseNote\.html");
6926
    if ( $response->is_success )
6927
    {
1534 dpurdie 6928
        Verbose("Retrieved Release Manager HTML Release note [$PkgReleaseNote\.html]");
1530 dpurdie 6929
        return 1;
6930
    }
6931
    else
6932
    {
1534 dpurdie 6933
        Warning("Unable to retrieve Release Manager Release Notes");
1530 dpurdie 6934
        return 0;
6935
    }
6936
}
6937
 
6938
#------------------------------------------------------------------------------
6939
sub checkDependencies
6940
#
6941
#------------------------------------------------------------------------------
6942
{
6943
    my ($i);
6944
    my ($retValue) = 0;
6945
 
6946
    # first we want to loop through all our local build archives
6947
    # 
6948
    my ($versionStr) = "";
6949
    foreach $i ( $BuildFileInfo->getDpkgArchiveList() )
6950
    {
6951
        my $moduleInfo = $BuildFileInfo->getDpkgArchiveInfo($i);
6952
 
6953
        $versionStr = "$moduleInfo->{version}"; 
6954
        $versionStr .= "\.$moduleInfo->{proj}" if ( $moduleInfo->{proj} ne "" );
6955
        my $depObj = $RmPkgDetails->getDependencyObject($i);
6956
 
6957
        if ( defined ( $depObj ) )
6958
        {
6959
            if ( $depObj->pkg_version() ne "$versionStr" )
6960
            {
1534 dpurdie 6961
                Warning("Dependency difference, [$i] Local version $versionStr, RM version " . $depObj->pkg_version());
1530 dpurdie 6962
                $retValue = 1;
6963
            }
6964
        }  
6965
        else
6966
        {
1534 dpurdie 6967
            Warning("Dependency difference, [$i] Cannot locate archive in Release Manager database.");
1530 dpurdie 6968
            $retValue = 1;
6969
        }
6970
    }
6971
 
6972
    # lets check to see if we detected a difference 
6973
    if ( $retValue != 0 )
6974
    { 
1534 dpurdie 6975
        Error("Difference detected between the local build.pl and Release Manager config.",
6976
              "Please check Release Manager configuration.");
1530 dpurdie 6977
    }
6978
 
6979
 
6980
 
6981
    # now we check release manager details against our local ones
6982
    #
6983
    foreach $i ( $RmPkgDetails->getDependencyNames() )
6984
    {
6985
        if ( "$i" eq "ishieldlibimg" || "$i" eq "ishieldlibicon" )
6986
        {
6987
            # these two packages are a special case,
6988
            # we do not include them in the dependecy check
6989
            #
6990
            next;
6991
        }
6992
 
6993
        my $moduleInfo = $BuildFileInfo->getDpkgArchiveInfo($i);
6994
 
6995
        if ( defined ( $moduleInfo ) )
6996
        {
6997
            $versionStr = "$moduleInfo->{version}"; 
6998
            $versionStr .= "\.$moduleInfo->{proj}" if ( $moduleInfo->{proj} ne "" );
6999
            my $depObj = $RmPkgDetails->getDependencyObject($i);
7000
 
7001
            if ( $depObj->pkg_version() ne "$versionStr" )
7002
            {
1534 dpurdie 7003
                Warning("Dependency difference, [$i] local version $versionStr, RM version " . $depObj->pkg_version());
1530 dpurdie 7004
                $retValue = 1;
7005
            }
7006
        }  
7007
        else
7008
        {
1534 dpurdie 7009
            Warning("Dependency difference, cannot locate archive [$i] in local build.pl.");
1530 dpurdie 7010
            $retValue = 1;
7011
        }
7012
    }
7013
 
7014
    # lets check to see if we detected a difference 
7015
    if ( $retValue != 0 )
7016
    { 
1534 dpurdie 7017
        Error("Difference detected between Release Manager config and the local build.pl. ",
7018
               "Please check the local configuration.");
1530 dpurdie 7019
    }
7020
 
7021
    return 1;
7022
}
7023
 
1544 dpurdie 7024
#-------------------------------------------------------------------------------
7025
# Function        : generateXmlDependancy
7026
#
7027
# Description     : Generate an XML file that describes the despendencies of the
7028
#                   released package.
7029
#
7030
#                   The generated file needs to be packaged for deployment. This
7031
#                   function will only create the file. It needs to be added to the
7032
#                   files that are deployed into the field. The file is primarily
7033
#                   to be used by Windows based applications, but its use may be
7034
#                   extended to other platforms.
7035
#
7036
#                   The file 'should' be deployed in the same directory as the main
7037
#                   application executable, so that the executable may locate it.
7038
#
7039
#                   The XML file is named after the package. It is prefixed with
7040
#                   the string "PkgInfo_".
7041
#
7042
#                   By default file will be placed in the 'TargetBaseDir'.
7043
#                   This behaviour may be modified by the user.
7044
#
7045
#                   Refer to package_info.xsd for details on the structure of the
7046
#                   generated XML file. Do not randomly chnage the structure.
7047
#                   It is being used.
7048
#
7049
#                   This function requires access to Release Manager in order
7050
#                   to locate the package description and build-time information
7051
#
7052
#                   The function will use the current/last version of the package
7053
#                   in an attempt to locate package information.
7054
#
7055
#
7056
# Inputs          : platform        - Platforms for which the file will be created
7057
#                                     '*' indicate ALL platforms.
7058
#                   options         - Options to control the detail of the generated file
7059
#
7060
#                   Valid options
7061
#                       --TargetDir         - Symbolic target directory
7062
#                                             Default: TargetBaseDir
7063
#
7064
#                       --Depth=nn          - Depth to traverse the dependancy tree
7065
#                                             All packages below this depth will be ignored
7066
#                                             Default: 0. All packages will be included
7067
#                       --VisibleDepth=nn   - Package beyond this depth will be marked as invisible
7068
#                                             Default: 1. Only top level packages will be marked
7069
#                                             as visible.
7070
#                       --Ignore=name       - Ignore this package
7071
#                                             It will not be included in the dependancy list
7072
#                                             Default: None
7073
#                       --IgnoreChildren=name   - Do not include children of this package\
7074
#                                             Default: None
7075
#                       --Invisible=name    - Mark this package and its dependents as invisible
7076
#                                             Default: None
7077
#                       --InvisibleChildren=name
7078
#                                           - Mark this package as visible, but its dependents as invisible
7079
#                                             Default: None
7080
#
7081
# Example:
7082
#               generateXmlDependancy('*', '--TargetDir=OcpDir' );
7083
#               
7084
#
7085
# Returns         : Nothing
7086
#
7087
sub generateXmlDependancy
7088
{
7089
    my ($platforms, @opts) = @_;
7090
    my %data;
7091
    my $filename = "PkgInfo_$PkgName" . '.xml';
7092
    my $targetTag;
1530 dpurdie 7093
 
1544 dpurdie 7094
    return if ( ! ActivePlatform($platforms) );
7095
    Information("Generating XML dependancy information from RM data: $filename");
1530 dpurdie 7096
 
1544 dpurdie 7097
    #
7098
    #   Insert defaults
7099
    #
7100
    $data{default_visible} = 1;
7101
 
7102
    #
7103
    #   Parse the user options
7104
    #
7105
    foreach ( @opts )
7106
    {
7107
        if ( m/^--Depth=(\d+)/ ) {
7108
            $data{default_depth} = $1;
7109
 
7110
        } elsif ( m/^--VisibleDepth=(\d+)/ ) {
7111
            $data{default_visible} = $1;
7112
 
7113
        } elsif ( m/^--Ignore=(.*)/ ) {
7114
            $data{ignore}{$1} = 1;
7115
 
7116
        } elsif ( m/^--IgnoreChildren=(.*)/ ) {
7117
            $data{ignore_child}{$1} = 1;
7118
 
7119
        } elsif ( m/^--Invisible=(.*)/ ) {
7120
            $data{invisible}{$1} = 1;
7121
 
7122
        } elsif ( m/^--InvisibleChildren=(.*)/ ) {
7123
            $data{invisible_child}{$1} = 1;
7124
 
7125
        } elsif ( m/^--TargetDir=(.*)/ ) {
7126
            $targetTag = $1;
7127
 
7128
        } else {
7129
            Error ("generateXmlDependancy: Unknown option: $_");
7130
        }
7131
    }
7132
 
7133
    #
7134
    #   Sanity Tests
7135
    #
7136
    if ( $data{default_visible} && $data{default_depth} )
7137
    {
7138
        Error ("generateXmlDependancy:Visible depth must be less than total depth")
7139
            if ( $data{default_visible} > $data{default_depth} );
7140
    }
7141
 
7142
    # lets check to see if the target tag exists
7143
    # if does not the process with log an error.
7144
    #
7145
    my $targetValue;
7146
    if ( $targetTag )
7147
    {
7148
        $targetValue = getTargetDstDirValue($targetTag, "A");
7149
    }
7150
    else
7151
    {
7152
        $targetValue = "$PkgBaseDir/$TargetBaseDir";
7153
    }
7154
    $filename = $targetValue . '/' . $filename;
7155
 
7156
 
7157
    #
7158
    #   Determine package information.
7159
    #   Must cater for a number of situations
7160
    #       1) Package rebuild
7161
    #       2) Package ripple
7162
    #       3) New package
7163
    #
7164
 
7165
 
7166
    # Set defaults for elements in RM if not found
7167
    DeployUtils::RmPkgInfo->DefaultDescription($PkgDesc);
7168
    DeployUtils::RmPkgInfo->DefaultLabel($PkgLabel);
7169
 
7170
    #
7171
    #   Try with the current package version. It may be in RM
7172
    #
7173
    $RmPkgDetails = DeployUtils::RmPkgInfo->new( {
7174
                        PKG_NAME => $PkgName,
7175
                        PKG_VERSION => $PkgVersionUser,
7176
                        NO_WARN => 1
7177
                    } );
7178
 
7179
    unless ( $RmPkgDetails->foundDetails() && $PkgPreviousVersionStr )
7180
    {
7181
        #
7182
        #   Try with the 'Previous' package
7183
        #
7184
        my $RmPkgDetailsPrev = DeployUtils::RmPkgInfo->new( {
7185
                        PKG_NAME => $PkgName,
7186
                        PKG_VERSION => $PkgPreviousVersionStr,
7187
                        NO_WARN => 1
7188
                    } );
7189
 
7190
        if ( $RmPkgDetailsPrev->foundDetails() )
7191
        {
7192
            Information ("generateXmlDependancy. Using previous version ($PkgPreviousVersionStr)");
7193
            $RmPkgDetails = $RmPkgDetailsPrev;
7194
        }
7195
    }
7196
 
7197
    unless ( $RmPkgDetails->foundDetails() )
7198
    {
7199
        Warning ("generateXmlDependancy. Package Information not in RM. Using defaults");
7200
    }
7201
 
7202
 
7203
    #
7204
    #   %packages   - information on packages that we have discovered
7205
    #   @to_process - An array of packages discovered, but not yet processed
7206
    #
7207
    my @to_process;
7208
 
7209
    #
7210
    #   Create the initial entry in the packages array
7211
    #
7212
    my @deps;
7213
    foreach my $i ( $BuildFileInfo->getDpkgArchiveList() )
7214
    {
7215
        my $moduleInfo = $BuildFileInfo->getDpkgArchiveInfo($i);
7216
        my $tag = join ($;, $i, $moduleInfo->{versionFull} );
7217
        push @deps, $tag;
7218
    }
7219
 
7220
    $data{packages}{$PkgName}{$PkgVersionUser}{date} = $RmPkgDetails->pv_modified_time() || localtime() ;
7221
    $data{packages}{$PkgName}{$PkgVersionUser}{overview} = $RmPkgDetails->pv_description();
7222
    $data{packages}{$PkgName}{$PkgVersionUser}{deps} = [ @deps ] ;
7223
 
7224
 
7225
    push @to_process, @deps;
7226
 
7227
    while ( my $entry = pop @to_process )
7228
    {
7229
        my ($package, $version) = split ( $;, $entry );
7230
 
7231
        #
7232
        #   Extract and save information for this package
7233
        #
7234
        next if ( exists $data{packages}{$package}{$version} );
7235
 
7236
        #
7237
        #   Some packages need to be totally ignored
7238
        #
7239
        next if ( exists $data{ignore}{$package} );
7240
 
7241
        my $RmPkgDetails = DeployUtils::RmPkgInfo->new(
7242
                        {
7243
                            PKG_NAME => $package,
7244
                            PKG_VERSION => $version,
7245
                        } );
7246
        Error ("generateXmlDependancy: Cannot locate base package: $package, $version")
7247
            unless ( $RmPkgDetails->foundPkg() );
7248
 
7249
        #
7250
        #   Determine the dependancies, unless we are ignoring the children too
7251
        #   Do not use the RmPkgInfo class method getDependencyNames to fetch the
7252
        #   dependancy information as this:
7253
        #       1) gets it wrong
7254
        #       2) Extracts a lot of data that we dont want.
7255
        #
7256
        my @deps;
7257
        unless ( exists $data{ignore_child}{$package} )
7258
        {
7259
            my $deps = $RmPkgDetails->getDependenciesHash();
7260
            foreach my $pkg ( keys %{$deps} )
7261
            {
7262
                foreach my $ver ( keys %{$deps->{$pkg}}  )
7263
                {
7264
                    my $tag = join ($;, $pkg, $ver );
7265
                    push @deps, $tag;
7266
                }
7267
            }
7268
        }
7269
 
7270
        $data{packages}{$package}{$version}{date} = $RmPkgDetails->pv_modified_time();
7271
        $data{packages}{$package}{$version}{overview} = $RmPkgDetails->pv_description();
7272
        $data{packages}{$package}{$version}{deps} = [ @deps ] ;
7273
 
7274
        push @to_process, @deps;
7275
    }
7276
#DebugDumpData ("Packages", \%packages);
7277
 
7278
    #
7279
    #   Now walk the tree and generate XML
7280
    #
7281
    sub output_entry
7282
    {
7283
        my ($datap, $depth, $package, $version, $vis ) = @_;
7284
        my $fh = $datap->{fh};
7285
        $depth++;
7286
 
7287
        #
7288
        #   Skip if too deep or an ignored package
7289
        #
7290
        return if ( $datap->{ignore}{$package} );
7291
        return if ( $datap->{default_depth} && $depth > $datap->{default_depth} );
7292
 
7293
        #
7294
        #   Check for invisible packages
7295
        #
7296
        $vis = 0 if ( $datap->{invisible}{$package} );
7297
 
7298
 
7299
        my $indent = "    " x ($depth - 1);
7300
        my $date = $datap->{packages}{$package}{$version}{date};
7301
        my $overview = $datap->{packages}{$package}{$version}{overview};
7302
 
7303
        #
7304
        #   Clean up the overview
7305
        #
7306
        $overview =~ s~\s+$~~;
7307
        $overview =~ s~\r\n~\n~g;
7308
        $overview =~ s~\n\r~\n~g;
7309
 
7310
        #
7311
        #   Determine visibility
7312
        #
7313
        $vis = 0 if ( $datap->{default_visible} && $depth > $datap->{default_visible} );
7314
        my $visible = ( $vis > 0 ) ? 'true' : 'false';
7315
        $vis = 0 if ( $datap->{invisible_child}{$package} );
7316
 
7317
        #
7318
        #   The top level entry is different
7319
        #
7320
        if ( $depth == 0 )
7321
        {
7322
            $indent = "    " ;
7323
            print $fh "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
7324
            print $fh "<ERG_Package xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"package_info.xsd\" SchemaVersion=\"1.0.0\">\n";
7325
            print $fh "$indent<Package_Name>$package</Package_Name>\n";
7326
            print $fh "$indent<Package_Version>$version</Package_Version>\n";
7327
            print $fh "$indent<Package_Overview>$overview</Package_Overview>\n";
7328
            print $fh "$indent<Build_Date>$date</Build_Date>\n";
7329
        }
7330
        else
7331
        {
7332
            print $fh "${indent}<Package Name=\"$package\" Version=\"$version\" BuildDate=\"$date\" Visible=\"$visible\">\n";
7333
		    print $fh "${indent}    ";
7334
            print $fh "<Overview>${overview}" if ($overview);
7335
		    print $fh "</Overview>\n";
7336
        }
7337
 
7338
        #
7339
        #   Process dependancies
7340
        #
7341
        unless ( $datap->{ignore_child}{$package} )
7342
        {
7343
            foreach my $entry ( @{ $datap->{packages}{$package}{$version}{deps} } )
7344
            {
7345
                my ($package, $version) = split ( $;, $entry );
7346
                output_entry ( $datap, $depth, $package, $version, $vis );
7347
            }
7348
        }
7349
 
7350
        if ( $depth == 0 )
7351
        {
7352
            print $fh "</ERG_Package>\n";
7353
        }
7354
        else
7355
        {
7356
		    print $fh "${indent}</Package>\n";
7357
        }
7358
    }
7359
 
7360
    #
7361
    #   Output the XML header and information about the first package
7362
    #
7363
    Information ( "Creating file $filename" );
7364
    open ( $data{fh}, ">", $filename ) || Error( "Cannot create $filename");
7365
    output_entry ( \%data, -1, $PkgName, $PkgVersionUser, 1 );
7366
    close $data{fh};
7367
 
7368
#    DebugDumpData( "DATA", \%data );
7369
}
7370
 
7371
 
1530 dpurdie 7372
#------------------------------------------------------------------------------
7373
sub createPerlSvcWin32
7374
#
7375
# Description:
7376
#       This sub-routine is used to create a Win32  service 
7377
#       using a PERL script as the input.
7378
#
7379
#       note we assume here that you have installed ther ActiveState PERL
7380
#       developement KIT and have also installed a valid license key.
7381
#
7382
#------------------------------------------------------------------------------
7383
{
7384
    # lets just check to see if we can execute this function on
7385
    # this machine.
7386
    #
7387
    if ( "$MachType" ne "win32" )
7388
    {
1534 dpurdie 7389
        Information("createPerlSvcWin32() not supported on this machine type.");
1530 dpurdie 7390
        return 1;
7391
    }
7392
 
7393
 
7394
    my ($m_srcDirTag, $m_sfile, $m_targetDirTag, $m_ofile, @m_libDirTags) = @_;
7395
 
7396
 
7397
    # lets get the src dir value
7398
    my ($m_targetDirValue) = getTargetDstDirValue($m_targetDirTag, "A");
7399
 
7400
 
7401
    # lets get the lib src dir value
7402
    my (@m_libDirValue) = ();
7403
    my $i;
7404
    my ($_libStr) = "";
7405
    foreach $i ( 0 .. $#m_libDirTags )
7406
    {
7407
        $m_libDirValue[$i] = getLocalDirValue($m_libDirTags[$i], "A");
7408
        $_libStr = $_libStr . "$m_libDirValue[$i];"
7409
    }
7410
    if ( -d $DpkgScriptsDir )
7411
    {
7412
        $_libStr = $_libStr . "$DpkgScriptsDir";
7413
    }
1534 dpurdie 7414
    Verbose("additional places to look for perl modules, [$_libStr]");
1530 dpurdie 7415
 
7416
 
7417
    # lets get the target dir value
7418
    my ($m_srcDirValue) = getLocalDirValue($m_srcDirTag, "A");
7419
 
7420
    # we know where we are getting this from and where we
7421
    # going to put them.
7422
    my ($m_sfileLoc) = "$m_srcDirValue/$m_sfile";
7423
 
7424
 
7425
    my ($_cmdStr) = "perlsvc --verbose --lib $_libStr --exe $m_targetDirValue/$m_ofile $m_sfileLoc";
7426
 
7427
 
7428
    # lets execute the package commands.
7429
    my ($retVal);
7430
    $retVal = system("$_cmdStr");
7431
    if ( $retVal != 0 )
7432
    {
1534 dpurdie 7433
        Error("Failed to complete command [$_cmdStr].");
1530 dpurdie 7434
    }
7435
 
7436
    # done.
7437
    return 1;
7438
}
7439
 
7440
 
7441
#------------------------------------------------------------------------------
7442
sub createPerlAppWin32
7443
#
7444
# Description:
7445
#       This sub-routine is used to create a Win32 free-standing application 
7446
#       using a PERL script as the input.
7447
#
7448
#       note we assume here that you have installed ther ActiveState PERL
7449
#       developement KIT and have also installed a valid license key.
7450
#
7451
#------------------------------------------------------------------------------
7452
{
7453
    # lets just check to see if we can execute this function on
7454
    # this machine.
7455
    #
7456
    if ( "$MachType" ne "win32" )
7457
    {
1534 dpurdie 7458
        Information("createPerlAppWin32() not supported on this machine type.");
1530 dpurdie 7459
        return 1;
7460
    }
7461
 
7462
 
7463
    my ($m_srcDirTag, $m_sfile, $m_targetDirTag, $m_ofile, @m_libDirTags) = @_;
7464
 
7465
 
7466
    # lets get the src dir value
7467
    my ($m_targetDirValue) = getTargetDstDirValue($m_targetDirTag, "A");
7468
 
7469
 
7470
    # lets get the lib src dir value
7471
    my (@m_libDirValue) = ();
7472
    my $i;
7473
    my ($_libStr) = "";
7474
    foreach $i ( 0 .. $#m_libDirTags )
7475
    {
7476
        $m_libDirValue[$i] = getLocalDirValue($m_libDirTags[$i], "A");
7477
        $_libStr = $_libStr . "$m_libDirValue[$i];"
7478
    }
7479
    if ( -d $DpkgScriptsDir )
7480
    {
7481
        $_libStr = $_libStr . "$DpkgScriptsDir";
7482
    }
1534 dpurdie 7483
    Verbose("additional places to look for perl modules, [$_libStr]");
1530 dpurdie 7484
 
7485
 
7486
    # lets get the target dir value
7487
    my ($m_srcDirValue) = getLocalDirValue($m_srcDirTag, "A");
7488
 
7489
    # we know where we are getting this from and where we
7490
    # going to put them.
7491
    my ($m_sfileLoc) = "$m_srcDirValue/$m_sfile";
7492
 
7493
 
7494
    my ($_cmdStr) = "perlapp --verbose --clean --force --lib $_libStr --exe $m_targetDirValue/$m_ofile --script $m_sfileLoc";
7495
 
7496
 
7497
    # lets execute the package commands.
7498
    my ($retVal);
7499
    $retVal = system("$_cmdStr");
7500
    if ( $retVal != 0 )
7501
    {
1534 dpurdie 7502
        Error("Failed to complete command [$_cmdStr].");
1530 dpurdie 7503
    }
7504
 
7505
    # done.
7506
    return 1;
7507
}
7508
 
7509
 
7510
#------------------------------------------------------------------------------
7511
sub generateProductContents
7512
#
7513
#------------------------------------------------------------------------------
7514
{
7515
    if ( ! defined($RmPkgDetails) )
7516
    {
7517
        # Set defaults for elements in RM if not found
7518
        DeployUtils::RmPkgInfo->DefaultDescription($PkgDesc);
7519
        DeployUtils::RmPkgInfo->DefaultLabel($PkgLabel);
7520
 
7521
        $RmPkgDetails = DeployUtils::RmPkgInfo->new( 
7522
                        {
7523
                            PKG_NAME => $PkgName,
7524
                            PKG_VERSION => ( "$PkgPatchNum" ne "" ) ? $PkgPatchID : $PkgVersionUser
7525
                        } );
7526
    }
7527
 
7528
 
7529
    # we only go on if we have a pkg 
7530
    if ( $RmPkgDetails->foundPkg() )
7531
    {
7532
        # lets zap the product contents
7533
        # only if the release manager entry is not locked.
7534
        if ( $RmPkgDetails->pv_dlocked() ne "Y" )
7535
        {
1534 dpurdie 7536
           Error("Failed to zap product contents.")
1530 dpurdie 7537
                if ( ! $RmPkgDetails->zapProductContents( $Platform ) );
7538
        }
7539
 
7540
 
7541
        # lets get a listing of the products contents
7542
        #
7543
        File::Find::find( \&ProductContentsFind, "$PkgBaseDir/$TargetBaseDir");
7544
    }
7545
    else
7546
    {
1534 dpurdie 7547
        Warning("Unable to load product contents because we do not have a connection to Release Manager.");
1530 dpurdie 7548
    }
7549
 
7550
 
7551
    # done
7552
    return 1;
7553
}
7554
 
7555
 
7556
#------------------------------------------------------------------------------
7557
sub ProductContentsFind
7558
#
7559
#    Description:
7560
#        This subroutine is used to locate all associated items that 
7561
#        have been designated for the product.
7562
#
7563
#------------------------------------------------------------------------------
7564
{
7565
    my($item)= "$File::Find::name";
7566
    my($base)= File::Basename::basename($item);
7567
 
7568
 
7569
    # we get the absolute path from the find, but we only require
7570
    # a relative path from the starting dir.
7571
 
7572
    my ($_item)   = $item;
7573
    my ($_subStr) = "$PkgBaseDir\/$TargetBaseDir";
7574
    $_item =~ s/$_subStr//;
7575
 
7576
    my $cksumStr;
7577
    my $cksumValue;
7578
    my $cksumSize;
7579
    my $cksumName;
7580
    my $_tmpStr;
7581
    my $retVal;
7582
    my $cksumPath;
7583
 
7584
    if ( "$base" ne "." && "$base" ne ".." && "x$_item" ne "x" )
7585
    {
7586
        $_item =~ s/^\///;
7587
        $cksumPath = $_item;
7588
        $cksumName = File::Basename::basename($_item);
7589
 
7590
        # we need to determine which file we are dealing with
7591
        if ( ! -d "$item")
7592
        {
7593
            $cksumStr  = `cksum "$item"`;
7594
            $retVal    = $? / 256;
7595
            if ( $retVal != 0 )
7596
            {
1534 dpurdie 7597
                Error("Failed to determine cksum for product content item [$item].") 
1530 dpurdie 7598
            }
7599
            else
7600
            {
7601
                chomp($cksumStr);
7602
                $cksumStr =~ s/^\s+|\s+$//g;
7603
                if ( $cksumStr =~ m/^([0-9]*)\s*([0-9]*)\s*(.*)$/ )
7604
                {
7605
                    ($cksumValue, $cksumSize, $_tmpStr) = ($1, $2, $3);
7606
                    $cksumValue =~ s/^\s+|\s+$//g;
7607
                    $cksumSize  =~ s/^\s+|\s+$//g;
7608
                    $_tmpStr    =~ s/^\s+|\s+$//g;
7609
                }
7610
                else
7611
                {
7612
                    $cksumValue = '';
7613
                    $cksumSize  = 0;
7614
                    $_tmpStr    = '';
7615
                }
7616
            }
7617
 
7618
            $cksumPath = File::Basename::dirname($_item);
7619
            if ( $cksumPath eq "." )
7620
            {
7621
                $cksumPath = '';
7622
            }
7623
            else
7624
            {
7625
                $cksumPath =~ s/$/\//;
7626
            }
7627
 
7628
            # we only mess with the product contents
7629
            # if the package is not released.
7630
            if ( $RmPkgDetails->pv_dlocked() ne "Y" )
7631
            {
1534 dpurdie 7632
                Error("Failed to insert product content item.")
1530 dpurdie 7633
                     if ( ! $RmPkgDetails->insertProductContentItem( $Target, $cksumPath, $cksumName, '', $cksumSize, $cksumValue) );
7634
            }
7635
            else
7636
            {
1534 dpurdie 7637
                Verbose("product item - $Target, $cksumPath, $cksumName, '', $cksumSize, $cksumValue");
1530 dpurdie 7638
            }
7639
        }
7640
        else
7641
        {
7642
            $cksumPath =~ s/$/\//;
7643
            if ( $RmPkgDetails->pv_dlocked() ne "Y" )
7644
            {
1534 dpurdie 7645
               Error("Failed to insert product content item.")
1530 dpurdie 7646
                     if ( ! $RmPkgDetails->insertProductContentItem( $Target, $cksumPath, '', '', 0, '') );
7647
            }
7648
            else
7649
            {
1534 dpurdie 7650
                Verbose("product dir - $Target, $cksumPath, '', '', 0, ''");
1530 dpurdie 7651
            }
7652
        }
7653
    }
7654
}
7655
 
1534 dpurdie 7656
#-------------------------------------------------------------------------------
7657
# Function        : make_directory
7658
#
7659
# Description     : Create a directory if it does not already exist
7660
#                   Simple function to provide user messages on the way
7661
#                   Will create a complete path. There is no need to
7662
#                   break it into bits.
7663
#
7664
# Inputs          : name        - path to the directory
7665
#                   umask       - umask
7666
#                   text        - User text (optional)
7667
#
7668
# Returns         :
7669
#
7670
 
7671
sub make_directory
7672
{
7673
    my ($name, $umask, $text ) = @_;
7674
 
7675
    Error ("make_directory needs a umask") unless ( $umask );
7676
    Error ("make_directory needs a path") unless ( $name );
7677
    $text = "Create directory"  unless ( $text );
7678
 
7679
    my $umask_text = sprintf( "0%o", $umask );
7680
 
7681
    unless ( -d $name )
7682
    {
7683
        Verbose ( "$text: $name [$umask_text]");
7684
        mkpath ( $name, 0, $umask);
7685
    }
7686
    else
7687
    {
7688
        Verbose2 ( "$text: $name [$umask_text] - already exists");
7689
    }
1554 dpurdie 7690
 
7691
    #
7692
    #   Ensure that the target directory is not setgid
7693
    #   as this will mess up the Solaris packaging process. The setgid on the
7694
    #   directories will be propergated into the final package. This is not good.
7695
    #
7696
    #   If the user gets directories with SETGID, then they  must be created
7697
    #   specifically after the directory has been created.
7698
    #
7699
    #   Why is this a problem? Seen when a build user has directory setgid
7700
    #   for the purposes of making the directory accessible by many.
7701
    #
7702
    if ( -g $name )
7703
    {
7704
        system ('chmod', 'g-s', $name );
7705
        Error ("Cannot remove setGID on directory.", "Dir: $name") if ( -g $name );
7706
    }
1534 dpurdie 7707
}
7708
 
1544 dpurdie 7709
 
7710
#-------------------------------------------------------------------------------
7711
# Function        : ActivePlatform
7712
#
7713
# Description     : Determine if the specified platform is currently 'active'
7714
#                   This is used by all user directives in order to determine
7715
#                   if the directive should be ignored for the current platform
7716
#
7717
# Inputs          : $platform_spec      - A (simple)platform specifier
7718
#
7719
# Returns         : TRUE if the platform spec contains the current platform
7720
#
7721
sub ActivePlatform
7722
{
7723
    my( $platform_spec ) = @_;
7724
 
7725
    Error ("No platform specified in some directive") unless ( $platform_spec );
7726
 
7727
    #
7728
    #   Wild card
7729
    #
7730
    return 1 if ( $platform_spec eq '*' );
7731
 
7732
    #
7733
    #   Simple test
7734
    #
7735
    foreach ( split (',', $platform_spec))
7736
    {
7737
        return 1 if ( $_ eq $Platform );
7738
    }
7739
 
7740
    #
7741
    #   Not for me
7742
    #
7743
    return 0;
7744
}
7745
 
1546 dpurdie 7746
#-------------------------------------------------------------------------------
7747
# Function        : LocatePackageBase
7748
#
7749
# Description     : Locate a package and return the path to a directory within
7750
#                   the package
7751
#
7752
# Inputs          : $ufn            - User function. Error reporting
7753
#                   $PkgName        - Name of the Package
7754
#                   $PkgSubDir      - Subdir within the package
7755
#
7756
#
7757
# Returns         : Absolute path to a directory within the package
7758
#
7759
my %LocatePackageBase_cache;
7760
sub LocatePackageBase
7761
{
7762
    my ( $ufn, $PkgName, $PkgSubDir ) = @_;
7763
    my $src_base_dir;
7764
 
7765
    if ( exists $LocatePackageBase_cache{$PkgName} )
7766
    {
7767
        $src_base_dir = $LocatePackageBase_cache{$PkgName};
7768
    }
7769
    else
7770
    {
7771
        #
7772
        #   Convert the package name into a real path name to the package as
7773
        #   held in dpkg_archive. Do not use the copy in the 'interface' directory
7774
        #
7775
        for my $entry ( $BuildFileInfo->getBuildPkgRules() )
7776
        {
7777
            next unless ( $entry->{'DNAME'} eq $PkgName );
7778
            $src_base_dir = $entry->{'ROOT'};
7779
            Verbose ("Discovered package in: $src_base_dir");
7780
        }
7781
 
7782
        Error ("$ufn: Package not located: $PkgName")
7783
            unless ( $src_base_dir );
7784
 
7785
        Error ("$ufn: Package directory not found: $src_base_dir")
7786
            unless ( -d $src_base_dir );
7787
 
7788
        #
7789
        #   Mainatin a cache of located packages
7790
        #
7791
        $LocatePackageBase_cache{$PkgName} = $src_base_dir;
7792
    }
7793
 
7794
    if ( $PkgSubDir )
7795
    {
7796
        $src_base_dir .= '/' . $PkgSubDir;
7797
        Error ("$ufn: Package subdirectory not found: $PkgSubDir" )
7798
            unless ( -d $src_base_dir );
7799
    }
7800
 
7801
    return $src_base_dir;
7802
}
7803
 
1552 dpurdie 7804
#===============================================================================
7805
#
7806
#   Internal Package
1596 dpurdie 7807
#   An attempt to simplify the WildCarding interface by capturing the parameters
1552 dpurdie 7808
#   in a package. The idea is that storing the arguments can be easier
7809
#
7810
package LocateFiles;
7811
use JatsError;
7812
 
7813
#-------------------------------------------------------------------------------
7814
# Function        : new
7815
#
7816
# Description     : Create a new instance of a searcher
7817
#
7818
# Inputs          : 
7819
#
7820
# Returns         : 
7821
#
7822
sub new {
7823
    my $class = shift;
7824
    my $self  = {};
7825
    $self->{recurse}  = 0;
7826
    $self->{exclude}  = [];
7827
    $self->{include}  = [];
7828
    $self->{base_dir} = undef;
7829
    $self->{results}  = [];
1592 dpurdie 7830
    $self->{dirs_too} = 0;
1552 dpurdie 7831
    bless ($self, $class);
7832
 
7833
    #
7834
    #   Process user arguments
7835
    #   These are are a hash
7836
    #
7837
    my %href = @_;
7838
    foreach my $entry ( keys %href )
7839
    {
7840
        Error( "LocateFiles:new. Unknown initialiser: $entry") unless ( exists $self->{$entry} );
7841
        $self->{$entry} = $href{$entry};
7842
    }
7843
    return $self;
7844
}
7845
 
7846
#-------------------------------------------------------------------------------
1596 dpurdie 7847
# Function        :  Class accessor fucntions
7848
#                   recurse                     - Recurse subdirs
7849
#                   filter_in                   - Filter in these files
7850
#                   filter_in_re                - Filter in (Regular Expression)
7851
#                   filter_out                  - Filter out these files
7852
#                   filter_out_re               - Filter out (RE)
7853
#                   base_dir                    - Base dir for search
7854
#                   results                     - Results of the last search
7855
#                   dirs_too                    - Include dirs in the search
7856
#                   has_filter                  - Has any filter been defined
7857
#                   search                      - Perform the search
1552 dpurdie 7858
#
7859
# Description     : Accessor functions
7860
#
7861
# Inputs          : class
7862
#                   One argument (optional)
7863
#
7864
# Returns         : Current value of the daat item
7865
#
7866
sub recurse
7867
{
7868
    my $self = shift;
7869
    if (@_) { $self->{recurse} = shift }
7870
    return $self->{recurse};
7871
}
7872
 
7873
sub filter_in
7874
{
7875
    my $self = shift;
7876
    if (@_) { push @{$self->{include}}, glob2pat( shift ) }
7877
    return $self->{include};
7878
}
7879
 
7880
sub filter_in_re
7881
{
7882
    my $self = shift;
7883
    if (@_) { push @{$self->{include}}, shift }
7884
    return $self->{include};
7885
}
7886
 
7887
sub filter_out
7888
{
7889
    my $self = shift;
7890
    if (@_) { push @{$self->{exclude}}, glob2pat( shift ) }
7891
    return $self->{exclude};
7892
}
7893
 
7894
sub filter_out_re
7895
{
7896
    my $self = shift;
7897
    if (@_) { push @{$self->{exclude}}, shift }
7898
    return $self->{exclude};
7899
}
7900
 
1592 dpurdie 7901
sub dirs_too
7902
{
7903
    my $self = shift;
7904
    if (@_) { $self->{dirs_too} = shift }
7905
    return $self->{dirs_too};
7906
}
7907
 
1552 dpurdie 7908
sub base_dir
7909
{
7910
    my $self = shift;
7911
    if (@_) { $self->{base_dir} = shift }
7912
    return $self->{base_dir};
7913
}
7914
 
7915
sub has_filter
7916
{
7917
    my $self = shift;
7918
    return ( ( @{$self->{include}} || @{$self->{exclude}} ) );
7919
}
7920
 
7921
 
7922
#-------------------------------------------------------------------------------
7923
# Function        : search
7924
#
7925
# Description     : This function performs the search for files as specified
7926
#                   by the arguments already provided
7927
#
7928
# Inputs          : base_dir (Optional)
7929
#
7930
# Returns         : List of files that match the search criteria
7931
#
7932
 
7933
my @search_list;             # Must be global to avoid closure problems
7934
my $search_len;
1594 gchristi 7935
my $search_base_dir;
7936
my $search_dirs_too;
1552 dpurdie 7937
 
7938
sub search
7939
{
7940
    my $self = shift;
7941
    $self->{base_dir} = $_[0] if (defined $_[0] );
7942
    $self->{results} = ();
7943
 
7944
    #
7945
    #   Ensure user has provided enough info
7946
    #
7947
    Error ("LocateFiles: No base directory provided") unless ( $self->{base_dir} );
7948
 
7949
    #
7950
    #   Clean up the user dir. Remove any trailing / as we will be adding it back
7951
    #
7952
    $self->{base_dir} =~ s~/*$~~g;
7953
 
7954
    #
7955
    #   Init recursion information
7956
    #   Needed to avoid closure interactions
7957
    #
7958
    @search_list = ();
7959
    $search_len = length( $self->{base_dir} );
7960
 
7961
    #
7962
    #   Create a list of candidate files
7963
    #   If we are recursing the subtree, then this is a little harder
7964
    #   If we are not recursing then we can't simply glob the directory as
7965
    #   not all files are processed.
7966
    #
7967
    #   Will end up with a list of files that
7968
    #       1) Start with a '/'
7969
    #       2) Are rooted as $dir, but don't include $dir
7970
    #
7971
    if ( $self->{recurse} )
7972
    {
1594 gchristi 7973
        $search_dirs_too = $self->{dirs_too};
7974
        $search_base_dir = $self->{base_dir};
1552 dpurdie 7975
        sub find_file_wanted
7976
        {
1594 gchristi 7977
            return if ( !$search_dirs_too && -d $_ );               # skip if current is dir and we are not including dirs
7978
            return if ( $search_base_dir eq $File::Find::name );    # skip if current is base_dir as we dont include it
1552 dpurdie 7979
            my $file = $File::Find::name;
7980
            push @search_list, substr($file, $search_len );
7981
        }
7982
 
7983
        #
7984
        #       Under Unix we need to follow symbolic links, but Perl's
7985
        #       Find:find does not work with -follow under windows if the source
7986
        #       path contains a drive letter.
7987
        #
7988
        #       Solution. Only use follow under non-windows systems.
7989
        #                 Works as Windows does not have symlinks (yet).
7990
        #
7991
        my $follow_opt =  ! ( "$MachType" eq "win32" || "$MachType" eq "WinCE" );
7992
 
7993
        File::Find::find( {wanted => \&find_file_wanted, follow_fast => $follow_opt }, $self->{base_dir} );
7994
    }
7995
    else
7996
    {
7997
        local *DIR ;
7998
        opendir DIR, $self->{base_dir} || die ("Cannot open $self->{base_dir}");
7999
        foreach ( readdir( DIR ) )
8000
        {
8001
            next if /^\Q.\E$/;
8002
            next if /^\Q..\E$/;
1592 dpurdie 8003
            next if ( !$self->{dirs_too} && -d "$self->{base_dir}/$_" );
1552 dpurdie 8004
            push @search_list, '/' . $_;
8005
 
8006
        }
8007
        closedir DIR;
8008
    }
8009
 
8010
    #
8011
    #   If filtering is not present then return the entire file list
8012
    #
8013
    $self->{results} = \@search_list ;
8014
    return @search_list
8015
        unless ( @{$self->{include}} || @{$self->{exclude}} );
8016
 
8017
    #
8018
    #   Filtering is present
8019
    #   Apply the filterin rules and then the filter out rules
8020
    #   If no filter-in rules, then assume that all files are allowed in and
8021
    #   simply apply the filter-out rules.
8022
    #
8023
    my @patsin  = map { qr/$_/ } @{$self->{include}};
8024
    my @patsout = map { qr/$_/ } @{$self->{exclude}};
8025
    my @result;
8026
 
8027
#    map { print "Include:$_\n"; } @{$self->{include}};
8028
#    map { print "Exclude:$_\n"; } @{$self->{exclude}};
8029
 
8030
 
8031
    file:
8032
    foreach my $file ( @search_list )
8033
    {
8034
        if ( @{$self->{include}} )
8035
        {
8036
            my $in = 0;
8037
            for my $pat (@patsin)
8038
            {
8039
                if ( $file =~ /$pat/ )
8040
                {
8041
                    $in = 1;
8042
                    last;
8043
                }
8044
            }
8045
#print "------- Not included $file\n" unless $in;
8046
            next unless ( $in );
8047
        }
8048
 
8049
        for my $pat (@patsout)
8050
        {
8051
#print "------- REJECT $file :: $pat \n" if ( $file =~ /$pat/ );
8052
            next file if ( $file =~ /$pat/ );
8053
        }
8054
 
8055
        push @result, $file;
8056
    }
8057
 
8058
    $self->{results} = \@result;
8059
#DebugDumpData ("Search", $self);
8060
 
8061
    return @result;
8062
}
8063
 
8064
#-------------------------------------------------------------------------------
8065
# Function        : glob2pat
8066
#
8067
# Description     : Convert four shell wildcard characters into their equivalent
8068
#                   regular expression; all other characters are quoted to
8069
#                   render them literals.
8070
#
8071
# Inputs          : Shell style wildcard pattern
8072
#
8073
# Returns         : Perl RE
8074
#
8075
 
8076
sub glob2pat
8077
{
8078
    my $globstr = shift;
8079
    $globstr =~ s~^/~~;
8080
    my %patmap = (
8081
        '*' => '[^/]*',
8082
        '?' => '[^/]',
8083
        '[' => '[',
8084
        ']' => ']',
8085
    );
8086
    $globstr =~ s{(.)} { $patmap{$1} || "\Q$1" }ge;
8087
    return '/' . $globstr . '$';
8088
}
8089
 
1530 dpurdie 8090
#------------------------------------------------------------------------------
8091
1;