aboutsummaryrefslogtreecommitdiffstats
path: root/genhdlist_cz2
blob: 6a178a47d6fef24411aa4175d451cf57c09d4744 (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
58
59
60
61
62
63
64
#!/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, $arch) = /(.*)\.(.*)\.rpm$/ or next;
    system("rpm2header $dir/$_ > $_") unless -e $_;
    $? == 0 or unlink($_), die "bad rpm $dir/$_\n";
    -s $_ or unlink($_), die "bad rpm $dir/$_\n";
    if ($keys{$key}) {
	my ($name, $tail) = $key =~ /(.*)(-[^-]*-[^-]*)/;
	$keys{"$name($keys{$key})$tail"} = $keys{$key}; unlink "$name($keys{$key})$tail"; link $_, "$name($keys{$key})$tail";
	$keys{"$name($arch)$tail"} = $arch; unlink "$name($arch)$tail"; link $_, "$name($arch)$tail";
	delete $keys{$key};
    } else {
	$keys{$key} = $arch; unlink $key; link $_, $key;
    }
}
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;