1 | package Greenstone::Package::_pacman;
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 | use warnings;
|
---|
5 | use utf8;
|
---|
6 | use parent 'Greenstone::Package';
|
---|
7 | use Digest::MD5;
|
---|
8 |
|
---|
9 | sub replacement_array {
|
---|
10 | my $self = shift;
|
---|
11 | my $array = shift;
|
---|
12 | return join "\n", @{$array};
|
---|
13 | }
|
---|
14 |
|
---|
15 | sub add_md5 {
|
---|
16 | my $self = shift;
|
---|
17 | my $md5 = Digest::MD5->new;
|
---|
18 | for my $source (@_) {
|
---|
19 | open my $MD5FH, '<', "$self->{output}/$source";
|
---|
20 | binmode $MD5FH;
|
---|
21 | $md5->addfile ($MD5FH);
|
---|
22 | push @{$self->{config}->{SOURCE_SUMS}}, $md5->hexdigest;
|
---|
23 | close $MD5FH
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | sub add_sources {
|
---|
28 | my $self = shift;
|
---|
29 | $self->SUPER::add_sources;
|
---|
30 | $self->{config}->{SOURCE_SUMS} = [];
|
---|
31 | $self->add_md5 (@{$self->{config}->{SOURCES}});
|
---|
32 | }
|
---|
33 |
|
---|
34 | sub add_makefile {
|
---|
35 | my $self = shift;
|
---|
36 | $self->SUPER::add_makefile;
|
---|
37 | $self->add_md5 ('Makefile');
|
---|
38 | }
|
---|
39 |
|
---|
40 | sub write_function {
|
---|
41 | my ($name, $out, @lines) = @_;
|
---|
42 | print $out $name, "() {\n";
|
---|
43 | for my $line (@lines) {
|
---|
44 | print $out "\t", $line, "\n";
|
---|
45 | }
|
---|
46 | print $out "}\n\n";
|
---|
47 | }
|
---|
48 |
|
---|
49 | sub add_install {
|
---|
50 | my $self = shift;
|
---|
51 | if (exists $self->{config}->{PRE_INSTALL} or
|
---|
52 | exists $self->{config}->{POST_INSTALL} or
|
---|
53 | exists $self->{config}->{PRE_REMOVE} or
|
---|
54 | exists $self->{config}->{POST_REMOVE}) {
|
---|
55 | my $name = "$self->{config}->{NAME}.install";
|
---|
56 | open my $INSTALL, '>', "/tmp/$name";
|
---|
57 | exists $self->{config}->{PRE_INSTALL} and do {
|
---|
58 | write_function "pre_install", $INSTALL, @{$self->{config}->{PRE_INSTALL}};
|
---|
59 | write_function "pre_upgrade", $INSTALL, @{$self->{config}->{PRE_INSTALL}};
|
---|
60 | };
|
---|
61 | exists $self->{config}->{POST_INSTALL} and do {
|
---|
62 | write_function "post_install", $INSTALL, @{$self->{config}->{POST_INSTALL}};
|
---|
63 | write_function "post_upgrade", $INSTALL, @{$self->{config}->{POST_INSTALL}};
|
---|
64 | };
|
---|
65 | exists $self->{config}->{PRE_REMOVE} and
|
---|
66 | write_function "pre_remove", $INSTALL, @{$self->{config}->{PRE_REMOVE}};
|
---|
67 | exists $self->{config}->{POST_REMOVE} and
|
---|
68 | write_function "post_remove", $INSTALL, @{$self->{config}->{POST_REMOVE}};
|
---|
69 | close $INSTALL;
|
---|
70 | $self->add ("/tmp/$name", "$self->{output}/$name");
|
---|
71 | $self->{config}->{INSTALL} = "install=$name";
|
---|
72 | } else {
|
---|
73 | $self->{config}->{INSTALL} = "";
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | 1;
|
---|