-
Notifications
You must be signed in to change notification settings - Fork 1
/
show_rpm_macros.pl
executable file
·50 lines (44 loc) · 1.36 KB
/
show_rpm_macros.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
#!/usr/bin/perl -w
#
# show_rpm_macros.pl
#
# Show the values of the macros that rpm knows
#
# Variables
our $raw = 0;
# Get options
use Getopt::Long;
GetOptions('raw' => \$raw,
);
# Pull out some info we will need from rpm
my %rpmrc;
foreach my $line (split(/\n(?=\S)/, `rpm --showrc`)) {
next unless ($line =~ /^-\d+:\s+([\w\-]+)\s+(.+)$/s);
$rpmrc{$1} = $2;
}
# Not running in raw mode
if (!$raw) {
# Fill in any easy-to-parse macros
my $done = 0;
my $overload = 0;
until ($done || ++$overload > 50) {
my $count = 0;
foreach my $key (keys %rpmrc) {
$count += $rpmrc{$key} =~ s/(\%\{([\w\-]+)\})/if ($rpmrc{$2}) { $rpmrc{$2} } else { --$count; $1 }/sge;
}
$done = 1 if ($count == 0);
}
$done = $overload = 0;
until ($done || ++$overload > 50) {
my $count = 0;
foreach my $key (keys %rpmrc) {
$count += $rpmrc{$key} =~ s/\%\{\?([\w\-]+)\s*:\s*(.+?)\}/$rpmrc{$1} ? $2 : ''/sge;
$count += $rpmrc{$key} =~ s/\%\{!\?([\w\-]+)\s*:\s*(.+?)\}/$rpmrc{$1} ? '' : $2/sge;
}
$done = 1 if ($count == 0);
}
}
# Print the macros out
foreach my $key (sort keys %rpmrc) {
print "\%$key:\n $rpmrc{$key}\n";
}