line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Pkg::Debian; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
16
|
use v5.12.5; |
|
1
|
|
|
|
|
3
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
71
|
|
13
|
1
|
|
|
1
|
|
9
|
use Rex::Commands::File; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
14
|
1
|
|
|
1
|
|
8
|
use Rex::Commands::Fs; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
7
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
9
|
use Rex::Pkg::Base; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
16
|
|
17
|
1
|
|
|
1
|
|
44
|
use base qw(Rex::Pkg::Base); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1051
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
0
|
|
|
0
|
0
|
|
my $that = shift; |
21
|
0
|
|
0
|
|
|
|
my $proto = ref($that) || $that; |
22
|
0
|
|
|
|
|
|
my $self = $proto->SUPER::new(@_); |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
bless( $self, $proto ); |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $env = |
27
|
|
|
|
|
|
|
'APT_LISTBUGS_FRONTEND=none APT_LISTCHANGES_FRONTEND=none DEBIAN_FRONTEND=noninteractive'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$self->{commands} = { |
30
|
0
|
|
|
|
|
|
install => "$env apt-get -o Dpkg::Options::=--force-confold -y install %s", |
31
|
|
|
|
|
|
|
install_version => |
32
|
|
|
|
|
|
|
"$env apt-get -o Dpkg::Options::=--force-confold -y install %s=%s", |
33
|
|
|
|
|
|
|
update_system => "$env apt-get -y -qq upgrade", |
34
|
|
|
|
|
|
|
dist_update_system => "$env apt-get -y -qq dist-upgrade", |
35
|
|
|
|
|
|
|
remove => "$env apt-get -y remove %s", |
36
|
|
|
|
|
|
|
purge => "$env dpkg --purge %s", |
37
|
|
|
|
|
|
|
update_package_db => "$env apt-get -y update", |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub bulk_install { |
44
|
0
|
|
|
0
|
0
|
|
my ( $self, $packages_aref, $option ) = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
delete $option->{version}; # makes no sense to specify the same version for several packages |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$self->update( "@{$packages_aref}", $option ); |
|
0
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub get_installed { |
54
|
0
|
|
|
0
|
0
|
|
my ( $self, $pkg ) = @_; |
55
|
0
|
|
|
|
|
|
my @pkgs; |
56
|
0
|
|
|
|
|
|
my $dpkg_cmd = |
57
|
|
|
|
|
|
|
'dpkg-query -W --showformat "\${Status} \${Package}|\${Version}|\${Architecture}\n"'; |
58
|
0
|
0
|
|
|
|
|
if ($pkg) { |
59
|
0
|
|
|
|
|
|
$dpkg_cmd .= " " . $pkg; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my @lines = i_run $dpkg_cmd; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
for my $line (@lines) { |
65
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^install ok installed ([^\|]+)\|([^\|]+)\|(.*)$/ ) { |
66
|
0
|
|
|
|
|
|
push( |
67
|
|
|
|
|
|
|
@pkgs, |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
name => $1, |
70
|
|
|
|
|
|
|
version => $2, |
71
|
|
|
|
|
|
|
architecture => $3, |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return @pkgs; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub diff_package_list { |
81
|
0
|
|
|
0
|
0
|
|
my ( $self, $list1, $list2 ) = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my @old_installed = @{$list1}; |
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my @new_installed = @{$list2}; |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my @modifications; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# getting modifications of old packages |
89
|
|
|
|
|
|
|
OLD_PKG: |
90
|
0
|
|
|
|
|
|
for my $old_pkg (@old_installed) { |
91
|
|
|
|
|
|
|
NEW_PKG: |
92
|
0
|
|
|
|
|
|
for my $new_pkg (@new_installed) { |
93
|
0
|
0
|
0
|
|
|
|
if ( $old_pkg->{name} eq $new_pkg->{name} |
94
|
|
|
|
|
|
|
&& $old_pkg->{architecture} eq $new_pkg->{architecture} ) |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# flag the package as found in new package list, |
98
|
|
|
|
|
|
|
# to find removed and new ones. |
99
|
0
|
|
|
|
|
|
$old_pkg->{found} = 1; |
100
|
0
|
|
|
|
|
|
$new_pkg->{found} = 1; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
if ( $old_pkg->{version} ne $new_pkg->{version} ) { |
103
|
0
|
|
|
|
|
|
push @modifications, { %{$new_pkg}, action => 'updated' }; |
|
0
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} |
105
|
0
|
|
|
|
|
|
next OLD_PKG; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# getting removed old packages |
111
|
0
|
|
|
|
|
|
push @modifications, map { $_->{action} = 'removed'; $_ } |
|
0
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
grep { !exists $_->{found} } @old_installed; |
|
0
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# getting new packages |
115
|
0
|
|
|
|
|
|
push @modifications, map { $_->{action} = 'installed'; $_ } |
|
0
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
grep { !exists $_->{found} } @new_installed; |
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
for (@modifications) { |
119
|
0
|
|
|
|
|
|
delete $_->{found}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
return @modifications; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub add_repository { |
126
|
0
|
|
|
0
|
0
|
|
my ( $self, %data ) = @_; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $name = $data{"name"}; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my $fh = file_write "/etc/apt/sources.list.d/$name.list"; |
131
|
0
|
|
|
|
|
|
$fh->write("# This file is managed by Rex\n"); |
132
|
0
|
0
|
|
|
|
|
if ( exists $data{"arch"} ) { |
133
|
|
|
|
|
|
|
$fh->write( "deb [arch=" |
134
|
|
|
|
|
|
|
. $data{"arch"} . "] " |
135
|
|
|
|
|
|
|
. $data{"url"} . " " |
136
|
|
|
|
|
|
|
. $data{"distro"} . " " |
137
|
0
|
|
|
|
|
|
. $data{"repository"} |
138
|
|
|
|
|
|
|
. "\n" ); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
else { |
141
|
|
|
|
|
|
|
$fh->write( "deb " |
142
|
|
|
|
|
|
|
. $data{"url"} . " " |
143
|
|
|
|
|
|
|
. $data{"distro"} . " " |
144
|
0
|
|
|
|
|
|
. $data{"repository"} |
145
|
|
|
|
|
|
|
. "\n" ); |
146
|
|
|
|
|
|
|
} |
147
|
0
|
0
|
0
|
|
|
|
if ( exists $data{"source"} && $data{"source"} ) { |
148
|
|
|
|
|
|
|
$fh->write( "deb-src " |
149
|
|
|
|
|
|
|
. $data{"url"} . " " |
150
|
|
|
|
|
|
|
. $data{"distro"} . " " |
151
|
0
|
|
|
|
|
|
. $data{"repository"} |
152
|
|
|
|
|
|
|
. "\n" ); |
153
|
|
|
|
|
|
|
} |
154
|
0
|
|
|
|
|
|
$fh->close; |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
|
|
|
|
if ( exists $data{"key_url"} ) { |
157
|
0
|
|
|
|
|
|
i_run "wget -O - " . $data{"key_url"} . " | apt-key add -"; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
0
|
0
|
|
|
|
|
if ( exists $data{"key_file"} ) { |
161
|
0
|
|
|
|
|
|
i_run "apt-key add $data{'key_file'}"; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
0
|
0
|
|
|
|
if ( exists $data{"key_id"} && $data{"key_server"} ) { |
165
|
|
|
|
|
|
|
i_run "apt-key adv --keyserver " |
166
|
|
|
|
|
|
|
. $data{"key_server"} |
167
|
|
|
|
|
|
|
. " --recv-keys " |
168
|
0
|
|
|
|
|
|
. $data{"key_id"}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub rm_repository { |
173
|
0
|
|
|
0
|
0
|
|
my ( $self, $name ) = @_; |
174
|
0
|
|
|
|
|
|
unlink "/etc/apt/sources.list.d/$name.list"; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |