This commit was generated by cvs2svn to compensate for changes in r6252,
[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 FS/) {
15         $suppress{$_} = $_;
16 }
17
18 ## These are root packages that shouldn't be cited multiple times
19 ## Should figure this out with CPAN
20 #my %rootpkgs;
21 #
22 #foreach (qw/FS/) {
23 #       $rootpkgs{$_} = 1;
24 #}
25
26 foreach my $rawrpm (@ARGV) {
27         $rawrpm =~ /^([-\.a-z0-9\/]+)\s*$/i;
28         my $rpm = $1 or next;
29         my @parts = split '/', $rpm;
30         my $name = pop @parts;
31         my $version = 0.01;
32         if ($name =~ m<([^/]+?)[-._]?v?-?([-_.\d]+[a-z]*?\d*)\.\w+\.rpm$>) {
33                 $name = $1;
34                 $version = $2;
35         }
36         print STDERR "rpm: $rpm ($name, $version)\n";
37         my @deps = sort `rpm -qp --requires $rpm`;
38
39         my %mods;
40
41         foreach (@deps) {
42                 if (/^perl\((.*)\)\s*(>=\s+([\d\.]+))?$/) {
43                         next if exists($suppress{$1});
44                         my @parts = split /::/, $1;
45                         if (scalar @parts > 1) {
46                                 next if exists($suppress{$parts[0]});
47                         }
48                         if ($verbose) {
49                                 print STDERR "$1";
50                                 print STDERR " >= $3" if $3;
51                                 print STDERR "\n";
52                         }
53                         $mods{$1} = $3 ? $3 : undef;
54                 }
55         }
56
57         my $hdr =<<END;
58 # -*- perl -*-
59
60 package Bundle::$name;
61
62 \$VERSION = '$version';
63
64 1;
65
66 __END__
67
68 =head1 NAME
69
70 Bundle::$name - A bundle to install prerequisites for the $name package
71
72 =head1 SYNOPSIS
73
74 C<perl -MCPAN -e 'install Bundle::$name'>
75
76 =head1 CONTENTS
77
78 END
79
80         my $ftr =<<END;
81 =head1 DESCRIPTION
82
83 This bundle includes all prerequisites needed by the $name package.
84
85 =cut
86 END
87
88         print $hdr;
89         foreach (sort keys %mods) {
90                 print "$_";
91                 print " $mods{$_}" if exists($mods{$_}) && $mods{$_};
92                 print " -\n\n";
93         }
94         print $ftr;
95 }
96
97 1;
98