root/main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm @ 29613

Revision 29613, 3.7 KB (checked in by jts21, 5 years ago)

All package managers now work using sub-packages (see r29595)

Line 
1package Greenstone::Package::_apt;
2
3use strict;
4use warnings;
5use utf8;
6use parent 'Greenstone::Package';
7
8# Deb packages expect lists to be comma separated
9sub replacement_array {
10    my $self = shift;
11    my $array = shift;
12    return join ", ", @{$array};
13}
14
15sub write_function {
16    my ($self, $name, @lines) = @_;
17    my $file = "$self->{output}/debian/$name";
18    print "    - $file\n";
19    open my $OUT, '>', $file
20        or die "Failed to open $file: $!";
21    for my $line (@lines) {
22        print $OUT $line, "\n";
23    }
24    close $OUT;
25    chmod 0755, $file;
26}
27
28# Add pre/post install/remove hooks
29sub add_install {
30    my ($self, $name) = @_;
31    my $prefix = (defined $name ? "$name." : "");
32    exists $self->{config}->{PRE_INSTALL} and
33        $self->write_function ("${prefix}preinst", @{$self->{config}->{PRE_INSTALL}});
34    exists $self->{config}->{POST_INSTALL} and
35        $self->write_function ("${prefix}postinst", @{$self->{config}->{POST_INSTALL}});
36    exists $self->{config}->{PRE_REMOVE} and
37        $self->write_function ("${prefix}prerm", @{$self->{config}->{PRE_REMOVE}});
38    exists $self->{config}->{POST_REMOVE} and
39        $self->write_function ("${prefix}postrm", @{$self->{config}->{POST_REMOVE}});
40}
41
42# Adds a definition for a package or subpackage
43sub add_package_section {
44    my ($self, $out) = @_;
45    for my $line (
46        'Package: %NAME%',
47        'Architecture: %ARCHITECTURE%',
48        'Homepage: %HOMEPAGE%',
49        'Depends: %DEPENDS%',
50        'Description: %DESCRIPTION_SHORT%',
51        '  %DESCRIPTION%',
52        ''
53    ) {
54        my $copy = $line;
55        $self->subst ($copy);
56        print $out $copy, "\n";
57    }
58}
59
60# Adds a definition for files included in a subpackage
61sub add_package_files {
62    my $self = shift;
63    my $file = "$self->{output}/debian/$self->{config}->{NAME}.install";
64    print "    - $file\n";
65    open my $INSTALL, '>', $file;
66    for my $line (@{$self->{config}->{FILES}}) {
67        print $INSTALL $line, "\n";
68    }
69    close $INSTALL;
70}
71
72# Handles the apt-specific package generation
73sub add_package_impl {
74    my ($self, $packages) = @_;
75    my $file = "$self->{output}/debian/control";
76    print "    - $file\n";
77    open my $CONTROL, '>', $file
78        or die "Failed to open $file: $!";
79    for my $line (
80        'Source: %NAME%',
81        'Section: java',
82        'Priority: optional',
83        'Maintainer: %MAINTAINER_NAME% <%MAINTAINER_EMAIL%>',
84        'Build-Depends: %MAKEDEPENDS%',
85        ''
86    ) {
87        my $copy = $line;
88        $self->subst ($copy);
89        print $CONTROL $copy, "\n";
90    }
91    if (defined $packages) {
92        my @names;
93        # add main package
94        my $root = $self->{config}->{NAME};
95        push @names, $self->{config}->{NAME};
96        $self->add_install ($self->{config}->{NAME});
97        $self->add_package_section ($CONTROL);
98        $self->add_package_files;
99
100        my $config = $self->{config};
101        # add subpackages
102        for my $package (@{$packages}) {
103            $package->{NAME} = "$root-$package->{NAME}";
104            push @names, $package->{NAME};
105            $package->{HOMEPAGE} = $config->{HOMEPAGE};
106            $self->{config} = $package;
107            $self->add_install ($package->{NAME});
108            $self->add_package_section ($CONTROL);
109            $self->add_package_files;
110        }
111        $self->{config} = $config;
112        my $rules = "$self->{output}/debian/rules";
113        open my $RULES, '>>', $rules
114            or die "Failed to open $rules: $!";
115        print $RULES "\noverride_dh_gencontrol:\n";
116        for my $name (@names) {
117            print $RULES "\tdh_gencontrol -p$name\n";
118        }
119        close $RULES;
120    } else {
121        $self->add_install;
122        $self->add_package_section ($CONTROL);
123    }
124    close $CONTROL;
125}
126
1271;
Note: See TracBrowser for help on using the browser.