aboutsummaryrefslogtreecommitdiffstats
path: root/genhdlist_cz2
blob: ec83e54d6fa557b8e6d3dd910cdcd64aa969de31 (plain)
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
#!/usr/bin/perl

($noclean,         @ARGV) = @ARGV if $ARGV[0] eq "--noclean";
(undef, $depslist, @ARGV) = @ARGV if $ARGV[0] eq "--ordered-depslist";
(undef, $hdlist,   @ARGV) = @ARGV if $ARGV[0] eq "-o";
(undef, $root,     @ARGV) = @ARGV if $ARGV[0] eq "--distrib";

$hdlist && @ARGV == 1 || $root && @ARGV == 0 or die 
"usage: genhdlist_cz2 [--noclean] [--ordered-depslist <depslist>] -o <hdlist_cz2> <rpm dir>
   or  genhdlist_cz2 [--noclean] --distrib <root distrib>
";

chop($pwd = `pwd`);

if ($root) {
    $root = "$pwd/$root" if $root !~ m|^/|;
    $depslist = "$root/Mandrake/base/depslist.ordered";
    $hdlist   = "$root/Mandrake/base/hdlist.cz2";
    $dir      = "$root/Mandrake/RPMS";
    $ENV{PATH} = "$ENV{PATH}:$root/misc";
} else {
    ($dir) = @ARGV;
}

$depslist = "$pwd/$depslist" if $depslist !~ m|^/|;
$hdlist   = "$pwd/$hdlist"   if $hdlist   !~ m|^/|;
$dir      = "$pwd/$dir"      if $dir      !~ m|^/|;

$work_dir = "/tmp/.build_hdlist";


-e $work_dir && !-d $work_dir and unlink($work_dir) || die "cannot use $work_dir as a working directory";
chmod 0755, $work_dir or system("rm -rf $work_dir");
-d $work_dir or mkdir $work_dir, 0755 or die "cannot create working directory $work_dir\n";
chdir $work_dir;

my (%keys, @keys);

opendir DIR, $dir or die "unable to opendir $dir: $!\n";
while ($_ = readdir DIR) {
    my ($key) = /(.*)\..*\.rpm$/ or next;
    system("rpm2header $dir/$_ > $key") unless -e $key;
    $? == 0 or unlink($key), die "bad rpm $dir/$_\n";
    -s $key or unlink($key), die "bad rpm $dir/$_\n";
    $keys{$key} = 1;
}
if (-e $depslist) {
    open F, $depslist;
    @keys = map { (split)[0] } <F>;
}
@keys = grep { delete $keys{$_} } @keys; 

open B, "| build_archive $hdlist 400000";
foreach (@keys, keys %keys) { print B "$_\n" }
close B or die "build_archive failed\n";

system("rm -rf $work_dir") unless $noclean;