invoice_sections_with_taxes per-agent, RT#79636
[freeside.git] / rpm / rpm2Bundle
1 #!/usr/bin/perl -Tw
2 #
3 # Make a bundle file from an RPM
4 #
5 use strict;
6
7 $ENV{PATH} = '/bin:/usr/bin/';
8
9 my $verbose = 0;
10
11 # These are Perl dependencies that should be ignored/suppressed
12 my %suppress;
13
14 foreach (qw/strict subs vars base lib warnings FS/) {
15         $suppress{$_} = $_;
16 }
17
18 # These are Perl modules corresponding to RPM names.
19 # Add entries when the mapping isn't simply "remove leading 'perl-' and replace - with ::"
20 my %rpm2mod=(
21         'DBD-MySQL' => 'DBD::mysql',
22 );
23
24 ## These are root packages that shouldn't be cited multiple times
25 ## Should figure this out with CPAN
26 #my %rootpkgs;
27 #
28 #foreach (qw/FS/) {
29 #       $rootpkgs{$_} = 1;
30 #}
31
32 foreach my $rawrpm (@ARGV) {
33         $rawrpm =~ /^([-\.a-z0-9\/]+)\s*$/i;
34         my $rpm = $1 or next;
35         my @parts = split '/', $rpm;
36         my $name = pop @parts;
37         my $version = 0.01;
38         if ($name =~ m<([^/]+?)[-._]?v?-?([-_.\d]+[a-z]*?\d*)\.\w+\.rpm$>) {
39                 $name = $1;
40                 $version = $2;
41         }
42         print STDERR "rpm: $rpm ($name, $version)\n";
43         my @deps = sort `rpm -qp --requires $rpm`;
44
45         my %mods;
46
47         foreach (@deps) {
48                 if (/^perl\((.*?)\)\s*((>=|=|<=)\s+([\d\.]+))?$/
49                  || /^perl-(.*?)\s*((>=|=|<=)\s+([\d\.]+))?$/) {
50                         my ($mod, $rel, $ver) = ($1, $3, $4);
51                         if (/^perl-/) {
52                                 print STDERR "\"$mod\"\n" if $verbose;
53                                 $mod = $rpm2mod{$mod} if exists($rpm2mod{$mod});
54                                 $mod =~ s/-/::/g
55                         }
56                         next if exists($suppress{$mod});
57                         my @parts = split /::/, $mod;
58                         if (scalar @parts > 1) {
59                                 next if exists($suppress{$parts[0]});
60                         }
61                         if ($verbose) {
62                                 print STDERR "$mod";
63                                 print STDERR " $rel $ver" if $ver;
64                                 print STDERR "\n";
65                         }
66                         $mods{$mod} = $ver ? $ver : undef; # Should also save $rel
67                 }
68         }
69
70         my $hdr =<<END;
71 # -*- perl -*-
72
73 package Bundle::$name;
74
75 \$VERSION = '$version';
76
77 1;
78
79 __END__
80
81 =head1 NAME
82
83 Bundle::$name - A bundle to install prerequisites for the $name package
84
85 =head1 SYNOPSIS
86
87 C<perl -MCPAN -e 'install Bundle::$name'>
88
89 =head1 CONTENTS
90
91 END
92
93         my $ftr =<<END;
94 =head1 DESCRIPTION
95
96 This bundle includes all prerequisites needed by the $name package.
97
98 =cut
99 END
100
101         print $hdr;
102         foreach (sort keys %mods) {
103                 print "$_";
104                 print " $mods{$_}" if exists($mods{$_}) && $mods{$_};
105                 print " -\n\n";
106         }
107         print $ftr;
108 }
109
110 1;
111