line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# system::package Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::System::Package; |
7
|
18
|
|
|
18
|
|
162
|
use strict; |
|
18
|
|
|
|
|
47
|
|
|
18
|
|
|
|
|
564
|
|
8
|
18
|
|
|
18
|
|
96
|
use warnings; |
|
18
|
|
|
|
|
40
|
|
|
18
|
|
|
|
|
580
|
|
9
|
|
|
|
|
|
|
|
10
|
18
|
|
|
18
|
|
102
|
use base qw(Metabrik::Shell::Command); |
|
18
|
|
|
|
|
37
|
|
|
18
|
|
|
|
|
19562
|
|
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
|
|
|
|
|
|
|
commands => { |
19
|
|
|
|
|
|
|
get_system_package => [ ], |
20
|
|
|
|
|
|
|
search => [ qw(string) ], |
21
|
|
|
|
|
|
|
install => [ qw(package|$package_list) ], |
22
|
|
|
|
|
|
|
remove => [ qw(package|$package_list) ], |
23
|
|
|
|
|
|
|
update => [ qw(version|OPTIONAL) ], |
24
|
|
|
|
|
|
|
upgrade => [ qw(version|OPTIONAL) ], |
25
|
|
|
|
|
|
|
is_os => [ qw(os) ], |
26
|
|
|
|
|
|
|
is_os_ubuntu => [ ], |
27
|
|
|
|
|
|
|
is_os_debian => [ ], |
28
|
|
|
|
|
|
|
is_os_kali => [ ], |
29
|
|
|
|
|
|
|
is_os_freebsd => [ ], |
30
|
|
|
|
|
|
|
is_os_centos => [ ], |
31
|
|
|
|
|
|
|
is_installed => [ qw(package|$package_list) ], |
32
|
|
|
|
|
|
|
my_os => [ ], |
33
|
|
|
|
|
|
|
which => [ qw(file) ], |
34
|
|
|
|
|
|
|
system_update => [ qw(version|OPTIONAL) ], |
35
|
|
|
|
|
|
|
system_upgrade => [ qw(version|OPTIONAL) ], |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
require_modules => { |
38
|
|
|
|
|
|
|
'Metabrik::System::Os' => [ ], |
39
|
|
|
|
|
|
|
'Metabrik::System::Ubuntu::Package' => [ ], |
40
|
|
|
|
|
|
|
'Metabrik::System::Debian::Package' => [ ], |
41
|
|
|
|
|
|
|
'Metabrik::System::Kali::Package' => [ ], |
42
|
|
|
|
|
|
|
'Metabrik::System::Freebsd::Package' => [ ], |
43
|
|
|
|
|
|
|
'Metabrik::System::Centos::Package' => [ ], |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_system_package { |
49
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
my $os = $self->my_os or return; |
52
|
0
|
|
|
|
|
|
my $sudo_args = $self->sudo_args; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $sp; |
55
|
0
|
0
|
|
|
|
|
if ($os eq 'ubuntu') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
$sp = Metabrik::System::Ubuntu::Package->new_from_brik_init($self) or return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif ($os eq 'debian') { |
59
|
0
|
0
|
|
|
|
|
$sp = Metabrik::System::Debian::Package->new_from_brik_init($self) or return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
elsif ($os eq 'kali') { |
62
|
0
|
0
|
|
|
|
|
$sp = Metabrik::System::Kali::Package->new_from_brik_init($self) or return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif ($os eq 'freebsd') { |
65
|
0
|
0
|
|
|
|
|
$sp = Metabrik::System::Freebsd::Package->new_from_brik_init($self) or return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
elsif ($os eq 'centos') { |
68
|
0
|
0
|
|
|
|
|
$sp = Metabrik::System::Centos::Package->new_from_brik_init($self) or return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
0
|
|
|
|
|
|
return $self->log->error("get_system_package: cannot determine package system for OS [$os]"); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$sp->sudo_args($sudo_args); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $sp; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub search { |
80
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
81
|
0
|
|
|
|
|
|
my ($package) = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('search', $package) or return; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
my $sp = $self->get_system_package or return; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $sp->search($package); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub install { |
91
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
92
|
0
|
|
|
|
|
|
my ($package) = @_; |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
my $sp = $self->get_system_package or return; |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
if (defined($package)) { |
|
|
0
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return $sp->install($package); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
elsif (! exists($self->brik_properties->{need_packages})) { |
100
|
|
|
|
|
|
|
#return $self->log->error($self->brik_help_run('install')); |
101
|
0
|
|
|
|
|
|
return 1; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
0
|
|
|
|
|
|
my $os = $self->my_os; |
105
|
0
|
0
|
|
|
|
|
if (exists($self->brik_properties->{need_packages}{$os})) { |
106
|
0
|
|
|
|
|
|
my $need_packages = $self->brik_properties->{need_packages}{$os}; |
107
|
0
|
|
|
|
|
|
return $sp->install($need_packages); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
0
|
|
|
|
|
|
return $self->log->error("install: don't know how to do that for OS [$os]"); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return 1; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub remove { |
118
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
119
|
0
|
|
|
|
|
|
my ($package) = @_; |
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('remove', $package) or return; |
122
|
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
|
my $sp = $self->get_system_package or return; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return $sp->remove($package); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub update { |
129
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
130
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
|
my $sp = $self->get_system_package or return; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return $sp->update(@_); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub upgrade { |
137
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
my $sp = $self->get_system_package or return; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return $sp->upgrade(@_); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub system_update { |
145
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
|
my $sp = $self->get_system_package or return; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
return $sp->system_update(@_); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub system_upgrade { |
153
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
154
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
my $sp = $self->get_system_package or return; |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
return $sp->system_upgrade(@_); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub list { |
161
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
162
|
|
|
|
|
|
|
|
163
|
0
|
0
|
|
|
|
|
my $sp = $self->get_system_package or return; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
return $sp->list; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub is_os { |
169
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
170
|
0
|
|
|
|
|
|
my ($os) = @_; |
171
|
|
|
|
|
|
|
|
172
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('is_os', $os) or return; |
173
|
|
|
|
|
|
|
|
174
|
0
|
0
|
|
|
|
|
my $so = Metabrik::System::Os->new_from_brik_init($self) or return; |
175
|
0
|
|
|
|
|
|
return $so->is($os); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub is_os_ubuntu { |
179
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
return $self->is_os('ubuntu'); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub is_os_debian { |
185
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
return $self->is_os('debian'); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub is_os_kali { |
191
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
return $self->is_os('kali'); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub is_os_freebsd { |
197
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
return $self->is_os('freebsd'); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub is_os_centos { |
203
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
return $self->is_os('centos'); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub is_installed { |
209
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
210
|
0
|
|
|
|
|
|
my ($package) = @_; |
211
|
|
|
|
|
|
|
|
212
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('is_installed', $package) or return; |
213
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('is_installed', $package, 'ARRAY', 'SCALAR') |
214
|
|
|
|
|
|
|
or return; |
215
|
|
|
|
|
|
|
|
216
|
0
|
0
|
|
|
|
|
my $sp = $self->get_system_package or return; |
217
|
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
|
return $sp->is_installed($package); |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub my_os { |
222
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
223
|
|
|
|
|
|
|
|
224
|
0
|
0
|
|
|
|
|
my $so = Metabrik::System::Os->new_from_brik_init($self) or return; |
225
|
0
|
|
|
|
|
|
return $so->my; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub which { |
229
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
230
|
0
|
|
|
|
|
|
my ($file) = @_; |
231
|
|
|
|
|
|
|
|
232
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('which', $file) or return; |
233
|
|
|
|
|
|
|
|
234
|
0
|
0
|
|
|
|
|
my $sp = $self->get_system_package or return; |
235
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
return $sp->which($file); |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
1; |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
__END__ |