source: main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm@ 29611

Last change on this file since 29611 was 29611, checked in by Jeremy Symon, 9 years ago

Changes to get RPM working. May have broken Pacman and APT, since I had to change the way it is done.

File size: 3.6 KB
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 push @names, $self->{config}->{NAME};
95 $self->add_install ($self->{config}->{NAME});
96 $self->add_package_section ($CONTROL);
97 $self->add_package_files;
98
99 my $config = $self->{config};
100 # add subpackages
101 for my $package (@{$packages}) {
102 push @names, $package->{NAME};
103 $package->{HOMEPAGE} = $config->{HOMEPAGE};
104 $self->{config} = $package;
105 $self->add_install ($package->{NAME});
106 $self->add_package_section ($CONTROL);
107 $self->add_package_files;
108 }
109 $self->{config} = $config;
110 my $rules = "$self->{output}/debian/rules";
111 open my $RULES, '>>', $rules
112 or die "Failed to open $rules: $!";
113 print $RULES "\noverride_dh_gencontrol:\n";
114 for my $name (@names) {
115 print $RULES "\tdh_gencontrol -p$name\n";
116 }
117 close $RULES;
118 } else {
119 $self->add_install;
120 $self->add_package_section ($CONTROL);
121 }
122 close $CONTROL;
123}
124
1251;
Note: See TracBrowser for help on using the repository browser.