line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# system::centos::package Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::System::Centos::Package; |
7
|
1
|
|
|
1
|
|
835
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Shell::Command); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1036
|
|
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
|
|
|
|
|
|
|
require_binaries => { |
34
|
|
|
|
|
|
|
yum => [ ], |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
need_packages => { |
37
|
|
|
|
|
|
|
centos => [ qw(yum) ], |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub search { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my ($package) = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('search', $package) or return; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $cmd = "yum search $package"; |
49
|
0
|
|
|
|
|
|
return $self->capture($cmd); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub install { |
53
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
54
|
0
|
|
|
|
|
|
my ($package) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('install', $package) or return; |
57
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('install', $package, 'ARRAY', 'SCALAR') |
58
|
|
|
|
|
|
|
or return; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $cmd = 'yum install -y '; |
61
|
0
|
0
|
|
|
|
|
$ref eq 'ARRAY' ? ($cmd .= join(' ', @$package)) : ($cmd .= $package); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $r = $self->sudo_system($cmd); |
64
|
0
|
0
|
|
|
|
|
if ($r != 1) { |
65
|
0
|
|
|
|
|
|
return $self->log->error("install: unable to install: returned error code: [$r]"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub remove { |
72
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
73
|
0
|
|
|
|
|
|
my ($package) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('remove', $package) or return; |
76
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('remove', $package, 'ARRAY', 'SCALAR') |
77
|
|
|
|
|
|
|
or return; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $cmd = 'yum remove -y '; |
80
|
0
|
0
|
|
|
|
|
$ref eq 'ARRAY' ? ($cmd .= join(' ', @$package)) : ($cmd .= $package); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub update { |
86
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $cmd = 'yum update'; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub upgrade { |
94
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $cmd = 'yum upgrade'; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub list { |
102
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
return $self->log->info("list: not available on this system"); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub is_installed { |
108
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
my ($package) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('is_installed', $package) or return; |
112
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('is_installed', $package, 'ARRAY', 'SCALAR') |
113
|
|
|
|
|
|
|
or return; |
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
if ($ref eq 'ARRAY') { |
116
|
0
|
|
|
|
|
|
my $installed = {}; |
117
|
0
|
|
|
|
|
|
for my $p (@$package) { |
118
|
0
|
|
|
|
|
|
my $r = $self->is_installed($p); |
119
|
0
|
0
|
|
|
|
|
next unless defined($r); |
120
|
0
|
|
|
|
|
|
$installed->{$p} = $r; |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
return $installed; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
else { |
125
|
0
|
0
|
|
|
|
|
my $r = $self->search($package) or return; |
126
|
0
|
|
|
|
|
|
for my $this (@$r) { |
127
|
0
|
|
|
|
|
|
my @toks = split(/\s+/, $this); |
128
|
0
|
0
|
0
|
|
|
|
if ($toks[1] eq $package && $toks[0] =~ m{^i}) { |
129
|
0
|
|
|
|
|
|
return 1; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return 0; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub which { |
138
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
139
|
0
|
|
|
|
|
|
my ($file) = @_; |
140
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('which', $file) or return; |
142
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('which', $file) or return; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# coreutils-8.22-15.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts |
145
|
|
|
|
|
|
|
# Repo : base |
146
|
|
|
|
|
|
|
# Matched from: |
147
|
|
|
|
|
|
|
# Filename : /bin/ls |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
my $cmd = "yum provides -q $file"; |
150
|
0
|
0
|
|
|
|
|
my $lines = $self->capture($cmd) or return; |
151
|
0
|
|
|
|
|
|
for my $line (@$lines) { |
152
|
0
|
|
|
|
|
|
$line =~ s{^\d+:}{}; # Remove if exists. |
153
|
0
|
|
|
|
|
|
my @toks = split(/\s*:\s*/, $line); |
154
|
0
|
0
|
0
|
|
|
|
if (defined($toks[0]) && defined($toks[1])) { |
155
|
0
|
0
|
0
|
|
|
|
if ($toks[0] ne 'Repo' && $toks[0] ne 'Matched from' && $toks[0] ne 'Filename') { |
|
|
|
0
|
|
|
|
|
156
|
0
|
|
|
|
|
|
return $toks[0]; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
return 'undef'; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub system_update { |
165
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
return $self->log->info("TODO"); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub system_upgrade { |
171
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
return $self->log->info("TODO"); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
__END__ |