Subversion Repositories DevTools

Rev

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

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