lib/Rex/GPU/NVIDIA/Setup/Debian.pm

filter: Statementstmt 98.8% 170 / 172 Branchbran 93.6% 88 / 94 Conditioncond 73.8% 48 / 65 MC/DCmcdc 60.5% 23 / 38 Subroutinesub 100% 22 / 22 Podpod 100% 11 / 11 totaltotal 90.0% 362 / 402 CC 78 SCAR 20.6
CC
78
Cov
92%
_deb822_enable_nonfree
15.0
_sources_list_enable_nonfree
13.0
is_debian_archive_uri
8.0
CRAP 7.9
« lib/Rex/GPU/NVIDIA.pm ↑ Summary blib/lib/Rex/GPU/Detect.pm »
1 # ABSTRACT: NVIDIA driver setup for Debian (experimental)
2  
3 package Rex::GPU::NVIDIA::Setup::Debian;
4 49 our $VERSION = '0.006';
5 49 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 49 ▶use Rex::Logger ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 49 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 49 extends 'Rex::GPU::NVIDIA::Setup::Apt';
10  
11 # Proxmox VE 9.2 (read-only on a live host, 2026-11-05, k88): os-release
12 # ID=debian VERSION_ID=13, kernel 7.0.14-20-pve, pve-firmware 3.18-6
13 # (candidate 3.18-9). apt-get -s install from the sources as this class
14 # writes them, none removed by either: debian-nonfree (nvidia-driver
15 # nvidia-smi libcuda1 linux-headers-$K, Debian 13 main contrib non-free
16 # non-free-firmware) 167 new, with firmware-nvidia-gsp 550.163.01-2;
17 # nvidia-cuda-repo debian13/x86_64 (nvidia-driver-cuda
18 # nvidia-kernel-open-dkms linux-headers-$K) 73 new, with
19 # firmware-nvidia-gsp 620.70.06-1.
20 # linux-headers-7.0.14-20-pve is no package; proxmox-headers-7.0.14-20-pve
21 # Provides it, and apt takes that.
22 # pve-firmware 3.18-6 to 3.18-9 Conflicts and Replaces
23 # firmware-amd-graphics, firmware-misc-nonfree, from 3.18-9 also
24 # firmware-nvidia-graphics -- never firmware-nvidia-gsp, whose files lie
25 # under lib/firmware/nvidia/<driver version>/; none of pve-firmware's
26 # 588 files under nvidia/ is in such a directory.
27 # Debian 13 and CUDA debian13/x86_64 indexes (2026-11-05): neither source
28 # pulls firmware-nvidia-graphics (in Debian only firmware-misc-nonfree
29 # depends on it); the only firmware either pulls is firmware-nvidia-gsp.
30 # Not checked: whether the DKMS module builds against the Proxmox kernel
31 # (nor against any kernel that is not Debian's).
32 # So Proxmox VE is not refused here, unlike the AMD driver paths (k81).
33  
34  
35 # nvidia-graphics-drivers per suite, sources.debian.org/api/src/
36 # nvidia-graphics-drivers/ checked 2026-09-23: bullseye 470.256.02,
37 # bookworm 535.261.03, trixie 550.163.01. forky/sid (550 today) is
38 # deliberately absent: it moves.
39 # karr #56, research of 2026-09-24 (Packages.gz of debian12): the CUDA repo
40 # builds nvidia-fabricmanager-570 / -575, and one unversioned
41 # nvidia-fabricmanager from 580 on. A fresh install always takes >= 590.
42 9 ▶sub fabric_manager_package {
Subroutine fabric_manager_package: called CC=4 SCAR=14.6
Pod documented
43 9 my ( $self, $source ) = @_;
44 9 my $pkg = $self->SUPER::fabric_manager_package($source);
45 9 ▶ return $pkg unless defined $pkg && ( $source->{branch} // '' ) =~ /\A57[05]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg and ($source->{"branch"} // "") =~ /\A57[05]\z/ 9 0 9
Condition80%4/5
defined $pkg and ($source->{"branch"} // "") =~ /\A57[05]\z/
!ll&&!rl&&r
270
$source->{"branch"} // ""
l!l
25
MC/DC100%2/2
defined $pkg and ($source->{"branch"} // "") =~ /\A57[05]\z/
defined $pkg $source->{"branch"}
Truth table100%3/3
A and B
A= defined $pkgB= $source->{"branch"}
ABresult
0X0
100
111
46 0 return 'nvidia-fabricmanager-'.$source->{branch};
47 }
48  
49 # nvlsm: CUDA repos debian12 and debian13 carry it (research 2026-09-24),
50 # Debian's archive does not.
51 5 ▶sub nvlink_fabric_unavailable {
Subroutine nvlink_fabric_unavailable: called CC=4 SCAR=20.1
Pod documented
52 5 my ( $self, $source ) = @_;
53 5 ▶ return if $source && $source->{cuda_repo};
Branch: 1 branch
BranchTrueFalseTotal
if $source and $source->{"cuda_repo"} 5 0 5
Condition33%1/3
$source and $source->{"cuda_repo"}
!ll&&!rl&&r
005
MC/DC0%0/2
$source and $source->{"cuda_repo"}
$source $source->{"cuda_repo"}
Truth table33%1/3
A and B
A= $sourceB= $source->{"cuda_repo"}
ABresult
0X0
100
111
54 return "nvlsm is only in NVIDIA's CUDA repository, and the driver source "
55 0 ▶ .( $source ? $source->{name} : '(none)' ).' is not it';
Branch: 1 branch
BranchTrueFalseTotal
$source ? : 0 0 0
56 }
57  
58 145 ▶sub nonfree_branch {
Subroutine nonfree_branch: called CC=2 SCAR=7.1
Pod documented
59 145 my ( $self, $major ) = @_;
60 145 my %branch = ( 11 => 470, 12 => 535, 13 => 550 );
61 145 ▶ return $branch{ $major // 0 };
Condition50%1/2
$major // 0
l!l
1450
MC/DC0%0/1
$major // 0
$major
Truth table50%1/2
A
A= $major
Aresult
11
00
62 }
63  
64 145 ▶sub sources {
Subroutine sources: called CC=1 SCAR=0.0
Pod documented
65 145 my ( $self ) = @_;
66 145 my $major = $self->_major_version($self->release);
67 return (
68 {
69 145 name => 'debian-nonfree',
70 kernel_module => 'proprietary',
71 branch => $self->nonfree_branch($major),
72 # libcuda1 explicitly (karr #42): only a recommends of nvidia-driver
73 # (via libnvidia-encode1 -> libnvcuvid1), and already_installed needs it
74 packages => [ 'nvidia-driver', 'nvidia-smi', 'libcuda1' ],
75 verify => [ 'nvidia-driver', 'libcuda1' ],
76 # k100: nvidia-driver Depends on nvidia-kernel-dkms (= its own version)
77 # | nvidia-kernel-VERSION | nvidia-open-kernel-VERSION (bookworm
78 # 535.309.01-0+deb12u1, trixie 550.163.01-2; packages.debian.org and
79 # apt-cache show, 2026-11-26), so its version is the kernel module's
80 driver_version_from => 'nvidia-driver',
81 nonfree => 1
82 },
83 $self->_cuda_repo_source($major)
84 );
85 }
86  
87 # Debian + Blackwell (karr #18): no Debian-packaged driver supports Blackwell
88 # (bookworm 535, trixie/sid 550; Blackwell needs >= 570 AND the open kernel
89 # module), so it comes from NVIDIA's CUDA apt repo. Falling back to Debian
90 # non-free where NVIDIA has no repo would install a driver that dpkg reports
91 # as ii but whose module never binds; guessing a neighbouring repo would mix
92 # a foreign distro's libc/dkms into the host -- so that source is simply
93 # unavailable there.
94 #
95 # branch_at_least 590: the branch every tree carries. Checked 2026-09-23 in
96 # the repos' Packages.gz (nvidia-kernel-open-dkms): debian12/x86_64 545..615,
97 # debian12/sbsa 590..615, debian13/x86_64 590..615, debian13/sbsa 595..615.
98 # The repo installs its newest branch, which is at least that.
99 #
100 # NOT nvidia-driver in verify: that name exists in Debian non-free too, so a
101 # leftover Debian 535/550 install would pass it. nvidia-kernel-open-dkms
102 # exists only in NVIDIA's repo.
103 145 ▶sub _cuda_repo_source {
Subroutine _cuda_repo_source: called CC=7 SCAR=19.5
104 145 my ( $self, $major ) = @_;
105 145 my $packages = [ 'nvidia-driver-cuda', 'nvidia-kernel-open-dkms' ];
106 # Fabric Manager (karr #23): unversioned nvidia-fabricmanager from 580 on,
107 # with no dependency on the driver (Packages.gz of debian12/13, checked
108 # 2026-09-24), so its version is pinned to nvidia-kernel-open-dkms's.
109 145 my %source = (
110 name => 'nvidia-cuda-repo',
111 kernel_module => 'open',
112 branch_at_least => 590,
113 packages => $packages,
114 verify => [ @$packages ],
115 fabric_manager => 'nvidia-fabricmanager',
116 fabric_manager_match => 'nvidia-kernel-open-dkms',
117 # k100: the open kernel module itself; a held older one passes verify
118 driver_version_from => 'nvidia-kernel-open-dkms'
119 );
120 145 ▶ my $release = $self->release // '';
Condition100%2/2
$self->release // ""
l!l
1441
MC/DC100%1/1
$self->release // ""
$self->release
Truth table100%2/2
A
A= $self->release
Aresult
11
00
121 145 ▶ my $arch = $self->arch // '';
Condition100%2/2
$self->arch // ""
l!l
1441
MC/DC100%1/1
$self->arch // ""
$self->arch
Truth table100%2/2
A
A= $self->arch
Aresult
11
00
122 145 ▶ if ($major != 12 && $major != 13) {
Branch: 2 branches
BranchTrueFalseTotal
if ($major != 12 and $major != 13) { } 19 126 145
elsif ($arch ne 'amd64' and $arch ne 'arm64') { } 4 122 126
Condition100%3/3
$major != 12 and $major != 13
!ll&&!rl&&r
774919
MC/DC100%2/2
$major != 12 and $major != 13
$major != 12 $major != 13
Truth table100%3/3
A and B
A= $major != 12B= $major != 13
ABresult
0X0
100
111
123 19 $source{unavailable} = "NVIDIA's CUDA repo only covers Debian 12 and 13, not release '$release'";
124 }
125 ▶ elsif ($arch ne 'amd64' && $arch ne 'arm64') {
Condition100%3/3
$arch ne "amd64" and $arch ne "arm64"
!ll&&!rl&&r
11934
MC/DC100%2/2
$arch ne "amd64" and $arch ne "arm64"
$arch ne "amd64" $arch ne "arm64"
Truth table100%3/3
A and B
A= $arch ne "amd64"B= $arch ne "arm64"
ABresult
0X0
100
111
126 4 $source{unavailable} = "NVIDIA's CUDA repo only covers amd64 and arm64, not '$arch'";
127 }
128 else {
129 122 my $distro = "debian$major";
130 122 my $repo_arch = $self->_cuda_repo_arch($arch); # arm64 -> sbsa, amd64 -> x86_64
131 $source{cuda_repo} = {
132 122 distro => $distro,
133 arch => $repo_arch,
134 keyring_url => "https://developer.download.nvidia.com/compute/cuda/repos/$distro/$repo_arch/cuda-keyring_1.1-1_all.deb"
135 };
136 }
137 145 return \%source;
138 }
139  
140  
141 154 ▶sub plan {
Subroutine plan: called CC=2 SCAR=7.0
Pod documented
142 154 my ( $self ) = @_;
143 154 my $plan = $self->SUPER::plan;
144 118 ▶ $plan->{cuda_repo} = $plan->{source} && $plan->{source}{cuda_repo};
Condition66%2/3
$plan->{'source'} && $plan->{'source'}{'cuda_repo'}
!ll&&!rl&&r
08137
MC/DC50%1/2
$plan->{'source'} && $plan->{'source'}{'cuda_repo'}
$plan->{'source'} $plan->{'source'}{'cuda_repo'}
Truth table66%2/3
A && B
A= $plan->{'source'}B= $plan->{'source'}{'cuda_repo'}
ABresult
0X0
100
111
145 118 return $plan;
146 }
147  
148  
149 98 ▶sub prepare_host {
Subroutine prepare_host: called CC=3 SCAR=11.0
Pod documented
150 98 my ( $self, $plan ) = @_;
151 98 ▶ $self->enable_nonfree if $plan->{source} && $plan->{source}{nonfree};
Branch: 1 branch
BranchTrueFalseTotal
if $plan->{"source"} and $plan->{"source"}{"nonfree"} 69 29 98
Condition66%2/3
$plan->{"source"} and $plan->{"source"}{"nonfree"}
!ll&&!rl&&r
02969
MC/DC50%1/2
$plan->{"source"} and $plan->{"source"}{"nonfree"}
$plan->{"source"} $plan->{"source"}{"nonfree"}
Truth table66%2/3
A and B
A= $plan->{"source"}B= $plan->{"source"}{"nonfree"}
ABresult
0X0
100
111
152 98 $self->SUPER::prepare_host($plan);
153 }
154  
155  
156 98 ▶sub prepare_source {
Subroutine prepare_source: called CC=2 SCAR=6.9
Pod documented
157 98 my ( $self, $plan ) = @_;
158 98 ▶ $self->add_nvidia_cuda_apt_repo($plan->{cuda_repo}) if $plan->{cuda_repo};
Branch: 1 branch
BranchTrueFalseTotal
if $plan->{"cuda_repo"} 29 69 98
159 97 $self->SUPER::prepare_source($plan);
160 }
161  
162  
163 32 ▶sub add_nvidia_cuda_apt_repo {
Subroutine add_nvidia_cuda_apt_repo: called CC=2 SCAR=6.9
Pod documented
164 32 my ( $self, $repo ) = @_;
165 32 Rex::Logger::info(" Adding NVIDIA CUDA repo ($repo->{distro}/$repo->{arch})...");
166 # curl is an inert helper, so pkg is fine for it
167 32 $self->pkg_cmd(["curl"], ensure => "present");
168 $self->run_cmd(q{t=$(mktemp -d) && curl -fsSL -o "$t/cuda-keyring.deb" }
169 . $repo->{keyring_url}
170 32 . q{ && DEBIAN_FRONTEND=noninteractive }.$self->apt_get.q{ install -y "$t/cuda-keyring.deb"; rm -rf "$t"},
171 auto_die => 0);
172 # k94: a held (hi) cuda-keyring counts, as in Apt's verify_packages
173 32 my $check = $self->run_cmd("dpkg -l cuda-keyring 2>/dev/null | grep -q '^[hi]i'", auto_die => 0);
174 32 ▶ die "cuda-keyring not installed — cannot add NVIDIA's CUDA repo ($repo->{keyring_url})\n"
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 2 30 32
175 if $? != 0;
176 }
177  
178  
179 71 ▶sub enable_nonfree {
Subroutine enable_nonfree: called CC=3 SCAR=11.0
Pod documented
180 71 my ( $self ) = @_;
181 71 my $classic = $self->_enable_nonfree_sources_list;
182 71 my $deb822 = $self->_enable_nonfree_deb822;
183 # Names the way out (karr #41): an unknown mirror is not edited on purpose
184 71 ▶ Rex::Logger::info(" No Debian archive entry recognised in /etc/apt/sources.list or "
Branch: 1 branch
BranchTrueFalseTotal
unless $classic or $deb822 1 70 71
Condition100%3/3
$classic or $deb822
l!l&&r!l&&!r
47231
MC/DC100%2/2
$classic or $deb822
$classic $deb822
Truth table100%3/3
A or B
A= $classicB= $deb822
ABresult
1X1
011
000
185 . "/etc/apt/sources.list.d/*.sources — non-free was not enabled, Debian's "
186 . "nvidia-driver may have no installation candidate. For a mirror of your own, "
187 . "add signed-by=/usr/share/keyrings/debian-archive-keyring.gpg to its entries, "
188 . "or override is_debian_archive_uri in a subclass of ".__PACKAGE__
189 . " and choose it with set gpu_nvidia_setup (see eg/custom-setup in Rex-GPU)", 'warn')
190 unless $classic || $deb822;
191 }
192  
193 # Classic one-line format, /etc/apt/sources.list (karr #40): read with cat,
194 # the edit computed in Perl (_sources_list_enable_nonfree, pure) and a changed
195 # file written back with `file`. Returns the number of Debian archive "deb"
196 # lines recognised (edited or already complete); 0 for a missing, empty or
197 # comment-only file.
198 71 ▶sub _enable_nonfree_sources_list {
Subroutine _enable_nonfree_sources_list: called CC=5 SCAR=16.2
199 71 my ( $self ) = @_;
200 71 my $path = '/etc/apt/sources.list';
201 71 my $content = $self->run_cmd("cat $path 2>/dev/null", auto_die => 0);
202 71 ▶ return 0 if $? != 0 || !defined $content || $content eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 or not defined $content or $content eq "" 23 48 71
Condition66%4/6
$? != 0 or not defined $content or $content eq ""
l!l&&r!l&&!r
23048
$? != 0 or not defined $content
l!l&&r!l&&!r
23048
MC/DC33%1/3
$? != 0 or not defined $content or $content eq ""
$? != 0 not defined $content $content eq ""
Truth table50%2/4
A or not(B) or C
A= $? != 0B= not defined $contentC= $content eq ""
ABCresult
1XX1
01X1
0011
0000
203 48 my ($new, $matched) = $self->_sources_list_enable_nonfree($content);
204 48 ▶ if (defined $new) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 46 2 48
205 46 Rex::Logger::info(" Enabling non-free repos for NVIDIA drivers ($path)");
206 46 $self->file_cmd($path, content => $new, mode => 644);
207 }
208 48 return $matched;
209 }
210  
211 # Pure (karr #40): add the components contrib non-free non-free-firmware --
212 # only those missing, after the last component -- to every one-line "deb"
213 # entry that is a Debian archive. $content is sources.list as `cat` returns
214 # it (last newline chomped). Returns ($new_content, $matched): $new_content
215 # undef when nothing changed (idempotent), $matched the Debian archive lines
216 # seen. Every other line -- comments, deb-src, third-party entries,
217 # unparseable lines -- is kept byte for byte; an edited line keeps its
218 # options, spacing and trailing # comment.
219 #
220 # A line is a Debian archive -- and edited -- only if ALL of:
221 # * it is an active "deb" line (not "deb-src", not commented out), in the
222 # form deb [ options ] URI suite component... (options optional);
223 # * its components include "main";
224 # * _debian_archive_entry accepts its URI and signed-by= (the same rules
225 # as deb822).
226 # The Debian 12 installer writes "deb ... bookworm main non-free-firmware":
227 # non-free-firmware is not non-free.
228 97 ▶sub _sources_list_enable_nonfree {
Subroutine _sources_list_enable_nonfree: called CC=13 SCAR=25.6
229 97 my ( $self, $content ) = @_;
230 97 ▶ return (undef, 0) unless defined $content && length $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content and length $content 2 95 97
Condition100%3/3
defined $content and length $content
!ll&&!rl&&r
1195
MC/DC100%2/2
defined $content and length $content
defined $content length $content
Truth table100%3/3
A and B
A= defined $contentB= length $content
ABresult
0X0
100
111
231  
232 95 my @lines = split /^/m, $content;
233 95 ▶ $lines[-1] .= "\n" unless $lines[-1] =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines[-1] =~ /\n\z/ 6 89 95
234  
235 95 my ($changed, $matched) = (0, 0);
236 95 for my $line (@lines) {
237 230 my ($body, $eol) = $line =~ /\A(.*?)(\r?\n)\z/s;
238 230 ▶ next unless $body =~ /\A[ \t]*deb[ \t]+
Branch: 1 branch
BranchTrueFalseTotal
unless $body =~ /\A[ \t]*deb[ \t]+ (?:\[([^\]]*)\][ \t]*)? # 1: options (\S+)[ \t]+(\S+) # 2: URI 3: suite ((?:[ \t]+[^\s\#]+)*) # 4: components ([ \t]*(?:\#.*)?)\z # 5: trailing space, comment /x 33 197 230
239 (?:\[([^\]]*)\][ \t]*)? # 1: options
240 (\S+)[ \t]+(\S+) # 2: URI 3: suite
241 ((?:[ \t]+[^\s\#]+)*) # 4: components
242 ([ \t]*(?:\#.*)?)\z # 5: trailing space, comment
243 /x;
244 197 ▶ my ($opts, $uri, $comps, $rest) = ($1 // '', $2, $4, $5);
Condition100%2/2
$1 // ""
l!l
24173
MC/DC100%1/1
$1 // ""
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
245 197 my @comps = split ' ', $comps;
246 197 ▶ next unless grep { $_ eq 'main' } @comps;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "main";} @comps 3 194 197
247 194 ▶ my @signed_by = map { /^signed-by=(.*)$/i ? ($1) : () } split ' ', $opts;
Branch: 1 branch
BranchTrueFalseTotal
/^signed-by=(.*)$/i ? : 21 1 22
248 next unless $self->_debian_archive_entry([ $uri ],
249 194 ▶ @signed_by ? [ map { split /,/ } @signed_by ] : undef);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->_debian_archive_entry([$uri], @signed_by ? [map({split(/,/, $_, 0);} @signed_by)] : undef) 23 171 194
@signed_by ? : 21 173 194
250 171 $matched++;
251  
252 171 my %have = map { $_ => 1 } @comps;
253 171 my @missing = grep { !$have{$_} } qw( contrib non-free non-free-firmware );
254 171 ▶ next unless @missing;
Branch: 1 branch
BranchTrueFalseTotal
unless @missing 12 159 171
255 159 my $head = substr($body, 0, length($body) - length($rest));
256 159 $line = $head.' '.join(' ', @missing).$rest.$eol;
257 159 $changed++;
258 }
259 95 ▶ return ($changed ? join('', @lines) : undef, $matched);
Branch: 1 branch
BranchTrueFalseTotal
$changed ? : 62 33 95
260 }
261  
262 # deb822 format (karr #36): /etc/apt/sources.list.d/*.sources, the default on
263 # Debian 13 and on Debian's cloud images (debian.sources). Files are read with
264 # cat, the edit is computed in Perl (_deb822_enable_nonfree, pure) and a
265 # changed file is written back with `file` -- exec-channel only under
266 # Rex::LibSSH, no SFTP. Only names apt itself reads are considered (letters,
267 # digits, _ . - ending in .sources), which also keeps them shell-safe.
268 # Returns the number of Debian archive stanzas recognised.
269 71 ▶sub _enable_nonfree_deb822 {
Subroutine _enable_nonfree_deb822: called CC=7 SCAR=20.2
270 71 my ( $self ) = @_;
271 71 my $dir = '/etc/apt/sources.list.d';
272 71 ▶ my @names = grep { /^[A-Za-z0-9_.-]+\.sources$/ }
Condition50%1/2
$self->run_cmd("ls -1 $dir/ 2>/dev/null", "auto_die", 0) // ""
l!l
710
MC/DC0%0/1
$self->run_cmd("ls -1 $dir/ 2>/dev/null", "auto_die", 0) // ""
$self->run_cmd("ls -1 $dir/ 2>/dev/null", "auto_die", 0)
Truth table50%1/2
A
A= $self->run_cmd("ls -1 $dir/ 2>/dev/null", "auto_die", 0)
Aresult
11
00
273 split /\n/, ($self->run_cmd("ls -1 $dir/ 2>/dev/null", auto_die => 0)) // '';
274  
275 71 my $recognised = 0;
276 71 for my $name (@names) {
277 25 my $path = "$dir/$name";
278 25 my $content = $self->run_cmd("cat $path 2>/dev/null", auto_die => 0);
279 25 ▶ next if $? != 0 || !defined $content || $content eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 or not defined $content or $content eq "" 0 25 25
Condition33%2/6
$? != 0 or not defined $content or $content eq ""
l!l&&r!l&&!r
0025
$? != 0 or not defined $content
l!l&&r!l&&!r
0025
MC/DC0%0/3
$? != 0 or not defined $content or $content eq ""
$? != 0 not defined $content $content eq ""
Truth table25%1/4
A or not(B) or C
A= $? != 0B= not defined $contentC= $content eq ""
ABCresult
1XX1
01X1
0011
0000
280 25 my ($new, $matched) = $self->_deb822_enable_nonfree($content);
281 25 $recognised += $matched;
282 25 ▶ next unless defined $new;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 2 23 25
283 23 Rex::Logger::info(" Enabling non-free repos for NVIDIA drivers ($path)");
284 23 $self->file_cmd($path, content => $new, mode => 644);
285 }
286 71 return $recognised;
287 }
288  
289 # Pure (karr #36): add the components contrib non-free non-free-firmware --
290 # only those missing -- to the Components: field of every deb822 stanza that
291 # is a Debian archive. Returns ($new_content, $matched) like
292 # _sources_list_enable_nonfree. Every line not rewritten is kept byte for
293 # byte, comments included.
294 #
295 # A stanza is a Debian archive -- and edited -- only if ALL of:
296 # * Types: lists "deb", and Enabled: is not "no";
297 # * Components: lists "main";
298 # * _debian_archive_entry accepts its URIs: and Signed-By:.
299 # Suites are deliberately not matched against codenames. An unknown mirror is
300 # NOT edited: the caller then warns, and the driver install dies at its dpkg
301 # check, rather than this editing a repository it cannot identify.
302 64 ▶sub _deb822_enable_nonfree {
Subroutine _deb822_enable_nonfree: called CC=15 SCAR=27.1
303 64 my ( $self, $content ) = @_;
304 64 ▶ return (undef, 0) unless defined $content && length $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content and length $content 2 62 64
Condition100%3/3
defined $content and length $content
!ll&&!rl&&r
1162
MC/DC100%2/2
defined $content and length $content
defined $content length $content
Truth table100%3/3
A and B
A= defined $contentB= length $content
ABresult
0X0
100
111
305  
306 62 my @lines = split /^/m, $content;
307 62 ▶ $lines[-1] .= "\n" unless $lines[-1] =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines[-1] =~ /\n\z/ 26 36 62
308  
309 # Stanzas: runs of lines separated by blank lines. Per stanza, per field
310 # (lower-cased name): its value and the index of its last line.
311 62 my (@stanzas, $cur, $field);
312 62 for my $i (0 .. $#lines) {
313 478 my $l = $lines[$i];
314 478 ▶ if ($l =~ /^\s*$/) { undef $cur; undef $field; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /^\s*$/) 30 448 478
315 448 ▶ unless ($cur) { $cur = {}; push @stanzas, $cur }
Branch: 1 branch
BranchTrueFalseTotal
unless ($cur) 91 357 448
316 448 ▶ next if $l =~ /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /^#/ 4 444 448
317 444 ▶ if ($l =~ /^([A-Za-z0-9][A-Za-z0-9_-]*):[ \t]*(.*?)\s*$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($l =~ /^([A-Za-z0-9][A-Za-z0-9_-]*):[ \t]*(.*?)\s*$/) { } 434 10 444
elsif ($field and $l =~ /^[ \t]+(.*?)\s*$/) { } 10 0 10
318 434 $field = lc $1;
319 434 $cur->{$field} = { value => $2, last => $i };
320 }
321 ▶ elsif ($field && $l =~ /^[ \t]+(.*?)\s*$/) {
Condition33%1/3
$field and $l =~ /^[ \t]+(.*?)\s*$/
!ll&&!rl&&r
0010
MC/DC0%0/2
$field and $l =~ /^[ \t]+(.*?)\s*$/
$field $l =~ /^[ \t]+(.*?)\s*$/
Truth table33%1/3
A and B
A= $fieldB= $l =~ /^[ \t]+(.*?)\s*$/
ABresult
0X0
100
111
322 10 $cur->{$field}{value} .= ' '.$1;
323 10 $cur->{$field}{last} = $i;
324 }
325 }
326  
327 62 my ($changed, $matched) = (0, 0);
328 62 for my $s (@stanzas) {
329 91 ▶ next unless $self->_deb822_is_debian_archive($s);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_deb822_is_debian_archive($s) 23 68 91
330 68 $matched++;
331 68 my %have = map { $_ => 1 } split ' ', $s->{components}{value};
332 68 my @missing = grep { !$have{$_} } qw( contrib non-free non-free-firmware );
333 68 ▶ next unless @missing;
Branch: 1 branch
BranchTrueFalseTotal
unless @missing 4 64 68
334 64 my $i = $s->{components}{last};
335 64 $lines[$i] =~ s/[ \t]*(\r?\n)\z/' '.join(' ', @missing).$1/e;
336 64 $changed++;
337 }
338 62 ▶ return ($changed ? join('', @lines) : undef, $matched);
Branch: 1 branch
BranchTrueFalseTotal
$changed ? : 38 24 62
339 }
340  
341 91 ▶sub _deb822_is_debian_archive {
Subroutine _deb822_is_debian_archive: called CC=6 SCAR=17.9
342 91 my ( $self, $s ) = @_;
343 91 ▶ my $tokens = sub { my $f = $s->{$_[0]}; $f ? split(' ', $f->{value}) : () };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$f ? : 265 2 267
344  
345 91 ▶ return 0 unless grep { $_ eq 'deb' } $tokens->('types');
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "deb";} &$tokens("types") 1 90 91
346 90 ▶ return 0 if $s->{enabled} && lc $s->{enabled}{value} eq 'no';
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"enabled"} and lc $s->{"enabled"}{"value"} eq "no" 1 89 90
Condition66%2/3
$s->{"enabled"} and lc $s->{"enabled"}{"value"} eq "no"
!ll&&!rl&&r
8901
MC/DC50%1/2
$s->{"enabled"} and lc $s->{"enabled"}{"value"} eq "no"
$s->{"enabled"} lc $s->{"enabled"}{"value"} eq "no"
Truth table66%2/3
A and B
A= $s->{"enabled"}B= lc $s->{"enabled"}{"value"} eq "no"
ABresult
0X0
100
111
347 89 ▶ return 0 unless grep { $_ eq 'main' } $tokens->('components');
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "main";} &$tokens("components") 2 87 89
348  
349 return $self->_debian_archive_entry([ $tokens->('uris') ],
350 87 ▶ $s->{'signed-by'} ? [ split /[\s,]+/, $s->{'signed-by'}{value} ] : undef);
Branch: 1 branch
BranchTrueFalseTotal
$s->{'signed-by'} ? : 70 17 87
351 }
352  
353 # Shared by both formats (karr #36, #40, #41): does an entry with these URIs
354 # and signed-by keys (arrayref; undef = no signed-by at all) point at
355 # Debian's archive? With signed-by, the keys alone decide: at least one, all
356 # accepted by is_debian_archive_keyring -- a repo apt verifies with Debian's
357 # archive key is Debian's archive or a mirror of it, whatever its host, and
358 # an inline key or any other keyring means a third-party repo even on a
359 # Debian URI. Without it every URI must pass is_debian_archive_uri.
360 281 ▶sub _debian_archive_entry {
Subroutine _debian_archive_entry: called CC=8 SCAR=20.8
361 281 my ( $self, $uris, $keys ) = @_;
362 281 ▶ return 0 unless @$uris;
Branch: 1 branch
BranchTrueFalseTotal
unless @$uris 1 280 281
363 280 ▶ if ($keys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keys) 91 189 280
364 91 my @keys = grep { length } @$keys;
365 91 ▶ return 0 unless @keys;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys 1 90 91
366 90 for my $key (@keys) {
367 96 ▶ return 0 unless $self->is_debian_archive_keyring($key);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_debian_archive_keyring($key) 22 74 96
368 }
369 68 return 1;
370 }
371 189 for my $uri (@$uris) {
372 190 ▶ return 0 unless $self->is_debian_archive_uri($uri);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_debian_archive_uri($uri) 18 172 190
373 }
374 171 return 1;
375 }
376  
377 189 ▶sub is_debian_archive_uri {
Subroutine is_debian_archive_uri: called CC=8 SCAR=20.8
Pod documented
378 189 my ( $self, $uri ) = @_;
379 189 ▶ return 1 if $uri =~ m{^mirror\+file:(?://)?/etc/apt/mirrors/debian(?:-security)?\.list$};
Branch: 1 branch
BranchTrueFalseTotal
if $uri =~ m[^mirror\+file:(?://)?/etc/apt/mirrors/debian(?:-security)?\.list$] 3 186 189
380 186 ▶ return 0 unless $uri =~ m{^(?:[a-z0-9]+\+)?(?:https?|ftp)://([^/:\s]+)(?::\d+)?(/\S*)?$}i;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri =~ m[^(?:[a-z0-9]+\+)?(?:https?|ftp)://([^/:\s]+)(?::\d+)?(/\S*)?$]i 1 185 186
381 185 ▶ my ($host, $path) = (lc $1, $2 // '/');
Condition100%2/2
$2 // "/"
l!l
1832
MC/DC100%1/1
$2 // "/"
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
382 185 ▶ return 1 if $host eq 'debian.org' || $host =~ /\.debian\.org$/;
Branch: 1 branch
BranchTrueFalseTotal
if $host eq "debian.org" or $host =~ /\.debian\.org$/ 163 22 185
Condition66%2/3
$host eq "debian.org" or $host =~ /\.debian\.org$/
l!l&&r!l&&!r
016322
MC/DC50%1/2
$host eq "debian.org" or $host =~ /\.debian\.org$/
$host eq "debian.org" $host =~ /\.debian\.org$/
Truth table66%2/3
A or B
A= $host eq "debian.org"B= $host =~ /\.debian\.org$/
ABresult
1X1
011
000
383 22 ▶ return 1 if $host =~ /^mirror\.hetzner\.(?:com|de)$/ && $path =~ m{^/debian/};
Branch: 1 branch
BranchTrueFalseTotal
if $host =~ /^mirror\.hetzner\.(?:com|de)$/ and $path =~ m[^/debian/] 4 18 22
Condition100%3/3
$host =~ /^mirror\.hetzner\.(?:com|de)$/ and $path =~ m[^/debian/]
!ll&&!rl&&r
1624
MC/DC100%2/2
$host =~ /^mirror\.hetzner\.(?:com|de)$/ and $path =~ m[^/debian/]
$host =~ /^mirror\.hetzner\.(?:com|de)$/ $path =~ m[^/debian/]
Truth table100%3/3
A and B
A= $host =~ /^mirror\.hetzner\.(?:com|de)$/B= $path =~ m[^/debian/]
ABresult
0X0
100
111
384 18 return 0;
385 }
386  
387 95 ▶sub is_debian_archive_keyring {
Subroutine is_debian_archive_keyring: called CC=2 SCAR=6.9
Pod documented
388 95 my ( $self, $path ) = @_;
389 95 ▶ return $path =~ m{^/usr/share/keyrings/debian-archive-[A-Za-z0-9_.-]+\.(?:gpg|pgp|asc)$} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$path =~ m[^/usr/share/keyrings/debian-archive-[A-Za-z0-9_.-]+\.(?:gpg|pgp|asc)$] ? : 73 22 95
390 }
391  
392 49 1;
393  
394 __END__
« lib/Rex/GPU/NVIDIA.pm ↑ Summary blib/lib/Rex/GPU/Detect.pm »