summaryrefslogtreecommitdiffstats
path: root/rpm-find-leaves
blob: b257d25f4940928c57364e68673558a62101789d (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
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl

use strict;

use urpm;
use urpm::msg;

my %options = (
    restrict_group => 0,
    group => 'System/Libraries',
    root => '',
);

my $usage = N("usage: %s [options]
where [options] are from
", $0) . N("   -h|--help      - print this help message.
") . N("   --root <path>  - use the given root instead of /
") . N("   -g [group]     - restrict results to specified group.
") . N("                    defaults to %s.
", $options{group}) . N("   -f             - output rpm full name (NVRA)
");

while ($_ = shift) {
    $_ eq '--root' and do {
	my $root = shift;
	$root and $options{root} = $root;
	next;

    };
    $_ eq '-g' and do {
	$options{restrict_group} = 1;
	next if !@ARGV || $ARGV[0] =~ /^-/;
	my $group = shift;
	$options{group} = $group;
	next;
    };
    $_ eq '-f' and do { $options{fullname} = 1; next };
    print $usage; exit 1;
}

my @packages;
{
    my $db = URPM::DB::open($options{root}) or die "Can't open RPM db\n";
    $db->traverse(sub {
	my ($p) = @_;
	$p->pack_header;
	push @packages, $p;
    });
}

my %l;
my %provides;
foreach my $pkg (@packages) {
    next if $options{restrict_group} && $pkg->group !~ /\Q$options{group}/oi;
    $l{$pkg->name} = $pkg;
    push @{$provides{$_}}, $pkg foreach $pkg->provides_nosense;
}

foreach my $pkg (@packages) {
    foreach my $prop ($pkg->requires) {
	my ($n, $s) = URPM::property2name_range($prop);
	foreach my $p (@{$provides{$n} || []}) {
	    $p != $pkg && $p->provides_overlap($prop) and 
	      delete $l{$p->name};
	}
    }
}

if ($options{fullname}) {
    foreach my $k (sort keys %l) {
	my $l = $l{$k};
	print $l->name, '-', $l->version, '-', $l->release, '.', $l->arch, "\n";
    }
} else {
    print "$_\n" foreach sort keys %l;
}