Subversion Repositories DevTools

Rev

Rev 1578 | Rev 1582 | 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
    #
1580 dpurdie 3107
    my ($ExcludedFlag) = "false";
1534 dpurdie 3108
    foreach my $sfile ( @flist )
3109
    {
3110
 
1530 dpurdie 3111
        # we exclude .dll files if this is a sparc build
3112
        #
3113
        if ( "$MachType" eq "sparc"  &&
3114
             $sfile =~ m/\.dll/
3115
           )
3116
        {
1534 dpurdie 3117
            Verbose("Excluding item [$sfile] from build, as we do not deliver dlls for this machine type [$MachType].");
1580 dpurdie 3118
            $ExcludedFlag = "true";
3119
            next;
1530 dpurdie 3120
        }
3121
 
3122
        # we exclude .so files if this is a win32 build
3123
        #
3124
        if ( "$MachType" eq "win32"  &&
3125
             $sfile =~ m/\.so/
3126
           )
3127
        {
1534 dpurdie 3128
            Verbose("Excluding item [$sfile] from build, as we do not deliver sosss for this machine type [$MachType].");
1580 dpurdie 3129
            $ExcludedFlag = "true";
3130
            next;
1530 dpurdie 3131
        }
3132
 
3133
        my ($libName) = $sfile;
3134
        if ( "$MachType" eq "sparc" )
3135
        {
3136
            $libName =~ s/\.so.*$//;
3137
        }
3138
 
3139
        # lets define the absolute location of the file
3140
        my ($m_srcFileLocation) = "";
3141
        my ($m_dstFileLocation) = "";
3142
        my ($m_DpkgLibDir) = "";
3143
 
3144
        my ($i);
3145
        my ($j);
3146
        my ($count);
3147
        my ($foundFileFlag) = "false";
3148
 
3149
        #
3150
        #   Search all the 'lib' locations, or a specified subset
3151
        #
1556 lkelly 3152
        my (@libDirList) = @{$DpkgLibDirList{$select}};
3153
        if ($installProdAndDebug)
1530 dpurdie 3154
        {
1556 lkelly 3155
            # we want to be able to search both prod and debug dirs. 
3156
            # we can just add them together here because the lib filenames
3157
            # are different (i.e. xxxD.so vs xxxP.so) and a P or D library 
3158
            # will only exist in one dir. i.e. P.so in prod dirs, D.so in debug dirs.
3159
            push @libDirList, @{$DpkgLibDirListAlternate{$select}};
3160
        }
1530 dpurdie 3161
 
1556 lkelly 3162
        foreach $i (@libDirList)
3163
        {
3164
 
1530 dpurdie 3165
            $m_DpkgLibDir = "$DpkgLibDir" . "/$i";
3166
            if ( ! -d "$m_DpkgLibDir" )
3167
            {
1534 dpurdie 3168
                Debug("Directory [$m_DpkgLibDir] not found.");
1530 dpurdie 3169
                next;
3170
            }
3171
 
1534 dpurdie 3172
 
1530 dpurdie 3173
            $m_srcFileLocation = "$m_DpkgLibDir/$sfile";
3174
            $m_dstFileLocation = "$targetValue/$sfile";
3175
 
3176
 
3177
            # we only want debug items in a debug build
1556 lkelly 3178
            # unless we are told to installProdAndDebug
3179
            if ( ( !$installProdAndDebug) && (excludeItemFromBuild($sfile)) )
1530 dpurdie 3180
            {
1534 dpurdie 3181
                Verbose("Excluding item [$sfile] from build as not compatible with build type [$BuildType].");
1530 dpurdie 3182
                $ExcludedFlag = "true";
3183
            }
3184
            else
3185
            {
3186
                # we need to ensure that only a single version/entry of the lib exists in the lib list
3187
                #
3188
                $count = 1;
3189
                foreach $j (@LibCheckList)
3190
                {
3191
                    if ( $j =~ m/^$libName$/ )
3192
                    {
3193
                        $count++;
3194
                    }
3195
 
3196
                    if ( $count > 1 )
3197
                    {
1534 dpurdie 3198
                        Error("Detected multiple references of lib [$libName] in lib list, check item [$sfile].");
1530 dpurdie 3199
                    }
3200
                }
3201
 
3202
                # we will check to see if the file exists.
3203
                #
3204
                if ( -f "$m_srcFileLocation" )
3205
                {
3206
                    # now we need to copy the file.
3207
 
3208
                    # we also want to create a generically named copy
1534 dpurdie 3209
                    # of the library. ie:
3210
                    #       libraryP.nn.nn.nn.dll -> library.dll, libraryP.dll
3211
                    #       libraryP.so.nn.nn.nn  -> library.so, libraryP.so
1530 dpurdie 3212
                    #
3213
                    my ($gName)    = $sfile;
3214
                    my ($nVerName) = $sfile;
3215
                    $gName = removeBuildTypeFromItemName($sfile);
3216
                    $gName = removeVersionNumberFromItemName($gName);
3217
                    $nVerName = removeVersionNumberFromItemName($sfile);
3218
 
3219
                    if(File::Copy::copy("$m_srcFileLocation", "$m_dstFileLocation"))
3220
                    {
1534 dpurdie 3221
                        Verbose("Copied Lib [$sfile] to [$m_dstFileLocation] ...");
1530 dpurdie 3222
                        $foundFileFlag = "true";
3223
 
3224
                        if ( $links && ( "x$PkgPatchID" eq "x" || "$MachType" eq "win32") )
3225
                        {
3226
                            # normal build or if we are building win32 we want generic names
3227
 
3228
                            # we want to create a copy of our target using
1556 lkelly 3229
                            # the generic name (no version number)
1530 dpurdie 3230
                            if ( $sfile ne $nVerName )
3231
                            {
3232
                                createGenericCopy("$sfile", "$m_srcFileLocation", "$nVerName", "$targetValue");
3233
                            }
1556 lkelly 3234
                            # and another copy with no build type or version number.
1530 dpurdie 3235
                            if ( $sfile ne $gName )
3236
                            {
1556 lkelly 3237
                                # because this link doesn't have a P/D 
3238
                                # differentiator, we can only have one, so 
3239
                                # do this for the $BuildType file, but not any
3240
                                # $AlternateBuildType files
3241
                                if ( (!$installProdAndDebug) || ( $sfile =~ /$BuildType\./ ) )
3242
                                {
3243
                                    createGenericCopy("$sfile", "$m_srcFileLocation", "$gName",    "$targetValue");
3244
                                }
1530 dpurdie 3245
                            }
3246
                        }
3247
 
3248
 
3249
                        # lets add this lib to our check list for next time.
3250
                        #
3251
                        push @LibCheckList, $libName;
3252
 
3253
                        # no need to go further, implies we found the file!
3254
                        #
3255
                        last;
3256
                    }
3257
                    else
3258
                    {
3259
                        # here found the file but we had some trouble
3260
                        #
1534 dpurdie 3261
                        Error("Failed to copy lib [$m_srcFileLocation]: $!");
1530 dpurdie 3262
                    }
3263
 
3264
                }
3265
                # else have not found the file yet!
3266
            }
3267
        }
3268
 
3269
        # if we do not find the file at all we need to inform
3270
        # the user.
3271
        #
3272
        if ( "$foundFileFlag" eq "false" && $ExcludedFlag eq "false" )
3273
        {
1534 dpurdie 3274
            Error("Dpkg_archive lib file [$sfile] does not exist or is not in correct directory structure.");
1530 dpurdie 3275
        }
3276
    }
3277
 
3278
    return 1;
3279
}
3280
 
3281
 
3282
#------------------------------------------------------------------------------
3283
sub installPkgAddConfigFile
3284
#
3285
# Description:
3286
#       This sub-routine is used to install a package config file from a supplied
3287
#       source location to a predefined destination location that is based on
3288
#       the build type.
3289
#
3290
#       The sub routine also updates to the prototype file with an appropriate
3291
#       entry for the associated file.
1546 dpurdie 3292
# Inputs:
3293
#       sDirTag                 - Source directory tag
1554 dpurdie 3294
#                                 Or --Package=name,subdir
3295
#                                 Or --Interface=subdir
1546 dpurdie 3296
#       sfile                   - Source File Name [Mandatory]
3297
#       tfile                   - Not sure. Used in the prototype file.
3298
#                                 Suggest using the same name as sfile
1530 dpurdie 3299
#
3300
#       If it has any problems it will log an error and stop processing.
3301
#
3302
#------------------------------------------------------------------------------
3303
{
3304
    # correct number of parameters?
3305
    if ( ($#_+1) != 3 )
3306
    {
1534 dpurdie 3307
        Error("Incorrect number of params passed to " .
3308
              "installPkgAddConfigFile() function. " ,
3309
              "Check deploy config.");
1530 dpurdie 3310
    }
3311
 
3312
    # lets just check to see if we can execute this function on
3313
    # this machine.
3314
    #
3315
    if ( "$MachType" ne "sparc" )
3316
    {
1534 dpurdie 3317
        Verbose("installPkgAddConfigFile() not supported on this machine type.");
1530 dpurdie 3318
        return 1;
3319
    }
3320
 
3321
 
3322
    my ($sDirTag, $sfile, $tfile) = @_;
3323
 
3324
 
3325
    # we must have a filename.
3326
    #
1546 dpurdie 3327
    unless ( $sfile )
1530 dpurdie 3328
    {
1534 dpurdie 3329
        Error("Source filename not supplied. Check deploy config.");
1530 dpurdie 3330
    }
3331
 
3332
    # lets check to see if the local src dir tag exists
3333
    # if does not the process with log an error.
3334
    #
3335
    my ($sDirValue) = getLocalDirValue("$sDirTag", "A");
3336
 
3337
 
3338
    # lets check to see if the source file exists
3339
    #
3340
    if ( ! -f "$sDirValue/$sfile" )
3341
    {
1534 dpurdie 3342
        Error("Failed to find local source file [$sDirValue/$sfile].");
1530 dpurdie 3343
    }
3344
 
3345
    if ( ! -f "$ProtoTypeFile" )
3346
    {
1534 dpurdie 3347
        Error("Prototype file [$ProtoTypeFile] does not exist.",
3348
              "Ensure createPrototypeFile() function has been called before executing installPkgAddConfigFile() function.",
3349
              "Check deploy config.");
1530 dpurdie 3350
    }
3351
 
3352
 
3353
    # lets determine which prototype file we are going to
3354
    # use
3355
    my ($dFileName);
3356
    $dFileName     = "$PkgBaseDir/$sfile";
3357
 
3358
    # lets copy the file
3359
    #
3360
    if(File::Copy::copy("$sDirValue/$sfile", "$dFileName"))
3361
    {
1534 dpurdie 3362
        Verbose("Copied [$sfile] to [$dFileName] ...");
1530 dpurdie 3363
    }
3364
    else
3365
    {
1534 dpurdie 3366
        Error("Failed to copy local source file [$sDirValue/$sfile]: $!"); 
1530 dpurdie 3367
    }
3368
 
3369
 
3370
    # now we need to update the prototype file
3371
    #
3372
    local *FILE;
3373
    open ( FILE, ">> $ProtoTypeFile") or
1534 dpurdie 3374
        Error("Failed to open file [$ProtoTypeFile].");
1530 dpurdie 3375
    printf FILE ("i $tfile=$sfile\n");
3376
    close (FILE);
3377
 
3378
 
3379
    return 1;
3380
}
3381
 
3382
 
3383
#------------------------------------------------------------------------------
3384
sub installPkgAddSystemClassFile
3385
#
3386
# Description:
3387
#       This sub-routine is used to install a package system class file from a supplied
3388
#       source location to a predefined destination location the class type is also 
3389
#       supplied and must be sed, awk, build or preserve
3390
#
3391
#       The sub routine also updates to the prototype file with an appropriate
3392
#       entry for the associated file.
3393
#
3394
#       If it has any problems it will log an error and stop processing.
3395
#
1554 dpurdie 3396
# Inputs:
3397
#       sDirTag                 - Source directory tag
3398
#                                 Or --Package=name,subdir
3399
#                                 Or --Interface=subdir
3400
#       sfile                   - Source File Name [Mandatory]
3401
#       tfile                   - Not sure. Used in the prototype file.
3402
#                                 Suggest using the same name as sfile
3403
#       class                   - Class Name
1530 dpurdie 3404
#------------------------------------------------------------------------------
3405
{
3406
    # correct number of parameters?
3407
    if ( ($#_+1) != 4 )
3408
    {
1534 dpurdie 3409
        Error("Incorrect number of params passed to " .
3410
              "installPkgAddConfigFile() function. " ,
3411
              "Check deploy config.");
1530 dpurdie 3412
    }
3413
 
3414
    # lets just check to see if we can execute this function on
3415
    # this machine.
3416
    #
3417
    if ( "$MachType" ne "sparc" )
3418
    {
1534 dpurdie 3419
        Verbose("installPkgAddConfigFile() not supported on this machine type.");
1530 dpurdie 3420
        return 1;
3421
    }
3422
 
3423
 
3424
    my ($sDirTag, $sfile, $tfile, $class) = @_;
3425
 
3426
    if ( $class ne "sed" && $class ne "build" && $class ne "awk" && $class ne "preserve" )
3427
    {
1534 dpurdie 3428
        Error("Class Name for System Class File can only be one of sed, build, awk or preserve");
1530 dpurdie 3429
    }
3430
 
3431
    # we must have a filename.
3432
    #
3433
    if ( "x$sfile" eq "x" )
3434
    {
1534 dpurdie 3435
        Error("Source filename not supplied. Check deploy config.");
1530 dpurdie 3436
    }
3437
 
3438
 
3439
    # lets check to see if the local src dir tag exists
3440
    # if does not the process with log an error.
3441
    #
3442
    my ($sDirValue) = getLocalDirValue("$sDirTag", "A");
3443
 
3444
 
3445
    # lets check to see if the source file exists
3446
    #
3447
    if ( ! -f "$sDirValue/$sfile" )
3448
    {
1534 dpurdie 3449
        Error("Failed to find local source file [$sDirValue/$sfile].");
1530 dpurdie 3450
    }
3451
 
3452
    if ( ! -f "$ProtoTypeFile" )
3453
    {
1534 dpurdie 3454
        Error("Prototype file [$ProtoTypeFile] does not exist.",
3455
              "Ensure createPrototypeFile() function has been called before executing installPkgAddConfigFile() function.",
3456
              "Check deploy config.");
1530 dpurdie 3457
    }
3458
 
3459
 
3460
    # lets determine which prototype file we are going to
3461
    # use
3462
    my ($dFileName);
3463
    $dFileName     = "$PkgBaseDir/$sfile";
3464
 
3465
    # lets copy the file
3466
    #
3467
    if(File::Copy::copy("$sDirValue/$sfile", "$dFileName"))
3468
    {
1534 dpurdie 3469
        Verbose("Copied [$sfile] to [$dFileName] ...");
1530 dpurdie 3470
    }
3471
    else
3472
    {
1534 dpurdie 3473
        Error("Failed to copy local source file [$sDirValue/$sfile]: $!"); 
1530 dpurdie 3474
    }
3475
 
3476
 
3477
    # now we need to update the prototype file
3478
    #
3479
    local *FILE;
3480
    open ( FILE, ">> $ProtoTypeFile") or
1534 dpurdie 3481
        Error("Failed to open file [$ProtoTypeFile].");
1530 dpurdie 3482
    printf FILE ("e $class $tfile=$sfile ? ? ?\n");
3483
    close (FILE);
3484
 
3485
 
3486
    return 1;
3487
}
3488
 
3489
 
3490
 
3491
#------------------------------------------------------------------------------
3492
sub updatePrototypeFileAddItem
3493
#
3494
# Description:
3495
#       This sub-routine is used to update the prototype file with an
3496
#       extra package add item. Here we pre-pend the ERGAFC_BASEDIR to the
3497
#       destination item.
3498
#
3499
#       The only item type we support at this stage are "s" and "f" types.
3500
#
3501
#       You also need to supply the source tag, destination tag, user id, group id 
3502
#       and permissions associated to this item.
3503
#
3504
#       If it has any problems it will log an error and stop processing.
3505
#
3506
#------------------------------------------------------------------------------
3507
{
3508
    # correct number of parameters?
3509
    if ( ($#_+1) != 6 )
3510
    {
1534 dpurdie 3511
        Error("Incorrect number of params passed to " .
3512
              "updatePrototypeFileAddItem() function. " ,
3513
              "Check deploy config.");
1530 dpurdie 3514
    }
3515
 
3516
 
3517
    # lets just check to see if we can execute this function on
3518
    # this machine.
3519
    #
3520
    if ( "$MachType" ne "sparc" )
3521
    {
1534 dpurdie 3522
        Verbose("updatePrototypeFileAddItem() not supported on this machine type.");
1530 dpurdie 3523
        return 1;
3524
    }
3525
 
3526
    my ($sTag, $dTag, $perms, $uid, $gid, $type) = @_;
3527
 
3528
    # lets determine which prototype file we are going to
3529
    # use
3530
    my ($protoTypeFile);
3531
    $protoTypeFile = "$ProtoTypeFile";
3532
 
3533
 
3534
    # lets check the valid types
3535
    $type = uc($type);
3536
    if ( "$type" !~ /S/ )
3537
    {
1534 dpurdie 3538
        Error("Invalid type field supplied in updatePrototypeFileAddItem(). Check deploy config.");
1530 dpurdie 3539
    }
3540
 
3541
    # now we need to update the prototype file
3542
    #
3543
    local *FILE;
3544
    open ( FILE, ">> $protoTypeFile") or
1534 dpurdie 3545
        Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 3546
 
3547
    my($m_Str)=""; 
3548
    if ( "$type" eq "S" )
3549
    {
3550
        $m_Str = "s none $sTag=$ERGAFC_BASEDIR/$dTag $perms $uid $gid";
1534 dpurdie 3551
        Verbose("Updated prototype file with entry [$m_Str]");
1530 dpurdie 3552
    }
3553
    else
3554
    {
3555
        $m_Str = "f none $sTag=$ERGAFC_BASEDIR/$dTag $perms $uid $gid";
1534 dpurdie 3556
        Verbose("Updated prototype file with entry [$m_Str]");
1530 dpurdie 3557
    }
3558
    printf FILE ("$m_Str\n");
3559
    close (FILE);
3560
 
3561
    return 1;
3562
}
3563
 
3564
 
3565
#------------------------------------------------------------------------------
3566
sub updatePrototypeFileAddItem2
3567
#
3568
# Description:
3569
#       This sub-routine is used to update the prototype file with an
3570
#       extra package add item. Here we do not pre-append the 
3571
#       ERGAFC_BASEDIR to the destination item.
3572
#
3573
#       The only item type we support at this stage are "s", "i" and "e" types.
3574
#
3575
#       You also need to supply the source tag, destination tag, user id, group id 
3576
#       and permissions associated to this item.
3577
#
3578
#       If it has any problems it will log an error and stop processing.
3579
#
3580
#------------------------------------------------------------------------------
3581
{
3582
    # correct number of parameters?
3583
    if ( ($#_+1) != 6 && ($#_+1) != 7 )
3584
    {
1534 dpurdie 3585
        Error("Incorrect number of params passed to " .
3586
              "updatePrototypeFileAddItem2() function. " ,
3587
              "Check deploy config.");
1530 dpurdie 3588
    }
3589
 
3590
 
3591
    # lets just check to see if we can execute this function on
3592
    # this machine.
3593
    #
3594
    if ( "$MachType" ne "sparc" )
3595
    {
1534 dpurdie 3596
        Verbose("updatePrototypeFileAddItem2() not supported on this machine type.");
1530 dpurdie 3597
        return 1;
3598
    }
3599
 
3600
    # class must be last as it is optional
3601
    my ($sTag, $dTag, $perms, $uid, $gid, $type, $class) = @_;
3602
 
3603
    $class = "none" if ( ($#_+1) == 6 );
3604
 
3605
    # lets determine which prototype file we are going to
3606
    # use
3607
    my ($protoTypeFile);
3608
    $protoTypeFile = "$ProtoTypeFile";
3609
 
3610
    # lets check the valid types
3611
    $type = uc($type);
3612
    if ( "$type" !~ /S/ && "$type" !~ /I/ && "$type" !~ /E/ )
3613
    {
1534 dpurdie 3614
        Error("Invalid type field supplied in updatePrototypeFileAddItem2(). Check deploy config.");
1530 dpurdie 3615
    }
3616
 
3617
    # now we need to update the prototype file
3618
    #
3619
    local *FILE;
3620
    open ( FILE, ">> $protoTypeFile") or
1534 dpurdie 3621
        Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 3622
 
3623
    my($m_Str)="";
3624
    if ( "$type" eq "S" )
3625
    {
3626
        $m_Str = "s $class $sTag=$dTag $perms $uid $gid";
1534 dpurdie 3627
        Verbose("Updated prototype file with entry [$m_Str]");
1530 dpurdie 3628
    }
3629
    elsif ( "$type" eq "E" )
3630
    {
3631
        $m_Str = "e $class $sTag=$dTag $perms $uid $gid";
1534 dpurdie 3632
        Verbose("Updated prototype file with entry [$m_Str]");
1530 dpurdie 3633
    }
3634
    else
3635
    {
3636
        $m_Str = "i $sTag=$dTag";
1534 dpurdie 3637
        Verbose("Updated prototype file with entry [$m_Str]");
1530 dpurdie 3638
    }
3639
    printf FILE ("$m_Str\n");
3640
    close (FILE);
3641
 
3642
    return 1;
3643
}
3644
 
3645
 
3646
#------------------------------------------------------------------------------
3647
sub addPath2Prototype
3648
#
3649
# Description:
3650
#       This sub-routine is used to add directory entries to the prototype file
3651
#   to make sure the supplied path exists in the prototype file
3652
#
3653
#------------------------------------------------------------------------------
3654
{
3655
    # lets just check to see if we can execute this function on
3656
    # this machine.
3657
    #
3658
    if ( "$MachType" ne "sparc" )
3659
    {
1534 dpurdie 3660
        Verbose("addPath2Prototype() not supported on this machine type.");
1530 dpurdie 3661
        return 1;
3662
    }
3663
 
3664
    # class must be last as it is optional
3665
    my ($path, $perms, $uid, $gid, $class) = @_;
3666
 
3667
    # set defaults if not supplied
3668
    $perms  = "?"       if ( ($#_+1) < 2 );
3669
    $uid    = "?"       if ( ($#_+1) < 3 );
3670
    $gid    = "?"       if ( ($#_+1) < 4 );
3671
    $class  = "none"    if ( ($#_+1) < 5 );
3672
 
1534 dpurdie 3673
    Information("addPathToPrototype adding path [$path $perms $uid $gid $class]");
1530 dpurdie 3674
 
3675
    # lets determine which prototype file we are going to
3676
    # use
3677
    my ($protoTypeFile);
3678
    $protoTypeFile = "$ProtoTypeFile";
3679
 
3680
    # now we need to update the prototype file
3681
    #
3682
    local *FILE;
1534 dpurdie 3683
    open ( FILE, "+<$protoTypeFile") or Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 3684
 
3685
    # set up has of all paths to be added
3686
    my ( %pathDirs );
3687
    my ( $workPath );
3688
    my ( $i );
3689
 
3690
    $workPath = "/" if ( $path =~ s|^/|| );
3691
    foreach $i ( split("/" , $path) )
3692
    {
3693
        $workPath .= $i;
3694
        $pathDirs{$workPath} = 1;
3695
        $workPath .= "/";
3696
    }
3697
 
3698
    while ( <FILE> )
3699
    {
3700
        # lets get all the current dir entries and check for duplicates
3701
        #        class   path    mode    owner   group
3702
        if ( /^d ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)/ )
3703
        {
3704
            # if this dir entry is defined in our paths to add we need to remove the entry
3705
            if ( defined($pathDirs{$2}) )
3706
            {
1534 dpurdie 3707
                Warning("addPath2Prototype: Path [$2] already exists in prototype file");
1530 dpurdie 3708
                delete($pathDirs{$2});
3709
            }
3710
        }
3711
    }
3712
 
3713
    my $protoLine;
3714
    # now we write the remaining dirs in the hash 
3715
    foreach $i ( sort keys(%pathDirs) )
3716
    {
3717
        $protoLine = sprintf("d %s %s %s %s %s", $class, $i, $perms, $uid, $gid);
1534 dpurdie 3718
        Verbose("addPath2Prototype: Adding Dir entry [$protoLine]");
1530 dpurdie 3719
        printf FILE "$protoLine\n"; 
3720
    }
3721
 
3722
    close FILE;
3723
    return 1;
3724
}
3725
 
3726
 
3727
#------------------------------------------------------------------------------
3728
sub createAfcRcScriptLink
3729
#
3730
#    Description:
3731
#        This sub-routine is used to create links into /afc/rc.d for start & stop 
3732
#         scripts.
3733
#
3734
#    INPUT:
3735
#        Start prefix number (2 digit number)
3736
#        Stop prefix Number (2 digit Number)
3737
#        Full path to script to create link to.
3738
#
3739
#------------------------------------------------------------------------------
3740
{
3741
    # correct number of parameters?
3742
    if ( ($#_+1) != 3 )
3743
    {
1534 dpurdie 3744
        Error("Incorrect number of params passed to " .
3745
              "createAfcRcScriptLink() function. " ,
3746
              "Check deploy config.");
1530 dpurdie 3747
    }
3748
 
3749
 
3750
    # lets just check to see if we can execute this function on
3751
    # this machine.
3752
    #
3753
    if ( "$MachType" ne "sparc" )
3754
    {
1534 dpurdie 3755
        Verbose("createAfcRcScriptLink() not supported on this machine type.");
1530 dpurdie 3756
        return 1;
3757
    }
3758
 
3759
    my ($startPrefix, $stopPrefix, $scriptPath) = @_;
3760
 
3761
    if ( $startPrefix ne "" )
3762
    {
3763
        updatePrototypeFileAddItem2(sprintf("/afc/rc.d/S%02d%s", $startPrefix, $PkgName), 
3764
                                    $scriptPath, "0755", "root", "other", "S");
3765
    }
3766
    if ( $stopPrefix ne "" )
3767
    {
3768
        updatePrototypeFileAddItem2(sprintf("/afc/rc.d/K%02d%s", $stopPrefix, $PkgName), 
3769
                                    $scriptPath, "0755", "root", "other", "S");        
3770
    }
3771
}
3772
 
3773
 
3774
#------------------------------------------------------------------------------
3775
sub createAfcRcScriptLink2
3776
#
3777
#    Description:
3778
#        This sub-routine is used to create links into the afc rc.d for start & stop 
3779
#        scripts.  It differs from the original in that you pass a TargetDirType
3780
#        parameter and the filename instead of a full path.  It then creates a relative
3781
#        link from $BASEDIR/rc.d to TargetBaseDir
3782
#
3783
#    INPUT:
3784
#        Start prefix number (2 digit number)
3785
#        Stop prefix Number (2 digit Number)
3786
#        Full path to script to create link to.
3787
#
3788
#------------------------------------------------------------------------------
3789
{
3790
    # correct number of parameters?
3791
    if ( ($#_+1) != 4 )
3792
    {
1534 dpurdie 3793
        Error("Incorrect number of params passed to " .
3794
              "createAfcRcScriptLink() function. " ,
3795
              "Check deploy config.");
1530 dpurdie 3796
    }
3797
 
3798
 
3799
    # lets just check to see if we can execute this function on
3800
    # this machine.
3801
    #
3802
    if ( "$MachType" ne "sparc" )
3803
    {
1534 dpurdie 3804
        Verbose("createAfcRcScriptLink() not supported on this machine type.");
1530 dpurdie 3805
        return 1;
3806
    }
3807
 
3808
    my ($startPrefix, $stopPrefix, $targetTag, $scriptPath) = @_;
3809
 
3810
    # lets check to see if the target tag exists if does not the process with log an error.
3811
    my ($targetValue) = getTargetDstDirValue($targetTag, "R");
3812
 
3813
    if ( $startPrefix ne "" )
3814
    {
3815
        updatePrototypeFileAddItem2(sprintf("rc.d/S%02d%s", $startPrefix, $PkgName), 
3816
                                    "../$targetValue/$scriptPath", "0755", "root", "other", "S");
3817
    }
3818
    if ( $stopPrefix ne "" )
3819
    {
3820
        updatePrototypeFileAddItem2(sprintf("rc.d/K%02d%s", $stopPrefix, $PkgName), 
3821
                                    "../$targetValue/$scriptPath", "0755", "root", "other", "S");        
3822
    }
3823
}
3824
 
3825
 
3826
#------------------------------------------------------------------------------
3827
sub createGenericCopy
3828
#
3829
#    Description:
3830
#        This sub-routine is used to create a generic copy of a specific item.
3831
#
3832
#        On sparc this will be a link, but on win32 it will be a file based on the
3833
#        buildType.
3834
#
3835
#    INPUT:
1556 lkelly 3836
#        sName = src item name without path
3837
#        sLoc = src item name including path
3838
#        gName = generic item name
3839
#        tDir = target dir
1530 dpurdie 3840
#
3841
#    RETURN:
3842
#         1
3843
#
3844
#------------------------------------------------------------------------------
3845
{
3846
    my ($sName, $sLoc, $gName, $tDir) = @_;
3847
 
3848
    my ($cmd);
3849
    my ($retVal);
3850
    if ( "$MachType" eq "sparc" )
3851
    {
3852
        # I want to cd into the tDir and then create the link.
3853
        # only if an item of the same name does not already exist
3854
        #
3855
        if ( ! -f "$tDir/$gName" )
3856
        {
3857
            $cmd = "cd $tDir; ln -s $sName $gName";
3858
            $retVal = system("$cmd");
3859
            if ( $retVal != 0 )
3860
            {
1534 dpurdie 3861
                Error("Failed to create generic link [$gName] to [$tDir/$sName]: $retVal");
1530 dpurdie 3862
            }
3863
            else
3864
            {
1534 dpurdie 3865
                Verbose("Created generic link [$gName] to [$tDir/$sName] ...");
1530 dpurdie 3866
            }
3867
        }
3868
    }
3869
    else
3870
    {
3871
 
3872
        # we only create a generic copy of the an item that matches
3873
        # our build type.  (i.e. if we are building a debug package then
3874
        # only the debug items shall be considered.
3875
        #
3876
        if ( "$BuildType" eq "D" )
3877
        {
3878
            if ( $sName !~ /D\./ )
3879
            {
3880
                # this item is not a debug one.
3881
                return 1;
3882
            }
3883
        }
3884
        else
3885
        {
3886
            # this is prod build
3887
            if ( $sName !~ /P\./ )
3888
            {
3889
                # this item is not a prod one.
3890
                return 1;
3891
            }
3892
        }
3893
 
3894
 
3895
        # we have a match, lets create the copy.
3896
        #
3897
        if(File::Copy::copy("$sLoc", "$tDir/$gName"))
3898
        {
1534 dpurdie 3899
            Verbose("Created generic lib copy [$tDir/$gName]...");
1530 dpurdie 3900
        }
3901
        else
3902
        {
1534 dpurdie 3903
            Error("Failed to create generic lib copy [$gName] from [$sLoc]: $!");
1530 dpurdie 3904
        }
3905
    }
3906
 
3907
    return 1;
3908
}
3909
 
3910
 
3911
 
3912
#------------------------------------------------------------------------------
3913
sub removeVersionNumberFromItemName
3914
#
3915
#    Description:
3916
#        This sub-routine is used to remove the version number from the item name.
3917
#        i.e.  myFile.so.1.2.3 ==> myFile.so
3918
#
3919
#    INPUT:
3920
#        item name
3921
#
3922
#    RETURN:
3923
#        new item name.
3924
#
3925
#------------------------------------------------------------------------------
3926
{
3927
    my ($file) = @_;
3928
 
3929
    my ($nfile) = $file;
3930
 
3931
    if ( "$MachType" eq "sparc" )
3932
    {
3933
        $nfile =~ s/\.so.*$/\.so/;
3934
    }
3935
    else
3936
    {
3937
        $nfile =~ s/\.[0-9]+\.[0-9]+.*dll$/\.dll/;
3938
    }
3939
    return "$nfile";
3940
}
3941
 
3942
 
3943
#------------------------------------------------------------------------------
3944
sub excludeItemFromBuild
3945
#
3946
#    Description:
3947
#        This sub-routine is used to determine is a item is to be included in
3948
#        a build based on the current build type and the extension 
3949
#        it SHOULD HAVE!.
3950
#
3951
#        i.e. debug files will be tagged with *D.* 
3952
#             prod  file will be tagged with *P.*
3953
#
3954
#        if the item does not have a *D.* or a *P.* we included it by default.
3955
#
3956
#        INPUT:
3957
#              filename
3958
#
3959
#        RETURN: 
3960
#              1  - exclude 
3961
#              0  - include 
3962
#
3963
#------------------------------------------------------------------------------
3964
{
3965
    my ($file) = @_;
3966
 
3967
    # we only want to deliver
3968
    if ( "$MachType" eq "win32" )
3969
    {
3970
        # we have to include it by default.
3971
        return 0;
3972
    }
3973
 
3974
 
3975
    #######################################################
3976
    #######################################################
3977
    #######################################################
3978
    # Third party packages do not adhere to the *D.* *P.*
3979
    # conventions of debug and production builds.
3980
    #
3981
    # Hopefully we won't have to many of these, only found 
3982
    # one so far.
3983
    # 
3984
    #######################################################
3985
    #######################################################
3986
    #######################################################
3987
    if ( $file =~ /libTAO_BiDirGIOP\.so/ )
3988
    {
3989
        return 0;
3990
    } 
3991
 
3992
    if ( $file !~ /D\./ &&
3993
         $file !~ /P\./
3994
       )
3995
    {
3996
        # we have to include it by default. 
3997
        return 0;
3998
    }
3999
 
4000
 
4001
    # we only want to deliver 
4002
    if ( "$BuildType" eq "D" )
4003
    { 
4004
        if ( $file !~ /D\./ )
4005
        {
4006
            # we do not want this file for this build type.
4007
            return 1;
4008
        }
4009
        else
4010
        {
4011
            return 0;
4012
        }
4013
    }
4014
    else
4015
    {
4016
        if ( $file !~ /P\./ )
4017
        {
4018
            # we do not want this file for this build type.
4019
            return 1;
4020
        }
4021
        else
4022
        {
4023
            return 0;
4024
        }
4025
    }
4026
 
4027
    return 1;
4028
}
4029
 
4030
 
4031
#------------------------------------------------------------------------------
4032
sub installAllDpkgArchiveBinFiles
4033
#
4034
# Description:
4035
#       This sub-routine is used to install all bin files from the
4036
#       dpkg_archive into the defined install area.
4037
#
4038
#       It assumes based on the build type where the src files will be located.
4039
#
4040
#       If it has any problems it will log an error and stop processing.
4041
#
4042
#------------------------------------------------------------------------------
4043
{
4044
    # correct number of parameters?
4045
    if ( ($#_+1) != 1 )
4046
    {
1534 dpurdie 4047
        Error("Incorrect number of params passed to " .
4048
              "installAllDpkgArchiveBinFiles() function. " ,
4049
              "Check deploy config.");
1530 dpurdie 4050
    }
4051
 
4052
    my ($targetTag) = @_;
4053
 
4054
    # lets check to see if the target tag exists
4055
    # if does not the process with log an error.
4056
    #
4057
    my ($targetValue) = getTargetDstDirValue($targetTag, "A");
4058
 
4059
 
4060
    # ok we have a valid dst value we now need to get a hold of all the 
4061
    # lib files for this buildtype
4062
    #
4063
    my ($i);
4064
    my ($m_DpkgBinDir);
4065
    foreach $i (@{$DpkgBinDirList{'_ALL_'}})
4066
    {
1534 dpurdie 4067
        $m_DpkgBinDir = "$DpkgBinDir/$i";
4068
        if ( ! -d $m_DpkgBinDir )
1530 dpurdie 4069
        {
1534 dpurdie 4070
            Verbose("Directory [$m_DpkgBinDir] not found.");
1530 dpurdie 4071
            next;
4072
        }
4073
 
4074
        local *DIR;
4075
        opendir(DIR, $m_DpkgBinDir) or 
1534 dpurdie 4076
            Error("can't opendir $m_DpkgBinDir : $!");
1530 dpurdie 4077
 
4078
        my ($file);
4079
        while (defined($file = readdir(DIR))) 
4080
        {
4081
            if ( $file !~ /^\.$/  &&     # we do not want the . and .. entries.
4082
                 $file !~ /^\.\.$/ &&
4083
                 $file !~ /\.pdb$/ )
4084
            {
4085
                my ($m_fLoc) = "$m_DpkgBinDir/$file"; 
4086
                if(File::Copy::copy("$m_fLoc", "$targetValue"))
4087
                {
1534 dpurdie 4088
                    Verbose("Copied [$file] to [$targetValue] ...");
1530 dpurdie 4089
                }
4090
                else
4091
                {
1534 dpurdie 4092
                    Error("Failed to copy bin [$m_fLoc]: $!"); 
1530 dpurdie 4093
                }
4094
            }
4095
        }
4096
        closedir(DIR);
4097
    }
4098
 
4099
    return 1;
4100
}
4101
 
4102
 
4103
#------------------------------------------------------------------------------
4104
sub rmDirectory
4105
#
4106
# Description:
4107
#       This sub-routine is used to remove an entire directory tree.
4108
#
4109
#       It recurses from a starting point removing each item and if it
4110
#       finds a dir it recurses into that dir cleaning it as well.
4111
#
4112
#------------------------------------------------------------------------------
4113
{
4114
    # correct number of parameters?
4115
    if ( ($#_+1) != 1  )
4116
    {
1534 dpurdie 4117
        Error("Incorrect number of params passed to rmDirectory() function.");
1530 dpurdie 4118
    }
4119
 
4120
    my ($startingPoint) = @_;
1548 dpurdie 4121
    return 0 unless ( -d $startingPoint );
1534 dpurdie 4122
    Verbose("Recursively removing Directory tree [$startingPoint]");
1530 dpurdie 4123
 
4124
    #
1542 dpurdie 4125
    #   Use the rmtree function
4126
    #   It works better than glob when given a filepath with spaces
4127
    #
4128
    rmtree($startingPoint, IsVerbose(1), 1);
4129
    Error("Failed to remove dir [$startingPoint] : $!") if (-d $startingPoint);
4130
 
1530 dpurdie 4131
    return 1;
4132
}
4133
 
4134
#------------------------------------------------------------------------------
4135
sub CreateTargetDirStructure
4136
#
4137
# Description:
4138
#       This sub-routine create the target stucture based on what the user has
4139
#       previously defined in the %TargetDstDirStructure hash array
4140
#
4141
#       It will also clean the contents of this location prior to creation.
4142
#
4143
#       In this function we also check to see if all the LocalSrcDirStructure
4144
#       directories exist. We warn if they do not.
4145
#
4146
#------------------------------------------------------------------------------
4147
{
1534 dpurdie 4148
    Information("Cleaning any previous target file items...");
1530 dpurdie 4149
 
4150
    my ($i);
1570 gchristi 4151
    my $dirRoot;
1554 dpurdie 4152
    #   Clean out PkgBaseDir
4153
    #   This is the directory in which the final package image will be assembled
4154
    #   Recreate the directory. Ensure that it does not have setgid on the directory
4155
    #   as this will affect all the subdirectories that are created and will
4156
    #   propergate into the target package.
1530 dpurdie 4157
    #
1554 dpurdie 4158
    rmDirectory( $PkgBaseDir );
4159
    make_directory( $PkgDir, 0777, "Create target base dir");
1530 dpurdie 4160
 
4161
    # lets create.
4162
    #
1534 dpurdie 4163
    Information ("Creating target directory structure...");
1570 gchristi 4164
 
4165
    $dirRoot = ($TargetBaseDir ne ".") ? "$PkgBaseDir/$TargetBaseDir" : $PkgBaseDir;
4166
    make_directory( $dirRoot, 0777, "Create target dir");
4167
 
1530 dpurdie 4168
    foreach $i ( sort {$a cmp $b} values %TargetDstDirStructure )
4169
    {
1570 gchristi 4170
        make_directory("$dirRoot/$i", 0777);
1530 dpurdie 4171
    }
4172
 
4173
 
4174
    # lets determine if we have a InstallShield config dir
4175
    #
4176
    if ( "$MachType" eq "win32" || "$MachType" eq "WinCE" )
4177
    {
4178
 
4179
        # if this is a patch build i expect to find a "p" in the front of the
4180
        # file names. we use this as a simple visual differentiation.
4181
        #
4182
        my ($m_ishieldDir);    
4183
        my ($m_ishieldProjFile);
4184
        if ( "x$PkgPatchNum" ne "x" )
4185
        {
4186
            # patch build.
4187
            $m_ishieldDir      = "$RootDir/" . "p$PkgName";
4188
            $m_ishieldProjFile = "$RootDir/" . "p$PkgName" . ".ism";
4189
        }
4190
        else
4191
        {
4192
            # normal build.
4193
            $m_ishieldDir      = "$RootDir/" . "$PkgName";
4194
            $m_ishieldProjFile = "$RootDir/" . "$PkgName" . ".ism";
4195
        }
4196
 
4197
        # here i can set the location of my IShield project dir
4198
        # so i can use it later if required.
4199
        $PKG_ISHIELD_DIR = $m_ishieldDir;
4200
 
4201
 
4202
        # we check for an ism file based on the pkg name
4203
        # if we find one we need to deal with the dir and
4204
        # the isheildlib files.
4205
        #
4206
        if ( -f "$m_ishieldProjFile" )
4207
        {
4208
            if ( ! -d "$m_ishieldDir" )
4209
            {
1534 dpurdie 4210
                Error ("Local InstallShield config dir [$m_ishieldDir] does not exist.",
4211
                       "Please create before continuing.");
1530 dpurdie 4212
            }
4213
            else
4214
            {
4215
                # we populate the ishield config dir with the ishieldlib files
4216
                #
4217
                my ($i);
1534 dpurdie 4218
                Verbose("Installing Standard ishieldlib files from [$PKG_UTIL_DIR] to [$m_ishieldDir]");
1530 dpurdie 4219
                foreach $i ( @PKG_ISHIELD_FILES )
4220
                {
4221
                    # first we remove the file (as previously it install read-only).
4222
                    unlink("$m_ishieldDir/$i");
4223
                    if( File::Copy::copy("$PKG_UTIL_DIR/$i", "$m_ishieldDir") )
4224
                    {
1534 dpurdie 4225
                        Verbose("Copied [$PKG_UTIL_DIR/$i] to [$m_ishieldDir] ...");
1530 dpurdie 4226
                    }
4227
                    else
4228
                    {
1534 dpurdie 4229
                        Error("Failed to copy info file [$PKG_UTIL_DIR/$i] to [$m_ishieldDir] : $!");
1530 dpurdie 4230
                    }
4231
                }
4232
 
4233
 
4234
                # we also want to deliver the patch rule files
4235
                # if this build is a patch build.
4236
                #
4237
                if ( "x$PkgPatchNum" ne "x" )
4238
                {
1534 dpurdie 4239
                    Verbose("Installing Patch ishieldlib files from [$PKG_UTIL_DIR] to [$m_ishieldDir]");
1530 dpurdie 4240
                    foreach $i ( @PATCH_ISHIELD_FILES )
4241
                    {
4242
                        # first we remove the file (as previously it install read-only).
4243
                        unlink("$m_ishieldDir/$i");
4244
                        if( File::Copy::copy("$PKG_UTIL_DIR/$i", "$m_ishieldDir") )
4245
                        {
1534 dpurdie 4246
                            Verbose("Copied [$PKG_UTIL_DIR/$i] to [$m_ishieldDir] ...");
1530 dpurdie 4247
                        }
4248
                        else
4249
                        {
1534 dpurdie 4250
                            Error("Failed to copy info file [$PKG_UTIL_DIR/$i] to [$m_ishieldDir] : $!");
1530 dpurdie 4251
                        }
4252
                    }
4253
                }
4254
 
4255
 
4256
                # we also want to deliver the islib imgages to be
4257
                # used by this project, we assume the image has a project
4258
                # acronym prefix, and if not found we just WARN the user
4259
                #
4260
                # we assume our source dir is the interface/etc dir and our
4261
                # dst dir is the PkgBaseDir
4262
                #
4263
                my ($m_islibImgFile) = "";
1534 dpurdie 4264
                Verbose("Installing ishield image files from [$DpkgEtcDir] to [$m_ishieldDir]");
1530 dpurdie 4265
                foreach $i ( @PKG_ISHIELD_IMG_FILES )
4266
                {
4267
                    $m_islibImgFile = "$DpkgEtcDir/$ProjectAcronym" . "_" . $i;
4268
                    if ( -f "$m_islibImgFile" )
4269
                    {
4270
                        if( File::Copy::copy("$m_islibImgFile", "$PkgBaseDir") )
4271
                        {
1534 dpurdie 4272
                            Verbose("Copied [$m_islibImgFile] to [$PkgBaseDir] ...");
1530 dpurdie 4273
                        }
4274
                        else
4275
                        {
1534 dpurdie 4276
                            Error("Failed to copy info file [$m_islibImgFile] to " .
1530 dpurdie 4277
                                     "[$PkgBaseDir] : $!");
4278
                        }
4279
                    }
4280
                    else
4281
                    {
4282
                        # we shall check for the MASS items, if the exist we copy them
4283
                        # over. Here we assume the 'mas' acronymn is correct.
4284
                        #
4285
                        $m_islibImgFile = "$DpkgEtcDir/mas" . "_" . $i;
4286
                        if ( -f "$m_islibImgFile" )
4287
                        {
4288
                            if( File::Copy::copy("$m_islibImgFile", "$PkgBaseDir") )
4289
                            {
1534 dpurdie 4290
                                Verbose("Copied [$m_islibImgFile] to [$PkgBaseDir] ...");
1530 dpurdie 4291
                            }
4292
                            else
4293
                            {
1534 dpurdie 4294
                                Error("Failed to copy info file [$m_islibImgFile] to " .
1530 dpurdie 4295
                                         "[$PkgBaseDir] : $!");
4296
                            } 
4297
                        } 
4298
                        else
4299
                        {
1534 dpurdie 4300
                            Warning("Failed to locate ishieldlib image [xxx_$i], no image copied, " .
1530 dpurdie 4301
                                    "check depolylib config.");
4302
                        }
4303
                    }
4304
                }
4305
 
4306
            }
4307
        }
4308
        else
4309
        {
1534 dpurdie 4310
            Warning("Did not detect InstallShield project file [$m_ishieldProjFile]");
4311
            Warning("Not installing InstallShield library files.");
1530 dpurdie 4312
        }
4313
    }
4314
 
4315
    # done.
4316
    return 1;
4317
}
4318
 
4319
#------------------------------------------------------------------------------
4320
sub generateIShieldIncludeFile ()
4321
#
4322
# Description:
4323
#     This subroutine is used to generate a definition include file 
4324
#     that is used during IShield builds.
4325
#
4326
#     The output location of the file is the IShieldProjDir.
4327
#    
4328
#------------------------------------------------------------------------------
4329
{
4330
    my ($outFile) = "$PKG_ISHIELD_DIR/$PKG_ISHIELD_DEF_FILE";
4331
 
4332
    # this is only relavent for win32 builds.
4333
    if ( "$MachType" eq "sparc" )
4334
    {
4335
        return 1;
4336
    }
4337
 
4338
    # lets open the file.
4339
    #
4340
    local *FILE;
4341
    open ( FILE, "> $outFile") or
1534 dpurdie 4342
        Error("Failed to open file [$outFile].");
1530 dpurdie 4343
 
4344
    # lets populate the pkgdef file.
4345
 
4346
    printf FILE ("// This is an automatically generated include file.\n");
4347
    printf FILE ("// Please do not modify, and please do not check into ClearCase.\n");
4348
    printf FILE ("//\n");
4349
    printf FILE ("#define PKG_NAME         \"$PkgName\"\n");
4350
    printf FILE ("#define PKG_NAMELONG     \"$PkgNameLong\"\n");
4351
    printf FILE ("#define PKG_VERSION      \"$PkgVersion\"\n");
4352
    printf FILE ("#define PKG_BUILDNUM     \"$PkgBuildNum\"\n");
4353
    printf FILE ("#define PKG_PROJACRONYM  \"$ProjectAcronym\"\n");
4354
    printf FILE ("#define PKG_DESC         \"$PkgDesc\"\n");
4355
 
4356
    # if this build is a patch build.
4357
    #
4358
    if ( "x$PkgPatchNum" ne "x" )
4359
    {
4360
        printf FILE ("#define PATCH_NAME       \"$PkgPatchName\"\n");
4361
        printf FILE ("#define PATCH_NUM        \"$PkgPatchNum\"\n");
4362
        printf FILE ("#define PATCH_ID         \"$PkgPatchID\"\n");
4363
    }
4364
    else
4365
    {
4366
        printf FILE ("#define PATCH_NAME       \"\"\n");
4367
        printf FILE ("#define PATCH_NUM        \"\"\n");
4368
        printf FILE ("#define PATCH_ID         \"\"\n");
4369
    }
4370
 
4371
    # lets close the file
4372
    close FILE;
4373
 
4374
    # done.
4375
    return 1;
4376
}
4377
 
4378
 
4379
#------------------------------------------------------------------------------
4380
sub ValidateLocalSrcDirStructure
4381
#
4382
# Description:
4383
#       This sub-routine is used to check the existence the local dir 
4384
#       configuration items, these are stored in 
4385
#       %LocalSrcDirStructure.
4386
#
4387
#------------------------------------------------------------------------------
4388
{
4389
    # lets check the configured local direcotry structure
4390
    #
4391
    my ($i);
4392
    foreach $i ( values %LocalSrcDirStructure )
4393
    {
4394
        my ($m_Dir) = "$SrcDir/$i";
4395
        if ( ! -d "$m_Dir" )
4396
        {
1534 dpurdie 4397
            Warning ("Local src dir [$m_Dir] does not exist.");
1530 dpurdie 4398
        }
4399
    }
4400
 
4401
    return 1;
4402
}
4403
 
4404
 
4405
#------------------------------------------------------------------------------
4406
sub getLocalDirValue
4407
#
4408
# Description:
4409
#       This sub-routine is used to return the local dir value from
4410
#       %LocalSrcDirStructure based on providing the 
4411
#       associated key.
4412
#
1546 dpurdie 4413
#
4414
# Input:
4415
#       m_key               - A symbolic directory name to be found in the
4416
#                             LocalSrcDirStructure
4417
#
4418
#                             A Package Name of the form
4419
#                             --Package=PackageName,subdir
4420
#
4421
#                             A directory within the interface directory
4422
#                             --Interface=subdir
4423
#
4424
#                             This form is only valid for an ABS address
4425
#
4426
#       m_type              - "A"   Absolute address
4427
#                             else  Relative address
4428
#
1530 dpurdie 4429
#       If the value does not exist then it will return an error
4430
#       and terminate processing.
4431
#
4432
#------------------------------------------------------------------------------
4433
{
4434
    # correct number of parameters?
4435
    if ( ($#_+1) != 2 ) 
4436
    {
1534 dpurdie 4437
        Error("Incorrect number of params passed to " .
1530 dpurdie 4438
                  "getLocalDirValue() function.");
4439
    }
4440
 
4441
    my ($m_key, $m_type) = @_;
1546 dpurdie 4442
 
4443
    #
4444
    #   Determine the type of lookup
4445
    #
4446
    if ( $m_key =~ m~^--Interface=(.*)~ )
1530 dpurdie 4447
    {
1546 dpurdie 4448
        Error("Locating Interface directory must be used in conjunction with an Absolute path")
4449
            unless ( $m_type eq 'A' );
4450
 
4451
        my $SubDir = $1;
4452
        my $Dir = "$InterfaceDir/$SubDir";
4453
        Error ("Interface subdirectory not found: $SubDir" )
4454
            unless ( -d $Dir );
4455
        return $Dir;
4456
    }
4457
 
4458
    if ( $m_key =~ m~^--Package=(.*)~ )
4459
    {
4460
        Error("Locating local source directory must be used in conjunction with an Absolute path")
4461
            unless ( $m_type eq 'A' );
4462
 
4463
        #
4464
        #   Locate directory within a package
4465
        #
4466
        my ($PkgName, $PkgSubDir) = split /[\/,]/, $1, 2;
4467
        Error ("--Package requres a package name and a subdirectory") unless ( $PkgName && $PkgSubDir );
4468
        my $PkgDir = LocatePackageBase( "getLocalDirValue", $PkgName, $PkgSubDir );
4469
        return $PkgDir;
4470
    }
4471
 
4472
    #
4473
    #   Locate the directory within the LocalSrcDirStructure
4474
    #   This is a symbolic reference to a local directory
4475
    #
4476
    if (exists  $LocalSrcDirStructure{$m_key} )
4477
    {
1530 dpurdie 4478
        if ( "$m_type" eq "A" )
4479
        {
1546 dpurdie 4480
            return "$SrcDir/$LocalSrcDirStructure{$m_key}";
1530 dpurdie 4481
        }
4482
        else
4483
        {
4484
            return "$LocalSrcDirStructure{$m_key}";
4485
        }
4486
    }
4487
    else
4488
    {
1534 dpurdie 4489
        Error("Local src tag [$m_key] does not exist in " .
4490
             "LocalSrcDirStructure. " ,
4491
             "Check deploy configuration.");
1530 dpurdie 4492
    }
4493
 
4494
    return 1;
4495
}
4496
 
4497
 
4498
#------------------------------------------------------------------------------
4499
sub getTargetDstDirValue
4500
#
4501
# Description:
4502
#       This sub-routine is used to return the target dest dir value from
4503
#       %TargetDstDirStructure based on providing the 
4504
#       associated key.
4505
#
4506
#       If the value does not exist then it will return an error
4507
#       and terminate processing.
4508
#
1532 dpurdie 4509
# Inputs:   $m_key          Symbolic name for target directory
4510
#           $m_type         Type : A    - Absolute
4511
#                                  R    - Relative
4512
#
1530 dpurdie 4513
#------------------------------------------------------------------------------
4514
{
4515
    # correct number of parameters?
4516
    if ( ($#_+1) != 2 ) 
4517
    {
1534 dpurdie 4518
        Error("Incorrect number of params passed to " .
1530 dpurdie 4519
                  "getTargetDstDirValue() function.");
4520
    }
4521
 
4522
    my ($m_key, $m_type) = @_;
1570 gchristi 4523
    my $tdir = ($TargetBaseDir ne ".") ? "$TargetBaseDir/" : "";
1532 dpurdie 4524
 
4525
    #
4526
    #   Look up the users tag conversion hash
4527
    #
4528
    if ( exists $TargetDstDirStructure{$m_key} )
1530 dpurdie 4529
    {
1570 gchristi 4530
        $tdir .= $TargetDstDirStructure{$m_key};
1530 dpurdie 4531
    }
4532
    else
4533
    {
1534 dpurdie 4534
        Error("Target destination dir tag [$m_key] does not exist in " .
4535
             "TargetDstDirStructure. " ,
4536
             "Check deploy configuration.");
1530 dpurdie 4537
    }
4538
 
1532 dpurdie 4539
 
4540
    #
4541
    #   If an absolute path is required than add the PkgBaseDir
4542
    #   otherwise the user must be requesting a relative path.
4543
    #
4544
    if ( "$m_type" eq "A" ) {
4545
        $tdir = "$PkgBaseDir/$tdir";
4546
    } elsif ( "$m_type" eq "R" )  {
4547
    } else {
1534 dpurdie 4548
        Error("getTargetDstDirValue: Bad call. Unknown type: $m_type");
1532 dpurdie 4549
    }
4550
 
4551
    return $tdir;
1530 dpurdie 4552
}
4553
 
4554
 
4555
#------------------------------------------------------------------------------
4556
sub createPatch
4557
#
4558
# Description:
4559
#       This sub-routine is used to create a solaris patch.
4560
#
4561
#------------------------------------------------------------------------------
4562
{
4563
    # correct number of parameters?
4564
    if ( ($#_+1) != 0 )
4565
    {
1534 dpurdie 4566
        Error("Incorrect number of params passed to " .
4567
              "createPatch() function.",
4568
              "Check deploy config.");
1530 dpurdie 4569
    }
4570
 
4571
    # lets just check to see if we can execute this function on
4572
    # this machine.
4573
    #
4574
    if ( "$MachType" ne "sparc" )
4575
    {
1534 dpurdie 4576
        Verbose("createPatch() not supported on this machine type.");
1530 dpurdie 4577
        return 1;
4578
    }
4579
 
4580
    # lets just check to see if we can execute this function on
4581
    # for  this build.
4582
    #
4583
    if ( "x$PkgPatchNum" eq "x" )
4584
    {
1534 dpurdie 4585
        Warning("createPatch() can only be called during a PATCH build.");
1530 dpurdie 4586
        return 1;
4587
    }
4588
 
4589
    # we need to create the patch directory that contains
4590
    #
1534 dpurdie 4591
    Information("Creating patch ...");
1530 dpurdie 4592
 
4593
    my ( $m_pkgmkCmd );
4594
    my ( $m_pkgtransCmd );
4595
    $m_pkgmkCmd = "pkgmk -o " .
4596
                  "-f $PkgBaseDir/prototype " .
4597
                  "-d $PkgBaseDir";
4598
 
4599
    # lets execute the package commands.
4600
    my ($retVal);
4601
    $retVal = system("$m_pkgmkCmd");
4602
    if ( $retVal != 0 )
4603
    {
1534 dpurdie 4604
        Error("Failed to complete command [$m_pkgmkCmd].");
1530 dpurdie 4605
    }
4606
 
4607
    # we need to generate a README file to help during installation
4608
    #
4609
    generatePatchREADME();
4610
 
4611
 
4612
    my ($m_Cmd)    = ""; 
4613
    my ($m_tmpDir) = "$PkgPatchTmpDir/$PkgPatchID";
4614
 
1534 dpurdie 4615
    Information("Creating staging area of patch...");
1530 dpurdie 4616
    $m_Cmd = "cd $PkgBaseDir && mkdir -p $m_tmpDir;";
4617
    system($m_Cmd);
4618
 
1534 dpurdie 4619
    Information("Copying patch contents to staging area of patch...");
1530 dpurdie 4620
    $m_Cmd = "cd $PkgBaseDir && cp -r $PkgName $m_tmpDir;";
4621
    system($m_Cmd);
4622
 
4623
    # we need to copy the patch install utility files from
4624
    # their resting place.
4625
    #
4626
    my ($i);
4627
    foreach $i ( @PATCH_UTIL_FILES )
4628
    {
4629
        if( File::Copy::copy("$PATCH_UTIL_DIR/$i", "$PkgPatchTmpDir") )
4630
        {
1534 dpurdie 4631
            Verbose("Copied [$PATCH_UTIL_DIR/$i] to [$PkgPatchTmpDir] ...");
1530 dpurdie 4632
            system("chmod 0755 $PkgPatchTmpDir/$i");
4633
        }
4634
        else
4635
        {
1534 dpurdie 4636
            Error("Failed to copy info file [$PATCH_UTIL_DIR/$i] to [$PkgPatchTmpDir] : $!");
1530 dpurdie 4637
        }
4638
    }
4639
 
4640
    # Lets put the readme in place
4641
    #
4642
    if( File::Copy::copy("$PkgPatchReadme", "$PkgPatchTmpDir") )
4643
    {
1534 dpurdie 4644
        Verbose("Copied [$PkgPatchReadme] to [$PkgPatchTmpDir] ...");
1530 dpurdie 4645
    }
4646
    else
4647
    {
1534 dpurdie 4648
        Error("Failed to copy info file [$PkgPatchReadme] to [$PkgPatchTmpDir] : $!");
1530 dpurdie 4649
    }
4650
 
1534 dpurdie 4651
    Information("Copying patch contents to staging area of patch...");
1530 dpurdie 4652
    $m_Cmd = "cd $PkgBaseDir && cp -r $PkgName $m_tmpDir;";
4653
    system($m_Cmd);
4654
 
4655
    my ($m_oFile) = "$PkgPatchID-$ProjectAcronym\.tgz";
1534 dpurdie 4656
    Information("Creating a gzip'd compressed tar (.tgz) output file [$m_oFile]...");
1530 dpurdie 4657
    my ($base) = File::Basename::basename($PkgPatchTmpDir);
4658
    $m_Cmd = "cd $PkgBaseDir && tar cvf - $base | gzip > $m_oFile";
4659
    system($m_Cmd);
4660
 
4661
    return 1;
4662
}
4663
 
4664
 
4665
 
4666
#------------------------------------------------------------------------------
4667
sub generatePatchREADME
4668
#
4669
#   This function is used to generate a README text file to help the user
4670
#   duing the patch installation.
4671
#
4672
#------------------------------------------------------------------------------
4673
{
4674
    local *FILE;
4675
    open ( FILE, "> $PkgPatchReadme") or
1534 dpurdie 4676
        Error("Failed to open file [$PkgPatchReadme].");
1530 dpurdie 4677
 
4678
    printf FILE ("This is a patch for $PkgName $PkgVersion\n");
4679
    printf FILE ("---------------------------------------------------------------\n");
4680
    printf FILE ("\n");
4681
    printf FILE ("Installing patch (as the 'root' user) :\n");
4682
    printf FILE ("---------------------------------------------------------------\n");
4683
    printf FILE ("./installpatch $PkgPatchID\n");
4684
    printf FILE ("\n");
4685
    printf FILE ("Backing Out patch:\n");
4686
    printf FILE ("---------------------------------------------------------------\n");
4687
    printf FILE ("./backoutpatch $PkgPatchID\n");
4688
    printf FILE ("\n");
4689
 
4690
    printf FILE ("Patch contents of $PkgPatchID\n");
4691
    printf FILE ("---------------------------------------------------------------\n");
4692
    close FILE;
4693
 
4694
    # now we need to get the contents of the patch we are creating.
4695
    #
1570 gchristi 4696
    File::Find::find(\&getPatchContents, ($TargetBaseDir ne ".") ? "$PkgBaseDir/$TargetBaseDir" : $PkgBaseDir );
1530 dpurdie 4697
 
4698
    return 1;
4699
}
4700
 
4701
 
4702
#------------------------------------------------------------------------------
4703
sub getPatchContents
4704
#
4705
#   This sub-routine adds an entry into the readme file for each
4706
#   item in the patch delivery tree.
4707
#
4708
#------------------------------------------------------------------------------
4709
{
4710
    my($file)= "$File::Find::name";
4711
    my($base)= File::Basename::basename($file);
4712
 
4713
    # we get the absolute path from the find, but we only require
4714
    # a relative path from the starting dir.
4715
    # so our start dir.
4716
 
4717
    my ($m_sfile) = $file;
4718
    $file =~ s/$PkgBaseDir//;
4719
 
4720
    open ( FILE, ">> $PkgPatchReadme") or
1534 dpurdie 4721
         Error("Failed to open file [$deplylib::PkgPatchReadme].");
1530 dpurdie 4722
 
4723
    # lets populate the prototype file.
4724
    printf FILE ("* $file\n");
4725
 
4726
    close (FILE);
4727
}
4728
 
4729
 
4730
#------------------------------------------------------------------------------
4731
sub createPackage
4732
#
4733
# Description:
1532 dpurdie 4734
#       This sub-routine is used to create a package.
4735
#       The type of package is machine specific. The subroutine will invoke a
4736
#       machine specfic function to do the real work.
1530 dpurdie 4737
#
4738
#------------------------------------------------------------------------------
4739
{
1534 dpurdie 4740
    Information("createPackage");
1530 dpurdie 4741
 
4742
    # lets just check to see if we can execute this function on
4743
    # this machine.
4744
    #
1532 dpurdie 4745
    my $createRoutine = 'createPackage_' . $MachType;
4746
    if ( exists &$createRoutine )
1530 dpurdie 4747
    {
1532 dpurdie 4748
        # lets just check to see if we can execute this function on
4749
        # for  this build.
4750
        #
4751
        if ( $PkgPatchNum )
4752
        {
1534 dpurdie 4753
            Warning("createPackage() can only be called during a RELEASE build.");
1532 dpurdie 4754
            return 1;
4755
        }
4756
 
4757
        #
4758
        #   Ensure the Release directory is present
4759
        #
1534 dpurdie 4760
        make_directory( $ReleaseDir, 0777 );
1532 dpurdie 4761
 
4762
        # Ensure that the package descriptor is transferred
4763
        #
4764
        my ($m_copydesc) = "cp $SrcDir/descpkg $ReleaseDir";
4765
        system($m_copydesc);
4766
 
4767
        # Invoke the machine specific package builder by name
4768
        # Need to relax strictness. Yes we do know what we are doing here
4769
        #
4770
        no strict "refs";
1534 dpurdie 4771
        &$createRoutine( @_ ) || Error("Unspecified error building package");
1532 dpurdie 4772
        use strict "refs";
1530 dpurdie 4773
    }
1532 dpurdie 4774
    else
1530 dpurdie 4775
    {
1534 dpurdie 4776
        Verbose("createPackage() not supported on this machine type: $MachType.");
1530 dpurdie 4777
    }
1532 dpurdie 4778
    return 1;
4779
}
1530 dpurdie 4780
 
4781
 
1532 dpurdie 4782
#------------------------------------------------------------------------------
4783
sub createPackage_sparc
4784
#
4785
# Description:
4786
#       This sub-routine is used to create a package.
4787
#       The type of package is machine specific. The subroutine will invoke a
4788
#       machine specfic function to do the real work.
4789
#
4790
#------------------------------------------------------------------------------
4791
{
1534 dpurdie 4792
    Verbose("createPackage_sparc");
1532 dpurdie 4793
 
1530 dpurdie 4794
    # we need to copy the package utility files from
4795
    # their resting place.
4796
    #
1532 dpurdie 4797
    foreach my $i ( @PKG_UTIL_FILES )
1530 dpurdie 4798
    {
4799
        if( File::Copy::copy("$PKG_UTIL_DIR/$i", "$PkgBaseDir") )
4800
        {
1534 dpurdie 4801
            Verbose("Copied [$PKG_UTIL_DIR/$i] to [$PkgBaseDir] ...");
1530 dpurdie 4802
            updatePrototypeFileAddItem2("$i", "$i", "", "", "", "I");
4803
            system("chmod 0755 $PkgBaseDir/$i");
4804
        }
4805
        else
4806
        {
1534 dpurdie 4807
            Error("Failed to copy info file [$PKG_UTIL_DIR/$i] to [$PkgBaseDir] : $!");
1530 dpurdie 4808
        }
4809
    }
4810
 
1556 lkelly 4811
    #
4812
    #   Scan the install 'image' looking for files and directories that have a 'space' in the name
4813
    #   These are not handled by the pkgmk utility, so it is best to create a nice error message now.
4814
    #
4815
    my $search = LocateFiles->new( recurse => 1, dirs_too => 1 );
4816
    $search->filter_in_re('\s');                                  
4817
    my @m_nfiles = $search->search($PkgBaseDir);                                  
4818
    if ( @m_nfiles )
4819
    {
4820
        Error ("Pathnames containing a space cannot be packaged under Solaris",
4821
               "The following paths contain a space",
4822
               @m_nfiles );
4823
    }
4824
 
1530 dpurdie 4825
    my ( $m_pkgmkCmd );
4826
    my ( $m_pkgtransCmd );
4827
    $m_pkgmkCmd = "pkgmk -o " .
4828
                  "-f $PkgBaseDir/prototype " .
1556 lkelly 4829
                  "-d $PkgBaseDir " .
4830
                  "-r $PkgBaseDir";
1530 dpurdie 4831
 
4832
    $m_pkgtransCmd = "pkgtrans -o " .
4833
                     "-s $PkgBaseDir " .
4834
                     "$PkgOutputFile " .
4835
                     "$PkgName";
4836
 
4837
    # lets execute the package commands.
4838
    my ($retVal);
4839
    $retVal = system("$m_pkgmkCmd");
4840
    if ( $retVal != 0 )
4841
    {
1534 dpurdie 4842
        Error("Failed to complete command [$m_pkgmkCmd].");
1530 dpurdie 4843
    }
4844
 
4845
    $retVal = system("$m_pkgtransCmd");
4846
    system("$m_pkgtransCmd");
4847
    if ( $retVal != 0 )
4848
    {
1534 dpurdie 4849
        Error("Failed to complete command [$m_pkgtransCmd].");
1530 dpurdie 4850
    }
4851
 
4852
    # lets compress the output to save some space.
4853
    #
1534 dpurdie 4854
    Information("Compressing $PkgOutputFile");
1532 dpurdie 4855
    my ($m_compressCmd) = "cd $PkgBaseDir; gzip $PkgOutputFile; mv ${PkgOutputFile}.gz $ReleaseDir";
1530 dpurdie 4856
    system($m_compressCmd);
4857
 
4858
    return 1;
4859
}
4860
 
1532 dpurdie 4861
#------------------------------------------------------------------------------
4862
sub createPackage_WinCE
4863
#
4864
# Description:
4865
#       This sub-routine is used to create a package.
4866
#       Really a win32 machine type, but for some reason, the MachType gets
4867
#       stuffed around. Don't know why.
4868
#
4869
#       Do have the option of creating a WinCE specific packager
4870
#
4871
#------------------------------------------------------------------------------
4872
{
1534 dpurdie 4873
    Verbose("createPackage_WinCE");
1532 dpurdie 4874
    createPackage_win32(@_);
4875
}
1530 dpurdie 4876
 
4877
#------------------------------------------------------------------------------
1532 dpurdie 4878
sub createPackage_win32
4879
#
4880
# Description:
4881
#       This sub-routine is used to create a package.
4882
#       Invoke the isbuild.pl utility to build the install shield project
4883
#
4884
#------------------------------------------------------------------------------
4885
{
1534 dpurdie 4886
    Verbose("createPackage_win32");
1538 dpurdie 4887
 
1532 dpurdie 4888
    #
1538 dpurdie 4889
    #   Process any options that may be present
4890
    #   Don't complain about args we don't understand. They may apply to other
4891
    #   platforms
4892
    #
4893
    my @user_options = ();
4894
    foreach my $arg ( @_ )
4895
    {
4896
        if ( $arg =~ m/^-nonameversion/ || $arg =~ m/^-nameversion/   ) {
4897
            push @user_options, $arg;
4898
 
4899
        } elsif ( $arg =~ m/^-nocode/ || $arg =~ m/^-code/   ) {
4900
            push @user_options, $arg;
4901
 
1564 dpurdie 4902
        } elsif ( $arg =~ m/^-nomultiprod/ || $arg =~ m/^-multiprod/   ) {
4903
            push @user_options, $arg;
4904
 
4905
        } elsif ( $arg =~ m/^-nomultirel/ || $arg =~ m/^-multirel/   ) {
4906
            push @user_options, $arg;
4907
 
1538 dpurdie 4908
        } else {
4909
            Message ( "createPackage_win32: Unknown option: $_");
4910
        }
4911
    }
4912
 
4913
    #
1532 dpurdie 4914
    #   Locate MergeModules in external packages
4915
    #   These will be used by the InstallShield compiler
4916
    #
4917
    my @mm_dirs;
4918
    my @mm_tld;
4919
    my $tdir;
4920
 
4921
    #
4922
    #   Check for Merge Modules in the local directory
4923
    #   This must be a flat directory structure. ie: all files in the
4924
    #   subdirectory called MergeModule.
4925
    #
4926
    $tdir = "$RootDir/MergeModules";
4927
    push @mm_dirs, $tdir if ( -d $tdir );
1534 dpurdie 4928
    Verbose ("Discovered MergeModules in: $tdir") if ( -d $tdir );
1532 dpurdie 4929
 
4930
    #
4931
    #   Check for Merge Modules in the Interface directory
4932
    #   This will be pulled in via a BuildPkgArchive
4933
    #
4934
    $tdir = "$InterfaceDir/MergeModules";
4935
    push @mm_tld, $tdir if ( -d $tdir );
1534 dpurdie 4936
    Verbose ("Discovered MergeModules in: $tdir") if ( -d $tdir );
1532 dpurdie 4937
 
4938
    #
4939
    #   Check in LinkPkgArchive locations too
4940
    for my $entry ( $BuildFileInfo->getBuildPkgRules() )
4941
    {
4942
        next unless ( $entry->{'TYPE'} eq 'link' );
4943
        $tdir = $entry->{'ROOT'} . '/MergeModules';
4944
        push @mm_tld, $tdir if ( -d $tdir );
1534 dpurdie 4945
        Verbose ("Discovered MergeModules in: $tdir") if ( -d $tdir );
1532 dpurdie 4946
    }
4947
 
4948
    #
4949
    #   Expand the merge module subdirectory tree into
4950
    #   suitable paths:
4951
    #       Modules/i386
4952
    #       Modules/i386/<language>
4953
    #       Objects
4954
    #       Merge Modules
4955
    #
4956
    foreach my $dir ( @mm_tld )
4957
    {
4958
        $tdir = $dir . '/Modules/i386';
4959
        if ( -d $tdir )
4960
        {
4961
            push @mm_dirs, $tdir;
4962
            foreach my $file ( glob( "$tdir/*" ))
4963
            {
4964
                next unless ( -d $file );
4965
                push @mm_dirs, $file;
4966
            }
4967
        }
4968
 
4969
        $tdir = $dir . '/Objects';
4970
        push @mm_dirs, $tdir if ( -d $tdir );
4971
 
4972
        $tdir = $dir . '/Merge Modules';
4973
        push @mm_dirs, $tdir if ( -d $tdir );
4974
    }
4975
 
4976
 
4977
    #
4978
    #   Locate the program
4979
    #   It will be in a location addressed by the @INC path
4980
    #
4981
    my $prog_found;
4982
    my $prog;
4983
    foreach my $dir ( @INC )
4984
    {
4985
        $prog = $dir . '/isbuild.pl';
4986
        next unless ( -f $prog );
4987
        $prog_found = 1;
4988
        last;
4989
    }
4990
 
1556 lkelly 4991
    #
4992
    #   Note: Use $RootDir for the ISBUILD workdir
4993
    #         Would like t use interface, but it makes
4994
    #         the pathname longer and some MergeModules can
4995
    #         be extracted. ISBUILD appears to have a path length limit of
4996
    #         about 204 character. We need all we can get.
4997
    #
4998
 
1534 dpurdie 4999
    Error("isbuild.pl not found") unless $prog_found;
5000
    Verbose("isbuild: $prog");
1532 dpurdie 5001
    my $rv = system ( $ENV{GBE_PERL}, $prog,
5002
                            "-project=../$PkgName.ism",
5003
                            "-version=$PkgVersionUser",
5004
                            "-out=$ReleaseDir",
1556 lkelly 5005
                            "-workdir=$RootDir",
1538 dpurdie 5006
                            @user_options,
1532 dpurdie 5007
                            map { "-mergemodule=$_" } @mm_dirs
5008
                             );
1534 dpurdie 5009
    Error ("InstallShield Builder Error" ) if ( $rv );
1532 dpurdie 5010
    return 1;
5011
}
5012
 
5013
#------------------------------------------------------------------------------
1530 dpurdie 5014
sub createPrototypeFile
5015
#
5016
# Description:
1532 dpurdie 5017
#       This sub-routine is used to create the required package prototype file
1530 dpurdie 5018
#       from a known directory struture using the search path method.
5019
#
5020
#------------------------------------------------------------------------------
5021
{
5022
    # correct number of parameters?
5023
    if ( ($#_+1) != 2 )
5024
    {
1534 dpurdie 5025
        Error("Incorrect number of params passed to " .
5026
              "createPrototypeFile() function",
5027
              "Check deploy config.");
1530 dpurdie 5028
    }
5029
 
5030
    # lets just check to see if we can execute this function on
5031
    # this machine.
5032
    #
5033
    if ( "$MachType" ne "sparc" )
5034
    {
1534 dpurdie 5035
        Verbose("createPrototypeFile() not supported on this machine type.");
1530 dpurdie 5036
        return 1;
5037
    }
5038
 
5039
    # lets take the passed in args.
5040
    my ($uid, $gid) = @_;
5041
 
5042
    # we need to locate the prototype file
1570 gchristi 5043
    if ( -f "$ProtoTypeFile" )
1530 dpurdie 5044
    {
1570 gchristi 5045
        unlink("$ProtoTypeFile");
5046
        Verbose("Removing prototype file [$ProtoTypeFile].");
1530 dpurdie 5047
    }
5048
 
5049
    # lets open the prototype file.
5050
    #    
5051
    local *FILE;
1570 gchristi 5052
    open ( FILE, "> $ProtoTypeFile") or
5053
        Error("Failed to open file [$ProtoTypeFile].");
1530 dpurdie 5054
 
5055
    # lets populate the prototype file.
5056
    printf FILE ("i pkginfo\n");
1570 gchristi 5057
    printf FILE ("!search");
5058
    close(FILE);
1530 dpurdie 5059
 
5060
    # now we need to add entries for each directory we will 
5061
    # be installing 
1570 gchristi 5062
    File::Find::find( \&prototypeFind, ($TargetBaseDir ne ".") ? "$PkgBaseDir/$TargetBaseDir" : $PkgBaseDir );
1530 dpurdie 5063
 
5064
    # lets populate the prototype file with a newline.
1570 gchristi 5065
    open ( FILE, ">> $ProtoTypeFile") or
5066
        Error("Failed to open file [$ProtoTypeFile].");
1530 dpurdie 5067
    printf FILE ("\n");
5068
    close (FILE);
5069
 
5070
 
5071
    # lets put the pre-deinfed generic entries into the 
5072
    # prototype file
5073
    #
5074
    if ( "x$PkgPatchNum" ne "x" )
5075
    {
5076
        addPatchInfo2ProtoTypeFile();
5077
    }
5078
 
5079
 
5080
    # we need to expand and complete the creation of the 
5081
    # prototype file
1570 gchristi 5082
    # if Targetbasedir is "." the pkgproto will pick up the pkginfo and
1530 dpurdie 5083
    # prototype files so we need to remove them
5084
    my ($m_cmd) = "pkgproto " .
5085
                  "$TargetBaseDir " .
5086
                  "| egrep -v \"($ProtoTypeFileName|$PkgInfoFileName)\"" .
5087
                  "| cut -f1-4 -d' ' | sed " . '"s/\$/ ' . "$uid $gid" . '/g"' . 
1570 gchristi 5088
                  " >> $ProtoTypeFile";
1530 dpurdie 5089
 
1570 gchristi 5090
    my ($retVal) = system("cd $PkgBaseDir; $m_cmd");
1530 dpurdie 5091
    if ( $retVal != 0 )
5092
    {
1570 gchristi 5093
        Error("Failed to create prototype file [$ProtoTypeFile].");
1530 dpurdie 5094
    }
5095
 
1570 gchristi 5096
    Information("Created prototype file [$ProtoTypeFile].");
1530 dpurdie 5097
 
5098
    return 1;
5099
}
5100
 
5101
#------------------------------------------------------------------------------
5102
sub prototypeFind
5103
#
5104
#    Description:
5105
#        This subroutine is used to locate all associated package dirs.
5106
#        It also adds an entry into the prototype file for each dir.
5107
#
5108
#------------------------------------------------------------------------------
5109
{
1570 gchristi 5110
    my ($file)  = $File::Find::name;
1530 dpurdie 5111
 
1570 gchristi 5112
    # Our topdir will either be $PkgBaseDir or $PkgBaseDir/$TargetBaseDir (if there is a TargetBaseDir).
5113
    # if we have PKgBaseDir only we dont want to include this in the search path, 
5114
    # if TargetBaseDir is defined we include it in the search paths
5115
    if ( $file ne $PkgBaseDir && -d $file )
1530 dpurdie 5116
    {
1570 gchristi 5117
        # we get the absolute path from the find, but we only require a relative path from the starting dir.
5118
        # So remove PkgBaseDir from path and include all dirs below it including TargetBaseDir if there is one
5119
        $file =~ s|$PkgBaseDir/*||;    
5120
 
5121
        open ( FILE, ">> $ProtoTypeFile") or
5122
             Error("Failed to open file [$ProtoTypeFile].");
1530 dpurdie 5123
 
1570 gchristi 5124
        # lets populate the prototype file.
5125
        printf FILE (" $file");
5126
        close (FILE);
1530 dpurdie 5127
    }
5128
}
5129
 
5130
 
5131
#------------------------------------------------------------------------------
5132
sub addPatchInfo2ProtoTypeFile
5133
#
5134
# Description:
5135
#       This sub-routine is used to add additonal genericinformation
5136
#       used by the patch.
5137
#
5138
#------------------------------------------------------------------------------
5139
{
1534 dpurdie 5140
    Information("Adding patch information files to patch build...");
1530 dpurdie 5141
 
5142
    # we need to determine whiich file we are dealing with
5143
    my ($protoTypeFile);
5144
    $protoTypeFile = "$ProtoTypeFile";
5145
 
5146
    # lets open the prototype file.
5147
    #
5148
    local *FILE;
5149
    open ( FILE, ">> $protoTypeFile") or
1534 dpurdie 5150
        Error("Failed to open file [$protoTypeFile].");
1530 dpurdie 5151
 
5152
 
5153
    # we need to copy the install informational files from
5154
    # their resting place.
5155
    my ($i);
5156
    foreach $i ( @PATCH_INFO_FILES )
5157
    {
5158
        if( File::Copy::copy("$PATCH_UTIL_DIR/$i", "$PkgBaseDir") )
5159
        {
1534 dpurdie 5160
            Verbose("Copied [$PATCH_UTIL_DIR/$i] to [$PkgBaseDir] ...");
1530 dpurdie 5161
            printf FILE ("i $i\n"); 
5162
        }
5163
        else
5164
        {
1534 dpurdie 5165
            Error("Failed to copy info file [$PATCH_UTIL_DIR/$i]: $!");
1530 dpurdie 5166
        }
5167
    }
5168
    close FILE;
5169
 
5170
    return 1;
5171
}
5172
 
5173
 
5174
#------------------------------------------------------------------------------
5175
sub useReplaceClass
5176
#
5177
# Description:
5178
#       This sub-routine is used to add replace class to the classes list and
5179
#       include the i.replace file in the PKG_INFO_FILES List
5180
#
5181
#------------------------------------------------------------------------------
5182
{
5183
 
1534 dpurdie 5184
    Information("useReplaceClass: Adding replace class to installer");
1530 dpurdie 5185
 
5186
    $PkgInfoClasses = $PkgInfoClasses . " " . "replace";
5187
    push(@PKG_UTIL_FILES, "i.replace");
5188
}
5189
 
5190
 
5191
#------------------------------------------------------------------------------
5192
sub addPkgInfoClasses
5193
#
5194
# Description:
5195
#       This sub-routine is used to add new classes to the pkginfo CLASSES variable.
5196
#
5197
#------------------------------------------------------------------------------
5198
{
5199
    # correct number of parameters?
5200
    if ( ($#_+1) == 0 )
5201
    {
1534 dpurdie 5202
        Error("Incorrect number of params passed to " .
5203
              "createPkginfoFile() function",
5204
              "Check deploy config.");
1530 dpurdie 5205
    }
5206
 
1534 dpurdie 5207
    Information("addPkgInfoClasses() Adding classes \"" . join(" ", @_) . "\" to CLASSES List");
1530 dpurdie 5208
 
5209
    $PkgInfoClasses = $PkgInfoClasses . " " . join(" ", @_);
5210
}
5211
 
5212
 
5213
#------------------------------------------------------------------------------
5214
sub addPkgInfoField
5215
#
5216
# Description:
5217
#       This sub-routine is used to add new fields to already created pkginfo file
5218
#       Acccepts any number of fields of format A=B as one string parameter.
5219
#------------------------------------------------------------------------------
5220
{
5221
    # lets just check to see if we can execute this function on this machine.
5222
    if ( "$MachType" ne "sparc" )
5223
    {
1534 dpurdie 5224
        Verbose("addPkgInfoField() not supported on this machine type.");
1530 dpurdie 5225
        return 1;
5226
    }
5227
    # lets open the pkginfo file.   
5228
    local *FILE;
1534 dpurdie 5229
    open ( FILE, ">> $PkgInfoFile") or Error("Failed to open file [$PkgInfoFile].");
1530 dpurdie 5230
 
5231
    foreach my $i ( @_ )
5232
    {
5233
        print FILE "$i\n";
5234
    }
5235
    close FILE;
5236
    return 1;
5237
}
5238
 
5239
#------------------------------------------------------------------------------
5240
sub updatePrototypeFileItemClass
5241
#
5242
# Description:
5243
#       This subroutine is used to change the class of a file already in the prototype file
5244
#
5245
#------------------------------------------------------------------------------
5246
{
5247
    # correct number of parameters?
5248
    if ( ($#_+1) != 2 )
5249
    {
1534 dpurdie 5250
        Error("Incorrect number of params passed to " .
1530 dpurdie 5251
                  "updatePrototypeFileItemClass() function. Check deploy config.");
5252
    }
5253
 
5254
 
5255
    # lets just check to see if we can execute this function on
5256
    # this machine.
5257
    #
5258
    if ( "$MachType" ne "sparc" )
5259
    {
1534 dpurdie 5260
        Verbose("updatePrototypeFileItemClass() not supported on this machine type.");
1530 dpurdie 5261
        return 1;
5262
    }
5263
 
5264
 
5265
    # lets setup the passed values.
5266
    my ($m_item, $class) = @_;
5267
 
5268
    my ($tmpProtoTypeFile) = "/tmp/xx_prototypefile.$$";
5269
 
5270
    # lets open the prototype file if it exists
5271
    #
5272
    open (PFILE, "< $ProtoTypeFile") or
1534 dpurdie 5273
        Error("Failed to open prototype file [$ProtoTypeFile].");
1530 dpurdie 5274
 
5275
    open (PFILETMP, "> $tmpProtoTypeFile") or
1534 dpurdie 5276
        Error("Failed to open tmp prototype file [$tmpProtoTypeFile].");
1530 dpurdie 5277
 
5278
    while ( <PFILE> )
5279
    {
5280
        chomp;
5281
        # The path section will normally contain "path [mode]" or path=path
5282
        # The passed arg can be full path or can skip top level dirs
5283
        # eg prototype can have line with path ergbpeod/etc/afcbp.ini
5284
        # arg to match can be ergbpeod/etc/afcbp.ini, etc/afcbp.ini or afcbp.ini
5285
        # therefore we need to match arg to the end of the path in line 
5286
        # so we append [= ] to arg
5287
        s/^(\s*[bcdefilpsvx]\s*)[^\s]*(.*$)/$1$class$2/ if ( /$m_item[ =]/ );
5288
        printf PFILETMP ("$_\n");
5289
    }
5290
    close PFILE;
5291
    close PFILETMP;
5292
 
5293
    # now we need to copy the file.
5294
    if(File::Copy::copy("$tmpProtoTypeFile", "$ProtoTypeFile"))
5295
    {
1534 dpurdie 5296
        Verbose("Updated file $m_item to class $class");
1530 dpurdie 5297
        unlink($tmpProtoTypeFile);
5298
    }
5299
    else
5300
    {
1534 dpurdie 5301
        Error("Failed to copy lib [$tmpProtoTypeFile]: $!");
1530 dpurdie 5302
    }
5303
 
5304
    return 1;
5305
 
5306
}
5307
 
5308
 
5309
 
5310
#------------------------------------------------------------------------------
5311
sub setReplaceClassFiles
5312
#
5313
# Description:
5314
#       This subroutine is used to change the class of a file already in the prototype file
5315
#
5316
#------------------------------------------------------------------------------
5317
{
5318
    # lets just check to see if we can execute this function on
5319
    # this machine.
5320
    #
5321
    if ( "$MachType" ne "sparc" )
5322
    {
1534 dpurdie 5323
        Verbose("updatePrototypeFileItemClass() not supported on this machine type.");
1530 dpurdie 5324
        return 1;
5325
    }
5326
 
1534 dpurdie 5327
    Error("Must call useReplaceClass() before calling setReplaceClassFiles()") if ( $PkgInfoClasses !~ /replace/ );
1530 dpurdie 5328
 
5329
    my ($tmpProtoTypeFile) = "/tmp/xx_prototypefile.$$";
5330
 
5331
    # lets open the prototype file if it exists
5332
    #
5333
    open (PFILE, "< $ProtoTypeFile") or
1534 dpurdie 5334
        Error("Failed to open prototype file [$ProtoTypeFile].");
1530 dpurdie 5335
 
5336
    open (PFILETMP, "> $tmpProtoTypeFile") or
1534 dpurdie 5337
        Error("Failed to open tmp prototype file [$tmpProtoTypeFile].");
1530 dpurdie 5338
 
5339
    my $line;
5340
    while ( $line = <PFILE> )
5341
    {
5342
        chomp $line;
5343
        # The path section will normally contain "path [mode]" or path=path
5344
        # The passed args can be full path or can skip top level dirs
5345
        # eg prototype can have line with path ergbpeod/etc/afcbp.ini
5346
        # args to match can be ergbpeod/etc/afcbp.ini, etc/afcbp.ini or afcbp.ini
5347
        # therefore we need to match each arg to the end of the path in line 
5348
        # so we append [= ] to end of each arg
5349
        $line =~ s/^(\s*[bcdefilpsvx]\s*)[^\s]*(.*$)/$1replace$2/ if ( scalar(grep { $line =~ /$_[ =]/ } @_) > 0 );
5350
        printf PFILETMP ("$line\n");
5351
    }
5352
    close PFILE;
5353
    close PFILETMP;
5354
 
5355
    # now we need to copy the file.
5356
    if(File::Copy::copy("$tmpProtoTypeFile", "$ProtoTypeFile"))
5357
    {
1534 dpurdie 5358
        Verbose("Updated prototype file entries to class replace");
1530 dpurdie 5359
        unlink($tmpProtoTypeFile);
5360
    }
5361
    else
5362
    {
1534 dpurdie 5363
        Error("Failed to copy lib [$tmpProtoTypeFile]: $!");
1530 dpurdie 5364
    }
5365
 
5366
    return 1;
5367
 
5368
}
5369
 
5370
 
5371
#------------------------------------------------------------------------------
5372
sub createPkginfoFile
5373
#
5374
# Description:
5375
#       This sub-routine is used to create the required package info.
5376
#       Accepts any number of parameters, with each parameter taken as a literal
5377
#       Field=Value string and inserted into the PkgInfo File
5378
#------------------------------------------------------------------------------
5379
{
5380
    # lets check to see if our description has been set
5381
    if ( $PkgDesc eq "" )
5382
    {
1534 dpurdie 5383
        Error("Package description not set. " .
1530 dpurdie 5384
                 "Use setPkgDescription('my package description') function.");
5385
    }
5386
 
5387
    # lets check to see if our long name has been set
5388
    if ( $PkgNameLong eq "" )
5389
    {
1534 dpurdie 5390
        Error("Package name not set. Use setPkgName('my package long name') function.");
1530 dpurdie 5391
    }
5392
 
5393
 
5394
    # lets just check to see if we can execute this function on
5395
    # this machine.
5396
    #
5397
    if ( "$MachType" ne "sparc" )
5398
    {
5399
        generateIShieldIncludeFile();
5400
        return 1;
5401
    }
5402
 
5403
    # we need to determine whiich file we are dealing with
5404
    my ($pkginfoFile) = "$PkgInfoFile"; 
5405
 
5406
    # we need to locate the pkginfo file
5407
    if ( -f "$pkginfoFile" )
5408
    {
5409
        unlink("$pkginfoFile");
1534 dpurdie 5410
        Verbose("Removing pkginfo file [$pkginfoFile].");
1530 dpurdie 5411
    }
5412
 
5413
    # lets open the pkginfo file.
5414
    #    
5415
    local *FILE;
5416
    open ( FILE, "> $pkginfoFile") or
1534 dpurdie 5417
        Error("Failed to open file [$pkginfoFile].");
1530 dpurdie 5418
 
5419
    # lets populate the pkginfo file.
5420
    printf FILE ("PKG=$PkgName\n");
5421
 
5422
 
5423
    # here we deal with the new version number format
5424
    #
1568 dpurdie 5425
    Error ("Internal: MachArch is not defined") unless ( $MachArch );
1530 dpurdie 5426
    printf FILE ("NAME=$PkgNameLong\n");
5427
    printf FILE ("VERSION=$PkgVersion.$ProjectAcronym\n");
1568 dpurdie 5428
    printf FILE ("ARCH=$MachArch\n");
1570 gchristi 5429
    printf FILE ("SUNW_ISA=$MachISA\n") if ( $MachISA );
1530 dpurdie 5430
    printf FILE ("VENDOR=$VENDOR_DESC\n");
5431
    printf FILE ("DESC=$PkgDesc\n");
5432
    printf FILE ("CATEGORY=$CATEGORY_DESC\n");
5433
    printf FILE ("BASEDIR=$ERGAFC_BASEDIR\n");
1570 gchristi 5434
    printf FILE ("TARGETBASEDIR=$TargetBaseDir\n") unless ( $TargetBaseDir eq "." );
1530 dpurdie 5435
    printf FILE ("CLASSES=$PkgInfoClasses\n");
5436
 
5437
    foreach my $param ( @_ )
5438
    {
5439
        printf FILE "$param\n";
5440
    }
5441
 
5442
    if ( "x$PkgPatchNum" ne "x" )
5443
    {
5444
        my ($count)=1;
5445
        my ($pRev)="";
5446
        printf FILE ("MAXINST=$MAXINST\n");
5447
        printf FILE ("SUNW_PATCHID=$PkgPatchID\n");
5448
        printf FILE ("SUNW_REQUIRES=\n");
5449
        printf FILE ("SUNW_INCOMPAT=\n");
5450
 
5451
        $count=1;
5452
        $pRev="";
5453
        printf FILE ("SUNW_OBSOLETES=");
5454
        while ( $count < $PkgPatchNum )
5455
        {
5456
            $pRev = sprintf ("%02s", $count); 
5457
            printf FILE ("$PkgPatchName" . 
5458
                         "$PkgVersionStr" . 
5459
                         "-" . 
5460
                         "$pRev ");
5461
            $count++;
5462
        }
5463
        printf FILE ("\n");
5464
 
5465
        $count=1;
5466
        $pRev="";
5467
        printf FILE ("PATCH_OBSOLETES=");
5468
        while ( $count < $PkgPatchNum )
5469
        {
5470
            $pRev = sprintf ("%02s", $count); 
5471
            printf FILE ("$PkgPatchName" . 
5472
                         "$PkgVersionStr" . 
5473
                         "-" . 
5474
                         "$pRev ");
5475
            $count++;
5476
        }
5477
        printf FILE ("\n");
5478
    }
5479
 
5480
 
5481
    # now we will list the build dependencies so
5482
    # we can refer to them online
5483
    #
5484
    my ($i);
5485
    my ($m_Str);
5486
    # printf FILE ("\n");
5487
    my ($count) = 1;
5488
    foreach $i ( $BuildFileInfo->getDpkgArchiveList() )
5489
    {
5490
         my $moduleInfo = $BuildFileInfo->getDpkgArchiveInfo($i);
5491
 
5492
         printf FILE ( "$moduleInfo->{type}\_$count=$i $moduleInfo->{version}");
5493
 
5494
         # we shall print the project bit if we have one
5495
         if ( $moduleInfo->{proj} ne "" )
5496
         {
5497
             printf FILE ( "\.$moduleInfo->{proj}\n");
5498
         }
5499
         else
5500
         {
5501
             printf FILE ("\n");
5502
         }
5503
         $count++;
5504
    }
5505
    close FILE;
5506
 
5507
 
5508
    # lets close the pkginfo file.
5509
    close (FILE);
1534 dpurdie 5510
    Information("Created pkginfo file [$pkginfoFile].");
1530 dpurdie 5511
 
5512
    return 1;
5513
}
5514
 
5515
 
5516
#------------------------------------------------------------------------------
5517
sub updatePrototypeFileItemOwner
5518
#
5519
# Description:
5520
#       This sub-routine is used to change the ownership of a file item
5521
#       in the prototype file.
5522
#
5523
#------------------------------------------------------------------------------
5524
{
5525
    # correct number of parameters?
5526
    if ( ($#_+1) != 4 )
5527
    {
1534 dpurdie 5528
        Error("Incorrect number of params passed to " .
1530 dpurdie 5529
                  "updatePrototypeFileItemOwner() function. Check deploy config.");
5530
    }
5531
 
5532
 
5533
    # lets just check to see if we can execute this function on
5534
    # this machine.
5535
    #
5536
    if ( "$MachType" ne "sparc" )
5537
    {
1534 dpurdie 5538
        Verbose("chmod() not supported on this machine type.");
1530 dpurdie 5539
        return 1;
5540
    }
5541
 
5542
 
5543
    # lets setup the passed values.
5544
    my ($m_item, $m_ownPerms, $m_ownUser, $m_ownGroup) = @_;
5545
 
5546
 
5547
    my ($tmpProtoTypeFile) = "/tmp/xx_prototypefile.$$";
5548
 
5549
 
5550
    # lets open the prototype file if it exists
5551
    #
5552
    open (PFILE, "< $ProtoTypeFile") or
1534 dpurdie 5553
        Error("Failed to open prototype file [$ProtoTypeFile].");
1530 dpurdie 5554
 
5555
    open (PFILETMP, "> $tmpProtoTypeFile") or
1534 dpurdie 5556
        Error("Failed to open tmp prototype file [$tmpProtoTypeFile].");
1530 dpurdie 5557
 
5558
    my ($inLine);
5559
    while ( <PFILE> )
5560
    {
5561
        $inLine = $_;
5562
        chomp($inLine);
5563
        if ( "$inLine" =~ /^f / && "$inLine" =~ /$m_item/ )
5564
        {
5565
            my ($b1, $b2, $b3, $b4, $b5, $b6) = split (/ /, $inLine); 
5566
            printf PFILETMP ("$b1 $b2 $b3 $m_ownPerms $m_ownUser $m_ownGroup\n");
5567
        }
5568
        else
5569
        {
5570
            printf PFILETMP ("$inLine\n");
5571
        }
5572
    }
5573
    close PFILE;
5574
    close PFILETMP;
5575
 
5576
    # now we need to copy the file.
5577
    if(File::Copy::copy("$tmpProtoTypeFile", "$ProtoTypeFile"))
5578
    {
1534 dpurdie 5579
        Verbose("Copied [$tmpProtoTypeFile] to [$ProtoTypeFile] ...");
1530 dpurdie 5580
        unlink($tmpProtoTypeFile);
5581
    }
5582
    else
5583
    {
1534 dpurdie 5584
        Error("Failed to copy lib [$tmpProtoTypeFile]: $!");
1530 dpurdie 5585
    }
5586
 
5587
    return 1;
5588
 
5589
}
5590
 
5591
 
5592
#------------------------------------------------------------------------------
1556 lkelly 5593
sub setPermissions
5594
#   Called to set permissions of files/dirs in a directory structure.
5595
#       With no options sets DirTag and all files/dirs in it to perms
5596
#   
5597
#   Parameters:  
5598
#               DirTag:  The directory tag to start setting permissions on
5599
#       
5600
#   Required Options:
5601
#       One or both of
5602
#               --FilePerms=    Sets the permissions of files to this permission.
5603
#                               If not supplied then no files have their permissions changed
5604
#               --DirPerms=     Sets the permissions of directories to this permission
5605
#                               If not supplied then no directories have their permissions changed
5606
#       OR
5607
#               --Perms=        Sets the permissions of both files and directories to this permissions
5608
#                               Equivalent to supplying both --FilePerms=X && --DirPerms=X
5609
#               
5610
#   Options:
5611
#               --Recurse       Recurse the directory tree.  Does a deptth first recurse so that all 
5612
#                               dir entries are processed before the dir itself
5613
#               --NoRecurse     Dont recurse, default
5614
#               --DirTagOnly    Only sets the permissions on the DirTag directory, 
5615
#                               all other options ignored
5616
#               --SkipDirTag    Does not set permissions on the DirTag Directory, 
5617
#                               obviously mutually exlusive with --DirTagOnly
5618
#               --FilterIn=     Apply permissions to files/directories that matches this value.
5619
#               --FilterInRE=   Perl RE's can be used (Not Shell wildcards) and this option
5620
#                               can be supplied mulitple times
5621
#               --FilterOut=    Dont apply permissions to any files/directories matching this value
5622
#               --FilterOutRE=  Perl RE's can be used (Not Shell wildcards) and this option
5623
#                               can be supplied mulitple times
5624
#               
5625
#                               FilterIn is applied before FilterOut.  If Recurse is specified 
5626
#                               the directory will be recursed regardless of these filters, however
5627
#                               the filter will be applied when it comes time to chmod the dir 
1530 dpurdie 5628
#
5629
#------------------------------------------------------------------------------
5630
{
1556 lkelly 5631
    my ( $dirTag, $filePerms, $dirPerms );
5632
    my ( $dirTagOnly, $skipDirTag ) = ( 0, 0 );
5633
 
5634
    my $search =  LocateFiles->new( recurse => 0, dirs_too =>1 );
5635
 
5636
    foreach ( @_ )
1530 dpurdie 5637
    {
1556 lkelly 5638
        if ( m/^--Perms=(.*)/ ) {
5639
            $filePerms = $1;
5640
            $dirPerms = $1;
1530 dpurdie 5641
 
1556 lkelly 5642
        } elsif ( m/^--FilePerms=(.*)/ )  {
5643
            $filePerms = $1;
1530 dpurdie 5644
 
1556 lkelly 5645
        } elsif ( m/^--DirPerms=(.*)/ )  {
5646
            $dirPerms = $1;
1530 dpurdie 5647
 
1556 lkelly 5648
        } elsif ( m/^--Recurse/ ) {
5649
            $search->recurse(1);
5650
        }
5651
        elsif ( m/^--NoRecurse/ ) {
5652
            $search->recurse(0);
1530 dpurdie 5653
 
1556 lkelly 5654
        }  elsif ( m/^--DirTagOnly/ ) {
5655
            $dirTagOnly = 1;
5656
 
5657
        } elsif ( m/^--SkipDirTag/ )  {
5658
            $skipDirTag = 1;
5659
 
5660
        }  elsif ( m/^--FilterInRE=(.*)/ ) {
5661
            $search->filter_in_re($1);
5662
 
5663
        } elsif ( m/^--FilterIn=(.*)/ ) {
5664
            $search->filter_in($1);
5665
 
5666
        }  elsif ( m/^--FilterOutRE=(.*)/ ) {
5667
            $search->filter_out_re($1);
5668
 
5669
        }  elsif ( m/^--FilterOut=(.*)/ ) {
5670
            $search->filter_out($1);
5671
 
5672
        } else  {
5673
            Error("SetPermissions DirTag already set") if ( $dirTag );
5674
            $dirTag = $_;
5675
        }
5676
    }
5677
 
5678
    Error("SetPermissions called with out DirTag parameter") if ( !defined($dirTag) );
5679
    Error("SetPermissions called with out any Permission options") if ( !defined($filePerms) && !defined($dirPerms) );
5680
    Error("SetPermissions: Options --DirTagOnly & --SkipDirTag are mutually exclusive" ) if ( $dirTagOnly && $skipDirTag );
5681
 
5682
    #
1530 dpurdie 5683
    # lets just check to see if the perms are in correct format.
5684
    #
1556 lkelly 5685
    if ( (defined($filePerms) && $filePerms !~ m/^\d{4}$/) || (defined($dirPerms) && $dirPerms !~ m/^\d{4}$/) )
1530 dpurdie 5686
    {
1556 lkelly 5687
        Error("setPermissions called with invalid permissions format");
1530 dpurdie 5688
    }
5689
 
1556 lkelly 5690
    #   Convert the symbolic target directory name into a real path
5691
    my ($topDir) = getTargetDstDirValue($dirTag, "A");
1530 dpurdie 5692
 
1556 lkelly 5693
    #
5694
    #   Only set perms on the root directory
5695
    #   This is a trivial operation
5696
    #
5697
    if ( $dirTagOnly )
1530 dpurdie 5698
    {
1556 lkelly 5699
        Error("SetPermissions:  --DirPerms or --Perms not supplied for setting perms with --DirTagOnly") 
5700
            if ( ! defined($dirPerms) );
5701
        Information("SetPermissions: Setting permissions on top level dir only [$topDir] to " . $dirPerms);
5702
        chmodFile($topDir, $dirPerms);
5703
        return;
1530 dpurdie 5704
    }
1556 lkelly 5705
 
5706
    Information("SetPermissions: Called with options " . join(", ", @_));
5707
 
5708
 
5709
    #
5710
    #   Create a list of files/dirs to process
5711
    #
5712
    my @elements = $search->search( $topDir );
5713
    Warning ("setPermissions: No files located") unless ( @elements );
5714
 
5715
    foreach my $dirEntry ( @elements )
1530 dpurdie 5716
    {
1556 lkelly 5717
        my $fullPath = "$topDir/$dirEntry";
5718
 
5719
        # A dir and we dont have dirperms, so skip
5720
        if ( -d $fullPath && !defined($dirPerms) )
5721
        {
5722
            Debug2("SetPermissions: Skipping dir $fullPath as we have no dir permissions");
5723
            next;
5724
        }
5725
 
5726
        # A file and we dont have fileperms, so skip
5727
        if ( -f $fullPath && !defined($filePerms) )
5728
        {
5729
            Debug2("SetPermissions: Skipping file $fullPath as we have no file permissions");
5730
            next;
5731
        }
5732
 
5733
        # a file or a dir and have the right permissions and we are not recursing
5734
        if ( -f $fullPath || -d $fullPath )
5735
        {
5736
            chmodFile($fullPath, ( -f $fullPath ) ? $filePerms : $dirPerms);
5737
        }
5738
        else
5739
        {
5740
            Warning("SetPermissions: Skipping $fullPath as its not a file or directory");
5741
        }
1530 dpurdie 5742
    }
5743
 
1556 lkelly 5744
 
1530 dpurdie 5745
    #
1556 lkelly 5746
    #   Process the topDir
5747
    #   May not be modified if --SkipDirTag has been requested
5748
    #
5749
    if ( !$skipDirTag && defined($dirPerms) )
1530 dpurdie 5750
    {
1556 lkelly 5751
        chmodFile($topDir, $dirPerms);
1530 dpurdie 5752
    }
5753
 
1556 lkelly 5754
}   # setPermissions
5755
 
5756
 
5757
#------------------------------------------------------------------------------
5758
sub chmod
5759
#
5760
# Description:
5761
#       This sub-routine is used to change the ownership of a file or
5762
#       directory structure.
5763
#
5764
#------------------------------------------------------------------------------
5765
{
5766
    # correct number of parameters?
5767
    Error("Incorrect number of params passed to chmod() function. Check deploy config.") if ( ($#_+1) != 3 );
5768
 
5769
    # lets setup the passed values.
5770
    my ($m_sDirTag, $m_sfile, $m_ownPerms) = @_;
5771
 
5772
    Warning("chmod has been deprecated by and now calls setPermissions, see deploylib.pm");
5773
 
5774
    # call setPermissions, if no File then do DirTagOnly, otherwise set FilterIn=File
5775
    setPermissions($m_sDirTag, "--NoRecurse", 
1558 lkelly 5776
                    ($m_sfile) ? "--FilePerms=$m_ownPerms" : "--DirPerms=$m_ownPerms",
5777
                    ($m_sfile) ? "--FilterIn=$m_sfile"     : "--DirTagOnly" );
1556 lkelly 5778
 
1530 dpurdie 5779
    return 1;
5780
}
5781
 
5782
 
5783
#------------------------------------------------------------------------------
5784
sub chmodRecursive
5785
#
5786
# Description:
5787
#       This sub-routine is used to change the permissions recursively in
5788
#       the target packgae.
5789
#
5790
#------------------------------------------------------------------------------
5791
{
5792
    # correct number of parameters?
1556 lkelly 5793
    Error("Incorrect number of params passed to chmodRecursive() function. Check deploy config.") if ( ($#_+1) != 2 );
1530 dpurdie 5794
 
5795
    # lets setup the passed values.
5796
    my ($m_sDirTag, $m_ownPerms) = @_;
5797
 
1556 lkelly 5798
    Warning("chmodRecursive has been deprecated by and now calls setPermissions, see deploylib.pm");
1530 dpurdie 5799
 
1556 lkelly 5800
    # call setPermissions, if no File then do DirTagOnly, otherwise set FilterIn=File
5801
    setPermissions($m_sDirTag, "--Recurse", "--Perms=$m_ownPerms");
1530 dpurdie 5802
 
5803
    return 1;
5804
}
5805
 
5806
 
5807
 
5808
 
5809
#------------------------------------------------------------------------------
5810
sub chmodDir
5811
#
5812
# Description:
5813
#       This sub-routine is used to change the permissions an entire directory tree.
5814
#
5815
#       It recurses from a starting point chmod'ing each item and if it
5816
#       finds a dir it recurses into that dir chmod'ing it as well.
5817
#
5818
#------------------------------------------------------------------------------
5819
{
5820
    # correct number of parameters?
1556 lkelly 5821
    Error("Incorrect number of params passed to chmodDir() function.") if ( ($#_+1) != 2 );
1530 dpurdie 5822
 
5823
    my ($startingPoint, $perms) = @_;
5824
 
1556 lkelly 5825
    Warning("chmodDir has been deprecated by setPermissions, see deploylib.pm");
5826
 
1534 dpurdie 5827
    Verbose("chmodDir: Recursively setting permsision of [$startingPoint] to [$perms]");
1530 dpurdie 5828
 
5829
    local *DIR;
1556 lkelly 5830
    opendir(DIR, $startingPoint) or Error("can't opendir $startingPoint: $!");
1530 dpurdie 5831
 
5832
    my ($item);
5833
    while (defined($item = readdir(DIR)))
5834
    {
1556 lkelly 5835
        if ( "$item" !~ /^\.$/  && "$item" !~ /^\.\.$/ )
1530 dpurdie 5836
        {
5837
            if ( -d "$startingPoint/$item" )
5838
            {
5839
                chmodDir("$startingPoint/$item", $perms);
5840
            }
5841
            else
5842
            {
5843
                chmodFile("$startingPoint/$item", $perms);
5844
            }
5845
        }
5846
    }
1568 dpurdie 5847
    closedir (DIR);
1530 dpurdie 5848
 
5849
    # lets deal with starting dir
5850
    # 
5851
    chmodFile("$startingPoint", $perms);
5852
 
5853
    return 1;
5854
}
5855
 
5856
 
5857
 
5858
#------------------------------------------------------------------------------
5859
sub chmodFile
5860
#
1556 lkelly 5861
#    this function is used to chmod the perms of an item
1530 dpurdie 5862
#    it is passed the absolute path to the item and the associated 
5863
#    perms.
5864
#
5865
#------------------------------------------------------------------------------
5866
{
5867
    my ($item, $perms) = @_;
5868
 
5869
    my ($noItems) = CORE::chmod oct($perms), $item;
5870
    if ( $noItems == 0 )
5871
    {
1556 lkelly 5872
        Error("ERROR: Failed to chmod $item=$perms, retVal=[$noItems]");
1530 dpurdie 5873
    }
5874
    else
5875
    {
1556 lkelly 5876
        Debug("Successfully chmod $item=$perms");
1530 dpurdie 5877
    }
5878
 
5879
    return 1;
5880
}
5881
 
5882
 
5883
 
5884
#------------------------------------------------------------------------------
5885
sub createSymbolicLink
5886
#
5887
# Description:
5888
#       This sub-routine is used to copy a local deployment file into
5889
#       the target destination dir. 
5890
#
5891
#
5892
#------------------------------------------------------------------------------
5893
{
5894
    # correct number of parameters?
5895
    if ( ($#_+1) != 3 )
5896
    {
1534 dpurdie 5897
        Error("Incorrect number of params passed to " .
1530 dpurdie 5898
                  "createSymbolicLink() function. Check deploy config.");
5899
    }
5900
 
5901
 
5902
    # lets just check to see if we can execute this function on
5903
    # this machine.
5904
    #
5905
    if ( "$MachType" ne "sparc" )
5906
    {
1534 dpurdie 5907
        Verbose("createSymbolicLink() not supported on this machine type.");
1530 dpurdie 5908
        return 1;
5909
    }
5910
 
5911
 
5912
    # lets setup the passed values.
5913
    my ($m_sDirTag, $m_srcStr, $m_linkStr) = @_;
5914
 
5915
    # lets get the absolute src dir value
5916
    my ($m_sDirAbsoluteValue) = getTargetDstDirValue($m_sDirTag, "A");
5917
 
5918
 
5919
    # lets see if the source item exists
5920
    #
5921
    if ( ! -f "$m_sDirAbsoluteValue/$m_srcStr" )
5922
    {
1534 dpurdie 5923
        Error("Failed to locate item [$m_sDirAbsoluteValue/$m_srcStr], link not created.");
1530 dpurdie 5924
    }
5925
 
5926
 
5927
 
5928
    my ($cmd) = "cd $m_sDirAbsoluteValue; ln -s $m_srcStr $m_linkStr";
5929
    system("$cmd");
5930
    if ( $? != 0 )
5931
    {
1534 dpurdie 5932
        Error("Failed to complete command: [$cmd]");
1530 dpurdie 5933
    }
5934
    else
5935
    {
1534 dpurdie 5936
        Verbose("Executed command: [$cmd]");
1530 dpurdie 5937
    }
5938
 
5939
    return 1;
5940
}
5941
 
5942
 
5943
#------------------------------------------------------------------------------
5944
sub createPrototypeFile2
5945
#
5946
# Description:
5947
#       This sub-routine is used to create the required package prototype file
5948
#       fom a known directory struture using the a=b format.
5949
#
5950
#------------------------------------------------------------------------------
5951
{
1556 lkelly 5952
    my ($opt_keep_mask, $opt_keep_links, @args);
1550 dpurdie 5953
 
5954
    #
5955
    #   Process the arguments and extract parameters and options
5956
    #
5957
    foreach ( @_ )
5958
    {
5959
        if ( m/^--KeepMask/ ) {
5960
            $opt_keep_mask = 1;
5961
 
1556 lkelly 5962
        } elsif ( m/^--KeepLinks/ ) {
5963
            $opt_keep_links = 1;
5964
 
1550 dpurdie 5965
        } elsif ( m/^--/ ) {
5966
            Error("createPrototypeFile2: Unknown option: $_")
5967
 
5968
        } else {
5969
            push @args, $_;
5970
 
5971
        }
5972
    }
5973
 
1530 dpurdie 5974
    # correct number of parameters?
1550 dpurdie 5975
    if ( ($#args + 1) != 3 )
1530 dpurdie 5976
    {
1534 dpurdie 5977
        Error("Incorrect number of params passed to " .
1530 dpurdie 5978
                  "createPrototypeFile2() function. Check deploy config.");
5979
    }
5980
 
5981
    # lets just check to see if we can execute this function on
5982
    # this machine.
5983
    #
5984
    if ( "$MachType" ne "sparc" )
5985
    {
1534 dpurdie 5986
        Verbose("createPrototypeFile2() not supported on this machine type.");
1530 dpurdie 5987
        return 1;
5988
    }
5989
 
5990
    # lets take the passed in args.
1550 dpurdie 5991
    my ($uid, $gid, $mask) = @args;
1530 dpurdie 5992
 
5993
 
5994
    # we need to locate the prototype file
1570 gchristi 5995
    if ( -f "$ProtoTypeFile" )
1530 dpurdie 5996
    {
1570 gchristi 5997
        unlink("$ProtoTypeFile");
5998
        Verbose("Removing prototype file [$ProtoTypeFile].");
1530 dpurdie 5999
    }
6000
 
6001
    # lets open the prototype file.
6002
    #    
6003
    local *FILE;
1570 gchristi 6004
    open ( FILE, "> $ProtoTypeFile") or
6005
        Error("Failed to open file [$ProtoTypeFile].");
1530 dpurdie 6006
    # lets populate the prototype file.
6007
    printf FILE ("!default $mask $uid $gid\n");
6008
    printf FILE ("i pkginfo\n");
6009
    close (FILE);
6010
 
6011
 
6012
    # lets put the pre-deinfed generic entries into the
6013
    # prototype file
6014
    #
6015
    if ( "x$PkgPatchNum" ne "x" )
6016
    {
6017
        addPatchInfo2ProtoTypeFile();
6018
    }
6019
 
6020
 
6021
    # lets set the associated uid, gid and mask
6022
    # for the bits in the prototype file.
6023
    #
6024
    $m_UID  = $uid;
6025
    $m_GID  = $gid;
6026
    $m_MASK = $mask;
1550 dpurdie 6027
    $m_KEEP_MASK = $opt_keep_mask;
1556 lkelly 6028
    $m_KEEP_LINKS = $opt_keep_links;
1530 dpurdie 6029
 
6030
 
6031
    # now we need to add entries for each directory we will 
6032
    # be installing 
1570 gchristi 6033
    File::Find::find( \&prototype2Find, ($TargetBaseDir ne ".") ? "$PkgBaseDir/$TargetBaseDir" : $PkgBaseDir );
1530 dpurdie 6034
 
6035
 
6036
    # lets populate the prototype file with a newline.
1570 gchristi 6037
    open ( FILE, ">> $ProtoTypeFile") or
6038
        Error("Failed to open file [$ProtoTypeFile].");
1530 dpurdie 6039
    printf FILE ("\n");
6040
    close (FILE);
6041
 
6042
 
1570 gchristi 6043
    Information("Created prototype file [$ProtoTypeFile].");
1530 dpurdie 6044
 
6045
    return 1;
6046
}
6047
 
1570 gchristi 6048
 
6049
#------------------------------------------------------------------------------
6050
sub prototype2Find
6051
#
6052
#    Description:
6053
#        This subroutine is used to locate all associated package dirs.
6054
#        It also adds an entry into the prototype file for each dir.
6055
#
6056
#------------------------------------------------------------------------------
6057
{
6058
    my $file = $File::Find::name;
6059
 
6060
    # Our topdir will either be $PkgBaseDir or $PkgBaseDir/$TargetBaseDir (if there is a TargetBaseDir).
6061
    # if we have PkgBaseDir only we dont want to include this in the prototype file, 
6062
    # if TargetBaseDir is defined we include it in the prototype
6063
    if ( $file ne $PkgBaseDir )
6064
    {
6065
        my ($sfile) = $file;
6066
 
6067
        # we get the absolute path from the find, but we only require a relative path from the starting dir.
6068
        # So remove PkgBaseDir from path and include all dirs below it including TargetBaseDir if there is one
6069
        $file =~ s|$PkgBaseDir/*||;    
6070
 
6071
        # if TargetBaseDir is "." then find will find the pkginfo & prototype files so we need to exclude them
6072
        if ( $file ne $ProtoTypeFileName && $file ne $PkgInfoFileName )
6073
        {
6074
            my $fmask = $m_MASK;
6075
            if ( $m_KEEP_MASK )
6076
            {
6077
                $fmask = sprintf "%lo", ( (stat($sfile))[2]) & 07777;
6078
            }
6079
 
6080
            open ( FILE, ">> $ProtoTypeFile") or
6081
                Error("Failed to open file [$ProtoTypeFile].");
6082
 
6083
            if ( $m_KEEP_LINKS && -l "$sfile" )
6084
            {
6085
                my $linkDest = readlink($sfile);
6086
                Warning("Link $sfile has an absolute path, may not be a problem but make sure its what you want") if ( $linkDest =~ /^\// );
6087
                printf FILE ("s none $file=$linkDest\n");
6088
            }
6089
            elsif ( -f $sfile )
6090
            {
6091
                printf FILE ("f none $file=$file $fmask $m_UID $m_GID\n");
6092
            }
6093
            elsif ( -d $sfile )
6094
            {
6095
                printf FILE ("d none $file $fmask $m_UID $m_GID\n");
6096
            }
6097
 
6098
            close (FILE);
6099
        }
6100
    }
6101
}
6102
 
1534 dpurdie 6103
#-------------------------------------------------------------------------------
6104
# Function        : createZip
6105
#
6106
# Description     : Create a ZIp file of a given directory
6107
#
6108
# Inputs          : --Recurse               - Recurse subdirs
6109
#                   --NoRecurse             - Done recurse subdirs
6110
#                   --Dirnames              - Record Dir names
6111
#                   --NoDirnames            - Don't record dirnames
6112
#                   --NoQuiet               - Display the operatios
6113
#                   --Dir=xxxx              - Symbolic Directory to zip
6114
#                   --ZipDir=ttt            - Symbolic target directory
6115
#                   --ZipFile=yyyy          - Zipfile to create
6116
#
6117
# Returns         : Will not return on error
6118
#                   Requires 'zip' to be provided by a 'package' such as InfoZip
6119
#
6120
sub createZip
6121
{
6122
    my $recurse = 1;
6123
    my $dirnames = 0;
6124
    my $quiet = 1;
6125
    my $sdir;
6126
    my $tdir;
6127
    my $tfile;
1530 dpurdie 6128
 
1534 dpurdie 6129
    #
6130
    #   Only on Windows at the moment.
6131
    #   Perhaps Unix should create a .gz file
6132
    #
6133
    Warning ("createZip not supported on $MachType. Operation skipped")
6134
        unless ( "$MachType" eq "win32" );
6135
 
6136
    #
6137
    #   Process user arguments
6138
    #
6139
    foreach ( @_ )
6140
    {
6141
        if ( m/^--Recurse/ ) {
6142
            $recurse = 1;
6143
 
6144
        } elsif ( m/^--NoRecurse/) {
6145
            $recurse = 0;
6146
 
6147
        } elsif ( m/^--Dirnames/ ) {
6148
            $dirnames = 1;
6149
 
6150
        } elsif ( m/^--NoDirnames/ ) {
6151
            $dirnames = 0;
6152
 
6153
        } elsif ( m/^--NoQuiets/ ) {
6154
            $quiet = 0;
6155
 
6156
        } elsif ( m/^--Dir=(.*)/ ) {
6157
            $sdir = $1;
6158
 
6159
        } elsif ( m/^--ZipDir=(.*)/ ) {
6160
            $tdir = $1;
6161
 
6162
        } elsif ( m/^--ZipFile=(.*)/ ) {
6163
            $tfile = $1;
6164
 
6165
        } else {
6166
            Warning("createZip: Unknown argument ignored: $_");
6167
 
6168
        }
6169
    }
6170
 
6171
    #
6172
    #   Convert the source directory TAG into a real directory
6173
    #
6174
    Error ("createZip: Source directory not specified") unless ( $sdir );
6175
    my $sdir_a = getTargetDstDirValue($sdir, "A");
6176
 
6177
    #
6178
    #   Convert the destination directory tag into a real directory
6179
    #
6180
    Error ("createZip: Target directory not specified") unless ( $tdir );
6181
    Error ("createZip: Target filename not specified") unless ( $tfile );
6182
    my $tdir_a = getTargetDstDirValue($tdir, "A");
6183
 
6184
    #
6185
    #   Locate the 'zip' uitilty
6186
    #
6187
    my $prog = LocateProgInPath( 'zip' );
6188
    Error ("createZip: Cannot locate ZIP executable",
6189
            "May need to use the 'infozip' package") unless ( $prog );
6190
 
6191
    #
6192
    #   Generate command file
6193
    #
6194
    my $args = '-9';
6195
    $args .= 'q' unless ( (! $quiet) || IsVerbose(1));
6196
    $args .= 'r' if ( $recurse );
6197
    $args .= 'j' unless ( $dirnames );
6198
 
6199
    #
6200
    #   Zip up the files
6201
    #
6202
    Information ("Create Zip File: [$tdir] $tfile");
6203
    chdir ( $sdir_a ) || Error ("Cannot cd to $sdir_a");
6204
    my $rv = System ($prog, $args, "$tdir_a/$tfile", "." );
6205
    chdir($CurrentDir) || Error ("Cannot cd to $CurrentDir");
6206
 
6207
    Error ("createZip: Zip file not created") if ( $rv );
6208
}
6209
 
6210
 
1552 dpurdie 6211
#-------------------------------------------------------------------------------
6212
# Function        : convertFile
1530 dpurdie 6213
#
1552 dpurdie 6214
# Description     : This sub-routine is used to remove all carrage return\line
6215
#                   feeds from a line and replace them with the platform
6216
#                   specific equivalent chars.
1530 dpurdie 6217
#
1552 dpurdie 6218
#                   We let PERL determine what characters are written to the
6219
#                   file base on the  platform you are running on.
1530 dpurdie 6220
#
1552 dpurdie 6221
#                   i.e. LF    for unix
6222
#                   CR\LF for win32
1530 dpurdie 6223
#
1552 dpurdie 6224
# Inputs          : m_targetDirTag          - Symbolic name of target directory
6225
#                   m_nfiles                - List of files in that directory
6226
#                   or
6227
#                   SearchOptions           - Search options to find files
6228
#                                           --Recurse
6229
#                                           --NoRecurse
6230
#                                           --FilterIn=xxx
6231
#                                           --FilterInRE=xxx
6232
#                                           --FilterOut=xxx
6233
#                                           --FilterOutRE=xxx
1530 dpurdie 6234
#
1552 dpurdie 6235
#
6236
# Returns         : 1
6237
#
6238
sub convertFile
1530 dpurdie 6239
{
1552 dpurdie 6240
    my @uargs;
6241
    my $search =  LocateFiles->new( recurse => 0 );
6242
 
6243
    #
6244
    #   Process user arguments extracting options
6245
    #
6246
    foreach  ( @_ )
1530 dpurdie 6247
    {
1552 dpurdie 6248
        if ( m~^--Recurse~ ) {
6249
            $search->recurse(1);
1530 dpurdie 6250
 
1552 dpurdie 6251
        } elsif ( m~^--NoRecurse~) {
6252
            $search->recurse(0);
1530 dpurdie 6253
 
1552 dpurdie 6254
        } elsif ( /^--FilterOut=(.*)/ ) {
6255
            $search->filter_out($1);
1530 dpurdie 6256
 
1552 dpurdie 6257
        } elsif ( /^--FilterOutRE=(.*)/ ) {
6258
            $search->filter_out_re($1);
1530 dpurdie 6259
 
1552 dpurdie 6260
        } elsif ( /^--FilterIn=(.*)/ ) {
6261
            $search->filter_in($1);
1530 dpurdie 6262
 
1552 dpurdie 6263
        } elsif ( /^--FilterInRE=(.*)/ ) {
6264
            $search->filter_in_re($1);
1530 dpurdie 6265
 
1552 dpurdie 6266
        } elsif ( m~^--~) {
6267
            Error ("convertFile: Unknown option: $_");
1530 dpurdie 6268
 
1552 dpurdie 6269
        } else {
6270
            push @uargs, $_;
1530 dpurdie 6271
        }
6272
    }
6273
 
1552 dpurdie 6274
    #
6275
    #   Process non-option arguments
6276
    #       - Base dir
6277
    #       - List of files
6278
    #
6279
    my ($m_targetDirTag, @m_nfiles) = @uargs;
6280
    Error ("convertFiles: Target Dir must be specified" ) unless ( $m_targetDirTag );
1530 dpurdie 6281
 
1552 dpurdie 6282
    #
6283
    # Convert symbolic dir tag to physical path
6284
    #
6285
    my ($m_targetDirValue) = getTargetDstDirValue($m_targetDirTag, "A");
1530 dpurdie 6286
 
6287
    #
1552 dpurdie 6288
    #   Need to determine if we are searching or simply using a file list
6289
    #   There are two forms of the functions. If any of the search options have
6290
    #   been used then we assume that we are searchine
6291
    #
6292
    if ( $search->has_filter() )
1530 dpurdie 6293
    {
1552 dpurdie 6294
        Error ("convertFiles: Cannot mix search options with named files") if ( @m_nfiles );
6295
        @m_nfiles = $search->search($m_targetDirValue);
1530 dpurdie 6296
    }
1552 dpurdie 6297
    Error ("convertFiles: No files specified") unless ( @m_nfiles );
6298
 
6299
    #
6300
    #   Process all named files
6301
    #
6302
    foreach my $m_nfile ( @m_nfiles )
1530 dpurdie 6303
    {
1552 dpurdie 6304
 
6305
        # this is our file that we want to clean.
6306
        my ($m_ifileLoc) = "$m_targetDirValue/$m_nfile";
6307
        my ($m_tfileLoc) = "$m_targetDirValue/$m_nfile\.tmp";
6308
 
6309
 
6310
        # we will check to see if the file exists.
6311
        #
6312
        local *IFILE;
6313
        local *TFILE;
6314
        if ( -f "$m_ifileLoc" )
6315
        {
6316
            open (IFILE, "< $m_ifileLoc" ) or
6317
                Error("Failed to open file [$m_ifileLoc] : $!");
6318
 
6319
            open (TFILE, "> $m_tfileLoc" ) or
6320
                Error("Failed to open file [$m_tfileLoc] : $!");
6321
 
6322
            while ( <IFILE> ) 
6323
            {
1562 dpurdie 6324
                s~[\n\r]+$~~;               # Chomp
1552 dpurdie 6325
                print TFILE "$_\n";
6326
            }
6327
        }
6328
        else
6329
        {
6330
            Error("Deploy file [$m_ifileLoc] does not exist.");
6331
        }
6332
 
6333
        close IFILE;
6334
        close TFILE;
6335
 
6336
 
6337
        # lets replace our original file with the new one
6338
        #
6339
        if(File::Copy::move("$m_tfileLoc", "$m_ifileLoc"))
6340
        {
6341
            Information("Renamed [$m_tfileLoc] to [$m_ifileLoc] ...");
6342
        }
6343
        else
6344
        {
6345
            Error("Failed to rename file [$m_tfileLoc] to [$m_ifileLoc]: $!");
6346
        }
1530 dpurdie 6347
    }
6348
 
6349
    return 1;
6350
}
6351
 
1534 dpurdie 6352
#-------------------------------------------------------------------------------
6353
# Function        : installDeployFile
1530 dpurdie 6354
#
1534 dpurdie 6355
# Description     : This sub-routine is used to copy a local deployment file into
6356
#                   the target destination dir.
1530 dpurdie 6357
#
1534 dpurdie 6358
# Inputs          : m_srcDirTag             - Tag for Source Dir name
6359
#                                             Tag defined in %LocalSrcDirStructure
1554 dpurdie 6360
#                                             Or --Package=name,subdir
6361
#                                             Or --Interface=subdir
6362
#
1534 dpurdie 6363
#                   m_sfile                 - Name of the source file
6364
#                   m_targetDirTag          - Tag for the target directory
6365
#                                             Tag defined in %TargetDstDirStructure
6366
#                   m_nfile                 - Target filename
6367
#                                             Must be specified. If set to "", then
6368
#                                             the source filename will be used.
1530 dpurdie 6369
#
1534 dpurdie 6370
# Returns         : True
6371
#
1530 dpurdie 6372
#------------------------------------------------------------------------------
1534 dpurdie 6373
 
6374
sub installDeployFile
1530 dpurdie 6375
{
6376
    # correct number of parameters?
6377
    if ( ($#_+1) != 4 )
6378
    {
1534 dpurdie 6379
        Error("Incorrect number of params passed to " .
1530 dpurdie 6380
                  "installDeployFile() function. Check deploy config.");
6381
    }
6382
 
6383
    my ($m_srcDirTag, $m_sfile, $m_targetDirTag, $m_nfile) = @_;
6384
 
6385
    # lets get the src dir value
6386
    my ($m_targetDirValue) = getTargetDstDirValue($m_targetDirTag, "A");
6387
 
6388
    # lets get the target dir value
6389
    my ($m_srcDirValue) = getLocalDirValue($m_srcDirTag, "A");
6390
 
6391
 
6392
    # we know where we are getting this from and where we 
6393
    # going to put them.
6394
    my ($m_sfileLoc) = "$m_srcDirValue/$m_sfile";
6395
 
6396
    my ($m_nfileLoc) = "";
6397
    # lets determine what we are going to call the new file.
6398
    #
6399
    if ( "x$m_nfile" eq "x" )
6400
    {
6401
        $m_nfileLoc = "$m_targetDirValue/$m_sfile";
6402
    }
6403
    else
6404
    {
6405
        $m_nfileLoc = "$m_targetDirValue/$m_nfile";
6406
    }
6407
 
6408
 
6409
    # we will check to see if the file exists.
6410
    #
6411
    if ( -f "$m_sfileLoc" )
6412
    {
6413
        # now we need to copy the file. 
6414
        if(File::Copy::copy("$m_sfileLoc", "$m_nfileLoc"))
6415
        {
1534 dpurdie 6416
            Verbose("Copied [$m_sfile] to [$m_nfileLoc] ...");
1530 dpurdie 6417
 
6418
            # now we need to ensure the item is writable as it
6419
            # has come from our VOB that is by definition read-only
6420
            #
6421
            CORE::chmod oct("0755"), $m_nfileLoc;
6422
 
6423
        }
6424
        else
6425
        {
1534 dpurdie 6426
            Error("Failed to copy lib [$m_sfileLoc]: $!"); 
1530 dpurdie 6427
        }
6428
    }
6429
    else
6430
    {
1534 dpurdie 6431
        Error("Deploy file [$m_sfileLoc] does not exist.");
1530 dpurdie 6432
    }
6433
 
6434
    return 1;
6435
}
6436
 
6437
 
6438
#------------------------------------------------------------------------------
6439
sub getGenericNameForLib
6440
#
6441
# Description:
6442
#       This sub-routine is used to determine the generic name for
6443
#       a library. I.E remove the buildtype and version number.
6444
#
6445
#       It also checks if the name provided should be excluded from
6446
#       the build.
6447
#
6448
#------------------------------------------------------------------------------
6449
{
6450
   # correct number of parameters?
6451
    if ( ($#_+1) != 1 )
6452
    {
1534 dpurdie 6453
        Error("Incorrect number of params passed to " .
1530 dpurdie 6454
                  "getGenericNameForLib() function. Check deploy config.");
6455
    }
6456
 
6457
    # lets just check to see if we can execute this function on
6458
    # this machine.
6459
    #
6460
    if ( "$MachType" ne "sparc" )
6461
    {
1534 dpurdie 6462
        Verbose("getGenericNameForLib() not supported on this machine type.");
1530 dpurdie 6463
        return "";
6464
    }
6465
 
6466
 
6467
    my($itemName) = @_;
6468
 
6469
    # first we need to check to see if it belongs in this build
6470
    #
6471
    my ($gName) = "";
6472
    if(excludeItemFromBuild($itemName))
6473
    {
1534 dpurdie 6474
        Verbose("Excluding item [$itemName] from build as not compatible with build type " .
1530 dpurdie 6475
                "[$BuildType].");
6476
        return "";  # file should be excluded.
6477
    }
6478
    else
6479
    {
6480
        $gName = removeBuildTypeFromItemName($itemName);
6481
        $gName = removeVersionNumberFromItemName($gName);
6482
 
6483
        return "$gName";
6484
    }
6485
 
6486
    return 1;
6487
}
6488
 
6489
 
6490
#------------------------------------------------------------------------------
6491
sub getGenericNameNoVersionForLib
6492
#
6493
# Description:
6494
#       This sub-routine is used to determine the generic name for
6495
#       a library. I.E removes the version number.
6496
#
6497
#       It also checks if the name provided should be excluded from
6498
#       the build.
6499
#
6500
#------------------------------------------------------------------------------
6501
{
1556 lkelly 6502
    my $installProdAndDebug;
6503
    my $itemName = "";
1530 dpurdie 6504
   # correct number of parameters?
1556 lkelly 6505
    if ( (($#_+1) < 1) || (($#_+1) > 2))
1530 dpurdie 6506
    {
1534 dpurdie 6507
        Error("Incorrect number of params passed to " .
1530 dpurdie 6508
                  "getGenericNameNoVersionForLib() function. Check deploy config.");
6509
    }
6510
 
1556 lkelly 6511
    #
6512
    #   Process parameters and extract options
6513
    #
6514
    foreach  ( @_ )
6515
    {
6516
        if ( m/^--InstallProdAndDebug/ ) {
6517
            # not sure if the filename conventions allow the installation
6518
            # of both prod/debug files on windows, so limit this to sparc/unix.
6519
            if ( "$MachType" ne "sparc" ){
6520
                Error("Can only use the InstallProdAndDebug option for sparc.");
6521
            }
6522
 
6523
            $installProdAndDebug = 1;
6524
        } else {
6525
            $itemName = $_;
6526
        }
6527
    }
6528
 
1530 dpurdie 6529
    # lets just check to see if we can execute this function on
6530
    # this machine.
6531
    #
6532
    if ( "$MachType" ne "sparc" )
6533
    {
1534 dpurdie 6534
        Verbose("getGenericNameNoVersionForLib() not supported on this machine type.");
1530 dpurdie 6535
        return "";
6536
    }
6537
 
6538
 
1556 lkelly 6539
    # first we need to check to see if it belongs in this build.
6540
    # if we've been told that both P & D are allowed, skip this check.
1530 dpurdie 6541
    my ($gName) = "";
1556 lkelly 6542
    if( !$installProdAndDebug && excludeItemFromBuild($itemName))
1530 dpurdie 6543
    {
1534 dpurdie 6544
        Verbose("Excluding item [$itemName] from build as not compatible with build type " .
1530 dpurdie 6545
                "[$BuildType].");
6546
        return "";  # file should be excluded.
6547
    }
6548
    else
6549
    {
6550
        $gName = removeVersionNumberFromItemName($itemName);
6551
        return "$gName";
6552
    }
6553
 
6554
    return 1;
6555
}
6556
 
6557
 
6558
#------------------------------------------------------------------------------
6559
sub getGenericNameNoVersionForXML
6560
#
6561
# Description:
6562
#       This sub-routine is used to determine the generic name for
6563
#       an XML file. I.E removes the version number.
6564
#
6565
#------------------------------------------------------------------------------
6566
{
6567
   # correct number of parameters?
6568
    if ( ($#_+1) != 1 )
6569
    {
1534 dpurdie 6570
        Error("Incorrect number of params passed to " .
1530 dpurdie 6571
                  "getGenericNameNoVersionForXML() function. Check deploy config.");
6572
    }
6573
 
6574
    my($itemName) = @_;
6575
    my ($gName) = "";
6576
    $gName = removeVersionNumberFromXMLItemName($itemName);
6577
    return "$gName";
6578
 
6579
    return 1;
6580
}
6581
 
6582
 
6583
#------------------------------------------------------------------------------
6584
sub removeVersionNumberFromXMLItemName
6585
#
6586
#    Description:
6587
#        This sub-routine is used to remove the version number from the item name.
6588
#        i.e.  myFile_1_2_3.xml ==> myFile.xml
6589
#
6590
#    INPUT:
6591
#        item name
6592
#
6593
#    RETURN:
6594
#        new item name.
6595
#
6596
#------------------------------------------------------------------------------
6597
{
6598
    my ($file)  = @_;
6599
    my ($nfile) = $file;
6600
 
6601
    if ( $nfile =~ m/_[0-9]+_[0-9]+_[0-9]+\.xml$/ )
6602
    {
6603
        # if we match lets deal with it.
6604
        $nfile =~ s/_[0-9]+_[0-9]+_[0-9]+\.xml$/\.xml/;
6605
    }
6606
    else
6607
    {
1534 dpurdie 6608
        Warning("Filename [$nfile] does not contain required format [myfile_N_N_N.xml].");
1530 dpurdie 6609
    }
6610
    return "$nfile";
6611
}
6612
 
6613
 
6614
#------------------------------------------------------------------------------
6615
sub createDpkgArchive
6616
#
6617
# Description:
6618
#       This sub-routine is used to create a dpkg_archive directory
6619
#       structure.
6620
#
6621
#------------------------------------------------------------------------------
6622
{
6623
    # correct number of parameters?
6624
    if ( ($#_+1) != 1 )
6625
    {
1534 dpurdie 6626
        Error("Incorrect number of params passed to " .
1530 dpurdie 6627
                  "createDpkgArchive() function. Check deploy config.");
6628
    }
6629
 
6630
    my ($desc) = @_;
6631
 
6632
    # lets just check to see if we can execute this function on
6633
    # for  this build.
6634
    #
6635
    if ( "x$PkgPatchNum" ne "x" )
6636
    {
1534 dpurdie 6637
        Verbose("createDpkgArchive() can only be called during a RELEASE build.");
1530 dpurdie 6638
        return 1;
6639
    }
6640
 
6641
 
6642
    # 1. we create a dpkg_archive top level dir within the output directory
6643
    #
6644
    my ($m_tmpDir) = "$PkgBaseDir/dpkg_archive";
1534 dpurdie 6645
    make_directory( $m_tmpDir, 0777 );
6646
 
1530 dpurdie 6647
    # 2. we create a sub-directory with the package name
6648
    #
1570 gchristi 6649
    $m_tmpDir = ($TargetBaseDir ne ".") ? "$PkgBaseDir/dpkg_archive/$TargetBaseDir" : "$PkgBaseDir/dpkg_archive";
1534 dpurdie 6650
    make_directory( $m_tmpDir, 0777 );
1530 dpurdie 6651
 
6652
    # 3. we create a sub-directory with the package version number
6653
    #
1570 gchristi 6654
    my ($m_tmpDir2) = "$m_tmpDir/${PkgVersion}.${ProjectAcronym}";
1534 dpurdie 6655
    make_directory( $m_tmpDir2, 0777 );
1530 dpurdie 6656
 
6657
 
6658
    # 4. we replacate the contents of the original outputdir/package name
6659
    #    to do this we shall execute a find starting within the original package target dir
6660
    #    any copy all items we find to the new location under the dpkg_archive/package/version dir.
6661
    #
1570 gchristi 6662
    File::Find::find( \&DpkgFind, ($TargetBaseDir ne ".") ? "$PkgBaseDir/$TargetBaseDir" : $PkgBaseDir );
1530 dpurdie 6663
 
6664
 
6665
    # 5. we create a descpkg file, with the Package Name, Version and Desc
6666
    #
1570 gchristi 6667
    my ($m_DescPkgFile) = "$m_tmpDir2/descpkg";
1530 dpurdie 6668
 
6669
    # now we need to update the prototype file
6670
    #
6671
    local *FILE;
6672
    open ( FILE, ">> $m_DescPkgFile") or
1534 dpurdie 6673
        Error("Failed to open file [$m_DescPkgFile].");
1530 dpurdie 6674
    printf FILE ("$PkgName, $PkgVersion.$ProjectAcronym - $desc\n");
6675
    close (FILE);
6676
 
6677
 
6678
    # done.
1534 dpurdie 6679
    Information("createDpkgArchive() completed.");
1530 dpurdie 6680
 
6681
    return 1;
6682
}
6683
 
6684
 
6685
#------------------------------------------------------------------------------
6686
sub DpkgFind
6687
#
6688
#    Description:
6689
#        This subroutine is used to locate all associated items to
6690
#        create a new dpkg_archive directory structure. 
6691
#
6692
#------------------------------------------------------------------------------
6693
{
6694
    my($item)= "$File::Find::name";
6695
    my($base)= File::Basename::basename($item);
6696
 
6697
 
6698
    # we get the absolute path from the find, but we only require
6699
    # a relative path from the starting dir.
6700
 
1570 gchristi 6701
    my $srcdir = ($TargetBaseDir ne ".") ? "$PkgBaseDir/$TargetBaseDir" : $PkgBaseDir;
6702
    my $dstdir = ($TargetBaseDir ne ".") ? "$PkgBaseDir/dpkg_archive/$TargetBaseDir" : "$PkgBaseDir/dpkg_archive";
1530 dpurdie 6703
    # we need to determine which file we are dealing with
6704
    if ( ! -d "$item")
6705
    {
6706
        my ($m_sfile) = $item;
1570 gchristi 6707
        $item =~ s|$srcdir|$dstdir/$PkgVersion\.$ProjectAcronym|;
1530 dpurdie 6708
 
6709
        if(File::Copy::copy("$m_sfile", "$item"))
6710
        {
1534 dpurdie 6711
            Verbose("Copied [$base] to [$item] ...");
1530 dpurdie 6712
        }
6713
        else
6714
        {
1534 dpurdie 6715
            Error("Failed to copy pkg file [$m_sfile] to [$item]: $!");
1530 dpurdie 6716
        }
6717
    }
6718
    else
6719
    {
1570 gchristi 6720
        # if no TargetBaseDir then we will pick up dpkg_archive dir so lets prune it
6721
        if ( $_ eq "dpkg_archive" )
6722
        {
6723
            $File::Find::prune = 1;
6724
        }
6725
        else
6726
        {
6727
            # we have found a dir
6728
            my ($m_sDir) = $item;
6729
            $item =~ s|$srcdir|$dstdir/$PkgVersion\.$ProjectAcronym|;
6730
            make_directory( $item, 0777 );
6731
        }
1530 dpurdie 6732
    }
6733
}
6734
 
6735
 
6736
# This is now depricated
6737
sub generateReleaseNote
6738
{
1534 dpurdie 6739
    Error("generateReleaseNote is depricated please use generateHtmlReleaseNote");
1530 dpurdie 6740
    return 1;
6741
}
6742
 
6743
#------------------------------------------------------------------------------
6744
sub generateHtmlReleaseNote
6745
#
6746
#    Description:
6747
#
6748
#------------------------------------------------------------------------------
6749
{
1560 dpurdie 6750
    Warning('Deprecated Function: generateHtmlReleaseNote');
1530 dpurdie 6751
}
6752
 
1544 dpurdie 6753
#-------------------------------------------------------------------------------
6754
# Function        : generateXmlDependancy
6755
#
6756
# Description     : Generate an XML file that describes the despendencies of the
6757
#                   released package.
6758
#
6759
#                   The generated file needs to be packaged for deployment. This
6760
#                   function will only create the file. It needs to be added to the
6761
#                   files that are deployed into the field. The file is primarily
6762
#                   to be used by Windows based applications, but its use may be
6763
#                   extended to other platforms.
6764
#
6765
#                   The file 'should' be deployed in the same directory as the main
6766
#                   application executable, so that the executable may locate it.
6767
#
6768
#                   The XML file is named after the package. It is prefixed with
6769
#                   the string "PkgInfo_".
6770
#
6771
#                   By default file will be placed in the 'TargetBaseDir'.
6772
#                   This behaviour may be modified by the user.
6773
#
6774
#                   Refer to package_info.xsd for details on the structure of the
6775
#                   generated XML file. Do not randomly chnage the structure.
6776
#                   It is being used.
6777
#
6778
#                   This function requires access to Release Manager in order
6779
#                   to locate the package description and build-time information
6780
#
6781
#                   The function will use the current/last version of the package
6782
#                   in an attempt to locate package information.
6783
#
6784
#
6785
# Inputs          : platform        - Platforms for which the file will be created
6786
#                                     '*' indicate ALL platforms.
6787
#                   options         - Options to control the detail of the generated file
6788
#
6789
#                   Valid options
6790
#                       --TargetDir         - Symbolic target directory
6791
#                                             Default: TargetBaseDir
6792
#
6793
#                       --Depth=nn          - Depth to traverse the dependancy tree
6794
#                                             All packages below this depth will be ignored
6795
#                                             Default: 0. All packages will be included
6796
#                       --VisibleDepth=nn   - Package beyond this depth will be marked as invisible
6797
#                                             Default: 1. Only top level packages will be marked
6798
#                                             as visible.
6799
#                       --Ignore=name       - Ignore this package
6800
#                                             It will not be included in the dependancy list
6801
#                                             Default: None
6802
#                       --IgnoreChildren=name   - Do not include children of this package\
6803
#                                             Default: None
6804
#                       --Invisible=name    - Mark this package and its dependents as invisible
6805
#                                             Default: None
6806
#                       --InvisibleChildren=name
6807
#                                           - Mark this package as visible, but its dependents as invisible
6808
#                                             Default: None
6809
#
6810
# Example:
6811
#               generateXmlDependancy('*', '--TargetDir=OcpDir' );
6812
#               
6813
#
6814
# Returns         : Nothing
6815
#
6816
sub generateXmlDependancy
6817
{
6818
    my ($platforms, @opts) = @_;
6819
    my %data;
6820
    my $filename = "PkgInfo_$PkgName" . '.xml';
6821
    my $targetTag;
1530 dpurdie 6822
 
1544 dpurdie 6823
    return if ( ! ActivePlatform($platforms) );
6824
    Information("Generating XML dependancy information from RM data: $filename");
1560 dpurdie 6825
    Warning ("This function is not compatible with Escrow builds");
1530 dpurdie 6826
 
1544 dpurdie 6827
    #
6828
    #   Insert defaults
6829
    #
6830
    $data{default_visible} = 1;
6831
 
6832
    #
6833
    #   Parse the user options
6834
    #
6835
    foreach ( @opts )
6836
    {
6837
        if ( m/^--Depth=(\d+)/ ) {
6838
            $data{default_depth} = $1;
6839
 
6840
        } elsif ( m/^--VisibleDepth=(\d+)/ ) {
6841
            $data{default_visible} = $1;
6842
 
6843
        } elsif ( m/^--Ignore=(.*)/ ) {
6844
            $data{ignore}{$1} = 1;
6845
 
6846
        } elsif ( m/^--IgnoreChildren=(.*)/ ) {
6847
            $data{ignore_child}{$1} = 1;
6848
 
6849
        } elsif ( m/^--Invisible=(.*)/ ) {
6850
            $data{invisible}{$1} = 1;
6851
 
6852
        } elsif ( m/^--InvisibleChildren=(.*)/ ) {
6853
            $data{invisible_child}{$1} = 1;
6854
 
6855
        } elsif ( m/^--TargetDir=(.*)/ ) {
6856
            $targetTag = $1;
6857
 
6858
        } else {
6859
            Error ("generateXmlDependancy: Unknown option: $_");
6860
        }
6861
    }
6862
 
6863
    #
6864
    #   Sanity Tests
6865
    #
6866
    if ( $data{default_visible} && $data{default_depth} )
6867
    {
6868
        Error ("generateXmlDependancy:Visible depth must be less than total depth")
6869
            if ( $data{default_visible} > $data{default_depth} );
6870
    }
6871
 
6872
    # lets check to see if the target tag exists
6873
    # if does not the process with log an error.
6874
    #
6875
    my $targetValue;
6876
    if ( $targetTag )
6877
    {
6878
        $targetValue = getTargetDstDirValue($targetTag, "A");
6879
    }
6880
    else
6881
    {
1570 gchristi 6882
        $targetValue = ($TargetBaseDir ne ".") ? "$PkgBaseDir/$TargetBaseDir" : $PkgBaseDir;
1544 dpurdie 6883
    }
6884
    $filename = $targetValue . '/' . $filename;
6885
 
6886
 
6887
    #
6888
    #   Determine package information.
6889
    #   Must cater for a number of situations
6890
    #       1) Package rebuild
6891
    #       2) Package ripple
6892
    #       3) New package
6893
    #
6894
 
6895
 
6896
    # Set defaults for elements in RM if not found
6897
    DeployUtils::RmPkgInfo->DefaultDescription($PkgDesc);
6898
    DeployUtils::RmPkgInfo->DefaultLabel($PkgLabel);
6899
 
6900
    #
6901
    #   Try with the current package version. It may be in RM
6902
    #
6903
    $RmPkgDetails = DeployUtils::RmPkgInfo->new( {
6904
                        PKG_NAME => $PkgName,
6905
                        PKG_VERSION => $PkgVersionUser,
6906
                        NO_WARN => 1
6907
                    } );
6908
 
6909
    unless ( $RmPkgDetails->foundDetails() && $PkgPreviousVersionStr )
6910
    {
6911
        #
6912
        #   Try with the 'Previous' package
6913
        #
6914
        my $RmPkgDetailsPrev = DeployUtils::RmPkgInfo->new( {
6915
                        PKG_NAME => $PkgName,
6916
                        PKG_VERSION => $PkgPreviousVersionStr,
6917
                        NO_WARN => 1
6918
                    } );
6919
 
6920
        if ( $RmPkgDetailsPrev->foundDetails() )
6921
        {
6922
            Information ("generateXmlDependancy. Using previous version ($PkgPreviousVersionStr)");
6923
            $RmPkgDetails = $RmPkgDetailsPrev;
6924
        }
6925
    }
6926
 
6927
    unless ( $RmPkgDetails->foundDetails() )
6928
    {
6929
        Warning ("generateXmlDependancy. Package Information not in RM. Using defaults");
6930
    }
6931
 
6932
 
6933
    #
6934
    #   %packages   - information on packages that we have discovered
6935
    #   @to_process - An array of packages discovered, but not yet processed
6936
    #
6937
    my @to_process;
6938
 
6939
    #
6940
    #   Create the initial entry in the packages array
6941
    #
6942
    my @deps;
6943
    foreach my $i ( $BuildFileInfo->getDpkgArchiveList() )
6944
    {
6945
        my $moduleInfo = $BuildFileInfo->getDpkgArchiveInfo($i);
6946
        my $tag = join ($;, $i, $moduleInfo->{versionFull} );
6947
        push @deps, $tag;
6948
    }
6949
 
6950
    $data{packages}{$PkgName}{$PkgVersionUser}{date} = $RmPkgDetails->pv_modified_time() || localtime() ;
6951
    $data{packages}{$PkgName}{$PkgVersionUser}{overview} = $RmPkgDetails->pv_description();
6952
    $data{packages}{$PkgName}{$PkgVersionUser}{deps} = [ @deps ] ;
6953
 
6954
 
6955
    push @to_process, @deps;
6956
 
6957
    while ( my $entry = pop @to_process )
6958
    {
6959
        my ($package, $version) = split ( $;, $entry );
6960
 
6961
        #
6962
        #   Extract and save information for this package
6963
        #
6964
        next if ( exists $data{packages}{$package}{$version} );
6965
 
6966
        #
6967
        #   Some packages need to be totally ignored
6968
        #
6969
        next if ( exists $data{ignore}{$package} );
6970
 
6971
        my $RmPkgDetails = DeployUtils::RmPkgInfo->new(
6972
                        {
6973
                            PKG_NAME => $package,
6974
                            PKG_VERSION => $version,
6975
                        } );
6976
        Error ("generateXmlDependancy: Cannot locate base package: $package, $version")
6977
            unless ( $RmPkgDetails->foundPkg() );
6978
 
6979
        #
6980
        #   Determine the dependancies, unless we are ignoring the children too
6981
        #   Do not use the RmPkgInfo class method getDependencyNames to fetch the
6982
        #   dependancy information as this:
6983
        #       1) gets it wrong
6984
        #       2) Extracts a lot of data that we dont want.
6985
        #
6986
        my @deps;
6987
        unless ( exists $data{ignore_child}{$package} )
6988
        {
6989
            my $deps = $RmPkgDetails->getDependenciesHash();
6990
            foreach my $pkg ( keys %{$deps} )
6991
            {
6992
                foreach my $ver ( keys %{$deps->{$pkg}}  )
6993
                {
6994
                    my $tag = join ($;, $pkg, $ver );
6995
                    push @deps, $tag;
6996
                }
6997
            }
6998
        }
6999
 
7000
        $data{packages}{$package}{$version}{date} = $RmPkgDetails->pv_modified_time();
7001
        $data{packages}{$package}{$version}{overview} = $RmPkgDetails->pv_description();
7002
        $data{packages}{$package}{$version}{deps} = [ @deps ] ;
7003
 
7004
        push @to_process, @deps;
7005
    }
7006
#DebugDumpData ("Packages", \%packages);
7007
 
7008
    #
7009
    #   Now walk the tree and generate XML
7010
    #
7011
    sub output_entry
7012
    {
7013
        my ($datap, $depth, $package, $version, $vis ) = @_;
7014
        my $fh = $datap->{fh};
7015
        $depth++;
7016
 
7017
        #
7018
        #   Skip if too deep or an ignored package
7019
        #
7020
        return if ( $datap->{ignore}{$package} );
7021
        return if ( $datap->{default_depth} && $depth > $datap->{default_depth} );
7022
 
7023
        #
7024
        #   Check for invisible packages
7025
        #
7026
        $vis = 0 if ( $datap->{invisible}{$package} );
7027
 
7028
 
7029
        my $indent = "    " x ($depth - 1);
7030
        my $date = $datap->{packages}{$package}{$version}{date};
7031
        my $overview = $datap->{packages}{$package}{$version}{overview};
7032
 
7033
        #
7034
        #   Clean up the overview
7035
        #
7036
        $overview =~ s~\s+$~~;
7037
        $overview =~ s~\r\n~\n~g;
7038
        $overview =~ s~\n\r~\n~g;
7039
 
7040
        #
7041
        #   Determine visibility
7042
        #
7043
        $vis = 0 if ( $datap->{default_visible} && $depth > $datap->{default_visible} );
7044
        my $visible = ( $vis > 0 ) ? 'true' : 'false';
7045
        $vis = 0 if ( $datap->{invisible_child}{$package} );
7046
 
7047
        #
7048
        #   The top level entry is different
7049
        #
7050
        if ( $depth == 0 )
7051
        {
7052
            $indent = "    " ;
7053
            print $fh "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
7054
            print $fh "<ERG_Package xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"package_info.xsd\" SchemaVersion=\"1.0.0\">\n";
7055
            print $fh "$indent<Package_Name>$package</Package_Name>\n";
7056
            print $fh "$indent<Package_Version>$version</Package_Version>\n";
7057
            print $fh "$indent<Package_Overview>$overview</Package_Overview>\n";
7058
            print $fh "$indent<Build_Date>$date</Build_Date>\n";
7059
        }
7060
        else
7061
        {
7062
            print $fh "${indent}<Package Name=\"$package\" Version=\"$version\" BuildDate=\"$date\" Visible=\"$visible\">\n";
7063
		    print $fh "${indent}    ";
7064
            print $fh "<Overview>${overview}" if ($overview);
7065
		    print $fh "</Overview>\n";
7066
        }
7067
 
7068
        #
7069
        #   Process dependancies
7070
        #
7071
        unless ( $datap->{ignore_child}{$package} )
7072
        {
7073
            foreach my $entry ( @{ $datap->{packages}{$package}{$version}{deps} } )
7074
            {
7075
                my ($package, $version) = split ( $;, $entry );
7076
                output_entry ( $datap, $depth, $package, $version, $vis );
7077
            }
7078
        }
7079
 
7080
        if ( $depth == 0 )
7081
        {
7082
            print $fh "</ERG_Package>\n";
7083
        }
7084
        else
7085
        {
7086
		    print $fh "${indent}</Package>\n";
7087
        }
7088
    }
7089
 
7090
    #
7091
    #   Output the XML header and information about the first package
7092
    #
7093
    Information ( "Creating file $filename" );
7094
    open ( $data{fh}, ">", $filename ) || Error( "Cannot create $filename");
7095
    output_entry ( \%data, -1, $PkgName, $PkgVersionUser, 1 );
7096
    close $data{fh};
7097
 
7098
#    DebugDumpData( "DATA", \%data );
7099
}
7100
 
7101
 
1530 dpurdie 7102
#------------------------------------------------------------------------------
7103
sub createPerlSvcWin32
7104
#
7105
# Description:
7106
#       This sub-routine is used to create a Win32  service 
7107
#       using a PERL script as the input.
7108
#
7109
#       note we assume here that you have installed ther ActiveState PERL
7110
#       developement KIT and have also installed a valid license key.
7111
#
7112
#------------------------------------------------------------------------------
7113
{
7114
    # lets just check to see if we can execute this function on
7115
    # this machine.
7116
    #
7117
    if ( "$MachType" ne "win32" )
7118
    {
1534 dpurdie 7119
        Information("createPerlSvcWin32() not supported on this machine type.");
1530 dpurdie 7120
        return 1;
7121
    }
7122
 
7123
 
7124
    my ($m_srcDirTag, $m_sfile, $m_targetDirTag, $m_ofile, @m_libDirTags) = @_;
7125
 
7126
 
7127
    # lets get the src dir value
7128
    my ($m_targetDirValue) = getTargetDstDirValue($m_targetDirTag, "A");
7129
 
7130
 
7131
    # lets get the lib src dir value
7132
    my (@m_libDirValue) = ();
7133
    my $i;
7134
    my ($_libStr) = "";
7135
    foreach $i ( 0 .. $#m_libDirTags )
7136
    {
7137
        $m_libDirValue[$i] = getLocalDirValue($m_libDirTags[$i], "A");
7138
        $_libStr = $_libStr . "$m_libDirValue[$i];"
7139
    }
7140
    if ( -d $DpkgScriptsDir )
7141
    {
7142
        $_libStr = $_libStr . "$DpkgScriptsDir";
7143
    }
1534 dpurdie 7144
    Verbose("additional places to look for perl modules, [$_libStr]");
1530 dpurdie 7145
 
7146
 
7147
    # lets get the target dir value
7148
    my ($m_srcDirValue) = getLocalDirValue($m_srcDirTag, "A");
7149
 
7150
    # we know where we are getting this from and where we
7151
    # going to put them.
7152
    my ($m_sfileLoc) = "$m_srcDirValue/$m_sfile";
7153
 
7154
 
7155
    my ($_cmdStr) = "perlsvc --verbose --lib $_libStr --exe $m_targetDirValue/$m_ofile $m_sfileLoc";
7156
 
7157
 
7158
    # lets execute the package commands.
7159
    my ($retVal);
7160
    $retVal = system("$_cmdStr");
7161
    if ( $retVal != 0 )
7162
    {
1534 dpurdie 7163
        Error("Failed to complete command [$_cmdStr].");
1530 dpurdie 7164
    }
7165
 
7166
    # done.
7167
    return 1;
7168
}
7169
 
7170
 
7171
#------------------------------------------------------------------------------
7172
sub createPerlAppWin32
7173
#
7174
# Description:
7175
#       This sub-routine is used to create a Win32 free-standing application 
7176
#       using a PERL script as the input.
7177
#
7178
#       note we assume here that you have installed ther ActiveState PERL
7179
#       developement KIT and have also installed a valid license key.
7180
#
7181
#------------------------------------------------------------------------------
7182
{
7183
    # lets just check to see if we can execute this function on
7184
    # this machine.
7185
    #
7186
    if ( "$MachType" ne "win32" )
7187
    {
1534 dpurdie 7188
        Information("createPerlAppWin32() not supported on this machine type.");
1530 dpurdie 7189
        return 1;
7190
    }
7191
 
7192
 
7193
    my ($m_srcDirTag, $m_sfile, $m_targetDirTag, $m_ofile, @m_libDirTags) = @_;
7194
 
7195
 
7196
    # lets get the src dir value
7197
    my ($m_targetDirValue) = getTargetDstDirValue($m_targetDirTag, "A");
7198
 
7199
 
7200
    # lets get the lib src dir value
7201
    my (@m_libDirValue) = ();
7202
    my $i;
7203
    my ($_libStr) = "";
7204
    foreach $i ( 0 .. $#m_libDirTags )
7205
    {
7206
        $m_libDirValue[$i] = getLocalDirValue($m_libDirTags[$i], "A");
7207
        $_libStr = $_libStr . "$m_libDirValue[$i];"
7208
    }
7209
    if ( -d $DpkgScriptsDir )
7210
    {
7211
        $_libStr = $_libStr . "$DpkgScriptsDir";
7212
    }
1534 dpurdie 7213
    Verbose("additional places to look for perl modules, [$_libStr]");
1530 dpurdie 7214
 
7215
 
7216
    # lets get the target dir value
7217
    my ($m_srcDirValue) = getLocalDirValue($m_srcDirTag, "A");
7218
 
7219
    # we know where we are getting this from and where we
7220
    # going to put them.
7221
    my ($m_sfileLoc) = "$m_srcDirValue/$m_sfile";
7222
 
7223
 
7224
    my ($_cmdStr) = "perlapp --verbose --clean --force --lib $_libStr --exe $m_targetDirValue/$m_ofile --script $m_sfileLoc";
7225
 
7226
 
7227
    # lets execute the package commands.
7228
    my ($retVal);
7229
    $retVal = system("$_cmdStr");
7230
    if ( $retVal != 0 )
7231
    {
1534 dpurdie 7232
        Error("Failed to complete command [$_cmdStr].");
1530 dpurdie 7233
    }
7234
 
7235
    # done.
7236
    return 1;
7237
}
7238
 
1534 dpurdie 7239
#-------------------------------------------------------------------------------
7240
# Function        : make_directory
7241
#
7242
# Description     : Create a directory if it does not already exist
7243
#                   Simple function to provide user messages on the way
7244
#                   Will create a complete path. There is no need to
7245
#                   break it into bits.
7246
#
7247
# Inputs          : name        - path to the directory
7248
#                   umask       - umask
7249
#                   text        - User text (optional)
7250
#
7251
# Returns         :
7252
#
7253
 
7254
sub make_directory
7255
{
7256
    my ($name, $umask, $text ) = @_;
7257
 
7258
    Error ("make_directory needs a umask") unless ( $umask );
7259
    Error ("make_directory needs a path") unless ( $name );
7260
    $text = "Create directory"  unless ( $text );
7261
 
7262
    my $umask_text = sprintf( "0%o", $umask );
7263
 
7264
    unless ( -d $name )
7265
    {
7266
        Verbose ( "$text: $name [$umask_text]");
7267
        mkpath ( $name, 0, $umask);
7268
    }
7269
    else
7270
    {
7271
        Verbose2 ( "$text: $name [$umask_text] - already exists");
7272
    }
1554 dpurdie 7273
 
7274
    #
7275
    #   Ensure that the target directory is not setgid
7276
    #   as this will mess up the Solaris packaging process. The setgid on the
7277
    #   directories will be propergated into the final package. This is not good.
7278
    #
7279
    #   If the user gets directories with SETGID, then they  must be created
7280
    #   specifically after the directory has been created.
7281
    #
7282
    #   Why is this a problem? Seen when a build user has directory setgid
7283
    #   for the purposes of making the directory accessible by many.
7284
    #
7285
    if ( -g $name )
7286
    {
7287
        system ('chmod', 'g-s', $name );
7288
        Error ("Cannot remove setGID on directory.", "Dir: $name") if ( -g $name );
7289
    }
1534 dpurdie 7290
}
7291
 
1544 dpurdie 7292
 
7293
#-------------------------------------------------------------------------------
7294
# Function        : ActivePlatform
7295
#
7296
# Description     : Determine if the specified platform is currently 'active'
7297
#                   This is used by all user directives in order to determine
7298
#                   if the directive should be ignored for the current platform
7299
#
7300
# Inputs          : $platform_spec      - A (simple)platform specifier
7301
#
7302
# Returns         : TRUE if the platform spec contains the current platform
7303
#
7304
sub ActivePlatform
7305
{
7306
    my( $platform_spec ) = @_;
7307
 
7308
    Error ("No platform specified in some directive") unless ( $platform_spec );
7309
 
7310
    #
7311
    #   Wild card
7312
    #
7313
    return 1 if ( $platform_spec eq '*' );
7314
 
7315
    #
7316
    #   Simple test
7317
    #
7318
    foreach ( split (',', $platform_spec))
7319
    {
7320
        return 1 if ( $_ eq $Platform );
7321
    }
7322
 
7323
    #
7324
    #   Not for me
7325
    #
7326
    return 0;
7327
}
7328
 
1546 dpurdie 7329
#-------------------------------------------------------------------------------
7330
# Function        : LocatePackageBase
7331
#
7332
# Description     : Locate a package and return the path to a directory within
7333
#                   the package
7334
#
7335
# Inputs          : $ufn            - User function. Error reporting
7336
#                   $PkgName        - Name of the Package
7337
#                   $PkgSubDir      - Subdir within the package
7338
#
7339
#
7340
# Returns         : Absolute path to a directory within the package
7341
#
7342
my %LocatePackageBase_cache;
7343
sub LocatePackageBase
7344
{
7345
    my ( $ufn, $PkgName, $PkgSubDir ) = @_;
7346
    my $src_base_dir;
7347
 
7348
    if ( exists $LocatePackageBase_cache{$PkgName} )
7349
    {
7350
        $src_base_dir = $LocatePackageBase_cache{$PkgName};
7351
    }
7352
    else
7353
    {
7354
        #
7355
        #   Convert the package name into a real path name to the package as
7356
        #   held in dpkg_archive. Do not use the copy in the 'interface' directory
7357
        #
7358
        for my $entry ( $BuildFileInfo->getBuildPkgRules() )
7359
        {
7360
            next unless ( $entry->{'DNAME'} eq $PkgName );
7361
            $src_base_dir = $entry->{'ROOT'};
7362
            Verbose ("Discovered package in: $src_base_dir");
7363
        }
7364
 
7365
        Error ("$ufn: Package not located: $PkgName")
7366
            unless ( $src_base_dir );
7367
 
7368
        Error ("$ufn: Package directory not found: $src_base_dir")
7369
            unless ( -d $src_base_dir );
7370
 
7371
        #
7372
        #   Mainatin a cache of located packages
7373
        #
7374
        $LocatePackageBase_cache{$PkgName} = $src_base_dir;
7375
    }
7376
 
7377
    if ( $PkgSubDir )
7378
    {
7379
        $src_base_dir .= '/' . $PkgSubDir;
7380
        Error ("$ufn: Package subdirectory not found: $PkgSubDir" )
7381
            unless ( -d $src_base_dir );
7382
    }
7383
 
7384
    return $src_base_dir;
7385
}
7386
 
1552 dpurdie 7387
#===============================================================================
7388
#
7389
#   Internal Package
1556 lkelly 7390
#   An attempt to simplify the WildCarding interface by capturing the parameters
1552 dpurdie 7391
#   in a package. The idea is that storing the arguments can be easier
7392
#
7393
package LocateFiles;
7394
use JatsError;
7395
 
7396
#-------------------------------------------------------------------------------
7397
# Function        : new
7398
#
7399
# Description     : Create a new instance of a searcher
7400
#
7401
# Inputs          : 
7402
#
7403
# Returns         : 
7404
#
7405
sub new {
7406
    my $class = shift;
7407
    my $self  = {};
7408
    $self->{recurse}  = 0;
7409
    $self->{exclude}  = [];
7410
    $self->{include}  = [];
7411
    $self->{base_dir} = undef;
7412
    $self->{results}  = [];
1556 lkelly 7413
    $self->{dirs_too} = 0;
1552 dpurdie 7414
    bless ($self, $class);
7415
 
7416
    #
7417
    #   Process user arguments
7418
    #   These are are a hash
7419
    #
7420
    my %href = @_;
7421
    foreach my $entry ( keys %href )
7422
    {
7423
        Error( "LocateFiles:new. Unknown initialiser: $entry") unless ( exists $self->{$entry} );
7424
        $self->{$entry} = $href{$entry};
7425
    }
7426
    return $self;
7427
}
7428
 
7429
#-------------------------------------------------------------------------------
1556 lkelly 7430
# Function        :  Class accessor fucntions
7431
#                   recurse                     - Recurse subdirs
7432
#                   filter_in                   - Filter in these files
7433
#                   filter_in_re                - Filter in (Regular Expression)
7434
#                   filter_out                  - Filter out these files
7435
#                   filter_out_re               - Filter out (RE)
7436
#                   base_dir                    - Base dir for search
7437
#                   results                     - Results of the last search
7438
#                   dirs_too                    - Include dirs in the search
7439
#                   has_filter                  - Has any filter been defined
7440
#                   search                      - Perform the search
1552 dpurdie 7441
#
7442
# Description     : Accessor functions
7443
#
7444
# Inputs          : class
7445
#                   One argument (optional)
7446
#
7447
# Returns         : Current value of the daat item
7448
#
7449
sub recurse
7450
{
7451
    my $self = shift;
7452
    if (@_) { $self->{recurse} = shift }
7453
    return $self->{recurse};
7454
}
7455
 
7456
sub filter_in
7457
{
7458
    my $self = shift;
7459
    if (@_) { push @{$self->{include}}, glob2pat( shift ) }
7460
    return $self->{include};
7461
}
7462
 
7463
sub filter_in_re
7464
{
7465
    my $self = shift;
7466
    if (@_) { push @{$self->{include}}, shift }
7467
    return $self->{include};
7468
}
7469
 
7470
sub filter_out
7471
{
7472
    my $self = shift;
7473
    if (@_) { push @{$self->{exclude}}, glob2pat( shift ) }
7474
    return $self->{exclude};
7475
}
7476
 
7477
sub filter_out_re
7478
{
7479
    my $self = shift;
7480
    if (@_) { push @{$self->{exclude}}, shift }
7481
    return $self->{exclude};
7482
}
7483
 
1556 lkelly 7484
sub dirs_too
7485
{
7486
    my $self = shift;
7487
    if (@_) { $self->{dirs_too} = shift }
7488
    return $self->{dirs_too};
7489
}
7490
 
1552 dpurdie 7491
sub base_dir
7492
{
7493
    my $self = shift;
7494
    if (@_) { $self->{base_dir} = shift }
7495
    return $self->{base_dir};
7496
}
7497
 
7498
sub has_filter
7499
{
7500
    my $self = shift;
7501
    return ( ( @{$self->{include}} || @{$self->{exclude}} ) );
7502
}
7503
 
7504
 
7505
#-------------------------------------------------------------------------------
7506
# Function        : search
7507
#
7508
# Description     : This function performs the search for files as specified
7509
#                   by the arguments already provided
7510
#
7511
# Inputs          : base_dir (Optional)
7512
#
7513
# Returns         : List of files that match the search criteria
7514
#
7515
 
7516
my @search_list;             # Must be global to avoid closure problems
7517
my $search_len;
1556 lkelly 7518
my $search_base_dir;
7519
my $search_dirs_too;
1552 dpurdie 7520
 
7521
sub search
7522
{
7523
    my $self = shift;
7524
    $self->{base_dir} = $_[0] if (defined $_[0] );
7525
    $self->{results} = ();
7526
 
7527
    #
7528
    #   Ensure user has provided enough info
7529
    #
7530
    Error ("LocateFiles: No base directory provided") unless ( $self->{base_dir} );
7531
 
7532
    #
7533
    #   Clean up the user dir. Remove any trailing / as we will be adding it back
7534
    #
7535
    $self->{base_dir} =~ s~/*$~~g;
7536
 
7537
    #
7538
    #   Init recursion information
7539
    #   Needed to avoid closure interactions
7540
    #
7541
    @search_list = ();
7542
    $search_len = length( $self->{base_dir} );
7543
 
7544
    #
7545
    #   Create a list of candidate files
7546
    #   If we are recursing the subtree, then this is a little harder
7547
    #   If we are not recursing then we can't simply glob the directory as
7548
    #   not all files are processed.
7549
    #
7550
    #   Will end up with a list of files that
7551
    #       1) Start with a '/'
7552
    #       2) Are rooted as $dir, but don't include $dir
7553
    #
7554
    if ( $self->{recurse} )
7555
    {
1556 lkelly 7556
        $search_dirs_too = $self->{dirs_too};
7557
        $search_base_dir = $self->{base_dir};
1552 dpurdie 7558
        sub find_file_wanted
7559
        {
1556 lkelly 7560
            return if ( !$search_dirs_too && -d $_ );               # skip if current is dir and we are not including dirs
7561
            return if ( $search_base_dir eq $File::Find::name );    # skip if current is base_dir as we dont include it
1552 dpurdie 7562
            my $file = $File::Find::name;
7563
            push @search_list, substr($file, $search_len );
7564
        }
7565
 
7566
        #
7567
        #       Under Unix we need to follow symbolic links, but Perl's
7568
        #       Find:find does not work with -follow under windows if the source
7569
        #       path contains a drive letter.
7570
        #
7571
        #       Solution. Only use follow under non-windows systems.
7572
        #                 Works as Windows does not have symlinks (yet).
7573
        #
7574
        my $follow_opt =  ! ( "$MachType" eq "win32" || "$MachType" eq "WinCE" );
7575
 
7576
        File::Find::find( {wanted => \&find_file_wanted, follow_fast => $follow_opt }, $self->{base_dir} );
7577
    }
7578
    else
7579
    {
7580
        local *DIR ;
7581
        opendir DIR, $self->{base_dir} || die ("Cannot open $self->{base_dir}");
7582
        foreach ( readdir( DIR ) )
7583
        {
7584
            next if /^\Q.\E$/;
7585
            next if /^\Q..\E$/;
1556 lkelly 7586
            next if ( !$self->{dirs_too} && -d "$self->{base_dir}/$_" );
1552 dpurdie 7587
            push @search_list, '/' . $_;
7588
 
7589
        }
7590
        closedir DIR;
7591
    }
7592
 
7593
    #
7594
    #   If filtering is not present then return the entire file list
7595
    #
7596
    $self->{results} = \@search_list ;
7597
    return @search_list
7598
        unless ( @{$self->{include}} || @{$self->{exclude}} );
7599
 
7600
    #
7601
    #   Filtering is present
7602
    #   Apply the filterin rules and then the filter out rules
7603
    #   If no filter-in rules, then assume that all files are allowed in and
7604
    #   simply apply the filter-out rules.
7605
    #
7606
    my @patsin  = map { qr/$_/ } @{$self->{include}};
7607
    my @patsout = map { qr/$_/ } @{$self->{exclude}};
7608
    my @result;
7609
 
7610
#    map { print "Include:$_\n"; } @{$self->{include}};
7611
#    map { print "Exclude:$_\n"; } @{$self->{exclude}};
7612
 
7613
 
7614
    file:
7615
    foreach my $file ( @search_list )
7616
    {
7617
        if ( @{$self->{include}} )
7618
        {
7619
            my $in = 0;
7620
            for my $pat (@patsin)
7621
            {
7622
                if ( $file =~ /$pat/ )
7623
                {
7624
                    $in = 1;
7625
                    last;
7626
                }
7627
            }
7628
#print "------- Not included $file\n" unless $in;
7629
            next unless ( $in );
7630
        }
7631
 
7632
        for my $pat (@patsout)
7633
        {
7634
#print "------- REJECT $file :: $pat \n" if ( $file =~ /$pat/ );
7635
            next file if ( $file =~ /$pat/ );
7636
        }
7637
 
7638
        push @result, $file;
7639
    }
7640
 
7641
    $self->{results} = \@result;
7642
#DebugDumpData ("Search", $self);
7643
 
7644
    return @result;
7645
}
7646
 
7647
#-------------------------------------------------------------------------------
7648
# Function        : glob2pat
7649
#
7650
# Description     : Convert four shell wildcard characters into their equivalent
7651
#                   regular expression; all other characters are quoted to
7652
#                   render them literals.
7653
#
7654
# Inputs          : Shell style wildcard pattern
7655
#
7656
# Returns         : Perl RE
7657
#
7658
 
7659
sub glob2pat
7660
{
7661
    my $globstr = shift;
7662
    $globstr =~ s~^/~~;
7663
    my %patmap = (
7664
        '*' => '[^/]*',
7665
        '?' => '[^/]',
7666
        '[' => '[',
7667
        ']' => ']',
7668
    );
7669
    $globstr =~ s{(.)} { $patmap{$1} || "\Q$1" }ge;
7670
    return '/' . $globstr . '$';
7671
}
7672
 
1530 dpurdie 7673
#------------------------------------------------------------------------------
7674
1;