summaryrefslogtreecommitdiffstats
path: root/rpm-find-leaves
blob: 587871849e8dbb00a516d112e39d45b3c6e74fdc (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
#!/usr/bin/perl
use urpm;
use urpm::msg;

sub main {
	
	my %options;
	$options{restrict_group} = 0;
	$options{group} = 'System/Libraries';
	$options{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 given group.
") . N("                    defaults is %s.
", $options{group});

	my $group;
	
	while ($_ = shift @_) {
	        /^--root$/ and do {
			$root=shift @_;
			$root and $options{root}=$root;
			next;

		};
		/^-g$/ and do {
			$options{restrict_group}=1;
			$group=shift @_;
			$group and $options{group}=$group;
			next;
		};
		die $usage;
	}

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

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

	foreach my $pkg (@packages) {
		delete @l{grep { $_ ne $pkg->name } @{$provides{$_} || []}} foreach $pkg->requires_nosense;
	}

	print "$_\n" foreach sort keys %l;
}

main(@ARGV);