Bug 25591: Update list-deps for Debian 10 and Ubuntu 20.04
[koha.git] / debian / list-deps
1 #!/usr/bin/perl
2 #
3 # Write dependency list from Koha cpanfile, in Debian format.
4 #
5 # Copyright 2010  Catalyst IT, Ltd
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 use Modern::Perl;
21
22 use C4::Installer::PerlModules;
23
24 # These are packages that may not be in the apt archive in a way that
25 # apt-file can find, e.g. in the Koha repo rather than the regular
26 # debian one.
27 my %overrides = (
28     'LWP::Protocol::https' => 'liblwp-protocol-https-perl|libwww-perl (<<6.02), libio-socket-ssl-perl',
29     'HTTP::OAI'            => 'libhttp-oai-perl (>= 3.2) | libhttp-oai-3.27-perl, libhttp-oai-perl (<< 4.0) | libhttp-oai-3.27-perl',
30     'IO::Socket::IP'       => 'perl-modules (>= 5.20.0) | libio-socket-ip-perl',
31     'Swagger2'             => 'libswagger2-perl (>= 0.59)',
32     'Mojolicious'          => 'libmojolicious-perl (>= 6.0)',
33 );
34
35 # These are packages we're going to ignore
36 my %ignore = (
37     'Data::Pagination'       => 1,
38     'CHI'                    => 1,
39     'CHI::Driver::Memcached' => 1,
40 );
41
42 my $prefix = "^/usr/((lib|share)/perl5|(lib|share)/perl/[0-9.]+|(lib|share)/.*-linux-gnu.*/perl/[0-9.]+|(lib|share)/.*-linux-gnu.*/perl5/[0-9.]+)";
43
44 my $modules = C4::Installer::PerlModules->new();
45 my $prereqs = $modules->prereqs;
46 foreach my $phase ($prereqs->phases) {
47     foreach my $type ($prereqs->types_in($phase)) {
48         my $reqs = $prereqs->requirements_for($phase, $type);
49         foreach my $module ( $reqs->required_modules ) {
50             next if $ignore{$module};
51             my $subpath = $module;
52             $subpath =~ s,::,/,g;
53             my $output = qx(apt-file -l -x search "$prefix/$subpath.pm\$");
54             my @temp   = split( /\n/, $output );
55             my @lines  = ();
56
57             # Remove packages that are required/essential and always installed on
58             # a Debian system. Debian packages should not have unversioned
59             # dependencies on such packages.
60
61
62             # skip perl-base and problematic version specific libperl* and
63             # perl-module* packages (they get installed as deps. anyway)
64             foreach my $line (@temp) {
65                 if ( $line ne "perl-base" and $line !~ /^libperl5\./ and $line !~ /^perl-modules-5\./ ) {
66                     @lines = ( @lines, $line );
67                 }
68             }
69
70             if ( exists $overrides{$module} ) {
71                 print "$overrides{$module}\n";
72             }
73             elsif ( scalar(@lines) == 1 && $lines[0] ne "" ) {
74                 my $pkg = $lines[0];
75                 print "$pkg\n";
76             }
77             elsif ( scalar(@lines) > 1 ) {
78                 foreach my $pkg (@lines) {
79                     print " | " if ( $pkg ne $lines[0] );
80                     print "$pkg";
81                 }
82                 print "\n";
83             }
84             elsif ( scalar(@temp) != 0 ) {
85
86                 # I'm an Essential and I'm OK,
87                 # I install all night, and work all day.
88                 # I chomp up strings. I eat my bugs.
89                 # I go to the base install.
90                 # On Fridays I go drinking,
91                 # and have buttered commits for git.
92                 # (Beer O'Clock is more than two hours
93                 # away. I don't even drink beer. There
94                 # is no reason to be suspicious of this
95                 # commit.)
96                 # RM note: suspicious?  me?  always!
97             }
98             elsif ( $type ne 'requires' ) {
99                 # Ignore because we don't have it and we don't care.
100             }
101             else {
102                 print "EEEK: unknown package for $module\n";
103             }
104         }
105     }
106 }