Subversion Repositories DevTools

Rev

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