line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# system::ubuntu::package Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::System::Ubuntu::Package; |
7
|
1
|
|
|
1
|
|
821
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
9
|
use base qw(Metabrik::Shell::Command); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1048
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes_default => { |
19
|
|
|
|
|
|
|
ignore_error => 0, |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
commands => { |
22
|
|
|
|
|
|
|
search => [ qw(string) ], |
23
|
|
|
|
|
|
|
install => [ qw(package|$package_list) ], |
24
|
|
|
|
|
|
|
remove => [ qw(package|$package_list) ], |
25
|
|
|
|
|
|
|
update => [ ], |
26
|
|
|
|
|
|
|
upgrade => [ ], |
27
|
|
|
|
|
|
|
list => [ ], |
28
|
|
|
|
|
|
|
is_installed => [ qw(package|$package_list) ], |
29
|
|
|
|
|
|
|
which => [ qw(file) ], |
30
|
|
|
|
|
|
|
system_update => [ ], |
31
|
|
|
|
|
|
|
system_upgrade => [ ], |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
optional_binaries => { |
34
|
|
|
|
|
|
|
aptitude => [ ], |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
require_binaries => { |
37
|
|
|
|
|
|
|
'apt-get' => [ ], |
38
|
|
|
|
|
|
|
dpkg => [ ], |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
need_packages => { |
41
|
|
|
|
|
|
|
ubuntu => [ qw(aptitude) ], |
42
|
|
|
|
|
|
|
debian => [ qw(aptitude) ], |
43
|
|
|
|
|
|
|
kali => [ qw(aptitude) ], |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub search { |
49
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
50
|
0
|
|
|
|
|
|
my ($package) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('search', $package) or return; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if ($self->brik_has_binary('aptitude')) { |
55
|
0
|
|
|
|
|
|
my $cmd = "aptitude search $package"; |
56
|
0
|
|
|
|
|
|
return $self->capture($cmd); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $self->log->error("search: you have to install aptitude package"); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub install { |
63
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
my ($package) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('install', $package) or return; |
67
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('install', $package, 'ARRAY', 'SCALAR') |
68
|
|
|
|
|
|
|
or return; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $cmd = 'apt-get install -y '; |
71
|
0
|
0
|
|
|
|
|
$ref eq 'ARRAY' ? ($cmd .= join(' ', @$package)) : ($cmd .= $package); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $r = $self->sudo_system($cmd); |
74
|
0
|
0
|
|
|
|
|
if ($r != 1) { |
75
|
0
|
|
|
|
|
|
return $self->log->error("install: unable to install: returned error code: [$r]"); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub remove { |
82
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
83
|
0
|
|
|
|
|
|
my ($package) = @_; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('remove', $package) or return; |
86
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('remove', $package, 'ARRAY', 'SCALAR') |
87
|
|
|
|
|
|
|
or return; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $cmd = 'apt-get remove -y '; |
90
|
0
|
0
|
|
|
|
|
$ref eq 'ARRAY' ? ($cmd .= join(' ', @$package)) : ($cmd .= $package); |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub update { |
96
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $cmd = 'apt-get update'; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub upgrade { |
104
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $cmd = 'apt-get dist-upgrade'; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub list { |
112
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return $self->log->info("list: not available on this system"); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub is_installed { |
118
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
119
|
0
|
|
|
|
|
|
my ($package) = @_; |
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('is_installed', $package) or return; |
122
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('is_installed', $package, 'ARRAY', 'SCALAR') |
123
|
|
|
|
|
|
|
or return; |
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
if ($ref eq 'ARRAY') { |
126
|
0
|
|
|
|
|
|
my $installed = {}; |
127
|
0
|
|
|
|
|
|
for my $p (@$package) { |
128
|
0
|
|
|
|
|
|
my $r = $self->is_installed($p); |
129
|
0
|
0
|
|
|
|
|
next unless defined($r); |
130
|
0
|
|
|
|
|
|
$installed->{$p} = $r; |
131
|
|
|
|
|
|
|
} |
132
|
0
|
|
|
|
|
|
return $installed; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
else { |
135
|
0
|
0
|
|
|
|
|
my $r = $self->search($package) or return; |
136
|
0
|
|
|
|
|
|
for my $this (@$r) { |
137
|
0
|
|
|
|
|
|
my @toks = split(/\s+/, $this); |
138
|
0
|
0
|
0
|
|
|
|
if ($toks[1] eq $package && $toks[0] =~ m{^i}) { |
139
|
0
|
|
|
|
|
|
return 1; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
return 0; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub which { |
148
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
149
|
0
|
|
|
|
|
|
my ($file) = @_; |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('which', $file) or return; |
152
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('which', $file) or return; |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my $cmd = "dpkg -S $file"; |
155
|
0
|
0
|
|
|
|
|
my $lines = $self->capture($cmd) or return; |
156
|
0
|
|
|
|
|
|
for my $line (@$lines) { |
157
|
0
|
|
|
|
|
|
my @toks = split(/\s*:\s*/, $line); |
158
|
0
|
0
|
0
|
|
|
|
if (defined($toks[0]) && defined($toks[1]) && ($toks[1] eq $file)) { |
|
|
|
0
|
|
|
|
|
159
|
0
|
|
|
|
|
|
return $toks[0]; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
return 'undef'; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub system_update { |
167
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
return 1; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub system_upgrade { |
173
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
my $cmd = 'do-release-upgrade'; |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
__END__ |