-
Notifications
You must be signed in to change notification settings - Fork 3
/
hpcp_exec.pl
executable file
·411 lines (311 loc) · 10.9 KB
/
hpcp_exec.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#!/usr/bin/env perl
use strict;
use Storable;
use FindBin;
use lib "$FindBin::Bin/tools";
use HPCPorts;
sub purge_state {
my ( $pdb, $pname, $state, $root, $system, $env, $prefix, $overrides ) = @_;
my $pkgdir = "${root}/packages/${pname}";
my $status;
if ( defined ( $overrides->{ $pname } ) ) {
$status = "overridden";
} else {
$status = HPCPorts::package_state ( $pdb, "${pkgdir}", $system, $env, $prefix, $overrides );
}
if ( ( $status eq $state ) || ( $state eq "any" ) ) {
my $fullversion = HPCPorts::package_fullversion ( $pdb, $pname, $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${pkgdir}; make purge" );
}
return;
}
sub install_list {
my ( $pdb, $plist, $root, $system, $env, $prefix, $overrides ) = @_;
# recursively install all dependencies and the package
my $pname;
foreach $pname ( @{$plist} ) {
if ( $pname ne "hpcp" ) {
purge_state ( $pdb, "hpcp", "stale", $root, $system, $env, $prefix, $overrides );
system ( "export PKG_FULLVERSION=${env}; cd ${root}/packages/hpcp; make install" );
}
my $dep;
my $fullversion;
foreach $dep ( @{$pdb->{ $pname }->{ "deps" }} ) {
purge_state ( $pdb, $dep, "stale", $root, $system, $env, $prefix, $overrides );
$fullversion = HPCPorts::package_fullversion ( $pdb, $dep, $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${root}/packages/${dep}; make install" );
}
purge_state ( $pdb, $pname, "stale", $root, $system, $env, $prefix, $overrides );
$fullversion = HPCPorts::package_fullversion ( $pdb, $pname, $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${root}/packages/${pname}; make install" );
}
return;
}
my $pre = "---> ";
# check system definition
my $system = $ENV{ "HPCP_HOST" };
if ( ! defined ( $system ) ) {
die ( "\nYou must have the \"HPCP_HOST\" environment variable defined\n\n" );
}
my $hpcp_root = $FindBin::Bin;
my $pkgdir = $hpcp_root."/packages";
my $dbfile = $pkgdir."/pkg_".$system.".db";
my $dbversion = $dbfile.".version";
my $envprefix = $ENV{ "HPCP_PREFIX" };
my $envpool = $ENV{ "HPCP_POOL" };
# Parse commands
my $ARGC = @ARGV;
if ( ( $ARGC < 1 ) || ( $ARGV[0] eq "help" ) ) {
print "\n Usage: $0 <command> <option>\n\n";
print " Where valid commands and options are:\n";
print " help : show this screen\n";
print " update : update package DB\n";
print " status : status of all packages\n";
print " info [ package(s) ] : detailed package info\n";
print " purge [ package(s) | ALL | state ] : purge extracted source\n";
print " install [ package(s) ] : install package(s)\n";
print " upgrade [ package(s) | ALL ] : recompile stale package(s)\n";
print " uninstall [ package(s) | ALL ] : uninstall package(s)\n";
print " fetch [ package(s) | ALL ] : fetch package source\n";
print " clean [ package(s) | ALL ] : clean extracted source\n";
print "\n";
exit(0);
}
my $command = shift ( @ARGV );
# Get current version
my $hpcpver = HPCPorts::hpcp_version ( $hpcp_root );
# Compare with DB version
my $dbver = "";
if ( -e $dbversion ) {
open ( DB, "$dbversion" ) || die ( "\nCannot open DB version file $dbversion\n\n" );
$dbver = <DB>;
close ( DB );
chomp ( $dbver );
}
my $needupdate = 0;
if ( ( $dbver ne $hpcpver ) || ( $command eq "update" ) ) {
$needupdate = 1;
}
my ( $env, $suffix, $prefix, $overrides ) = HPCPorts::config_vars ( "${hpcp_root}/system/${system}.make" );
# Update package DB if needed
if ( $needupdate ) {
my $pkgdb = HPCPorts::package_db ( $pkgdir, $env );
store ( $pkgdb, $dbfile );
open ( DB, ">$dbversion" ) || die ( "\nCannot open DB version file $dbversion\n\n" );
print DB $hpcpver,"\n";
close ( DB );
}
if ( $command eq "update" ) {
# we are done...
exit(0);
}
my $pkgdb = retrieve ( $dbfile );
#use Data::Dumper;
#print Dumper ( $pkgdb );
# Execute command
if ( $command eq "status" ) {
my $out = $pre."---------------------------------------------------------\n";
print $out;
$out = $pre."HPCP_HOST = \"".$system."\", HPCP_ENV = \"".$env."\"\n";
print $out;
$out = $pre."HPCP_PREFIX = \"".$envprefix."\"\n";
print $out;
$out = $pre."HPCP_POOL = \"".$envpool."\"\n";
print $out;
$out = $pre."---------------------------------------------------------\n";
print $out;
$out = sprintf ( "%s%18s | %20s | %s\n", $pre, "Package", "Version", "State" );
print $out;
$out = $pre."---------------------------------------------------------\n";
print $out;
my $key;
my $value;
foreach $key ( sort keys %{$pkgdb} ) {
$value = $pkgdb->{ $key };
my $status = "broken";
if ( defined ( $overrides->{ $key } ) ) {
$status = "overridden";
} else {
$status = HPCPorts::package_state ( $pkgdb, "${pkgdir}/${key}", $system, $env, $prefix, $overrides );
}
my $pkgver = $value->{ "version" };
if ( $value->{ "dephash" } ne "" ) {
$pkgver = $pkgver."_".$value->{ "dephash" };
}
$out = sprintf ( "%s%18s | %20s | %s\n", $pre, $key, $pkgver, $status );
print $out;
}
} elsif ( $command eq "purge" ) {
if ( @ARGV == 0 ) {
die ( "\nUsage: $0 purge [ package(s) | ALL | state ]\n\n" );
}
my @pps = ();
my @states = ();
my @allowed = HPCPorts::pkg_states();
my %allowhash;
@allowhash { @allowed } = ();
my $arg;
foreach $arg ( @ARGV ) {
if ( $arg eq "ALL" ) {
push ( @states, "any" );
} elsif ( exists ( $allowhash{ $arg } ) ) {
push ( @states, $arg );
} else {
push ( @pps, $arg );
}
}
my $key;
my $value;
my $state;
foreach $key ( keys %{$pkgdb} ) {
$value = $pkgdb->{ $key };
foreach $state ( @states ) {
purge_state ( $pkgdb, $key, $state, $hpcp_root, $system, $env, $prefix, $overrides );
}
}
foreach $state ( @states ) {
purge_state ( $pkgdb, "hpcp", $state, $hpcp_root, $system, $env, $prefix, $overrides );
}
my $pname;
foreach $pname ( @pps ) {
my $fullversion = HPCPorts::package_fullversion ( $pkgdb, $pname, $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${hpcp_root}/packages/${pname}; make purge" );
}
} elsif ( $command eq "install" ) {
if ( @ARGV == 0 ) {
die ( "\nUsage: $0 install <package(s)>\n\n" );
}
# recursively install all dependencies and the package
install_list ( $pkgdb, \@ARGV, $hpcp_root, $system, $env, $prefix, $overrides );
} elsif ( $command eq "upgrade" ) {
if ( @ARGV == 0 ) {
die ( "\nUsage: $0 upgrade <package(s)>\n\n" );
}
# get a list of all stale packages
my $stale = ();
if ( $ARGV[0] eq "ALL" ) {
my $key;
my $value;
my $status;
foreach $key ( keys %{$pkgdb} ) {
$value = $pkgdb->{ $key };
if ( ! defined ( $overrides->{ $key } ) ) {
$status = HPCPorts::package_state ( $pkgdb, "${pkgdir}/${key}", $system, $env, $prefix, $overrides );
if ( $status eq "stale" ) {
push ( @{$stale}, $key );
}
}
}
$status = HPCPorts::package_state ( $pkgdb, "${pkgdir}/hpcp", $system, $env, $prefix, $overrides );
if ( $status eq "stale" ) {
push ( @{$stale}, $key );
}
} else {
my $pname;
foreach $pname ( @ARGV ) {
if ( ! defined ( $overrides->{ $pname } ) ) {
my $status = HPCPorts::package_state ( $pkgdb, "${pkgdir}/${pname}", $system, $env, $prefix, $overrides );
if ( $status eq "stale" ) {
push ( @{$stale}, $pname );
}
}
}
}
# recursively install all dependencies and the packages
install_list ( $pkgdb, $stale, $hpcp_root, $system, $env, $prefix, $overrides );
} elsif ( $command eq "info" ) {
if ( @ARGV == 0 ) {
die ( "\nUsage: $0 info <package(s)>\n\n" );
}
my $pname;
foreach $pname ( @ARGV ) {
my $fullversion = HPCPorts::package_fullversion ( $pkgdb, $pname, $env, $overrides );
my $status = "broken";
if ( defined ( $overrides->{ $pname } ) ) {
$status = "overridden";
} else {
$status = HPCPorts::package_state ( $pkgdb, "${pkgdir}/${pname}", $system, $env, $prefix, $overrides );
}
print "$pre\n";
my $out = sprintf ( "%s%14s %s\n", $pre, "Name:", $pname );
print $out;
$out = sprintf ( "%s%14s %s\n", $pre, "Version:", $fullversion );
print $out;
$out = sprintf ( "%s%14s %s\n", $pre, "State:", $status );
print $out;
$out = sprintf ( "%s%14s\n", $pre, "Dependencies:" );
print $out;
my $dep;
for $dep ( @{ $pkgdb->{ $pname }->{ "deps" } } ) {
my $depversion = HPCPorts::package_fullversion ( $pkgdb, $dep, $env, $overrides );
$out = sprintf ( "%s%20s | %s\n", $pre, $dep, $depversion );
print $out;
}
print "$pre\n";
}
} elsif ( $command eq "uninstall" ) {
if ( @ARGV == 0 ) {
die ( "\nUsage: $0 uninstall <package(s) or ALL>\n\n" );
}
if ( $ARGV[0] eq "ALL" ) {
my $key;
my $value;
my $fullversion;
foreach $key ( keys %{$pkgdb} ) {
$value = $pkgdb->{ $key };
$fullversion = HPCPorts::package_fullversion ( $pkgdb, $key, $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${hpcp_root}/packages/${key}; make uninstall" );
}
$fullversion = HPCPorts::package_fullversion ( $pkgdb, "hpcp", $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${hpcp_root}/packages/hpcp; make uninstall" );
} else {
my $pname;
foreach $pname ( @ARGV ) {
my $fullversion = HPCPorts::package_fullversion ( $pkgdb, $pname, $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${hpcp_root}/packages/${pname}; make uninstall" );
}
}
} elsif ( $command eq "fetch" ) {
if ( @ARGV == 0 ) {
die ( "\nUsage: $0 fetch <package(s) or ALL>\n\n" );
}
if ( $ARGV[0] eq "ALL" ) {
my $key;
my $value;
foreach $key ( keys %{$pkgdb} ) {
$value = $pkgdb->{ $key };
my $fullversion = HPCPorts::package_fullversion ( $pkgdb, $key, $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${hpcp_root}/packages/${key}; make fetch" );
}
} else {
my $pname;
foreach $pname ( @ARGV ) {
my $fullversion = HPCPorts::package_fullversion ( $pkgdb, $pname, $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${hpcp_root}/packages/${pname}; make fetch" );
}
}
} elsif ( $command eq "clean" ) {
if ( @ARGV == 0 ) {
die ( "\nUsage: $0 clean <package(s) or ALL>\n\n" );
}
if ( $ARGV[0] eq "ALL" ) {
my $key;
my $value;
my $fullversion;
foreach $key ( keys %{$pkgdb} ) {
$value = $pkgdb->{ $key };
$fullversion = HPCPorts::package_fullversion ( $pkgdb, $key, $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${hpcp_root}/packages/${key}; make clean" );
}
$fullversion = HPCPorts::package_fullversion ( $pkgdb, "hpcp", $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${hpcp_root}/packages/hpcp; make clean" );
} else {
my $pname;
foreach $pname ( @ARGV ) {
my $fullversion = HPCPorts::package_fullversion ( $pkgdb, $pname, $env, $overrides );
system ( "export PKG_FULLVERSION=${fullversion}; cd ${hpcp_root}/packages/${pname}; make clean" );
}
}
} else {
die ( "\nUnknown command \"$command\"\n\n" );
}