lib/Rex/Pkg/FreeBSD.pm

filter: Statementstmt 32.8% 22 / 67 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 5 totaltotal 27.6% 29 / 105 CC 11 SCAR 30.4
CC
11
Cov
26%
is_installed
56.0
new
12.0
remove
6.0
CRAP 21.0
« lib/Rex/Commands/LVM.pm ↑ Summary blib/lib/Rex/Cloud/Amazon.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Pkg::FreeBSD;
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::Pkg::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use base qw(Rex::Pkg::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Net::OpenSSH::ShellQuoter;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
19 0 my $that = shift;
20 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
21 0 my $self = $proto->SUPER::new(@_);
22  
23 0 bless( $self, $proto );
24  
25 # Check if pkg is actually bootstraped (installed and activated)
26 0 i_run "pkg -N", fail_ok => 1;
27 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
28 0 i_run "pkg bootstrap", env => { 'ASSUME_ALWAYS_YES' => 'true' };
29 }
30  
31 $self->{commands} = {
32 0 install => 'pkg install -q -y %s',
33 install_glob => 'pkg install -q -y -g %s',
34 install_version => 'pkg install -q -y %s',
35 remove => 'pkg remove -q -y %s',
36 remove_glob => 'pkg remove -q -y -g %s',
37 query => 'pkg info',
38 update_package_db => 'pkg update -q -f',
39  
40 # pkg can't update system yet, only packages
41 update_system => 'pkg upgrade -q -y',
42 };
43  
44 0 return $self;
45 }
46  
47 0 ▶sub bulk_install {
Subroutine bulk_install: not called CC=1 SCAR=6.9
Pod undocumented
48 0 my ( $self, $packages_aref, $option ) = @_;
49  
50 # makes no sense to specify the same version for several packages
51 0 delete $option->{version};
52 0 $self->update( "@{$packages_aref}", $option );
53  
54 0 return 1;
55 }
56  
57 0 ▶sub remove {
Subroutine remove: not called CC=2 SCAR=17.9
Pod undocumented
58 0 my ( $self, $pkg ) = @_;
59  
60 0 my $pkg_version = '';
61  
62 0 ▶ if ( $pkg !~ /\*/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pkg =~ /\*/u) 0 0 0
63 0 my ($pkg_found) = grep { $_->{"name"} eq "$pkg" } $self->get_installed();
64 0 $pkg_version = '-' . $pkg_found->{"version"};
65 }
66  
67 0 return $self->SUPER::remove("$pkg$pkg_version");
68 }
69  
70 0 ▶sub is_installed {
Subroutine is_installed: not called CC=7 SCAR=40.3
Pod undocumented
71 0 my ( $self, $pkg, $option ) = @_;
72 0 my $version = $option->{version};
73  
74 0 ▶ Rex::Logger::debug(
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
75 "Checking if $pkg" . ( $version ? "-$version" : "" ) . " is installed" );
76  
77 # only need -g if pkg is a glob
78 0 my $extra_args = '';
79 0 ▶ if ( $pkg =~ /\*/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg =~ /\*/u) 0 0 0
80  
81 # quote the pkg glob so it will work
82 0 my $exec = Rex::Interface::Exec->create;
83 0 my $quoter = Net::OpenSSH::ShellQuoter->quoter( $exec->shell->name );
84 0 $pkg = $quoter->quote($pkg);
85 0 $extra_args = $extra_args . ' -g ';
86 }
87  
88 # pkg info -e allow get quick answer about is pkg installed or not.
89 my $command =
90 $self->{commands}->{query}
91 0 ▶ . $extra_args
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
92 . " -e $pkg"
93 . ( $version ? "-$version" : "" );
94 0 i_run $command, fail_ok => 1;
95  
96 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
97 0 ▶ Rex::Logger::debug(
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
98 "$pkg" . ( $version ? "-$version" : "" ) . " is NOT installed." );
99 0 return 0;
100 }
101  
102 Rex::Logger::debug(
103 0 ▶ "$pkg" . ( $version ? "-$version" : "" ) . " is installed." );
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
104 0 return 1;
105  
106 }
107  
108 0 ▶sub get_installed {
Subroutine get_installed: not called CC=2 SCAR=17.9
Pod undocumented
109 0 my ($self) = @_;
110  
111 0 my @lines = i_run $self->{commands}->{query};
112  
113 0 my @pkg;
114  
115 0 for my $line (@lines) {
116 0 my ( $pkg_name_v, $descr ) = split( /\s/, $line, 2 );
117  
118 0 my ( $pkg_name, $pkg_version ) = ( $pkg_name_v =~ m/^(.*)-(.*?)$/ );
119  
120 0 push(
121 @pkg,
122 {
123 name => $pkg_name,
124 version => $pkg_version,
125 }
126 );
127 }
128  
129 0 return @pkg;
130 }
131  
132 1 1;
« lib/Rex/Commands/LVM.pm ↑ Summary blib/lib/Rex/Cloud/Amazon.pm »