| 1 | # | ||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Rex::Interface::Shell::Csh; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Rex::Interface::Shell::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use base qw(Rex::Interface::Shell::Base); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 17 | 0 | ▶ | my $proto = ref($class) || $class; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 18 | 0 | my $self = $proto->SUPER::new(@_); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | bless( $self, $class ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | return $self; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub path { | ||||||||||||||||||||||||||
|
Subroutine
path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 0 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||
| 27 | 0 | $self->{path} = $path; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub source_global_profile { | ||||||||||||||||||||||||||
|
Subroutine
source_global_profile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 0 | my ( $self, $parse ) = @_; | |||||||||||||||||||||||||||
| 32 | 0 | $self->{source_global_profile} = $parse; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub source_profile { | ||||||||||||||||||||||||||
|
Subroutine
source_profile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 0 | my ( $self, $parse ) = @_; | |||||||||||||||||||||||||||
| 37 | 0 | $self->{source_profile} = $parse; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub set_locale { | ||||||||||||||||||||||||||
|
Subroutine
set_locale: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 0 | my ( $self, $locale ) = @_; | |||||||||||||||||||||||||||
| 42 | 0 | $self->{locale} = $locale; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # sub set_env { | ||||||||||||||||||||||||||||
| 46 | # my ( $self, $env ) = @_; | ||||||||||||||||||||||||||||
| 47 | # my $cmd = undef; | ||||||||||||||||||||||||||||
| 48 | # | ||||||||||||||||||||||||||||
| 49 | # die("Error: env must be a hash") | ||||||||||||||||||||||||||||
| 50 | # if ( ref $env ne "HASH" ); | ||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||
| 52 | # while ( my ( $k, $v ) = each($env) ) { | ||||||||||||||||||||||||||||
| 53 | # $cmd .= "setenv $k \"$v\"; "; | ||||||||||||||||||||||||||||
| 54 | # $self->{env_raw} .= "$k $v"; | ||||||||||||||||||||||||||||
| 55 | # } | ||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||
| 57 | # $self->{env} = $cmd; | ||||||||||||||||||||||||||||
| 58 | # } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub exec { | ||||||||||||||||||||||||||
|
Subroutine
exec: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | my ( $self, $cmd, $option ) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( exists $option->{path} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | $self->path( $option->{path} ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # if ( exists $option->{env} ) { | ||||||||||||||||||||||||||||
| 68 | # $self->set_env( $option->{env} ); | ||||||||||||||||||||||||||||
| 69 | # } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | my $complete_cmd = $cmd; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # if we need to execute without an sh command, | ||||||||||||||||||||||||||||
| 74 | # use the format_cmd key | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ( exists $option->{no_sh} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | $complete_cmd = $option->{format_cmd}; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ( exists $option->{cwd} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | $complete_cmd = "cd $option->{cwd} && $complete_cmd"; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ( $self->{path} && !exists $self->{__env__}->{PATH} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"path"} and not exists $self->{"__env__"}{"PATH"}
MC/DC0%0/2
$self->{"path"} and not exists $self->{"__env__"}{"PATH"}
$self->{"path"}
not exists $self->{"__env__"}{"PATH"}
Truth table0%0/3
A and not(B)
A= $self->{"path"}B= not exists $self->{"__env__"}{"PATH"}
| |||||||||||||||||||||||||||||
| 84 | 0 | $complete_cmd = "set PATH=$self->{path}; $complete_cmd "; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( $self->{locale} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | $complete_cmd = "set LC_ALL=$self->{locale} ; $complete_cmd "; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ( $self->{source_profile} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # csh is using .login | ||||||||||||||||||||||||||||
| 94 | 0 | $complete_cmd = "source ~/.login >& /dev/null ; $complete_cmd"; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( $self->{source_global_profile} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | $complete_cmd = "source /etc/profile >& /dev/null ; $complete_cmd"; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ( exists $self->{__env__} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ( ref $self->{__env__} eq "HASH" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | for my $key ( keys %{ $self->{__env__} } ) { | |||||||||||||||||||||||||||
| 104 | 0 | my $val = $self->{__env__}->{$key}; | |||||||||||||||||||||||||||
| 105 | 0 | $val =~ s/"/"'"'"/gms; | |||||||||||||||||||||||||||
| 106 | 0 | $complete_cmd = " setenv $key \"$val\" ; $complete_cmd "; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | else { | ||||||||||||||||||||||||||||
| 110 | 0 | $complete_cmd = $self->{__env__} . " $complete_cmd "; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # this is due to a strange behaviour with Net::SSH2 / libssh2 | ||||||||||||||||||||||||||||
| 115 | # it may occur when you run rex inside a kvm virtualized host connecting to another virtualized vm on the same hardware | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( Rex::Config->get_sleep_hack ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | $complete_cmd .= " ; set f=\$? ; sleep .00000001 ; exit \$f"; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # rewrite the command again | ||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( exists $option->{format_cmd} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | $complete_cmd =~ s/\{\{CMD\}\}/$cmd/; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | return $complete_cmd; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 3 | 1; | |||||||||||||||||||||||||||