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