• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ferki / Rex / 15240232617

28 Feb 2025 09:08AM UTC coverage: 50.961% (+10.2%) from 40.73%
15240232617

push

github

ferki
Use placeholders for template hints

10072 of 19764 relevant lines covered (50.96%)

101.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.63
/lib/Rex/Interface/Shell/Base.pm
1
#
2
# (c) Jan Gehring <jan.gehring@gmail.com>
3
#
4

5
package Rex::Interface::Shell::Base;
6

7
use v5.12.5;
4✔
8
use warnings;
4✔
9

10
our $VERSION = '9999.99.99_99'; # VERSION
11

12
sub new {
13
  my $class = shift;
14✔
14
  my $self  = {};
14✔
15
  $self->{path}            = undef;
14✔
16
  $self->{__inner_shell__} = undef;
14✔
17

18
  bless( $self, $class );
14✔
19

20
  return $self;
14✔
21
}
22

23
sub name {
24
  my ($self)     = @_;
14✔
25
  my $class_name = ref $self;
14✔
26
  my @parts      = split( /::/, $class_name );
14✔
27
  return lc( $parts[-1] );
14✔
28
}
29

30
sub set_environment {
31
  my ( $self, $env ) = @_;
×
32
  $self->{__env__} = $env;
×
33
}
34

35
sub set_inner_shell {
36
  my ( $self, $use_inner_shell ) = @_;
×
37
  $self->{__inner_shell__} = $use_inner_shell;
×
38
}
39

40
sub set_locale {
41
  my ( $self, $locale ) = @_;
×
42
  $self->{locale} = $locale;
×
43
}
44

45
sub set_sudo_env {
46
  my ( $self, $sudo_env ) = @_;
×
47
  $self->{__sudo_env__} = $sudo_env;
×
48
}
49

50
sub detect {
51
  my ( $self, $con ) = @_;
98✔
52

53
  my $shell_class = ref $self || $self; # $self might be only the classname
98✔
54
  my @parts       = split /::/, $shell_class;
98✔
55
  my $last_part   = lc( $parts[-1] || "" );
98✔
56

57
  my ($shell_path) = $con->_exec("echo \$SHELL");
98✔
58
  if ( !$shell_path ) {
98✔
59

60
    # try it a second time
61
    # we need this sometimes because the tty allocation is too slow, or
62
    # doesn't work, or ???
63
    # it seems that this happens only for the very first command with
64
    # Net::OpenSSH when using a tty.
65
    Rex::Logger::debug(
×
66
      "Failed detecting shell in the first try. Trying again.");
67

68
    ($shell_path) = $con->_exec("echo \$SHELL");
×
69
  }
70

71
  $shell_path =~ s/(\r?\n)//gms; # remove unnecessary newlines
98✔
72

73
  if ( $shell_path && $shell_path =~ m/\/\Q$last_part\E$/ ) {
98✔
74
    return 1;
×
75
  }
76

77
  return 0;
98✔
78
}
79

80
1;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc