File Coverage

blib/lib/LedgerSMB/Installer/OS/linux.pm
Criterion Covered Total %
statement 14 123 11.3
branch 0 20 0.0
condition n/a
subroutine 5 20 25.0
pod 0 15 0.0
total 19 178 10.6


line stmt bran cond sub pod time code
1             package LedgerSMB::Installer::OS::linux v0.999.11;
2              
3 1     1   681 use v5.20;
  1         4  
4 1     1   6 use experimental qw(signatures);
  1         3  
  1         7  
5 1     1   179 use parent qw(LedgerSMB::Installer::OS::unix);
  1         3  
  1         11  
6              
7 1     1   105 use Carp qw(croak);
  1         2  
  1         68  
8              
9 1     1   6 use Log::Any qw($log);
  1         2  
  1         5  
10              
11 0     0 0   sub new($class, %args) {
  0            
  0            
  0            
12 0           return bless {}, $class;
13             }
14              
15 0     0 0   sub name($self) {
  0            
  0            
16 0           return 'linux-generic';
17             }
18              
19 0     0 0   sub dependency_packages_identifier($self) {
  0            
  0            
20 0           return 'linux-generic';
21             }
22              
23 0     0 0   sub pkgs_from_modules($self, $mods) {
  0            
  0            
  0            
24 0           warn $log->warning('generic linux support does not include mapping modules to packages');
25 0           return ([], $mods);
26             }
27              
28 0     0 0   sub pkg_can_install($self) {
  0            
  0            
29 0           return 0;
30             }
31              
32 0     0 0   sub pkg_install($self, $pkgs) {
  0            
  0            
  0            
33 0           die $log->fatal('generic linux support does not include package manager support');
34             }
35              
36 0     0 0   sub pkg_uninstall($self, $pkgs) {
  0            
  0            
  0            
37 0           die $log->fatal('generic linux support does not include package manager support');
38             }
39              
40 0     0 0   sub cleanup_env($self, $config, %args) {
  0            
  0            
  0            
  0            
41 0           warn $log->fatal('generic linux support does not include package manager support');
42             }
43              
44 0     0 0   sub prepare_pkg_resolver_env($self, $config) {
  0            
  0            
  0            
45 0           warn $log->warning('generic linux support does not allow creating module-to-package mapping environment');
46             }
47              
48 0     0 0   sub pkg_deps_latex($self) {
  0            
  0            
49 0           return ([], []);
50             }
51              
52 0     0 0   sub pkg_deps_xml($self) {
  0            
  0            
53 0           return ([], []);
54             }
55              
56 0     0 0   sub pkg_deps_expat($self) {
  0            
  0            
57 0           return ([], []);
58             }
59              
60 0     0 0   sub pkg_deps_dbd_pg($self) {
  0            
  0            
61 0           return ([], []);
62             }
63              
64 0     0 0   sub detect_dss($self) {
  0            
  0            
65 0           my $dss_class;
66              
67 0 0         if (-r '/etc/os-release') {
68 0 0         if (open my $fh, '<', '/etc/os-release') {
69 0           my %params;
70 0           while (my $line = <$fh>) {
71 0 0         next if $line =~ m/^.*#/;
72 0 0         next if $line =~ m/^\s*$/;
73              
74 0           my ($var, $val) = split( /="?/, $line, 2);
75 0           $val =~ s/"$//;
76 0           chomp $val;
77 0           $params{$var} = $val;
78             }
79              
80 0           $self->{distro} = { %params{ qw(ID ID_LIKE VERSION_ID VERSION_CODENAME)} };
81 0 0         close($fh)
82             or warn $log->warn( "Unable to close /etc/os-release" );
83              
84 0           my $dist_id = $self->{distro}->{ID};
85 0           my $dist_like_id;
86 0           $dss_class = __PACKAGE__ . '::' . $dist_id;
87 0 0         if (not eval "require $dss_class") {
88 0           my $alt_dss_class;
89 0 0         if ($self->{distro}->{ID_LIKE}) { # ID_LIKE is optional
90 0           my @like_dists = split( / +/, $self->{distro}->{ID_LIKE} );
91 0           my @attempts;
92 0           for my $like_dist (@like_dists) {
93 0           $dist_like_id = $like_dist;
94 0           my $alt = __PACKAGE__ . "::$like_dist";
95 0 0         if (eval "require $alt") {
96 0           $alt_dss_class = $alt;
97 0           last;
98             }
99 0           push @attempts, $alt;
100             }
101 0 0         if (not $alt_dss_class) {
102 0           my $distros = join(', ', $self->{distro}->{ID}, @like_dists);
103 0           warn $log->warning( 'Unable to load support for any of these linux '
104             . "distributions: $distros" );
105 0           warn $log->info( 'Continuing with generic linux support' );
106 0           return $self;
107             }
108             }
109             else {
110 0           die 'Unable to load support for linux distribution: '
111             . "$self->{distro}->{ID}\n";
112             }
113 0           $dss_class = $alt_dss_class;
114             }
115 0 0         if ($dist_like_id) {
116 0           $log->info( "Dectected distribution: $dist_like_id (from: $dist_id)" );
117             }
118             else {
119 0           $log->info( "Detected distribution: $dist_id" );
120             }
121             }
122             else {
123 0           $log->warn( "Failed to open /etc/os-release: $!" );
124 0           die $log->error( "Failed to identify distribution using /etc/os-release" );
125             }
126             }
127              
128              
129             return $dss_class->new(
130             distro => $self->{distro},
131 0           );
132             }
133              
134 0     0 0   sub generate_startup($self, $config) {
  0            
  0            
  0            
135 0           $log->warning( "Generation of startup scripts not implemented" );
136             }
137              
138             1;