Subversion Repositories DevTools

Rev

Rev 6856 | Rev 6859 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6856 Rev 6857
Line 1... Line 1...
1
########################################################################
1
########################################################################
2
# Copyright (C) 1998-2013 Vix Technology, All rights reserved
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
3
#
3
#
4
# Module name   : DebianPackager.pl
4
# Module name   : DebianPackager.pl
5
# Module type   : Makefile system
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
6
# Compiler(s)   : Perl
7
# Environment(s): jats
7
# Environment(s): jats
8
#
8
#
9
# Description   : This program is invoked by the MakeDebianPackage
9
# Description   : This program is invoked by the MakeDebianPackage and MakeRpmPackage
10
#                 directive, that is a part of this package
10
#                 directive that is a part of this package
11
#
11
#
12
#                 The program will use a user-provided script in order
12
#                 The program will use a user-provided script in order
13
#                 to create a Debian Package.
13
#                 to create the output Package.
14
#
14
#
15
#                 The user script may call a number of directives in order to
15
#                 The user script may call a number of directives in order to
16
#                 construct an image of the package being installed.
16
#                 construct an image of the package being installed.
17
#
17
#
18
#                 The script specifies Debian configuration scaripts that
18
#                 The script specifies Debian/RPM configuration scripts that
19
#                 will be embedded in the package.
19
#                 will be embedded in the package.
20
#
20
#
21
#                 This program will:
21
#                 This program will:
22
#                   Construct a filesystem image under control of the directives
22
#                   Construct a filesystem image under control of the directives
23
#                   within the user script
23
#                   within the user script
24
#
24
#
-
 
25
#                   Debian:
25
#                   Massage the Debian control file
26
#                       Massage the Debian control file
26
#
-
 
27
#                   Create a Debian Package
27
#                       Create a Debian Package
-
 
28
#                       Transfer it to the users 'BIN' directory, where it is available to be packaged.
28
#
29
#                       
-
 
30
#                   RedHat Package:    
-
 
31
#                       Generate rpmBuilder control files
-
 
32
#                       Create the RPM image
29
#                   Transfer it to the users 'BIN' directory, where it is
33
#                       Transfer it to the users 'BIN' directory, where it is available to be packaged.
-
 
34
#                   
-
 
35
#                   TarFile:
30
#                   available to be packaged.
36
#                       Tar Gzip the image
-
 
37
#                       Transfer it to the users 'BIN' directory, where it is available to be packaged.
31
#
38
#
32
#                 Summary of directives available to the user-script:
39
#                 Summary of directives available to the user-script:
33
#                       Message                 - Display progress text
40
#                       Message                 - Display progress text
34
#                       AddInitScript           - Add an init script
41
#                       AddInitScript           - Add an init script
35
#                       CatFile                 - Append to a file
42
#                       CatFile                 - Append to a file
Line 38... Line 45...
38
#                       CopyFile                - Copy a file
45
#                       CopyFile                - Copy a file
39
#                       CopyBinFile             - Copy an executable file
46
#                       CopyBinFile             - Copy an executable file
40
#                       CopyLibFile             - Copy a library file
47
#                       CopyLibFile             - Copy a library file
41
#                       CopyDebPackage          - Copy a Debian Package
48
#                       CopyDebPackage          - Copy a Debian Package
42
#                       CreateDir               - Create a directory
49
#                       CreateDir               - Create a directory
43
#                       DebianFiles             - Specify control and script files
50
#                       DebianFiles             - Specify control and script files (Debian Only)
-
 
51
#                       RpmFiles                - Specify control and script files (RPM Only)
44
#                       DebianControlFile       - Specify control and script files
52
#                       DebianControlFile       - Specify control and script files (Debian Only)
-
 
53
#                       RpmControlFile          - Specify control and script files (RPM Only)
-
 
54
#                       AllControlFile          - Specify control and script files (Debian and RPM)
45
#                       DebianDepends           - Add Depends entry to control file
55
#                       DebianDepends           - Add Depends entry to control file (Debian Only)
-
 
56
#                       RpmDepends              - Add Depends entry to control file (RPM Only)
-
 
57
#                       AllDepends              - Add Depends entry to control file (Debian and RPM)
46
#                       EchoFile                - Place text into a file
58
#                       EchoFile                - Place text into a file
47
#                       MakeSymLink             - Create a symbolic link
59
#                       MakeSymLink             - Create a symbolic link
48
#                       PackageDescription      - Specify the package description
60
#                       PackageDescription      - Specify the package description
49
#                       ReplaceTags             - Replace Tags on target file
61
#                       ReplaceTags             - Replace Tags on target file
50
#                       SetFilePerms            - Set file permissions
62
#                       SetFilePerms            - Set file permissions
Line 52... Line 64...
52
#                       IsProduct               - Flow control
64
#                       IsProduct               - Flow control
53
#                       IsPlatform              - Flow control
65
#                       IsPlatform              - Flow control
54
#                       IsTarget                - Flow control
66
#                       IsTarget                - Flow control
55
#                       IsVariant               - Flow control
67
#                       IsVariant               - Flow control
56
#                       IsAlias                 - Flow control
68
#                       IsAlias                 - Flow control
-
 
69
#                       RpmSetDefAttr           - Specify default file properties (RPM Only)
-
 
70
#                       RpmSetAttr              - Specify file properties (RPM Only)    
57
#
71
#
58
#                 Thoughts for expansion:
72
#                 Thoughts for expansion:
59
#                       SrcDir                  - Extend path for resolving local files
73
#                       SrcDir                  - Extend path for resolving local files
60
#
74
#
61
#                   Less used:
75
#                   Less used:
Line 84... Line 98...
84
use JatsCopy ();                            # Don't import anything
98
use JatsCopy ();                            # Don't import anything
85
 
99
 
86
#
100
#
87
#   Globals
101
#   Globals
88
#
102
#
89
my $DebianWorkDirBase;                      # Workspace
103
my $WorkDirBase;                            # Workspace
90
my $DebianWorkDir;                          # Dir to create file system image within
104
my $WorkDir;                                # Dir to create file system image within
91
 
105
 
92
#
106
#
93
#   Command line options
107
#   Command line options
94
#
108
#
95
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
109
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
Line 110... Line 124...
110
my $opt_localbindir;
124
my $opt_localbindir;
111
my $opt_pkgdir;
125
my $opt_pkgdir;
112
my $opt_pkglibdir;
126
my $opt_pkglibdir;
113
my $opt_pkgbindir;
127
my $opt_pkgbindir;
114
my $opt_pkgpkgdir;
128
my $opt_pkgpkgdir;
115
my $opt_output;
-
 
116
my $opt_tarFile;
-
 
117
my $opt_noarch;
129
my $opt_noarch;
-
 
130
my $opt_tarFile;
-
 
131
my $opt_rpm = 0;
-
 
132
my $opt_debian = 0;
-
 
133
my $opt_output;
118
 
134
 
119
#
135
#
120
#   Options marked as 'our' so that they are visible within the users script
136
#   Options marked as 'our' so that they are visible within the users script
121
#   Don't give the user too much
137
#   Don't give the user too much
122
#
138
#
Line 127... Line 143...
127
our $opt_target;
143
our $opt_target;
128
our $opt_product;
144
our $opt_product;
129
our $opt_name;
145
our $opt_name;
130
our $opt_variant;
146
our $opt_variant;
131
our $opt_pkgarch;
147
our $opt_pkgarch;
-
 
148
our $opt_rpmRelease = '';
132
 
149
 
133
#
150
#
134
#   Options derived from script directives
151
#   Options derived from script directives
135
#
152
#
136
my $opt_description;
153
my $opt_description;
-
 
154
my $opt_specFile;
137
 
155
 
138
#
156
#
139
#   Globals
157
#   Globals
140
#
158
#
141
my @ResolveFileList;                    # Cached Package File List
159
my @ResolveFileList;                        # Cached Package File List
142
my @ResolveBinFileList;                 # Cached PackageBin File List
160
my @ResolveBinFileList;                     # Cached PackageBin File List
143
my @ResolveDebFileList;                 # Cached PackageDeb File List
161
my @ResolveDebFileList;                     # Cached PackageDeb File List
144
my @ResolveLibFileList;                 # Cached PackageLib File List
162
my @ResolveLibFileList;                     # Cached PackageLib File List
145
my %DebianControlFiles;                 # Control Files
163
my %ControlFiles;                           # Control Files
146
my %DebianControlFileNames;             # Control Files by name
164
my %ControlFileNames;                       # Control Files by name
147
my @DependencyList;                     # Package Dependencies
165
my @DependencyList;                         # Package Dependencies
148
my @ConfigList;                         # Config Files
166
my @ConfigList;                             # Config Files
149
my %opt_aliases;                        # Cached Alias Names
167
my %opt_aliases;                            # Cached Alias Names
-
 
168
my @RpmDefAttr = ('-','root','root','-');   # RPM: Default File Attributes
-
 
169
my @RpmAttrList;                            # RPM: File attributes
-
 
170
 
150
 
171
 
151
#-------------------------------------------------------------------------------
172
#-------------------------------------------------------------------------------
152
# Function        : Main Entry point
173
# Function        : Main Entry point
153
#
174
#
154
# Description     : This function will be called when the package is initialised
175
# Description     : This function will be called when the package is initialised
Line 163... Line 184...
163
#
184
#
164
main();
185
main();
165
sub main
186
sub main
166
{
187
{
167
    my $result = GetOptions (
188
    my $result = GetOptions (
168
                "verbose:s"         => \$opt_vargs,
189
                'verbose:s'         => \$opt_vargs,
169
                "clean"             => \$opt_clean,
190
                'clean'             => \$opt_clean,
170
                "Type=s"            => \$opt_type,
191
                'Type=s'            => \$opt_type,
171
                "BuildName=s"       => \$opt_buildname,                     # Raw Jats Package Name (Do not use)
192
                'BuildName=s'       => \$opt_buildname,                     # Raw Jats Package Name (Do not use)
172
                "Name=s"            => \$opt_name,                          # Massaged Debian Package Name
193
                'Name=s'            => \$opt_name,                          # Massaged Debian Package Name
173
                "BuildVersion=s"    => \$opt_buildversion,
194
                'BuildVersion=s'    => \$opt_buildversion,
174
                "Platform=s"        => \$opt_platform,
195
                'Platform=s'        => \$opt_platform,
175
                "Target=s"          => \$opt_target,
196
                'Target=s'          => \$opt_target,
176
                "Product=s"         => \$opt_product,
197
                'Product=s'         => \$opt_product,
177
                "DebianPackage=s"   => \$opt_package_script,
-
 
178
                "InterfaceDir=s"    => \$opt_interfacedir,
198
                'InterfaceDir=s'    => \$opt_interfacedir,
179
                "InterfaceIncDir=s" => \$opt_interfaceincdir,
199
                'InterfaceIncDir=s' => \$opt_interfaceincdir,
180
                "InterfaceLibDir=s" => \$opt_interfacelibdir,
200
                'InterfaceLibDir=s' => \$opt_interfacelibdir,
181
                "InterfaceBinDir=s" => \$opt_interfacebindir,
201
                'InterfaceBinDir=s' => \$opt_interfacebindir,
182
                "LibDir=s"          => \$opt_libdir,
202
                'LibDir=s'          => \$opt_libdir,
183
                "BinDir=s"          => \$opt_bindir,
203
                'BinDir=s'          => \$opt_bindir,
184
                "LocalIncDir=s"     => \$opt_localincdir,
204
                'LocalIncDir=s'     => \$opt_localincdir,
185
                "LocalLibDir=s"     => \$opt_locallibdir,
205
                'LocalLibDir=s'     => \$opt_locallibdir,
186
                "LocalBinDir=s"     => \$opt_localbindir,
206
                'LocalBinDir=s'     => \$opt_localbindir,
187
                "PackageDir=s"      => \$opt_pkgdir,
207
                'PackageDir=s'      => \$opt_pkgdir,
188
                "PackageLibDir=s"   => \$opt_pkglibdir,
208
                'PackageLibDir=s'   => \$opt_pkglibdir,
189
                "PackageBinDir=s"   => \$opt_pkgbindir,
209
                'PackageBinDir=s'   => \$opt_pkgbindir,
190
                "PackagePkgDir=s"   => \$opt_pkgpkgdir,
210
                'PackagePkgDir=s'   => \$opt_pkgpkgdir,
191
                "Output=s"          => \$opt_output,
211
                'Variant:s'         => \$opt_variant,
-
 
212
                'PkgArch:s'         => \$opt_pkgarch,
-
 
213
                'NoArch'            => \$opt_noarch,
192
                "tarFile=s"         => \$opt_tarFile,
214
                'tarFile=s'         => \$opt_tarFile,
193
                "Variant:s"         => \$opt_variant,
215
                'genRpm'            => \$opt_rpm,
194
                "PkgArch:s"         => \$opt_pkgarch,
216
                'genDeb'            => \$opt_debian,
195
                "NoArch"            => \$opt_noarch,
217
                'output=s'          => \$opt_output,
-
 
218
                'script=s'          => \$opt_package_script,
-
 
219
                'rpmRelease=s'      => \$opt_rpmRelease,
196
    );
220
    );
197
    $opt_verbose++ unless ( $opt_vargs eq '@' );
221
    $opt_verbose++ unless ( $opt_vargs eq '@' );
198
 
222
 
199
    ErrorConfig( 'name'    => 'DebianUtils',
223
    ErrorConfig( 'name'    => 'PackagerUtils',
200
                 'verbose' => $opt_verbose,
224
                 'verbose' => $opt_verbose,
201
                 'debug'   => $opt_debug );
225
                 'debug'   => $opt_debug );
202
 
226
 
203
    #
227
    #
204
    #   Init the FileSystem Uiltity interface
228
    #   Init the FileSystem Uiltity interface
Line 209... Line 233...
209
    #   Ensure that we have all required options
233
    #   Ensure that we have all required options
210
    #
234
    #
211
    Error ("Platform not set")                  unless ( $opt_platform );
235
    Error ("Platform not set")                  unless ( $opt_platform );
212
    Error ("Type not set")                      unless ( $opt_type );
236
    Error ("Type not set")                      unless ( $opt_type );
213
    Error ("BuildName not set")                 unless ( $opt_buildname );
237
    Error ("BuildName not set")                 unless ( $opt_buildname );
214
    Error ("Debian Package Name not set")       unless ( $opt_name );
238
    Error ("Package Name not set")              unless ( $opt_name );
215
    Error ("BuildVersion not set")              unless ( $opt_buildversion );
239
    Error ("BuildVersion not set")              unless ( $opt_buildversion );
216
    Error ("InterfaceDir not set")              unless ( $opt_interfacedir );
240
    Error ("InterfaceDir not set")              unless ( $opt_interfacedir );
217
    Error ("Target not set")                    unless ( $opt_target );
241
    Error ("Target not set")                    unless ( $opt_target );
218
    Error ("Product not set")                   unless ( $opt_product );
242
    Error ("Product not set")                   unless ( $opt_product );
219
    Error ("DebianPackage not set")             unless ( $opt_package_script );
243
    Error ("Packaging Script not set")          unless ( $opt_package_script );
220
    Error ("Ouput File not set")                unless ( $opt_output );
-
 
221
 
244
 
222
    #
245
    #
223
    #   Read in relevent config information
246
    #   Read in relevent config information
224
    #
247
    #
225
    ReadBuildConfig ($opt_interfacedir, $opt_platform, '--NoTest' );
248
    ReadBuildConfig ($opt_interfacedir, $opt_platform, '--NoTest' );
226
 
249
 
227
    #
250
    #
228
    #   Build the package image in a directory based on the target being created
251
    #   Build the package image in a directory based on the target being created
229
    #
252
    #
230
    $DebianWorkDirBase = uc("$opt_platform$opt_type.image");
253
    $WorkDirBase = uc("$opt_platform$opt_type.image");
231
    $DebianWorkDir = "$DebianWorkDirBase/$opt_name";
254
    $WorkDir = "$WorkDirBase/$opt_name";
232
 
255
 
233
    #
256
    #
234
    #   Configure the System command to fail on any error
257
    #   Configure the System command to fail on any error
235
    #
258
    #
236
    SystemConfig ( ExitOnError => 1 );
259
    SystemConfig ( ExitOnError => 1 );
237
 
260
 
238
    #
261
    #
239
    #   Defaults
262
    #   Defaults
240
    #
263
    #
241
    $opt_pkgarch = $opt_platform unless ( $opt_pkgarch );
264
    $opt_pkgarch = $opt_platform unless ( $opt_pkgarch );
242
    $opt_pkgarch = 'all' if ( $opt_noarch );
-
 
243
 
265
 
244
    #
266
    #
245
    #   Display variables used
267
    #   Display variables used
246
    #
268
    #
247
    Message    ("=Building Debian Package =============================================");
269
    Message    ("= Building Installer ================================================");
-
 
270
    Message    ("        Format: Debian") if ($opt_debian);
-
 
271
    Message    ("        Format: RPM") if ($opt_rpm);
-
 
272
    Message    ("        Format: TGZ") if ($opt_tarFile);
248
    Message    ("Build $opt_name");
273
    Message    ("          Name: $opt_name");
249
    Message    ("       Package: $opt_buildname");
274
    Message    ("       Package: $opt_buildname");
250
    Message    ("       Variant: $opt_variant") if ($opt_variant);
275
    Message    ("       Variant: $opt_variant") if ($opt_variant);
251
    Message    ("       Version: $opt_buildversion");
276
    Message    ("       Version: $opt_buildversion");
252
    Message    ("  Building for: $opt_platform, $opt_target");
277
    Message    ("  Building for: $opt_platform");
-
 
278
    Message    ("        Target: $opt_target") if ( $opt_platform ne $opt_target);
253
    Message    ("       Product: $opt_product");
279
    Message    ("       Product: $opt_product") if ($opt_product ne $opt_platform);
254
    Message    ("          Type: $opt_type");
280
    Message    ("          Type: $opt_type");
-
 
281
    Message    ("   RPM Release: $opt_rpmRelease") if ($opt_rpmRelease);
255
    Message    ("      Pkg Arch: $opt_pkgarch") if ($opt_pkgarch);
282
    Message    ("      Pkg Arch: $opt_pkgarch") if ($opt_pkgarch);
256
    Verbose    ("       Verbose: $opt_verbose");
283
    Verbose    ("       Verbose: $opt_verbose");
257
    Verbose    ("  InterfaceDir: $opt_interfacedir");
284
    Verbose    ("  InterfaceDir: $opt_interfacedir");
258
    Message    ("       Package: " . StripDirExt($opt_output));
285
    Message    ("        Output: " . StripDir($opt_output));
259
    Message    ("       TarFile: " . StripDirExt($opt_tarFile)) if ($opt_tarFile);
286
    Message    ("        Output: " . StripDir($opt_tarFile)) if $opt_tarFile;
260
    Message    ("======================================================================");
287
    Message    ("======================================================================");
261
 
288
 
262
    #
289
    #
263
    #   Perform Clean up
290
    #   Perform Clean up
264
    #   Invoked during "make clean" or "make clobber"
291
    #   Invoked during "make clean" or "make clobber"
265
    #
292
    #
266
    if ( $opt_clean )
293
    if ( $opt_clean )
267
    {
294
    {
268
        Message ("Remove packaging directory: $DebianWorkDir");
295
        Message ("Remove packaging directory: $WorkDir");
269
 
296
 
270
        #
297
        #
271
        #   Remove the directory for this package
298
        #   Remove the directory for this package
272
        #   Remove the general work dir - if all packages have been cleaned
299
        #   Remove the general work dir - if all packages have been cleaned
273
        #
300
        #
274
        rmtree( $DebianWorkDir );
301
        rmtree( $WorkDirBase );
275
        rmdir( $DebianWorkDirBase );
302
        rmtree ($opt_tarFile) if ( defined($opt_tarFile) && -f $opt_tarFile );
276
        rmtree ($opt_output) if ( -f $opt_output );
303
        rmtree ($opt_output) if ( -f $opt_output );
277
        exit;
304
        exit;
278
    }
305
    }
279
 
306
 
280
    #
307
    #
281
    #   NoArch sanity test
308
    #   NoArch sanity test
282
    #   MUST only build no-arch for production
309
    #       MUST only build no-arch for production
283
    #   User MUST do this in the build.pl file
310
    #       User MUST do this in the build.pl file
284
    #
311
    #
285
    if ($opt_noarch && $opt_type ne 'P')
312
    if ($opt_noarch && $opt_type ne 'P')
286
    {
313
    {
287
        Error ("Debian Packages marked as NoArch (all) must be built ONLY for production",
314
        Error ("Installer Packages marked as NoArch (all) must be built ONLY for production",
288
               "This must be configured in the build.pl" );
315
               "This must be configured in the build.pl" );
289
    }
316
    }
290
 
317
 
291
    #
318
    #
292
    #   Clean  out the WORK directory
319
    #   Clean  out the WORK directory
Line 294... Line 321...
294
    #
321
    #
295
    #   Ensure that the base of the directory tree does not have 'setgid'
322
    #   Ensure that the base of the directory tree does not have 'setgid'
296
    #       This will upset the debian packager
323
    #       This will upset the debian packager
297
    #       This may be an artifact from the users directory and not expected
324
    #       This may be an artifact from the users directory and not expected
298
    #
325
    #
299
    rmtree( $DebianWorkDir );
326
    rmtree( $WorkDir );
300
    mkpath( $DebianWorkDir );
327
    mkpath( $WorkDir );
301
 
328
 
302
    my $perm = (stat $DebianWorkDir)[2] & 0777;
329
    my $perm = (stat $WorkDir)[2] & 0777;
303
    chmod ( $perm & 0777, $DebianWorkDir );
330
    chmod ( $perm & 0777, $WorkDir );
304
 
331
 
305
    #
332
    #
306
    #   Invoke the user script to do the hard work
333
    #   Invoke the user script to do the hard work
307
    #
334
    #
308
    unless (my $return = do $opt_package_script) {
335
    unless (my $return = do $opt_package_script) {
309
            Error ("Couldn't parse $opt_package_script: $@") if $@;
336
            Error ("Couldn't parse $opt_package_script: $@") if $@;
310
            Error ("Couldn't do $opt_package_script: $!")    unless defined $return;
337
            Error ("Couldn't do $opt_package_script: $!") unless defined $return;
311
        }
338
        }
312
 
339
 
313
    #
340
    #
-
 
341
    #   Now have an image of the directory that we wish to package
314
    #   Complete the building of the package
342
    #   Complete the building of the package
315
    #
343
    #
316
    if ($opt_tarFile)
344
    if ($opt_tarFile)
317
    {
345
    {
318
        BuildTarFile();
346
        BuildTarFile();
319
        Message ("Created TGZ file");
347
        Message ("Created TGZ file");
320
    }
348
    }
321
 
349
 
-
 
350
    #
-
 
351
    #   Create an RPM
-
 
352
    #
-
 
353
    if ($opt_rpm)
-
 
354
    {
-
 
355
        BuildRPM ();
-
 
356
        Message ("Created RPM");
-
 
357
    }
-
 
358
 
-
 
359
    if ($opt_debian)
-
 
360
    {
-
 
361
        BuildDebianPackage ();
-
 
362
        Message ("Created Debian Package");
-
 
363
    }
-
 
364
}
-
 
365
 
-
 
366
#-------------------------------------------------------------------------------
-
 
367
# Function        : BuildRPM 
-
 
368
#
-
 
369
# Description     : This function will create the Debian Package
-
 
370
#                   and transfer it to the target directory
-
 
371
#
-
 
372
# Inputs          : None
-
 
373
#
-
 
374
# Returns         : Nothing
-
 
375
# 
-
 
376
sub BuildRPM
-
 
377
{
-
 
378
    #
-
 
379
    #   Sanity Checks
-
 
380
    #
-
 
381
    Error ("BuildRPM: Release")
-
 
382
        unless ( $opt_rpmRelease );
-
 
383
    Error ("BuildRPM: No Control File or Package Description")
-
 
384
        unless ( exists($ControlFiles{'control'}) || $opt_description );
-
 
385
 
-
 
386
    #
-
 
387
    #   Massage the 'control' file
-
 
388
    #   Generate or Massage
-
 
389
    #
-
 
390
    $opt_specFile = catfile($WorkDirBase, 'RPM.spec' );
-
 
391
    UpdateRedHatControlFile ($ControlFiles{'control'} );
-
 
392
 
-
 
393
    #
-
 
394
    #   Run the RPM builder
-
 
395
    #   Expect it to be installed on the build machine
-
 
396
    #
-
 
397
    my $prog = LocateProgInPath( 'rpmbuild', '--All');
-
 
398
    Error ("RPM Packager: The rpmbuild utility is not installed") unless $prog;
-
 
399
    System ($prog, '-bb', $opt_specFile, 
-
 
400
                   '--buildroot', AbsPath($WorkDir) ,
-
 
401
                   '--define', '_rpmdir ' . StripFileExt($opt_output),
-
 
402
                   '--define', '_rpmfilename ' .  StripDir($opt_output),
-
 
403
                   '--noclean',
-
 
404
                   $opt_verbose ? '-v' : '--quiet',
-
 
405
                   $opt_noarch ?  '--target=noarch' : undef,
-
 
406
                   );
-
 
407
 
322
 
408
 
323
    BuildDebianPackage ();
-
 
324
    Message ("Created Debian Package");
-
 
325
}
409
}
326
 
410
 
327
#-------------------------------------------------------------------------------
411
#-------------------------------------------------------------------------------
328
# Function        : BuildDebianPackage
412
# Function        : BuildDebianPackage
329
#
413
#
Line 335... Line 419...
335
# Returns         : Nothing
419
# Returns         : Nothing
336
#
420
#
337
sub BuildDebianPackage
421
sub BuildDebianPackage
338
{
422
{
339
    Error ("BuildDebianPackage: No Control File or Package Description")
423
    Error ("BuildDebianPackage: No Control File or Package Description")
340
        unless ( exists($DebianControlFiles{'control'}) || $opt_description );
424
        unless ( exists($ControlFiles{'control'}) || $opt_description );
341
 
425
 
342
    #
426
    #
343
    #   Convert the FileSystem Image into a Debian Package
427
    #   Convert the FileSystem Image into a Debian Package
344
    #       Insert Debian control files
428
    #       Insert Debian control files
345
    #
429
    #
346
    Verbose ("Copy in the Debian Control Files");
430
    Verbose ("Copy in the Debian Control Files");
347
    mkdir ( "$DebianWorkDir/DEBIAN" );
431
    mkdir ( "$WorkDir/DEBIAN" );
348
 
432
 
349
    #
433
    #
350
    #   Copy in all the named Debian Control files
434
    #   Copy in all the named Debian Control files
351
    #       Ignore any control file. It will be done next
435
    #       Ignore any control file. It will be done next
352
    #
436
    #
353
    foreach my $key ( keys %DebianControlFiles )
437
    foreach my $key ( keys %ControlFiles )
354
    {
438
    {
355
        next if ($key eq 'control');
439
        next if ($key eq 'control');
356
        CopyFile ( $DebianControlFiles{$key}, '/DEBIAN', $key  );
440
        CopyFile ( $ControlFiles{$key}, '/DEBIAN', $key  );
357
    }
441
    }
358
 
442
 
359
    #
443
    #
360
    #   Create 'conffiles'
444
    #   Create 'conffiles'
361
    #       Append to any user provided file
445
    #       Append to any user provided file
362
    if ( @ConfigList )
446
    if ( @ConfigList )
363
    {
447
    {
364
        my $conffiles = "$DebianWorkDir/DEBIAN/conffiles";
448
        my $conffiles = "$WorkDir/DEBIAN/conffiles";
365
        Warning("Appending user specified entries to conffiles") if ( -f $conffiles);
449
        Warning("Appending user specified entries to conffiles") if ( -f $conffiles);
366
        FileAppend( $conffiles, @ConfigList );
450
        FileAppend( $conffiles, @ConfigList );
367
    }
451
    }
368
    
452
    
369
    #
453
    #
370
    #   Massage the 'control' file
454
    #   Massage the 'control' file
371
    #
455
    #
372
    UpdateControlFile ($DebianControlFiles{'control'} );
456
    UpdateDebianControlFile ($ControlFiles{'control'} );
373
 
457
 
374
    #
458
    #
375
    #   Mark all files in the debian folder as read-execute
459
    #   Mark all files in the debian folder as read-execute
376
    #
460
    #
377
    System ( 'chmod', '-R', 'a+rx', "$DebianWorkDir/DEBIAN" );
461
    System ( 'chmod', '-R', 'a+rx', "$WorkDir/DEBIAN" );
378
    System ( 'build_dpkg.sh', '-b', $DebianWorkDir);
462
    System ( 'build_dpkg.sh', '-b', $WorkDir);
379
    System ( 'mv', '-f', "$DebianWorkDir.deb", $opt_output );
463
    System ( 'mv', '-f', "$WorkDir.deb", $opt_output );
380
 
464
 
381
    System ("build_dpkg.sh", '-I', $opt_output) if (IsVerbose(1));
465
    System ("build_dpkg.sh", '-I', $opt_output) if (IsVerbose(1));
382
 
466
 
383
}
467
}
384
 
468
 
Line 400... Line 484...
400
            '--auto-compress',
484
            '--auto-compress',
401
            '--owner=0' ,
485
            '--owner=0' ,
402
            '--group=0' ,
486
            '--group=0' ,
403
            '--one-file-system' ,
487
            '--one-file-system' ,
404
            '--exclude=./DEBIAN' ,
488
            '--exclude=./DEBIAN' ,
405
            '-C', $DebianWorkDir,  
489
            '-C', $WorkDir,  
406
            '--file', $opt_tarFile,
490
            '--file', $opt_tarFile,
407
            '.'
491
            '.'
408
            );
492
            );
409
}
493
}
410
 
494
 
411
 
495
 
412
#-------------------------------------------------------------------------------
496
#-------------------------------------------------------------------------------
413
# Function        : UpdateControlFile
497
# Function        : UpdateDebianControlFile
414
#
498
#
415
# Description     : Update the Debian 'control' file to fix up various fields
499
# Description     : Update the Debian 'control' file to fix up various fields
416
#                   within the file.
500
#                   within the file.
417
#
501
#
418
#                   If the files has not been specified, then a basic control
502
#                   If the files has not been specified, then a basic control
Line 424... Line 508...
424
# Inputs          : $src            - Path to source file
508
# Inputs          : $src            - Path to source file
425
#                   Uses global variables
509
#                   Uses global variables
426
#
510
#
427
# Returns         : Nothing
511
# Returns         : Nothing
428
#
512
#
429
sub UpdateControlFile
513
sub UpdateDebianControlFile
430
{
514
{
431
    my($src) = @_;
515
    my($src) = @_;
432
    my $dst = "$DebianWorkDir/DEBIAN/control";
516
    my $dst = "$WorkDir/DEBIAN/control";
433
 
517
 
434
    unless ( $src )
518
    unless ( $src )
435
    {
519
    {
436
        CreateControlFile();
520
        CreateDebianControlFile();
437
        return;
521
        return;
438
    }
522
    }
439
 
523
 
440
    #
524
    #
441
    #   User has provided a control file
525
    #   User has provided a control file
442
    #       Tweak the internals
526
    #       Tweak the internals
443
    #
527
    #
444
    Verbose ("UpdateControlFile: $dst" );
528
    Verbose ("UpdateDebianControlFile: $dst" );
445
    $src = ResolveFile( 0, $src );
529
    $src = ResolveFile( 0, $src );
446
 
530
 
447
    #   Calc depends line
531
    #   Calc depends line
448
    my $depData = join (', ', @DependencyList );
532
    my $depData = join (', ', @DependencyList );
449
 
533
 
450
    open (SF, '<', $src) || Error ("UpdateControlFile: Cannot open:$src, $!");
534
    open (SF, '<', $src) || Error ("UpdateDebianControlFile: Cannot open:$src, $!");
451
    open (DF, '>', $dst) || Error ("UpdateControlFile: Cannot create:$dst, $!");
535
    open (DF, '>', $dst) || Error ("UpdateDebianControlFile: Cannot create:$dst, $!");
452
    while ( <SF> )
536
    while ( <SF> )
453
    {
537
    {
454
        s~\s*$~~;
538
        s~\s*$~~;
455
        if ( m~^Package:~ ) {
539
        if ( m~^Package:~ ) {
456
            $_ = "Package: $opt_name";
540
            $_ = "Package: $opt_name";
Line 480... Line 564...
480
    Error ("No Depends section seen in user control file") 
564
    Error ("No Depends section seen in user control file") 
481
        if ($depData);
565
        if ($depData);
482
}
566
}
483
 
567
 
484
#-------------------------------------------------------------------------------
568
#-------------------------------------------------------------------------------
485
# Function        : CreateControlFile
569
# Function        : CreateDebianControlFile
486
#
570
#
487
# Description     : Craete a basic debian control file
571
# Description     : Create a basic debian control file
488
#
572
#
489
# Inputs          : Uses global variables
573
# Inputs          : Uses global variables
490
#
574
#
491
# Returns         : 
575
# Returns         : 
492
#
576
#
493
sub CreateControlFile
577
sub CreateDebianControlFile
494
{
578
{
495
    my $dst = "$DebianWorkDir/DEBIAN/control";
579
    my $dst = "$WorkDir/DEBIAN/control";
496
 
580
 
497
    Verbose ("CreateControlFile: $dst" );
581
    Verbose ("CreateDebianControlFile: $dst" );
498
 
582
 
499
    my $depData = join (', ', @DependencyList );
583
    my $depData = join (', ', @DependencyList );
500
 
584
 
501
    open (DF, '>', $dst) || Error ("CreateControlFile: Cannot create:$dst");
585
    open (DF, '>', $dst) || Error ("CreateDebianControlFile: Cannot create:$dst");
502
    print DF "Package: $opt_name\n";
586
    print DF "Package: $opt_name\n";
503
    print DF "Version: $opt_buildversion\n";
587
    print DF "Version: $opt_buildversion\n";
504
    print DF "Section: main\n";
588
    print DF "Section: main\n";
505
    print DF "Priority: standard\n";
589
    print DF "Priority: standard\n";
506
    print DF "Architecture: $opt_pkgarch\n";
590
    print DF "Architecture: $opt_pkgarch\n";
Line 511... Line 595...
511
 
595
 
512
    close (DF);
596
    close (DF);
513
}
597
}
514
 
598
 
515
#-------------------------------------------------------------------------------
599
#-------------------------------------------------------------------------------
-
 
600
# Function        : UpdateRedHatControlFile 
-
 
601
#
-
 
602
# Description     : Update the Redhat 'control' file to fix up various fields
-
 
603
#                   within the file.
-
 
604
#
-
 
605
#                   If the files has not been specified, then a basic control
-
 
606
#                   (spec) file will be provided.
-
 
607
#                   Various tags will be replaced
-
 
608
#                       tag_name
-
 
609
#                       tag_version
-
 
610
#                       tag_buildarch
-
 
611
#                       tag_release
-
 
612
#                       tag_description
-
 
613
#                       tag_requires
-
 
614
#                       tag_filelist
-
 
615
#
-
 
616
# Inputs          : $src            - Path to source file
-
 
617
#                   Uses global variables
-
 
618
#
-
 
619
# Returns         : Nothing
-
 
620
#
-
 
621
sub UpdateRedHatControlFile
-
 
622
{
-
 
623
    my($src) = @_;
-
 
624
    my $dst = $opt_specFile;
-
 
625
    unless ( $src )
-
 
626
    {
-
 
627
        CreateRedHatControlFile();
-
 
628
        return;
-
 
629
    }
-
 
630
 
-
 
631
    #
-
 
632
    #   User has provided a control file
-
 
633
    #       Tweak the internals
-
 
634
    #
-
 
635
    Verbose ("UpdateRedHatControlFile: $dst" );
-
 
636
    $src = ResolveFile( 0, $src );
-
 
637
 
-
 
638
    my @depList = @DependencyList;
-
 
639
    my $cleanSeen;
-
 
640
 
-
 
641
    open (SF, '<', $src) || Error ("UpdateRedHatControlFile: Cannot open:$src, $!");
-
 
642
    open (DF, '>', $dst) || Error ("UpdateRedHatControlFile: Cannot create:$dst, $!");
-
 
643
    while ( <SF> )
-
 
644
    {
-
 
645
        s~\s*$~~;
-
 
646
        if ( m~^tag_Name~i ) {
-
 
647
            $_ = "Name: $opt_name";
-
 
648
 
-
 
649
        } elsif ( m~^tag_Version~i ) {
-
 
650
            $_ = "Version: $opt_buildversion";
-
 
651
 
-
 
652
        } elsif ( m~^tag_BuildArch~i ) {
-
 
653
            $_ = "BuildArch: $opt_pkgarch";
-
 
654
 
-
 
655
        } elsif ( m~^tag_Release~i ) {
-
 
656
            $_ = "Release: $opt_rpmRelease";
-
 
657
 
-
 
658
        } elsif ( $opt_description && m~^tag_Description~i ) {
-
 
659
            print DF "%description\n";
-
 
660
            print DF "$opt_description\n";
-
 
661
            $_ = undef;
-
 
662
 
-
 
663
        } elsif ( m~^tag_Requires~i ) {
-
 
664
            foreach my $item (@depList) {
-
 
665
                print DF "Requires:       $item\n";
-
 
666
            }
-
 
667
            $_ = undef;
-
 
668
            @depList = ();
-
 
669
        } elsif ( m~^tag_filelist~i ) {
-
 
670
            foreach my $item (@ConfigList) {
-
 
671
                print DF "%config $item\n";
-
 
672
            }
-
 
673
            opendir(my $dir, $WorkDir) || Error ("Cant read directory: $WorkDir: $!");
-
 
674
            while (readdir $dir)
-
 
675
            {
-
 
676
                next if $_ eq '.';
-
 
677
                next if $_ eq '..';
-
 
678
                my $fname = catdir( $WorkDir, $_);
-
 
679
                print DF ("/$_\n") if ( -f $fname );
-
 
680
                print DF ("/$_/*\n") if ( -d $fname );
-
 
681
            }
-
 
682
            close $dir;
-
 
683
 
-
 
684
        } elsif ( m~^%clean~i ) {
-
 
685
            $cleanSeen  = 1;
-
 
686
        }
-
 
687
        print DF ($_ , "\n") if defined ($_);
-
 
688
    }
-
 
689
 
-
 
690
    close (SF);
-
 
691
    close (DF);
-
 
692
 
-
 
693
    #
-
 
694
    #   Warn if Depends section is needed
-
 
695
    #
-
 
696
    Error ("No %clean section seen in user control file") unless $cleanSeen; 
-
 
697
    Error ("No Requires tag seen in user control file") if (@depList);
-
 
698
}
-
 
699
 
-
 
700
#-------------------------------------------------------------------------------
-
 
701
# Function        : CreateRedHatControlFile
-
 
702
#
-
 
703
# Description     : Create a binary RedHat spec file
-
 
704
#
-
 
705
# Inputs          : Uses global variables
-
 
706
#
-
 
707
# Returns         : 
-
 
708
#
-
 
709
sub CreateRedHatControlFile
-
 
710
{
-
 
711
    #
-
 
712
    #   Generate the RPM spec file
-
 
713
    #
-
 
714
    open (my $sf, '>', $opt_specFile) || Error ("RPM Spec File: Cannot create: $opt_specFile, $!");
-
 
715
 
-
 
716
    # Standard tags
-
 
717
    print $sf ("# Standard SPEC Tags\n");
-
 
718
    print $sf "Summary:        Installer for the $opt_name Package\n";
-
 
719
    print $sf "Name:           $opt_name\n";
-
 
720
    print $sf "Version:        $opt_buildversion\n";
-
 
721
    print $sf "Release:        $opt_rpmRelease\n";
-
 
722
    print $sf "License:        Vix Technology, All rights reserved.\n";
-
 
723
    print $sf "Source:         None\n";
-
 
724
    print $sf "BuildArch:      $opt_pkgarch\n";
-
 
725
    print $sf "Group:          VIX/System\n";
-
 
726
    print $sf "Vendor:         Vix Technology\n";
-
 
727
 
-
 
728
    #
-
 
729
    #   Requires tags
-
 
730
    #
-
 
731
    print $sf "\n# Dependencies\n" if @DependencyList;
-
 
732
    foreach my $item (@DependencyList) {
-
 
733
        print $sf "Requires:       $item\n";
-
 
734
    }
-
 
735
    
-
 
736
    print $sf "\n";
-
 
737
    print $sf "%description\n";
-
 
738
    print $sf "$opt_description\n";
-
 
739
 
-
 
740
    print $sf "\n";
-
 
741
    print $sf "%clean\n";
-
 
742
 
-
 
743
    #
-
 
744
    #   Insert various scripts
-
 
745
    #
-
 
746
    my $insertRpmControlFile = sub {
-
 
747
        my ($sname, $cname) = @_;
-
 
748
        if ( my $src = $ControlFiles{$cname} ) {
-
 
749
            print $sf "\n";
-
 
750
            print $sf '%' . $sname . "\n";
-
 
751
            open ( my $cf, '<', $src ) || Error ("BuildRPM: Cannot open:$src, $!");
-
 
752
            while ( <$cf> ) {
-
 
753
                print $sf $_;
-
 
754
            }
-
 
755
            close ($cf);
-
 
756
            print $sf "\n";
-
 
757
        }
-
 
758
    };
-
 
759
    
-
 
760
    #
-
 
761
    &$insertRpmControlFile ('pre',   'preinst');
-
 
762
    &$insertRpmControlFile ('post',  'postinst');
-
 
763
    &$insertRpmControlFile ('preun', 'prerm');
-
 
764
    &$insertRpmControlFile ('postun','postrm');
-
 
765
 
-
 
766
    #
-
 
767
    #   Insert the list of files to be processed
-
 
768
    #       Can't use /* as this will mess with permissions of the root directory. 
-
 
769
    #       Can list Top Level directories and then use *
-
 
770
    #
-
 
771
    print $sf "%files\n";
-
 
772
    print $sf "%defattr(",join (',', @RpmDefAttr),")\n";
-
 
773
 
-
 
774
    foreach my $item ( @RpmAttrList ) {
-
 
775
        print $sf "%attr(",join(',',@{$item}[1..3] ),") ", $item->[0],"\n";
-
 
776
    }
-
 
777
    
-
 
778
    #
-
 
779
    #   Flag configuration files ( ConfFile )
-
 
780
    #
-
 
781
    foreach my $item (@ConfigList) {
-
 
782
        print $sf "%config $item\n";
-
 
783
    }
-
 
784
 
-
 
785
    opendir(my $dir, $WorkDir) || Error ("Cant read directory: $WorkDir: $!");
-
 
786
    while (readdir $dir)
-
 
787
    {
-
 
788
        next if $_ eq '.';
-
 
789
        next if $_ eq '..';
-
 
790
        my $fname = catdir( $WorkDir, $_);
-
 
791
        print $sf ("/$_\n") if ( -f $fname );
-
 
792
        print $sf ("/$_/*\n") if ( -d $fname );
-
 
793
    }
-
 
794
    close $dir;
-
 
795
 
-
 
796
    print $sf "\n";
-
 
797
    close ($sf);
-
 
798
}
-
 
799
 
-
 
800
#-------------------------------------------------------------------------------
516
# Function        : SetVerbose
801
# Function        : SetVerbose
517
#
802
#
518
# Description     : Set the level of verbosity
803
# Description     : Set the level of verbosity
519
#                   Display activity
804
#                   Display activity
520
#
805
#
Line 534... Line 819...
534
}
819
}
535
 
820
 
536
 
821
 
537
#-------------------------------------------------------------------------------
822
#-------------------------------------------------------------------------------
538
# Function        : DebianFiles
823
# Function        : DebianFiles
-
 
824
#                   RpmFiles
539
#
825
#
540
# Description     : Name Debian builder control files
826
# Description     : Name Debian and RPM builder control files
541
#                   May be called multiple times
827
#                   May be called multiple times
542
#
828
#
-
 
829
# Inputs          :   $fName    - Name under which the function is being called
543
# Inputs          : Options
830
#                     Options
544
#                       --Control=file
831
#                       --Control=file
545
#                       --PreRm=file
832
#                       --PreRm=file
546
#                       --PostRm=file
833
#                       --PostRm=file
547
#                       --PreInst=file
834
#                       --PreInst=file
548
#                       --PostInst=file
835
#                       --PostInst=file
549
#                         
836
#                         
550
#
837
#
551
# Returns         : Nothing
838
# Returns         : Nothing
552
#
839
#
553
sub DebianFiles
840
sub MULTI_Files
554
{
841
{
555
    #
-
 
556
    #   Extract names
842
    my $fName = shift;
557
    #
-
 
558
    Verbose ("Specify Debian Control Files and Scripts");
843
    Verbose ("Specify Installer Control Files and Scripts");
559
    foreach  ( @_ )
844
    foreach  ( @_ )
560
    {
845
    {
561
        if ( m/^--Control=(.+)/i ) {
846
        if ( m/^--Control=(.+)/i ) {
562
            DebianControlFile('control',$1)
847
            MULTI_ControlFile($fName, 'control',$1)
563
 
848
 
564
        } elsif ( m/^--PreRm=(.+)/i ) {
849
        } elsif ( m/^--PreRm=(.+)/i ) {
565
            DebianControlFile('prerm',$1)
850
            MULTI_ControlFile($fName, 'prerm',$1)
566
 
851
 
567
        } elsif ( m/^--PostRm=(.+)/i ) {
852
        } elsif ( m/^--PostRm=(.+)/i ) {
568
            DebianControlFile('postrm',$1)
853
            MULTI_ControlFile($fName, 'postrm',$1)
569
 
854
 
570
        } elsif ( m/^--PreInst=(.+)/i ) {
855
        } elsif ( m/^--PreInst=(.+)/i ) {
571
            DebianControlFile('preinst',$1)
856
            MULTI_ControlFile($fName, 'preinst',$1)
572
 
857
 
573
        } elsif ( m/^--PostInst=(.+)/i ) {
858
        } elsif ( m/^--PostInst=(.+)/i ) {
574
            DebianControlFile('postinst',$1)
859
            MULTI_ControlFile($fName, 'postinst',$1)
575
 
860
 
576
        } else {
861
        } else {
577
            Error ("DebianFiles: Unknown option: $_");
862
            Error ("$fName: Unknown option: $_");
578
        }
863
        }
579
    }
864
    }
580
}
865
}
581
 
866
 
582
#-------------------------------------------------------------------------------
867
#-------------------------------------------------------------------------------
583
# Function        : DebianControlFile 
868
# Function        : DebianControlFile
-
 
869
#                   RpmControlFile 
584
#
870
#
585
# Description     : Add special control files to the Debian Installer 
871
# Description     : Add special control files to the Debian/RedHat Installer 
586
#                   Not useful for embedded installers
872
#                   Not useful for embedded installers
587
#
873
#
588
#                   More general than DebianFiles()
874
#                   More general than DebianFiles() or RpmFiles
589
#
875
#
590
# Inputs          : name            - Target Name
876
# Inputs          : name            - Target Name
591
#                                     If the name starts with 'package.' then it will be replaced
877
#                                     If the name starts with 'package.' then it will be replaced
592
#                                     with the name of the current package
878
#                                     with the name of the current package
-
 
879
#                                     Ideally: prerm, postrm, preinst, postinst
593
#                   file            - Source File Name
880
#                   file            - Source File Name
594
#                   options         - Options include
881
#                   options         - Options include
595
#                                       --FromPackage
882
#                                       --FromPackage
596
#
883
#
597
# Returns         : 
884
# Returns         : 
598
#
885
#
599
sub DebianControlFile
886
sub MULTI_ControlFile
600
{
887
{
601
    my ($name, $file, @options) = @_;
888
    my ($fName, $name, $file, @options) = @_;
602
    my $fromPackage = 0;
889
    my $fromPackage = 0;
603
 
890
 
604
    #
891
    #
605
    #   Process options
892
    #   Process options
606
    foreach ( @options)
893
    foreach ( @options)
607
    {
894
    {
608
        if (m~^--FromPackage~) {
895
        if (m~^--FromPackage~) {
609
            $fromPackage = 1;
896
            $fromPackage = 1;
610
        }
897
        }
611
        else  {
898
        else  {
612
            ReportError(("DebianControlFile: Unknown argument: $_"));
899
            ReportError(("$fName: Unknown argument: $_"));
613
        }
900
        }
614
    }
901
    }
615
    ErrorDoExit();
902
    ErrorDoExit();
616
 
903
 
617
    #
904
    #
Line 622... Line 909...
622
    #
909
    #
623
    #   Only allow one file of each type
910
    #   Only allow one file of each type
624
    #       Try to protect the user by testing for names by lowercase
911
    #       Try to protect the user by testing for names by lowercase
625
    #
912
    #
626
    my $simpleName = lc($name);
913
    my $simpleName = lc($name);
627
    Error("DebianControlFile: Multiple definitions for '$name' not allowed")
914
    Error("$fName: Multiple definitions for '$name' not allowed")
628
        if (exists $DebianControlFileNames{$simpleName});
915
        if (exists $ControlFileNames{$simpleName});
629
 
916
 
630
    my $filePath = ResolveFile($fromPackage, $file);
917
    my $filePath = ResolveFile($fromPackage, $file);
631
 
918
 
632
    #
919
    #
633
    #   Add info to data structures
920
    #   Add info to data structures
634
    #
921
    #
635
    $DebianControlFiles{$name} = $filePath;
922
    $ControlFiles{$name} = $filePath;
636
    $DebianControlFileNames{$simpleName} = $name;
923
    $ControlFileNames{$simpleName} = $name;
637
}
924
}
638
 
925
 
639
#-------------------------------------------------------------------------------
926
#-------------------------------------------------------------------------------
640
# Function        : DebianDepends 
927
# Function        : DebianDepends 
-
 
928
#                   RpmDepends
641
#
929
#
642
# Description     : This directive allows simple dependency information to be  
930
# Description     : This directive allows simple dependency information to be  
643
#                   inserted into the control file
931
#                   inserted into the control file
644
#
932
#
645
#                   Not useful in embedded system
933
#                   Not useful in embedded system
Line 648... Line 936...
648
#                   ...               - More entries
936
#                   ...               - More entries
649
#                   
937
#                   
650
#
938
#
651
# Returns         : Nothing
939
# Returns         : Nothing
652
#
940
#
653
sub DebianDepends
941
sub MULTI_Depends
654
{
942
{
-
 
943
    return unless $opt_debian;
655
    push @DependencyList, @_;
944
    push @DependencyList, @_;
656
}
945
}
657
 
946
 
658
 
-
 
659
#-------------------------------------------------------------------------------
947
#-------------------------------------------------------------------------------
660
# Function        : PackageDescription
948
# Function        : PackageDescription
661
#
949
#
662
# Description     : Specify the Package Description
950
# Description     : Specify the Package Description
663
#                   Keep it short
951
#                   Keep it short
Line 713... Line 1001...
713
        }
1001
        }
714
    }
1002
    }
715
 
1003
 
716
    my ($old_file, $new_file) = @args;
1004
    my ($old_file, $new_file) = @args;
717
 
1005
 
718
    my $tfile = $DebianWorkDir . '/' . $new_file;
1006
    my $tfile = $WorkDir . '/' . $new_file;
719
    $tfile =~ s~//~/~;
1007
    $tfile =~ s~//~/~;
720
    Verbose ("Symlink $old_file -> $new_file" );
1008
    Verbose ("Symlink $old_file -> $new_file" );
721
 
1009
 
722
    #
1010
    #
723
    #   Create the directory in which the link will be placed
1011
    #   Create the directory in which the link will be placed
Line 879... Line 1167...
879
#                   Options:
1167
#                   Options:
880
#                       --FromPackage
1168
#                       --FromPackage
881
#                       --FromBuild
1169
#                       --FromBuild
882
#                       --SoftLink=xxxx
1170
#                       --SoftLink=xxxx
883
#                       --LinkFile=xxxx
1171
#                       --LinkFile=xxxx
884
#                       --ConfigFile
1172
#                       --ConfFile
885
#
1173
#
886
# Returns         : 
1174
# Returns         : 
887
#
1175
#
888
sub CopyFileCommon
1176
sub CopyFileCommon
889
{
1177
{
Line 950... Line 1238...
950
        {
1238
        {
951
            CatFile ( $src, "$dst_dir/.LINKS" );
1239
            CatFile ( $src, "$dst_dir/.LINKS" );
952
        }
1240
        }
953
        else
1241
        else
954
        {
1242
        {
955
            mkpath( "$DebianWorkDir$dst_dir", 0, 0775);
1243
            mkpath( "$WorkDir$dst_dir", 0, 0775);
956
            unlink ("$DebianWorkDir$dst_file");
1244
            unlink ("$WorkDir$dst_file");
957
            System ('cp','-f', $src, "$DebianWorkDir$dst_file" );
1245
            System ('cp','-f', $src, "$WorkDir$dst_file" );
958
 
1246
 
959
            foreach my $lname ( @llist )
1247
            foreach my $lname ( @llist )
960
            {
1248
            {
961
                $lname = $dst_dir . '/' . $lname unless ( $lname =~ m ~^/~ );
1249
                $lname = $dst_dir . '/' . $lname unless ( $lname =~ m ~^/~ );
962
                MakeSymLink( $dst_file ,$lname);
1250
                MakeSymLink( $dst_file ,$lname);
Line 1023... Line 1311...
1023
    $copyOpts{'IgnoreDirs'} = ['.svn', '.git', '.cvs', '.hg'];
1311
    $copyOpts{'IgnoreDirs'} = ['.svn', '.git', '.cvs', '.hg'];
1024
    $copyOpts{'Ignore'} = ['.gbedir', '_gbedir'];
1312
    $copyOpts{'Ignore'} = ['.gbedir', '_gbedir'];
1025
    $copyOpts{'Log'} = 1 if ( $opt_verbose > 1 );
1313
    $copyOpts{'Log'} = 1 if ( $opt_verbose > 1 );
1026
    $copyOpts{'DeleteFirst'} = 1;
1314
    $copyOpts{'DeleteFirst'} = 1;
1027
 
1315
 
1028
    $dst_dir = $DebianWorkDir . '/' . $dst_dir;
1316
    $dst_dir = $WorkDir . '/' . $dst_dir;
1029
    $dst_dir =~ s~//~/~;
1317
    $dst_dir =~ s~//~/~;
1030
 
1318
 
1031
    #
1319
    #
1032
    #   Scan and collect user options
1320
    #   Scan and collect user options
1033
    #
1321
    #
Line 1224... Line 1512...
1224
    #   Must remove the DebianWorkDir prefix
1512
    #   Must remove the DebianWorkDir prefix
1225
    #
1513
    #
1226
    if(@fileList)
1514
    if(@fileList)
1227
    {
1515
    {
1228
        Verbose ("Mark all transfered files as ConfFiles");
1516
        Verbose ("Mark all transfered files as ConfFiles");
1229
        my $removePrefix = length ($DebianWorkDir);
1517
        my $removePrefix = length ($WorkDir);
1230
        foreach my $file (@fileList)
1518
        foreach my $file (@fileList)
1231
        {
1519
        {
1232
            push @ConfigList, substr($file, $removePrefix);
1520
            push @ConfigList, substr($file, $removePrefix);
1233
        }
1521
        }
1234
    }
1522
    }
1235
 
1523
 
1236
    #
1524
    #
1237
    #   Expand link files that may have been copied in
1525
    #   Expand link files that may have been copied in
1238
    #
1526
    #
1239
    Verbose ("Locate LINKFILES in $DebianWorkDir");
1527
    Verbose ("Locate LINKFILES in $WorkDir");
1240
    ExpandLinkFiles();
1528
    ExpandLinkFiles();
1241
}
1529
}
1242
 
1530
 
1243
#-------------------------------------------------------------------------------
1531
#-------------------------------------------------------------------------------
1244
# Function        : AddInitScript
1532
# Function        : AddInitScript
Line 1331... Line 1619...
1331
#
1619
#
1332
sub CatFile
1620
sub CatFile
1333
{
1621
{
1334
    my ($src, $dst) = @_;
1622
    my ($src, $dst) = @_;
1335
 
1623
 
1336
    $dst = $DebianWorkDir . '/' . $dst;
1624
    $dst = $WorkDir . '/' . $dst;
1337
    $dst =~ s~//~/~;
1625
    $dst =~ s~//~/~;
1338
    Verbose ("CatFile: $src, $dst");
1626
    Verbose ("CatFile: $src, $dst");
1339
    $src = ResolveFile(0, $src );
1627
    $src = ResolveFile(0, $src );
1340
 
1628
 
1341
    open (SF, '<', $src)  || Error ("CatFile: Cannot open $src");
1629
    open (SF, '<', $src)  || Error ("CatFile: Cannot open $src");
Line 1361... Line 1649...
1361
sub EchoFile
1649
sub EchoFile
1362
{
1650
{
1363
    my ($file, $text) = @_;
1651
    my ($file, $text) = @_;
1364
    Verbose ("EchoFile: $file");
1652
    Verbose ("EchoFile: $file");
1365
 
1653
 
1366
    $file = $DebianWorkDir . '/' . $file;
1654
    $file = $WorkDir . '/' . $file;
1367
    $file =~ s~//~/~;
1655
    $file =~ s~//~/~;
1368
 
1656
 
1369
    unlink $file;
1657
    unlink $file;
1370
    open (DT, ">", $file ) || Error ("Cannot create $file");
1658
    open (DT, ">", $file ) || Error ("Cannot create $file");
1371
    print DT  $text || Error ("Cannot print to $file");
1659
    print DT  $text || Error ("Cannot print to $file");
Line 1463... Line 1751...
1463
 
1751
 
1464
 
1752
 
1465
    #
1753
    #
1466
    # Convert output path to physical path
1754
    # Convert output path to physical path
1467
    #
1755
    #
1468
    my $topDir = catdir($DebianWorkDir, $outPath);
1756
    my $topDir = catdir($WorkDir, $outPath);
1469
    Verbose("ConvertFiles: topDir: $topDir");
1757
    Verbose("ConvertFiles: topDir: $topDir");
1470
    Error ("ConvertFiles: Path does not exist", $topDir) unless ( -e $topDir );
1758
    Error ("ConvertFiles: Path does not exist", $topDir) unless ( -e $topDir );
1471
    Error ("ConvertFiles: Path is not a directory", $topDir) unless ( -d $topDir );
1759
    Error ("ConvertFiles: Path is not a directory", $topDir) unless ( -d $topDir );
1472
 
1760
 
1473
    #
1761
    #
Line 1614... Line 1902...
1614
    Error ("ReplaceTags: No tags specified" ) unless ( @tagsList );
1902
    Error ("ReplaceTags: No tags specified" ) unless ( @tagsList );
1615
 
1903
 
1616
    #
1904
    #
1617
    # Convert output path to physical path
1905
    # Convert output path to physical path
1618
    #
1906
    #
1619
    my $topDir = catdir($DebianWorkDir, $outPath);
1907
    my $topDir = catdir($WorkDir, $outPath);
1620
    Verbose("ReplaceTags: topDir: $topDir");
1908
    Verbose("ReplaceTags: topDir: $topDir");
1621
    Error ("ReplaceTags: Path does not exist", $topDir) unless ( -e $topDir );
1909
    Error ("ReplaceTags: Path does not exist", $topDir) unless ( -e $topDir );
1622
    Error ("ReplaceTags: Path is not a directory", $topDir) unless ( -d $topDir );
1910
    Error ("ReplaceTags: Path is not a directory", $topDir) unless ( -d $topDir );
1623
 
1911
 
1624
    #
1912
    #
Line 1753... Line 2041...
1753
    Error ("SetFilePerms: No Permissions" ) unless ( $perms );
2041
    Error ("SetFilePerms: No Permissions" ) unless ( $perms );
1754
 
2042
 
1755
    foreach my $path ( @args )
2043
    foreach my $path ( @args )
1756
    {
2044
    {
1757
        Verbose ("Set permissions; $perms, $path");
2045
        Verbose ("Set permissions; $perms, $path");
1758
        my $full_path = $DebianWorkDir . '/' . $path;
2046
        my $full_path = $WorkDir . '/' . $path;
1759
        if ( -f $full_path )
2047
        if ( -f $full_path )
1760
        {
2048
        {
1761
            System ('chmod', $perms, $full_path );
2049
            System ('chmod', $perms, $full_path );
1762
        }
2050
        }
1763
        elsif ( -d $full_path )
2051
        elsif ( -d $full_path )
Line 1768... Line 2056...
1768
        else
2056
        else
1769
        {
2057
        {
1770
            Warning("SetFilePerms: Path not found: $path");
2058
            Warning("SetFilePerms: Path not found: $path");
1771
        }
2059
        }
1772
    }
2060
    }
-
 
2061
    return 1;
1773
}
2062
}
1774
 
2063
 
1775
#-------------------------------------------------------------------------------
2064
#-------------------------------------------------------------------------------
1776
# Function        : SetPermissions 
2065
# Function        : SetPermissions 
1777
#
2066
#
Line 1865... Line 2154...
1865
 
2154
 
1866
    #   Convert the target directory name into a physical path
2155
    #   Convert the target directory name into a physical path
1867
    #   User specifies '/' as the root of the image
2156
    #   User specifies '/' as the root of the image
1868
    #   User specifies 'name' as relateve to the root of the image
2157
    #   User specifies 'name' as relateve to the root of the image
1869
    #
2158
    #
1870
    my $topDir = $DebianWorkDir . '/' . $path;
2159
    my $topDir = $WorkDir . '/' . $path;
1871
    $topDir =~ s~/+$~~;
2160
    $topDir =~ s~/+$~~;
1872
 
2161
 
1873
    Verbose("SetPermissions: Called with options " . join(", ", @_));
2162
    Verbose("SetPermissions: Called with options " . join(", ", @_));
1874
 
2163
 
1875
    #
2164
    #
Line 1979... Line 2268...
1979
sub CreateDir
2268
sub CreateDir
1980
{
2269
{
1981
    my ($path) = @_;
2270
    my ($path) = @_;
1982
 
2271
 
1983
    Verbose ("Create Dir: $path");
2272
    Verbose ("Create Dir: $path");
1984
    mkpath( $DebianWorkDir . '/' . $path );
2273
    mkpath( $WorkDir . '/' . $path );
-
 
2274
}
-
 
2275
 
-
 
2276
#-------------------------------------------------------------------------------
-
 
2277
# Function        : RpmSetDefAttr 
-
 
2278
#
-
 
2279
# Description     : RPM only: Set the defAttr values 
-
 
2280
#
-
 
2281
# Inputs          : Expect 4 or less argument
-
 
2282
#                       The default permissions, or "mode" for files.
-
 
2283
#                       The default user id.
-
 
2284
#                       The default group id.
-
 
2285
#                       The default permissions, or "mode" for directories.
-
 
2286
#                   
-
 
2287
sub RpmSetDefAttr
-
 
2288
{
-
 
2289
    return 1 unless $opt_rpm;
-
 
2290
    my @args = @_;
-
 
2291
    Error ("RpmSetDefAttr: Expecting 4 arguments") if (scalar @args ne 4);
-
 
2292
    @RpmDefAttr = @_;
-
 
2293
    return 1;
-
 
2294
}
-
 
2295
 
-
 
2296
#-------------------------------------------------------------------------------
-
 
2297
# Function        : RpmSetAttr 
-
 
2298
#
-
 
2299
# Description     : RPM Only : Specify specific file attributes
-
 
2300
#
-
 
2301
# Inputs          : $file - file to target
-
 
2302
#                   $mode - File mode to place on the file (optional)
-
 
2303
#                   $user - user name to place on the file  (optional)
-
 
2304
#                   $group  - group name to place eon the file (optional)
-
 
2305
#
-
 
2306
sub RpmSetAttr
-
 
2307
{
-
 
2308
    return 1 unless $opt_rpm;
-
 
2309
    my ($file, $mode, $user, $group, @extra) = @_;
-
 
2310
    Error ("RpmSetAttr: Too many arguments") if @extra;
-
 
2311
 
-
 
2312
    #
-
 
2313
    #   Validate the file
-
 
2314
    #
-
 
2315
    $file = '/' . $file;
-
 
2316
    $file =~ s~//~/~g;
-
 
2317
    my $full_path = $WorkDir . $file;
-
 
2318
    Error ("RpmSetAttr: File not found: $file") unless -f $full_path;
-
 
2319
 
-
 
2320
    my @data;
-
 
2321
    $data[0] = $file;
-
 
2322
    $data[1] = $mode || '-';
-
 
2323
    $data[2] = $user || '-';
-
 
2324
    $data[3] = $group ||'-';
-
 
2325
    push @RpmAttrList, \@data;
-
 
2326
    return 1;
1985
}
2327
}
1986
 
2328
 
-
 
2329
 
1987
#-------------------------------------------------------------------------------
2330
#-------------------------------------------------------------------------------
1988
# Function        : IsProduct
2331
# Function        : IsProduct
1989
#                   IsPlatform
2332
#                   IsPlatform
1990
#                   IsTarget
2333
#                   IsTarget
1991
#                   IsVariant
2334
#                   IsVariant
Line 2155... Line 2498...
2155
#
2498
#
2156
# Description     : Look for .LINK files in the output image and expand
2499
# Description     : Look for .LINK files in the output image and expand
2157
#                   the links into softlinks
2500
#                   the links into softlinks
2158
#
2501
#
2159
# Inputs          : None
2502
# Inputs          : None
2160
#                   The rouine works on the $DebianWorkDir directory tree
2503
#                   The routine works on the $WorkDir directory tree
2161
#
2504
#
2162
# Returns         : Nothing
2505
# Returns         : Nothing
2163
#                   Will remove .LINKS files that are processed
2506
#                   Will remove .LINKS files that are processed
2164
#
2507
#
2165
sub ExpandLinkFiles
2508
sub ExpandLinkFiles
2166
{
2509
{
2167
    foreach my $linkfile ( FindFiles( $DebianWorkDir, ".LINKS" ))
2510
    foreach my $linkfile ( FindFiles( $WorkDir, ".LINKS" ))
2168
    {
2511
    {
2169
        next if ( $linkfile =~ m~/\.svn/~ );
2512
        next if ( $linkfile =~ m~/\.svn/~ );
2170
        my $BASEDIR = StripFileExt( $linkfile );
2513
        my $BASEDIR = StripFileExt( $linkfile );
2171
        $BASEDIR =~ s~^$DebianWorkDir/~~;
2514
        $BASEDIR =~ s~^$WorkDir/~~;
2172
        Verbose "Expand links: $BASEDIR";
2515
        Verbose "Expand links: $BASEDIR";
2173
 
2516
 
2174
        open (LF, "<", $linkfile ) || Error ("Cannot open link file: $linkfile" );
2517
        open (LF, "<", $linkfile ) || Error ("Cannot open link file: $linkfile" );
2175
        while ( <LF> )
2518
        while ( <LF> )
2176
        {
2519
        {
Line 2663... Line 3006...
2663
        Error ("ResolveDebPackage: Multiple instances of Package found.", @done);
3006
        Error ("ResolveDebPackage: Multiple instances of Package found.", @done);
2664
    }
3007
    }
2665
    return wantarray ? @done : $done[0];
3008
    return wantarray ? @done : $done[0];
2666
}
3009
}
2667
 
3010
 
2668
 
-
 
2669
 
-
 
2670
#-------------------------------------------------------------------------------
3011
#-------------------------------------------------------------------------------
2671
# Function        : AUTOLOAD
3012
# Function        : AUTOLOAD
2672
#
3013
#
2673
# Description     : Intercept bad user directives and issue a nice error message
3014
# Description     : Intercept unknown user directives and issue a nice error message
2674
#                   This is a simple routine to report unknown user directives
3015
#                   This is a simple routine to report unknown user directives
2675
#                   It does not attempt to distinguish between user errors and
3016
#                   It does not attempt to distinguish between user errors and
2676
#                   programming errors. It assumes that the program has been
3017
#                   programming errors. It assumes that the program has been
2677
#                   tested. The function simply report filename and line number
3018
#                   tested. The function simply report filename and line number
2678
#                   of the bad directive.
3019
#                   of the bad directive.
Line 2685... Line 3026...
2685
sub AUTOLOAD
3026
sub AUTOLOAD
2686
{
3027
{
2687
    my $fname = $AUTOLOAD;
3028
    my $fname = $AUTOLOAD;
2688
    $fname =~ s~^main::~~;
3029
    $fname =~ s~^main::~~;
2689
    my ($package, $filename, $line) = caller;
3030
    my ($package, $filename, $line) = caller;
-
 
3031
    my $prefix;
-
 
3032
 
-
 
3033
    #
-
 
3034
    #   Some directives are applicable to Rpm and/or Debian only
-
 
3035
    #   If a directive starts with Rpm, Debian or All, then invoke
-
 
3036
    #   the underlying directive iff we are process a Debian/Rpm file
-
 
3037
    #   
-
 
3038
    #   The underlying directive will start with MULTI_
-
 
3039
    #   It will be called with the first argument being the name of the function
-
 
3040
    #   that it is being called as.
-
 
3041
    #
-
 
3042
    $fname =~ m~^(Rpm|Debian|All)(.*)~;
-
 
3043
    my $type = $1;
-
 
3044
    my $tfname = 'MULTI_' . $2;
-
 
3045
    my $fRef = \&{$tfname}; 
-
 
3046
 
-
 
3047
    if (defined &{$tfname}) {
-
 
3048
        if ($type eq 'Rpm') {
-
 
3049
            $fRef->($fname, @_) if $opt_rpm;
-
 
3050
 
-
 
3051
        } elsif ($type eq 'Debian') {
-
 
3052
            $fRef->($fname, @_) if $opt_debian;
-
 
3053
 
-
 
3054
        } elsif ($type eq 'All') {
-
 
3055
            $fRef->($fname, @_);
-
 
3056
        }
-
 
3057
        return 1;
-
 
3058
    }
2690
 
3059
 
2691
    Error ("Directive not known or not allowed in this context: $fname",
3060
    Error ("Directive not known or not allowed in this context: $fname",
2692
           "Directive: $fname( @_ );",
3061
           "Directive: $fname( @_ );",
2693
           "File: $filename, Line: $line" );
3062
           "File: $filename, Line: $line" );
2694
}
3063
}
2695
 
3064
 
2696
 
-
 
2697
1;
3065
1;
2698
 
3066