Skip to content

Commit 306db22

Browse files
committed
Update firmware packages from bookworm-backports on Debian 12
Firmware packages in standard Debian repo are too old for recent kernels, and recent hardware in general. This affects all kernel-latest versions, but also soon-to-be-default kernel-6.12. This is at least necessary to support wifi network in NovaCustom laptops, but other modern systems need that too. Fresh template builds have firmware from bookworm-backports already selected, but do that for older versions too. Build the URL based on `apt-get --print-uris update` output to match protocol used for the main Debian repo (tor, apt-cacher-ng etc). Thanks @aronowski for the hint on apt properties. Fixes QubesOS/qubes-issues#9815
1 parent a415729 commit 306db22

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# coding=utf-8
2+
#
3+
# The Qubes OS Project, http://www.qubes-os.org
4+
#
5+
# Copyright (C) 2025 Marek Marczykowski-Górecki
6+
# <marmarek@invisiblethingslab.com>
7+
#
8+
# This program is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU General Public License
10+
# as published by the Free Software Foundation; either version 2
11+
# of the License, or (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program; if not, write to the Free Software
20+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21+
# USA.
22+
23+
import os
24+
import subprocess
25+
26+
sources_list = "/etc/apt/sources.list.d/backports.list"
27+
base_repo_url = "deb.debian.org/debian/dists/bookworm/InRelease"
28+
backports_line = (
29+
"deb {baseurl} bookworm-backports main contrib non-free-firmware\n"
30+
)
31+
prefs_path = "/etc/apt/preferences.d/firmware_backports"
32+
prefs_data = """\
33+
Package: src:firmware-nonfree
34+
Pin: release n=bookworm-backports
35+
Pin-Priority: 600
36+
"""
37+
38+
39+
def firmware_backports(os_data, log, **kwargs):
40+
"""
41+
Update firmware packages from backports repository.
42+
43+
https://github.com/QubesOS/qubes-issues/issues/9815
44+
"""
45+
if os_data.get("codename", "") == "bookworm":
46+
# do anything only if firmware package is installed already
47+
try:
48+
output = subprocess.check_output(
49+
["dpkg", "-l", "firmware-linux-nonfree"],
50+
stderr=subprocess.DEVNULL,
51+
)
52+
if b"bpo" in output:
53+
# version from backports already installed
54+
return
55+
except subprocess.CalledProcessError:
56+
return
57+
# find URL flavor used for deb.debian.org
58+
try:
59+
output = subprocess.check_output(
60+
["apt-get", "--print-uris", "update"],
61+
stderr=subprocess.DEVNULL,
62+
)
63+
except subprocess.CalledProcessError:
64+
return
65+
baseurl = None
66+
for url in output.decode().splitlines():
67+
if not baseurl and base_repo_url in url:
68+
baseurl = (
69+
url.split()[0]
70+
.strip("'")
71+
.replace("/dists/bookworm/InRelease", "")
72+
)
73+
if "/debian/dists/bookworm-backports/" in url:
74+
# backports already enabled
75+
return
76+
# add bookworm-backports if not already there
77+
if baseurl and not os.path.exists(sources_list):
78+
with open(sources_list, "w") as sources:
79+
sources.write(backports_line.format(baseurl=baseurl))
80+
# then pin firmware packages to backports repo
81+
if not os.path.exists(prefs_path):
82+
with open(prefs_path, "w") as prefs:
83+
prefs.write(prefs_data)

0 commit comments

Comments
 (0)