| 341 |
dpurdie |
1 |
########################################################################
|
| 5710 |
dpurdie |
2 |
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
|
| 341 |
dpurdie |
3 |
#
|
|
|
4 |
# Module name : jats_update_release.pl
|
|
|
5 |
# Module type : Makefile system
|
|
|
6 |
# Compiler(s) : Perl
|
|
|
7 |
# Environment(s): jats build system
|
|
|
8 |
#
|
|
|
9 |
# Description : Extracts current package version list from Deployment Manager
|
|
|
10 |
# SBom(s) and copies resultant packages to release specific
|
|
|
11 |
# directory.
|
|
|
12 |
#......................................................................#
|
|
|
13 |
|
|
|
14 |
require 5.008_002;
|
|
|
15 |
use File::Basename;
|
|
|
16 |
use File::Copy;
|
|
|
17 |
use File::Path;
|
|
|
18 |
use strict;
|
|
|
19 |
use warnings;
|
|
|
20 |
use JatsEnv;
|
|
|
21 |
use JatsError;
|
|
|
22 |
use JatsSystem;
|
|
|
23 |
use JatsRmApi;
|
| 3987 |
dpurdie |
24 |
use ArrayHashUtils;
|
| 341 |
dpurdie |
25 |
use DBI;
|
|
|
26 |
use Getopt::Long;
|
|
|
27 |
use Pod::Usage; # required for help support
|
|
|
28 |
use Storable qw (dclone);
|
|
|
29 |
|
|
|
30 |
#
|
|
|
31 |
# Config Options
|
|
|
32 |
#
|
|
|
33 |
my $VERSION = "1.0.0"; # Update this
|
|
|
34 |
my $opt_help = 0;
|
|
|
35 |
my $opt_verbose = $ENV{'GBE_VERBOSE'}; # Allow global verbose
|
|
|
36 |
my @opt_sbom_ids;
|
|
|
37 |
my $opt_rootdir;
|
|
|
38 |
my @opt_filters;
|
|
|
39 |
my $opt_projectdir;
|
|
|
40 |
my $opt_releasedir;
|
|
|
41 |
my $opt_test;
|
| 3987 |
dpurdie |
42 |
my @opt_addFilters;
|
|
|
43 |
my @opt_delFilters;
|
| 341 |
dpurdie |
44 |
|
|
|
45 |
#
|
|
|
46 |
# Constants
|
|
|
47 |
#
|
|
|
48 |
my $CONFFILE = ".updateRelease";
|
|
|
49 |
|
|
|
50 |
#
|
|
|
51 |
# Data Base Interface
|
|
|
52 |
#
|
|
|
53 |
my $DM_DB;
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
#
|
|
|
57 |
# The directory we copy to.
|
|
|
58 |
#
|
|
|
59 |
my $projectDestDir;
|
|
|
60 |
|
|
|
61 |
#
|
|
|
62 |
# Configuration file vars
|
|
|
63 |
#
|
|
|
64 |
my @confFilters;
|
|
|
65 |
my $writeConf = 0;
|
| 3987 |
dpurdie |
66 |
my %filtersUsed;
|
| 341 |
dpurdie |
67 |
|
|
|
68 |
# -------------------------------------------------------------------------
|
|
|
69 |
sub GetYesNo
|
|
|
70 |
#
|
|
|
71 |
# -------------------------------------------------------------------------
|
|
|
72 |
{
|
|
|
73 |
my ($question) = @_;
|
|
|
74 |
my ($u_tmp) = "";
|
|
|
75 |
Question ("$question, (default: y) [y,n]: ");
|
|
|
76 |
|
|
|
77 |
while ( <STDIN> )
|
|
|
78 |
{
|
|
|
79 |
$u_tmp = $_;
|
|
|
80 |
chomp($u_tmp);
|
|
|
81 |
|
|
|
82 |
return 1
|
|
|
83 |
if ( "$u_tmp" eq "" );
|
|
|
84 |
|
|
|
85 |
if( $u_tmp =~ /[yn]{1}/i )
|
|
|
86 |
{
|
|
|
87 |
return ( "$u_tmp" eq "y" );
|
|
|
88 |
}
|
|
|
89 |
else
|
|
|
90 |
{
|
|
|
91 |
Question("Please re-enter response? (default: y) [y,n]: ");
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
#==============================================================================
|
|
|
98 |
# getSbomProjectAndRelease
|
|
|
99 |
# Returns the Project Name and Release for supplied SBoms
|
|
|
100 |
# Calls Error and exists on error condition
|
|
|
101 |
#==============================================================================
|
|
|
102 |
sub getSbomProjectAndRelease
|
|
|
103 |
{
|
|
|
104 |
my ( $DB, $sboms ) = @_;
|
|
|
105 |
my ( $bom, $proj, $rel, $lastProj, $lastRel );
|
|
|
106 |
|
|
|
107 |
Error("getSbomProjectAndRelease: SBom Parameter Error, must pass array") if ( ref($sboms) ne "ARRAY" );
|
|
|
108 |
|
|
|
109 |
# create a hash of sbom values so we can test after if any sboms could not be found
|
|
|
110 |
my %sbomIdx = map { $_ => 1 } @{$sboms};
|
|
|
111 |
|
|
|
112 |
my $m_sqlstr = "SELECT boms.bom_id, dm_projects.proj_name, branches.branch_name " .
|
|
|
113 |
"FROM deployment_manager.boms, deployment_manager.branches, deployment_manager.dm_projects " .
|
|
|
114 |
"WHERE branches.branch_id = boms.branch_id AND " .
|
|
|
115 |
" dm_projects.proj_id = branches.proj_id AND " .
|
|
|
116 |
" boms.bom_id " . ( $#{$sboms} == 0 ? "= " . $sboms->[0] : "IN ( " . join(",", @{$sboms}) . ")" );
|
|
|
117 |
|
|
|
118 |
my $sth = $DB->prepare($m_sqlstr);
|
|
|
119 |
if ( defined($sth) )
|
|
|
120 |
{
|
|
|
121 |
if ( $sth->execute( ) )
|
|
|
122 |
{
|
|
|
123 |
if ( $sth->rows )
|
|
|
124 |
{
|
|
|
125 |
while ( ( $bom, $proj, $rel ) = $sth->fetchrow_array )
|
|
|
126 |
{
|
|
|
127 |
if ( ! defined($proj) )
|
|
|
128 |
{
|
|
|
129 |
Error("getSbomProjectAndRelease: NULL Project Name from Deployment Manager Sbom : $bom");
|
|
|
130 |
}
|
|
|
131 |
elsif ( ! defined($rel) )
|
|
|
132 |
{
|
|
|
133 |
Error("getSbomProjectAndRelease: NULL Release Tag Name from Deployment Manager Sbom : $bom");
|
|
|
134 |
}
|
|
|
135 |
elsif ( defined($lastProj) && $proj ne $lastProj )
|
|
|
136 |
{
|
|
|
137 |
Error("getSbomProjectAndRelease: SBom Id [$bom] is in a different project [$proj]", "All SBom Id's must all be part of the same Deployment Manager Project");
|
|
|
138 |
}
|
|
|
139 |
elsif ( defined($lastRel) && $rel ne $lastRel )
|
|
|
140 |
{
|
|
|
141 |
Error("getSbomProjectAndRelease: SBom Id [$bom] is in a different project release [$rel]", "All SBom Id's must all be part of the same Deployment Manager Project Release");
|
|
|
142 |
}
|
|
|
143 |
$lastProj = $proj;
|
|
|
144 |
$lastRel = $rel;
|
|
|
145 |
|
|
|
146 |
# delete sbom from idx, any remaining after loop will indicate we have an sbom that could not found
|
|
|
147 |
delete($sbomIdx{$bom});
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
my @sbomsNotFound = keys %sbomIdx;
|
|
|
151 |
if ( $#sbomsNotFound > -1 )
|
|
|
152 |
{
|
|
|
153 |
Error("getSbomProjectAndRelease: Could not find details for the following SBomId(s) " . join(",", @sbomsNotFound) );
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
else
|
|
|
157 |
{
|
|
|
158 |
Error("getSbomProjectAndRelease: No SBom(s) found for Deployment Manager SBomId(s) " . join(",", @{$sboms}) );
|
|
|
159 |
}
|
|
|
160 |
$sth->finish();
|
|
|
161 |
}
|
|
|
162 |
else
|
|
|
163 |
{
|
|
|
164 |
Error("getSbomProjectAndRelease: Execute failure", $m_sqlstr );
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
else
|
|
|
168 |
{
|
|
|
169 |
Error("getSbomProjectAndRelease: Prepare failure", $m_sqlstr );
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
return ( $lastProj, $lastRel );
|
|
|
173 |
} # getSbomProjectAndRelease
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
#-------------------------------------------------------------------------------
|
|
|
177 |
# Function : Main
|
|
|
178 |
#
|
|
|
179 |
# Description : Main entry point
|
|
|
180 |
# Parse user options
|
|
|
181 |
#
|
|
|
182 |
# Inputs :
|
|
|
183 |
#
|
|
|
184 |
# Returns :
|
|
|
185 |
#
|
|
|
186 |
|
|
|
187 |
my $result = GetOptions (
|
|
|
188 |
"help:+" => \$opt_help, # flag, multiple use allowed
|
|
|
189 |
"manual:3" => \$opt_help, # flag, multiple use allowed
|
|
|
190 |
"verbose:+" => \$opt_verbose, # flag
|
|
|
191 |
"sbomid|sbom_id=s" => \@opt_sbom_ids, # multiple numbers
|
|
|
192 |
"filter=s" => \@opt_filters, # multiple strings
|
| 3987 |
dpurdie |
193 |
"addfilter=s" => \@opt_addFilters, # multiple strings
|
|
|
194 |
"delfilter=s" => \@opt_delFilters, # multiple strings
|
| 341 |
dpurdie |
195 |
"rootdir=s" => \$opt_rootdir, # string
|
|
|
196 |
"projectdir=s" => \$opt_projectdir, # string
|
|
|
197 |
"releasedir=s" => \$opt_releasedir, # string
|
|
|
198 |
"test" => \$opt_test, # flag
|
|
|
199 |
);
|
|
|
200 |
|
|
|
201 |
#
|
|
|
202 |
# Process help and manual options
|
|
|
203 |
#
|
|
|
204 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
205 |
pod2usage(-verbose => 1) if ($opt_help == 2 );
|
|
|
206 |
pod2usage(-verbose => 2) if ($opt_help > 2);
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
ErrorConfig( 'name' => 'updateRelease',
|
|
|
210 |
'verbose' => $opt_verbose );
|
|
|
211 |
|
|
|
212 |
#
|
|
|
213 |
# Sanity tests
|
|
|
214 |
#
|
|
|
215 |
|
|
|
216 |
# Must supply at least one SbomId and the rootdir
|
|
|
217 |
if ( $#opt_sbom_ids == -1 || ! defined($opt_rootdir) )
|
|
|
218 |
{
|
|
|
219 |
Error("Need -sbomid and -rootdir", "Example: -sbomid=2362 -rootdir=/export/devl/releases" ) ;
|
|
|
220 |
}
|
|
|
221 |
# Supplied rootdir must exists as a directory
|
|
|
222 |
elsif ( ! -d $opt_rootdir )
|
|
|
223 |
{
|
|
|
224 |
Error("Root dir $opt_rootdir not a valid directory");
|
|
|
225 |
}
|
|
|
226 |
# Environment var GBE_DPKG must exists as a directory
|
|
|
227 |
elsif ( ! -d $ENV{GBE_DPKG} )
|
|
|
228 |
{
|
|
|
229 |
Error("GBE_DPKG Environment var is not a directory") ;
|
|
|
230 |
}
|
|
|
231 |
# projectdir and releasedir must be specified together or not at all
|
|
|
232 |
elsif ( ( defined($opt_projectdir) && !defined($opt_releasedir) ) ||
|
|
|
233 |
( !defined($opt_projectdir) && defined($opt_releasedir) ) )
|
|
|
234 |
{
|
|
|
235 |
Error("Both -projectdir and -releasedir are required if either one is specified") ;
|
|
|
236 |
}
|
|
|
237 |
# if projectdir is specified it must be a valid dir in the rootdir
|
|
|
238 |
elsif ( defined($opt_projectdir) && ! -d "$opt_rootdir/$opt_projectdir" )
|
|
|
239 |
{
|
|
|
240 |
Error("The specified project directory does not exist in the root directory");
|
|
|
241 |
}
|
|
|
242 |
# if releasedir is specified it must be a valid dir in the projectdir
|
|
|
243 |
elsif ( defined($opt_releasedir) && ! -d "$opt_rootdir/$opt_projectdir/$opt_releasedir" )
|
|
|
244 |
{
|
|
|
245 |
Error("The specified project/release directory does not exist in the root directory");
|
|
|
246 |
}
|
|
|
247 |
|
| 4086 |
dpurdie |
248 |
#
|
|
|
249 |
# This command is destined to be used in a directory where group permissions
|
|
|
250 |
# are important. Ensure that the user is not killing group access
|
|
|
251 |
#
|
|
|
252 |
umask 0002;
|
| 341 |
dpurdie |
253 |
|
|
|
254 |
# Now lets connect and do our thing
|
|
|
255 |
connectRM(\$DM_DB);
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
if ( defined($opt_projectdir) && defined($opt_releasedir) )
|
|
|
259 |
{
|
|
|
260 |
# If project and release dirs are specified we DONT need to get projectDir & releaseDir from DM but
|
|
|
261 |
# we do need to make sure that all sbomids specified have the same project & release in DM
|
|
|
262 |
# so we call the getSbomProjectAndRelease but ignore the return values for project and release names
|
|
|
263 |
getSbomProjectAndRelease($DM_DB, \@opt_sbom_ids);
|
|
|
264 |
}
|
|
|
265 |
else
|
|
|
266 |
{
|
|
|
267 |
# If project and release dirs not specified then get the projectDir & releaseDir from DM and in addition
|
|
|
268 |
# we need to check that all sbomids specified have the same project & release in DM
|
|
|
269 |
( $opt_projectdir, $opt_releasedir ) = getSbomProjectAndRelease($DM_DB, \@opt_sbom_ids);
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
|
|
|
273 |
Message("Using Project [$opt_projectdir] Release [$opt_releasedir]");
|
|
|
274 |
|
|
|
275 |
# now set the projectDestDir
|
|
|
276 |
$projectDestDir = "$opt_rootdir/$opt_projectdir/$opt_releasedir";
|
|
|
277 |
|
|
|
278 |
# load the config file if one exists
|
|
|
279 |
if ( -f "$projectDestDir/$CONFFILE" )
|
|
|
280 |
{
|
|
|
281 |
Message("Loading release specific Config File");
|
|
|
282 |
|
|
|
283 |
open(CONF, "<$projectDestDir/$CONFFILE") || Error("Failed to open config file");
|
|
|
284 |
while( <CONF> )
|
|
|
285 |
{
|
|
|
286 |
chomp;
|
|
|
287 |
if ( /^\s*filter\s*=\s*(.*)\s*$/ )
|
|
|
288 |
{
|
|
|
289 |
push(@confFilters, $1);
|
|
|
290 |
}
|
|
|
291 |
}
|
|
|
292 |
close(CONF);
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
# validate config and command line options
|
|
|
296 |
if ( $#opt_filters > -1 && $#confFilters > -1 )
|
|
|
297 |
{
|
|
|
298 |
Message("Filters supplied on Command line", @opt_filters);
|
|
|
299 |
Message("Filters in release configuration file", @confFilters);
|
| 3987 |
dpurdie |
300 |
if ( !GetYesNo("Replace Config Filters with command line Filters, be careful as this may change the copy rules") )
|
| 341 |
dpurdie |
301 |
{
|
|
|
302 |
Error("Script terminated by user.");
|
|
|
303 |
}
|
| 3987 |
dpurdie |
304 |
@confFilters = ();
|
|
|
305 |
foreach my $element (@opt_filters) {
|
|
|
306 |
UniquePush (\@confFilters, $_ ) foreach ( split(/,/, $element));
|
|
|
307 |
}
|
| 341 |
dpurdie |
308 |
$writeConf = 1;
|
|
|
309 |
}
|
|
|
310 |
elsif ( $#opt_filters > -1 && $#confFilters == -1 )
|
|
|
311 |
{
|
|
|
312 |
Message("Filters supplied on Command line will be written to config file for release", @opt_filters);
|
| 3987 |
dpurdie |
313 |
@confFilters = ();
|
|
|
314 |
foreach my $element (@opt_filters) {
|
|
|
315 |
UniquePush (\@confFilters, $_ ) foreach ( split(/,/, $element));
|
|
|
316 |
}
|
| 341 |
dpurdie |
317 |
$writeConf = 1;
|
|
|
318 |
}
|
|
|
319 |
elsif ( $#opt_filters == -1 && $#confFilters > -1 )
|
|
|
320 |
{
|
|
|
321 |
Message("Filters loaded from config file for release will be used", @confFilters) if ( IsVerbose(1) );
|
|
|
322 |
}
|
|
|
323 |
elsif ( $#opt_filters == -1 && $#confFilters == -1 )
|
|
|
324 |
{
|
|
|
325 |
Error("No Filters supplied on command line or release config file");
|
|
|
326 |
}
|
|
|
327 |
|
| 3987 |
dpurdie |
328 |
if ( @opt_addFilters )
|
|
|
329 |
{
|
|
|
330 |
Message ("Adding command line filters to the release config file");
|
|
|
331 |
foreach my $element (@opt_addFilters) {
|
|
|
332 |
UniquePush (\@confFilters, $_ ) foreach ( split(/,/, $element));
|
|
|
333 |
}
|
|
|
334 |
$writeConf = 1;
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
if ( @opt_delFilters )
|
|
|
338 |
{
|
|
|
339 |
Message ("Deleting command line filters to the release config file");
|
|
|
340 |
foreach my $element (@opt_delFilters) {
|
|
|
341 |
ArrayDelete (\@confFilters, $_ ) foreach ( split(/,/, $element));
|
|
|
342 |
}
|
|
|
343 |
$writeConf = 1;
|
|
|
344 |
}
|
|
|
345 |
|
| 341 |
dpurdie |
346 |
Message("Copying packages from $ENV{GBE_DPKG} to $projectDestDir");
|
|
|
347 |
|
|
|
348 |
if ( ! -d $projectDestDir )
|
|
|
349 |
{
|
|
|
350 |
if ( defined($opt_test) )
|
|
|
351 |
{
|
|
|
352 |
Message("mkdir $projectDestDir");
|
|
|
353 |
}
|
|
|
354 |
else
|
|
|
355 |
{
|
|
|
356 |
eval { mkpath($projectDestDir) };
|
|
|
357 |
Error("Failed to make project directory tree $projectDestDir") if ( $@ || ! -d $projectDestDir );
|
|
|
358 |
}
|
|
|
359 |
}
|
|
|
360 |
|
|
|
361 |
my $m_sqlstr = "SELECT packages.pkg_name, package_versions.pkg_version " .
|
|
|
362 |
"FROM deployment_manager.bom_contents, " .
|
|
|
363 |
" deployment_manager.network_nodes, " .
|
|
|
364 |
" deployment_manager.os_contents, " .
|
|
|
365 |
" deployment_manager.operating_systems, " .
|
|
|
366 |
" release_manager.package_versions, " .
|
|
|
367 |
" release_manager.packages " .
|
|
|
368 |
"WHERE network_nodes.node_id = bom_contents.node_id AND " .
|
|
|
369 |
" network_nodes.node_id = operating_systems.node_id AND " .
|
|
|
370 |
" operating_systems.os_id = os_contents.os_id AND " .
|
|
|
371 |
" os_contents.prod_id = package_versions.pv_id AND " .
|
|
|
372 |
" package_versions.pkg_id = packages.pkg_id AND " .
|
|
|
373 |
" bom_contents.bom_id " . ( $#opt_sbom_ids == 0 ? "= " . $opt_sbom_ids[0] : "IN ( " . join(",", @opt_sbom_ids) . ")" ) . " " .
|
|
|
374 |
"GROUP BY packages.pkg_name, package_versions.pkg_version " .
|
|
|
375 |
"ORDER BY packages.pkg_name ASC, package_versions.pkg_version ASC";
|
|
|
376 |
|
|
|
377 |
my ( $PKG_NAME, $PKG_VERSION );
|
|
|
378 |
|
|
|
379 |
my $sth = $DM_DB->prepare($m_sqlstr);
|
|
|
380 |
if ( defined($sth) )
|
|
|
381 |
{
|
|
|
382 |
if ( $sth->execute( ) )
|
|
|
383 |
{
|
|
|
384 |
if ( $sth->rows )
|
|
|
385 |
{
|
|
|
386 |
while ( ( $PKG_NAME, $PKG_VERSION ) = $sth->fetchrow_array )
|
|
|
387 |
{
|
|
|
388 |
my $pkgDir = "$ENV{GBE_DPKG}/$PKG_NAME";
|
|
|
389 |
my $srcDir = "$ENV{GBE_DPKG}/$PKG_NAME/$PKG_VERSION";
|
|
|
390 |
my $dstDir = "$projectDestDir/$PKG_NAME/$PKG_VERSION";
|
|
|
391 |
|
|
|
392 |
if ( -d "$srcDir" )
|
|
|
393 |
{
|
|
|
394 |
my @filelist;
|
|
|
395 |
my $foundFiltered = 0;
|
|
|
396 |
|
|
|
397 |
# for each of the filter rules we glob the rule in the src pkg/version dir
|
|
|
398 |
# and if any of the globbed files dont exist in the dst dir add it to the
|
|
|
399 |
# the filelist array of files to copy
|
|
|
400 |
foreach my $filter ( @confFilters )
|
|
|
401 |
{
|
|
|
402 |
foreach my $srcPath ( glob("$srcDir/$filter") )
|
|
|
403 |
{
|
| 3987 |
dpurdie |
404 |
next unless ( -f $srcPath );
|
| 341 |
dpurdie |
405 |
$foundFiltered = 1;
|
| 3987 |
dpurdie |
406 |
$filtersUsed{$filter} = 1;
|
|
|
407 |
my $dstFile = basename($srcPath);
|
|
|
408 |
my $srcFile = $srcPath;
|
|
|
409 |
$srcFile =~ s~^$srcDir/~~;
|
|
|
410 |
push(@filelist, $srcFile) if ( ! -f "$dstDir/$dstFile" );
|
| 341 |
dpurdie |
411 |
}
|
|
|
412 |
}
|
|
|
413 |
|
|
|
414 |
# if no files found using filters then issue warning
|
|
|
415 |
if ( $foundFiltered == 0 )
|
|
|
416 |
{
|
|
|
417 |
Warning("No Files found for Package Version $PKG_NAME/$PKG_VERSION using supplied filters");
|
|
|
418 |
}
|
| 3987 |
dpurdie |
419 |
# else we have found filtered files but they may already exist
|
|
|
420 |
# if so filelist may be empty, so check it b4 doing anything
|
| 341 |
dpurdie |
421 |
elsif ( $#filelist > -1 )
|
|
|
422 |
{
|
|
|
423 |
Message("Copying files for package $PKG_NAME version $PKG_VERSION");
|
|
|
424 |
if ( defined($opt_test) )
|
|
|
425 |
{
|
|
|
426 |
Message( map("$_...", @filelist) );
|
|
|
427 |
}
|
|
|
428 |
else
|
|
|
429 |
{
|
|
|
430 |
eval { mkpath($dstDir) };
|
|
|
431 |
Error("Failed to make destination directory") if ( $@ || ! -d $dstDir );
|
|
|
432 |
foreach my $file ( @filelist )
|
|
|
433 |
{
|
|
|
434 |
Verbose("$file...");
|
|
|
435 |
if ( ! copy("$srcDir/$file", $dstDir) )
|
|
|
436 |
{
|
|
|
437 |
Warning("Failed to copy $file ($!)");
|
|
|
438 |
}
|
|
|
439 |
}
|
|
|
440 |
}
|
|
|
441 |
}
|
|
|
442 |
}
|
|
|
443 |
elsif ( ! -d "$pkgDir" )
|
|
|
444 |
{
|
|
|
445 |
# if srcDir and pkgDir dont exist then package is not in dpkg_archive so display message
|
|
|
446 |
Verbose("Skipping Package $PKG_NAME as it does not exist in dpkg_archive");
|
|
|
447 |
}
|
|
|
448 |
else
|
|
|
449 |
{
|
|
|
450 |
# However if srcDir does not exist but pkgDir does exist then the package version is missing which maybe an issue
|
|
|
451 |
Warning("Missing Version $PKG_VERSION for Package $PKG_NAME in dpkg_archive");
|
|
|
452 |
}
|
|
|
453 |
}
|
| 3987 |
dpurdie |
454 |
|
|
|
455 |
#
|
|
|
456 |
# Report filter elements that where not used.
|
|
|
457 |
#
|
|
|
458 |
my @notUsed;
|
|
|
459 |
foreach my $filter ( @confFilters )
|
|
|
460 |
{
|
|
|
461 |
next if ( exists $filtersUsed{$filter} );
|
|
|
462 |
push @notUsed, $filter
|
|
|
463 |
}
|
|
|
464 |
Warning ("Unused filter rules:", @notUsed )
|
|
|
465 |
if ( @notUsed );
|
|
|
466 |
|
| 341 |
dpurdie |
467 |
}
|
|
|
468 |
else
|
|
|
469 |
{
|
|
|
470 |
Error("No Boms found for Deployment Manager SBomId(s) " . join(",", @opt_sbom_ids) );
|
|
|
471 |
}
|
|
|
472 |
$sth->finish();
|
|
|
473 |
}
|
|
|
474 |
else
|
|
|
475 |
{
|
|
|
476 |
Error("Execute failure", $m_sqlstr );
|
|
|
477 |
}
|
|
|
478 |
}
|
|
|
479 |
else
|
|
|
480 |
{
|
|
|
481 |
Error("Prepare failure", $m_sqlstr );
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
if ( ! defined($opt_test) && $writeConf )
|
|
|
485 |
{
|
|
|
486 |
open(CONF, ">$projectDestDir/$CONFFILE") || Error("Failed to open config file");
|
|
|
487 |
print CONF map( "filter=$_\n", @confFilters);
|
|
|
488 |
close CONF;
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
#-------------------------------------------------------------------------------
|
|
|
492 |
# Documentation
|
|
|
493 |
#
|
|
|
494 |
|
|
|
495 |
=pod
|
|
|
496 |
|
| 361 |
dpurdie |
497 |
=for htmltoc DEPLOY::Update Release
|
|
|
498 |
|
| 341 |
dpurdie |
499 |
=head1 NAME
|
|
|
500 |
|
|
|
501 |
jats_update_release - Extracts current package version list from Deployment Manager SBom(s)
|
|
|
502 |
and copy resultant packages to release specific directory.
|
|
|
503 |
|
|
|
504 |
=head1 SYNOPSIS
|
|
|
505 |
|
|
|
506 |
jats update_release -sbomid=xxx -rootdir=xxx [options]
|
|
|
507 |
|
|
|
508 |
Options:
|
|
|
509 |
-help - brief help message
|
|
|
510 |
-help -help - Detailed help message
|
|
|
511 |
-man - Full documentation
|
|
|
512 |
-sbomid=xxx - Specify the Deployment Manager SBom(s) to process (Mandatory)
|
|
|
513 |
- Can be specified multiple times to combine SBoms
|
|
|
514 |
-rootdir=xxx - Specifies the root of the releases directory (Mandatory)
|
|
|
515 |
-projectdir=xxx - Override the project directory name that normally comes
|
|
|
516 |
- from the Deployment Manager Project Name
|
|
|
517 |
-releasedir=xxx - Override the project release directory name that normally
|
|
|
518 |
- comes from the Deployment Manager Project Release Name
|
|
|
519 |
-filter=xxx - Specifies a shell wildcard used to filter package files to copy
|
|
|
520 |
- Can be specified multiple times to use multiple filters
|
| 3987 |
dpurdie |
521 |
-addfilter=xxx - Add a new filter to the existing filter set
|
|
|
522 |
-delfilter=xxx - Delete a filter from the existing filter set
|
| 341 |
dpurdie |
523 |
-test - Just log actions without copying files.
|
|
|
524 |
-verbose - Enable verbose output
|
|
|
525 |
|
|
|
526 |
=head1 OPTIONS
|
|
|
527 |
|
|
|
528 |
=over 8
|
|
|
529 |
|
|
|
530 |
=item B<-help>
|
|
|
531 |
|
|
|
532 |
Print a brief help message and exits.
|
|
|
533 |
|
|
|
534 |
=item B<-help -help>
|
|
|
535 |
|
|
|
536 |
Print a detailed help message with an explanation for each option.
|
|
|
537 |
|
|
|
538 |
=item B<-man>
|
|
|
539 |
|
|
|
540 |
Prints the manual page and exits.
|
|
|
541 |
|
|
|
542 |
=item B<-sbomid=xxx>
|
|
|
543 |
|
|
|
544 |
This option specifies one or more SBOM_ID's to use as the source of packages that will be copied.
|
|
|
545 |
The SBoms will be used to get a unique list of package/versions that can be copied from dpkg_archive.
|
|
|
546 |
|
|
|
547 |
This option is Mandatory and a minimum of one SBom must be supplied. If more that one SBom is
|
|
|
548 |
supplied then all Sbom Ids must be of the same project and release with in that project.
|
|
|
549 |
|
|
|
550 |
=item B<-rootdir=xxx>
|
|
|
551 |
|
|
|
552 |
This option specifies the root directory where the packages will be copied to.
|
|
|
553 |
It is the top level directory in which the project/release directories will be created
|
|
|
554 |
and the packages copied to.
|
|
|
555 |
|
|
|
556 |
This option is mandatory and must specify a directory that exists.
|
|
|
557 |
|
|
|
558 |
=item B<-projectdir=xxx>
|
|
|
559 |
|
|
|
560 |
This option specifies the project directory that will be used in the rootdir for this release.
|
|
|
561 |
The project directory by default comes from the project name in Deployment Manager under which the
|
|
|
562 |
SBom sbomid is under.
|
|
|
563 |
|
|
|
564 |
This option is provided to allow this script to be used against releases that are already
|
|
|
565 |
populated and whose project directory does not match the Deployment Manager project name.
|
|
|
566 |
|
|
|
567 |
If the option is specified it must be used with the -releasedir option and must be a directory
|
|
|
568 |
name that exists in the rootdir.
|
|
|
569 |
Additionally if used to populate a release then it must always be used to update the release.
|
|
|
570 |
|
|
|
571 |
=item B<-releasedir=xxx>
|
|
|
572 |
|
|
|
573 |
This option specifies the release directory that will be used in the projectdir for this release.
|
|
|
574 |
The release directory by default comes from the release name in Deployment Manager under
|
|
|
575 |
which the SBom sbomid is under.
|
|
|
576 |
|
|
|
577 |
This option is provided to allow this script to be used against releases that are already
|
|
|
578 |
populated and whose release directory does not match the Deployment Manager release name.
|
|
|
579 |
|
|
|
580 |
If the option is specified it must be used with the -projectdir option and must be a directory
|
|
|
581 |
name that exists in the projectdir.
|
|
|
582 |
Additionally if used to populate a release then it must always be used to update the release.
|
|
|
583 |
|
| 3987 |
dpurdie |
584 |
=item B<-filter=xxx[,yyy]>
|
| 341 |
dpurdie |
585 |
|
| 3987 |
dpurdie |
586 |
This option specifies a comma separated list of shell wildcard filter rule that
|
|
|
587 |
is used to determine which files are copied from package version directory in
|
|
|
588 |
GBE_DPKG to the release directory. This can be supplied multiple times to
|
|
|
589 |
specify rules for copying.
|
| 341 |
dpurdie |
590 |
|
|
|
591 |
This must be specified on the command line the first time this command is run against a release
|
|
|
592 |
and packages are copied to the project/release directory. These values are then written to a
|
|
|
593 |
config file in the project/release directory so the same values can be used on subsequent runs.
|
|
|
594 |
In these subsequent runs this option need not be specified as the config items will be used, however
|
|
|
595 |
they can be changed by specifying them again on the command line and the config will be re-written.
|
|
|
596 |
|
|
|
597 |
The values of these will depend on what builds are required for each project. Some examples are
|
| 5035 |
dpurdie |
598 |
--filter='*-SOLARIS10_SPARC64-[DP].pkg.gz'
|
|
|
599 |
--filter='*-SOLARIS10_SPARC86-[DP].pkg.gz'
|
|
|
600 |
--filter='*-SOLARIS10_X64-[DP].pkg.gz'
|
|
|
601 |
--filter='*-SOLARIS10_X86-[DP].pkg.gz'
|
|
|
602 |
--filter='*-WIN32.exe,*.deb'
|
|
|
603 |
--filter='scripts/*.sh'
|
| 341 |
dpurdie |
604 |
|
| 3987 |
dpurdie |
605 |
=item B<-addFilter=xxx[,yyy]>
|
|
|
606 |
|
|
|
607 |
This option allows new filters to be added to an existing set of filters. This
|
|
|
608 |
option can be specified multiple times.
|
|
|
609 |
|
|
|
610 |
=item B<-delFilter=xxx[,yyy]>
|
|
|
611 |
|
|
|
612 |
This option deletes one or more filter rules from an existing set of filters. This
|
|
|
613 |
option can be specified multiple times.
|
|
|
614 |
|
| 341 |
dpurdie |
615 |
=item B<-test>
|
|
|
616 |
|
|
|
617 |
This option will display what would be copied without actually copying anything
|
|
|
618 |
|
|
|
619 |
=item B<-verbose>
|
|
|
620 |
|
|
|
621 |
This option will display progress information as the program executes.
|
|
|
622 |
|
|
|
623 |
=back
|
|
|
624 |
|
|
|
625 |
=head1 DESCRIPTION
|
|
|
626 |
|
|
|
627 |
This program is used to update a projects release directory with the versions of
|
|
|
628 |
packages as indicated by the specified Deployment Manager SBoms.
|
|
|
629 |
|
|
|
630 |
Every invocation of this tool requires the -sbomid and -rootdir options specified.
|
|
|
631 |
|
|
|
632 |
The sbomid is used to get all the required information from Deployment Manager about
|
|
|
633 |
which package version are required, as well as the project name and release name under
|
|
|
634 |
which the Sboms are under.
|
|
|
635 |
|
|
|
636 |
The sbomid option can be specified multiple times to copy packages from multiple SBoms
|
|
|
637 |
to the Project Release directory. All Sboms that are specified must be under the
|
|
|
638 |
same Release under the same Project otherwise the script will abort.
|
|
|
639 |
|
|
|
640 |
The rootdir is used to specify the root location of the global releases directory.
|
|
|
641 |
This will be used as the root location from where the project and release specific
|
|
|
642 |
directories will be created to copy the files to.
|
|
|
643 |
|
|
|
644 |
By default the project and release names come from the project and release tree under
|
|
|
645 |
which the Sboms appear in Deployment Manager. These values are used to populate the releasedir
|
|
|
646 |
and projectdir respectively.
|
|
|
647 |
|
|
|
648 |
Alternatively you may override the projectdir and releasedir from Deployment Manager
|
|
|
649 |
by specifying the -projectdir=xxx and -releasedir=xxx options on the command line.
|
|
|
650 |
If they are used they must both be specified and must be valid directories of
|
|
|
651 |
rootdir/projectdir/releasedir. These options are provided to allow existing release
|
|
|
652 |
directory structures to be used that don't match Deployment Managers project and release names.
|
|
|
653 |
|
|
|
654 |
The final release specific directory will be B<rootdir/projectdir/releasedir> and
|
|
|
655 |
all packages will be copied into this directory under a PkgName/PkgVersion directory tree.
|
|
|
656 |
|
|
|
657 |
For example running the command
|
|
|
658 |
|
|
|
659 |
=over 8
|
|
|
660 |
|
|
|
661 |
=item jats updateRelease -sbomid=51904 -rootdir=/export/devl/releases
|
|
|
662 |
|
|
|
663 |
=back
|
|
|
664 |
|
|
|
665 |
will retrieve "BANGKOK (BKK)" as the project and "R1" as the release and will
|
|
|
666 |
copy packages into the "/export/devl/releases/BANGKOK (BKK)/R1" directory.
|
|
|
667 |
|
|
|
668 |
In addition to using Deployment Manager SBoms to determine which Package/Versions are
|
|
|
669 |
required to be copied this script also uses a set of shell wildcard filters that are
|
|
|
670 |
used to determine which files are actually copied when invoked.
|
|
|
671 |
|
|
|
672 |
The filter rules can be supplied on the command line if available read from a
|
|
|
673 |
configuration file saved in the project/releasedir the last time the script was run
|
|
|
674 |
on this release directory.
|
|
|
675 |
|
|
|
676 |
One or more filter rules must be specified on the command line the first time this command
|
|
|
677 |
is run against a project release directory. These filter values are then written to a config
|
|
|
678 |
file in the project/release directory so the same values can be used on subsequent runs.
|
|
|
679 |
In subsequent runs the filter rules will be loaded from the config file and need not be specified
|
|
|
680 |
on the command line, however the filter rules in the config file can be changed by specifying
|
|
|
681 |
them again on the command line and the config will be re-written.
|
|
|
682 |
|
|
|
683 |
=cut
|
|
|
684 |
|