|
| 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 subprocess |
| 24 | + |
| 25 | +APT_CONF = "/etc/apt/apt.conf.d/01qubes-update" |
| 26 | +sources_list = "/etc/apt/sources.list" |
| 27 | +backports_line = "deb https://deb.debian.org/debian bookworm-backports main contrib non-free-firmware" |
| 28 | +prefs_path = "/etc/apt/preferences.d/firmware_backports" |
| 29 | +prefs_data = """\ |
| 30 | +Package: src:firmware-nonfree |
| 31 | +Pin: release n=bookworm-backports |
| 32 | +Pin-Priority: 600 |
| 33 | +""" |
| 34 | + |
| 35 | + |
| 36 | +def firmware_backports(os_data, log, **kwargs): |
| 37 | + """ |
| 38 | + Update firmware packages from backports repository. |
| 39 | +
|
| 40 | + https://github.com/QubesOS/qubes-issues/issues/9815 |
| 41 | + """ |
| 42 | + if os_data.get("codename", "") == "bookworm": |
| 43 | + # do anything only if firmware package is installed already |
| 44 | + try: |
| 45 | + output = subprocess.check_output( |
| 46 | + ["dpkg", "-l", "firmware-linux-nonfree"], |
| 47 | + stderr=subprocess.DEVNULL, |
| 48 | + ) |
| 49 | + if b"bpo" in output: |
| 50 | + # version from backports already installed |
| 51 | + return |
| 52 | + except subprocess.CalledProcessError: |
| 53 | + return |
| 54 | + # first, add bookworm-backports if not already there: |
| 55 | + with open(sources_list) as sources: |
| 56 | + current_sources = sources.read() |
| 57 | + if "bookworm-backports" not in current_sources: |
| 58 | + with open(sources_list, "a") as sources: |
| 59 | + sources.write("\n" + backports_line + "\n") |
| 60 | + # then pin firmware packages to backports repo |
| 61 | + if not os.path.exists(prefs_path): |
| 62 | + with open(prefs_path, "w") as prefs: |
| 63 | + prefs.write(prefs_data) |
0 commit comments