| 1 | # | ||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Rex::Pkg::Debian; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Rex::Helper::Run; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Rex::Commands::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Rex::Commands::Fs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Rex::Pkg::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use base qw(Rex::Pkg::Base); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 0 | my $that = shift; | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $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 | 0 | ▶ | sub bulk_install { | ||||||||||||||||||||||||||
|
Subroutine
bulk_install: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 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 ); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | return 1; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub get_installed { | ||||||||||||||||||||||||||
|
Subroutine
get_installed: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 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 | ▶ | if ($pkg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | $dpkg_cmd .= " " . $pkg; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | my @lines = i_run $dpkg_cmd; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | for my $line (@lines) { | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $line =~ m/^install ok installed ([^\|]+)\|([^\|]+)\|(.*)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub diff_package_list { | ||||||||||||||||||||||||||
|
Subroutine
diff_package_list: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 0 | my ( $self, $list1, $list2 ) = @_; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | my @old_installed = @{$list1}; | |||||||||||||||||||||||||||
| 84 | 0 | my @new_installed = @{$list2}; | |||||||||||||||||||||||||||
| 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 | ▶ | if ( $old_pkg->{name} eq $new_pkg->{name} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$old_pkg->{"name"} eq $new_pkg->{"name"} and $old_pkg->{"architecture"} eq $new_pkg->{"architecture"}
MC/DC0%0/2
$old_pkg->{"name"} eq $new_pkg->{"name"} and $old_pkg->{"architecture"} eq $new_pkg->{"architecture"}
$old_pkg->{"name"} eq $new_pkg->{"name"}
$old_pkg->{"architecture"} eq $new_pkg->{"architecture"}
Truth table0%0/3
A and B
A= $old_pkg->{"name"} eq $new_pkg->{"name"}B= $old_pkg->{"architecture"} eq $new_pkg->{"architecture"}
| |||||||||||||||||||||||||||||
| 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 | ▶ | if ( $old_pkg->{version} ne $new_pkg->{version} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | push @modifications, { %{$new_pkg}, action => 'updated' }; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 0 | next OLD_PKG; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # getting removed old packages | ||||||||||||||||||||||||||||
| 111 | 0 | push @modifications, map { $_->{action} = 'removed'; $_ } | |||||||||||||||||||||||||||
| 112 | 0 | grep { !exists $_->{found} } @old_installed; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # getting new packages | ||||||||||||||||||||||||||||
| 115 | 0 | push @modifications, map { $_->{action} = 'installed'; $_ } | |||||||||||||||||||||||||||
| 116 | 0 | grep { !exists $_->{found} } @new_installed; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | for (@modifications) { | |||||||||||||||||||||||||||
| 119 | 0 | delete $_->{found}; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | return @modifications; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub add_repository { | ||||||||||||||||||||||||||
|
Subroutine
add_repository: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 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 | ▶ | if ( exists $data{"arch"} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | if ( exists $data{"source"} && $data{"source"} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $data{"source"} and $data{"source"}
MC/DC0%0/2
exists $data{"source"} and $data{"source"}
exists $data{"source"}
$data{"source"}
Truth table0%0/3
A and B
A= exists $data{"source"}B= $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 | ▶ | if ( exists $data{"key_url"} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | i_run "wget -O - " . $data{"key_url"} . " | apt-key add -"; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ( exists $data{"key_file"} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | i_run "apt-key add $data{'key_file'}"; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ( exists $data{"key_id"} && $data{"key_server"} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $data{"key_id"} and $data{"key_server"}
MC/DC0%0/2
exists $data{"key_id"} and $data{"key_server"}
exists $data{"key_id"}
$data{"key_server"}
Truth table0%0/3
A and B
A= exists $data{"key_id"}B= $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 | 0 | ▶ | sub rm_repository { | ||||||||||||||||||||||||||
|
Subroutine
rm_repository: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 173 | 0 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||
| 174 | 0 | unlink "/etc/apt/sources.list.d/$name.list"; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 1 | 1; | |||||||||||||||||||||||||||