line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Slaughter::Packages::linux - Abstractions for GNU/Linux package management. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
This module contains code for dealing with system packages. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
If you wish to support a new packaging system for GNU/Linux based |
14
|
|
|
|
|
|
|
distributions this should be the only place you need to touch. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 METHODS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Now follows documentation on the available methods. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
8
|
|
|
8
|
|
26
|
use strict; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
197
|
|
26
|
8
|
|
|
8
|
|
24
|
use warnings; |
|
8
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
3681
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package Slaughter::Packages::linux; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = "3.0.5"; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Create a new instance of this object. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new |
42
|
|
|
|
|
|
|
{ |
43
|
1
|
|
|
1
|
1
|
1775
|
my ( $proto, %supplied ) = (@_); |
44
|
1
|
|
33
|
|
|
4
|
my $class = ref($proto) || $proto; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
2
|
my $self = {}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
3
|
foreach my $key ( keys %supplied ) |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
|
|
0
|
$self->{ lc $key } = $supplied{ $key }; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
3
|
bless( $self, $class ); |
57
|
1
|
|
|
|
|
2
|
return $self; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 recognised |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Does the local system match a known type? |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub recognised |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
0
|
1
|
|
my ($self) = (@_); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
0
|
|
|
|
if ( ( -x "/bin/rpm" ) && |
|
|
|
0
|
|
|
|
|
77
|
|
|
|
|
|
|
( -x "/usr/bin/yum" ) && |
78
|
|
|
|
|
|
|
( -d "/etc/sysconfig" ) ) |
79
|
|
|
|
|
|
|
{ |
80
|
0
|
|
|
|
|
|
return ("rpm"); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
0
|
|
|
|
if ( ( -x "/usr/bin/apt-get" ) && |
|
|
|
0
|
|
|
|
|
88
|
|
|
|
|
|
|
( -e "/etc/apt/sources.list" ) && |
89
|
|
|
|
|
|
|
( -d "/etc/network" ) ) |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
|
|
|
return ("apt-get"); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return 0; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 isInstalled |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Is the package installed? |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub isInstalled |
106
|
|
|
|
|
|
|
{ |
107
|
0
|
|
|
0
|
1
|
|
my ( $self, $package ) = (@_); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $type = $self->recognised(); |
113
|
0
|
0
|
|
|
|
|
return 0 unless ($type); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if ( $type eq "apt-get" ) |
119
|
|
|
|
|
|
|
{ |
120
|
0
|
|
|
|
|
|
my %installed; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$ENV{ 'COLUMNS' } = 300; |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
open my $handle, "-|", "dpkg --list" or |
125
|
|
|
|
|
|
|
die "Failed to run dpkg: $!"; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
while (<$handle>) |
128
|
|
|
|
|
|
|
{ |
129
|
0
|
0
|
|
|
|
|
if ( $_ =~ /ii([ \t]+)([^\t ]+)[\t ]/ ) |
130
|
|
|
|
|
|
|
{ |
131
|
0
|
|
|
|
|
|
$installed{ $2 } += 1; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
0
|
|
|
|
|
|
close($handle); |
135
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
if ( $installed{ $package } ) |
137
|
|
|
|
|
|
|
{ |
138
|
0
|
|
|
|
|
|
return 1; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
0
|
0
|
|
|
|
|
if ( $type eq "rpm" ) |
146
|
|
|
|
|
|
|
{ |
147
|
0
|
|
|
|
|
|
my %installed; |
148
|
|
|
|
|
|
|
|
149
|
0
|
0
|
|
|
|
|
open my $handle, "-|", "rpm -qa" or |
150
|
|
|
|
|
|
|
die "Failed to run rpm: $!"; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
while (<$handle>) |
153
|
|
|
|
|
|
|
{ |
154
|
0
|
0
|
|
|
|
|
if ( $_ =~ /^(.*?)-([0-9])(.*)$/ ) |
155
|
|
|
|
|
|
|
{ |
156
|
0
|
|
|
|
|
|
$installed{ $1 } += 1; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
0
|
|
|
|
|
|
close($handle); |
160
|
|
|
|
|
|
|
|
161
|
0
|
0
|
|
|
|
|
if ( $installed{ $package } ) |
162
|
|
|
|
|
|
|
{ |
163
|
0
|
|
|
|
|
|
return 1; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
return 0; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 installPackage |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Install a package upon the local system. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub installPackage |
179
|
|
|
|
|
|
|
{ |
180
|
0
|
|
|
0
|
1
|
|
my ( $self, $package ) = (@_); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
my $type = $self->recognised(); |
186
|
0
|
0
|
|
|
|
|
return 0 unless ($type); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
0
|
0
|
|
|
|
|
if ( $type eq "apt-get" ) |
192
|
|
|
|
|
|
|
{ |
193
|
0
|
|
|
|
|
|
$ENV{ 'DEBIAN_FRONTEND' } = "noninteractive"; |
194
|
0
|
|
|
|
|
|
my $cmd = "apt-get -q -y install $package"; |
195
|
0
|
|
|
|
|
|
system($cmd ); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
0
|
0
|
|
|
|
|
if ( $type eq "rpm" ) |
202
|
|
|
|
|
|
|
{ |
203
|
0
|
|
|
|
|
|
my $cmd = "yum install -y $package"; |
204
|
0
|
|
|
|
|
|
system($cmd ); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 removePackage |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Remove the specified package. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub removePackage |
217
|
|
|
|
|
|
|
{ |
218
|
0
|
|
|
0
|
1
|
|
my ( $self, $package ) = (@_); |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
my $type = $self->recognised(); |
224
|
0
|
0
|
|
|
|
|
return 0 unless ($type); |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
0
|
0
|
|
|
|
|
if ( $type eq "apt-get" ) |
230
|
|
|
|
|
|
|
{ |
231
|
0
|
|
|
|
|
|
$ENV{ 'DEBIAN_FRONTEND' } = "noninteractive"; |
232
|
0
|
|
|
|
|
|
my $cmd = "apt-get -q -y remove $package"; |
233
|
0
|
|
|
|
|
|
system($cmd ); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
0
|
0
|
|
|
|
|
if ( $type eq "rpm" ) |
240
|
|
|
|
|
|
|
{ |
241
|
0
|
|
|
|
|
|
my $cmd = "rpm -e $package"; |
242
|
0
|
|
|
|
|
|
system($cmd ); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
1; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 AUTHOR |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Steve Kemp <steve@steve.org.uk> |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=cut |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 LICENSE |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Copyright (c) 2010-2015 by Steve Kemp. All rights reserved. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
This module is free software; |
262
|
|
|
|
|
|
|
you can redistribute it and/or modify it under |
263
|
|
|
|
|
|
|
the same terms as Perl itself. |
264
|
|
|
|
|
|
|
The LICENSE file contains the full text of the license. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=cut |
267
|
|
|
|
|
|
|
|