forked from Mirror/pmbootstrap
pmb.config: do not prompt for nonfree fw/userland (MR 2255)
This drops the prompt for using non-free firmware in images. The logic for searching/installing non-free fw subpackages for devices is kept, and will always be installed. This is to support the many device packages in pmaports that still have nonfree-firmware subpackages. Going forward, device packages can list firmware in `depends=` (for required fw) or `pmb_recommends` (for optional fw). nonfree-userland wasn't used in pmaports as far as I could find.
This commit is contained in:
parent
0bed6a0437
commit
aa594b76fa
5 changed files with 19 additions and 107 deletions
|
@ -89,8 +89,6 @@ config_keys = [
|
||||||
"locale",
|
"locale",
|
||||||
"mirror_alpine",
|
"mirror_alpine",
|
||||||
"mirrors_postmarketos",
|
"mirrors_postmarketos",
|
||||||
"nonfree_firmware",
|
|
||||||
"nonfree_userland",
|
|
||||||
"qemu_redir_stdio",
|
"qemu_redir_stdio",
|
||||||
"ssh_key_glob",
|
"ssh_key_glob",
|
||||||
"ssh_keys",
|
"ssh_keys",
|
||||||
|
@ -126,8 +124,6 @@ defaults = {
|
||||||
# NOTE: mirrors_postmarketos variable type is supposed to be
|
# NOTE: mirrors_postmarketos variable type is supposed to be
|
||||||
# comma-separated string, not a python list or any other type!
|
# comma-separated string, not a python list or any other type!
|
||||||
"mirrors_postmarketos": "http://mirror.postmarketos.org/postmarketos/",
|
"mirrors_postmarketos": "http://mirror.postmarketos.org/postmarketos/",
|
||||||
"nonfree_firmware": True,
|
|
||||||
"nonfree_userland": False,
|
|
||||||
"qemu_redir_stdio": False,
|
"qemu_redir_stdio": False,
|
||||||
"ssh_key_glob": "~/.ssh/id_*.pub",
|
"ssh_key_glob": "~/.ssh/id_*.pub",
|
||||||
"ssh_keys": False,
|
"ssh_keys": False,
|
||||||
|
|
|
@ -349,54 +349,15 @@ def ask_for_device_kernel(args, device):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def ask_for_device_nonfree(args, device):
|
|
||||||
"""
|
|
||||||
Ask the user about enabling proprietary firmware (e.g. Wifi) and userland
|
|
||||||
(e.g. GPU drivers). All proprietary components are in subpackages
|
|
||||||
$pkgname-nonfree-firmware and $pkgname-nonfree-userland, and we show the
|
|
||||||
description of these subpackages (so they can indicate which peripherals
|
|
||||||
are affected).
|
|
||||||
|
|
||||||
:returns: answers as dict, e.g. {"firmware": True, "userland": False}
|
|
||||||
"""
|
|
||||||
# Parse existing APKBUILD or return defaults (when called from test case)
|
|
||||||
apkbuild_path = pmb.helpers.devices.find_path(args, device, 'APKBUILD')
|
|
||||||
ret = {"firmware": args.nonfree_firmware,
|
|
||||||
"userland": args.nonfree_userland}
|
|
||||||
if not apkbuild_path:
|
|
||||||
return ret
|
|
||||||
apkbuild = pmb.parse.apkbuild(apkbuild_path)
|
|
||||||
|
|
||||||
# Only run when there is a "nonfree" subpackage
|
|
||||||
nonfree_found = False
|
|
||||||
for subpackage in apkbuild["subpackages"].keys():
|
|
||||||
if subpackage.startswith(f"device-{device}-nonfree"):
|
|
||||||
nonfree_found = True
|
|
||||||
if not nonfree_found:
|
|
||||||
return ret
|
|
||||||
|
|
||||||
# Short explanation
|
|
||||||
logging.info("This device has proprietary components, which trade some of"
|
|
||||||
" your freedom with making more peripherals work.")
|
|
||||||
logging.info("We would like to offer full functionality without hurting"
|
|
||||||
" your freedom, but this is currently not possible for your"
|
|
||||||
" device.")
|
|
||||||
|
|
||||||
# Ask for firmware and userland individually
|
|
||||||
for type in ["firmware", "userland"]:
|
|
||||||
subpkgname = f"device-{device}-nonfree-{type}"
|
|
||||||
subpkg = apkbuild["subpackages"].get(subpkgname, {})
|
|
||||||
if subpkg is None:
|
|
||||||
raise RuntimeError("Cannot find subpackage function for "
|
|
||||||
f"{subpkgname}")
|
|
||||||
if subpkg:
|
|
||||||
logging.info(f"{subpkgname}: {subpkg['pkgdesc']}")
|
|
||||||
ret[type] = pmb.helpers.cli.confirm(args, "Enable this package?",
|
|
||||||
default=ret[type])
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def ask_for_device(args):
|
def ask_for_device(args):
|
||||||
|
"""
|
||||||
|
Prompt for the device vendor, model, and kernel.
|
||||||
|
|
||||||
|
:returns: Tuple consisting of: (device, device_exists, kernel)
|
||||||
|
* device: "<vendor>-<codename>" string for device
|
||||||
|
* device_exists: bool indicating if device port exists in repo
|
||||||
|
* kernel: type of kernel (downstream, etc)
|
||||||
|
"""
|
||||||
vendors = sorted(pmb.helpers.devices.list_vendors(args))
|
vendors = sorted(pmb.helpers.devices.list_vendors(args))
|
||||||
logging.info("Choose your target device vendor (either an "
|
logging.info("Choose your target device vendor (either an "
|
||||||
"existing one, or a new one for porting).")
|
"existing one, or a new one for porting).")
|
||||||
|
@ -463,8 +424,7 @@ def ask_for_device(args):
|
||||||
break
|
break
|
||||||
|
|
||||||
kernel = ask_for_device_kernel(args, device)
|
kernel = ask_for_device_kernel(args, device)
|
||||||
nonfree = ask_for_device_nonfree(args, device)
|
return (device, device_exists, kernel)
|
||||||
return (device, device_exists, kernel, nonfree)
|
|
||||||
|
|
||||||
|
|
||||||
def ask_for_additional_options(args, cfg):
|
def ask_for_additional_options(args, cfg):
|
||||||
|
@ -691,11 +651,9 @@ def frontend(args):
|
||||||
pmb.config.pmaports.install_githooks(args)
|
pmb.config.pmaports.install_githooks(args)
|
||||||
|
|
||||||
# Device
|
# Device
|
||||||
device, device_exists, kernel, nonfree = ask_for_device(args)
|
device, device_exists, kernel = ask_for_device(args)
|
||||||
cfg["pmbootstrap"]["device"] = device
|
cfg["pmbootstrap"]["device"] = device
|
||||||
cfg["pmbootstrap"]["kernel"] = kernel
|
cfg["pmbootstrap"]["kernel"] = kernel
|
||||||
cfg["pmbootstrap"]["nonfree_firmware"] = str(nonfree["firmware"])
|
|
||||||
cfg["pmbootstrap"]["nonfree_userland"] = str(nonfree["userland"])
|
|
||||||
|
|
||||||
info = pmb.parse.deviceinfo(args, device)
|
info = pmb.parse.deviceinfo(args, device)
|
||||||
apkbuild_path = pmb.helpers.devices.find_path(args, device, 'APKBUILD')
|
apkbuild_path = pmb.helpers.devices.find_path(args, device, 'APKBUILD')
|
||||||
|
|
|
@ -62,8 +62,8 @@ def get_subpartitions_size(args, suffix):
|
||||||
|
|
||||||
def get_nonfree_packages(args, device):
|
def get_nonfree_packages(args, device):
|
||||||
"""
|
"""
|
||||||
Get the non-free packages based on user's choice in "pmbootstrap init" and
|
Get any legacy non-free subpackages in the APKBUILD.
|
||||||
based on whether there are non-free packages in the APKBUILD or not.
|
Also see: https://postmarketos.org/edge/2024/02/15/default-nonfree-fw/
|
||||||
|
|
||||||
:returns: list of non-free packages to be installed. Example:
|
:returns: list of non-free packages to be installed. Example:
|
||||||
["device-nokia-n900-nonfree-firmware"]
|
["device-nokia-n900-nonfree-firmware"]
|
||||||
|
@ -76,9 +76,9 @@ def get_nonfree_packages(args, device):
|
||||||
# Check for firmware and userland
|
# Check for firmware and userland
|
||||||
ret = []
|
ret = []
|
||||||
prefix = "device-" + device + "-nonfree-"
|
prefix = "device-" + device + "-nonfree-"
|
||||||
if args.nonfree_firmware and prefix + "firmware" in subpackages:
|
if prefix + "firmware" in subpackages:
|
||||||
ret += [prefix + "firmware"]
|
ret += [prefix + "firmware"]
|
||||||
if args.nonfree_userland and prefix + "userland" in subpackages:
|
if prefix + "userland" in subpackages:
|
||||||
ret += [prefix + "userland"]
|
ret += [prefix + "userland"]
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,6 @@ def test_get_nonfree_packages(args):
|
||||||
func = pmb.install._install.get_nonfree_packages
|
func = pmb.install._install.get_nonfree_packages
|
||||||
|
|
||||||
# Device without any non-free subpackages
|
# Device without any non-free subpackages
|
||||||
args.nonfree_firmware = True
|
|
||||||
args.nonfree_userland = True
|
|
||||||
assert func(args, "lg-mako") == []
|
assert func(args, "lg-mako") == []
|
||||||
|
|
||||||
# Device with non-free firmware and userland
|
# Device with non-free firmware and userland
|
||||||
|
@ -43,10 +41,6 @@ def test_get_nonfree_packages(args):
|
||||||
device = "nonfree-userland"
|
device = "nonfree-userland"
|
||||||
assert func(args, device) == ["device-" + device + "-nonfree-userland"]
|
assert func(args, device) == ["device-" + device + "-nonfree-userland"]
|
||||||
|
|
||||||
# Device with non-free userland (but user disabled it init)
|
|
||||||
args.nonfree_userland = False
|
|
||||||
assert func(args, device) == []
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_recommends(args):
|
def test_get_recommends(args):
|
||||||
args.aports = pmb_test.const.testdata + "/pmb_recommends"
|
args.aports = pmb_test.const.testdata + "/pmb_recommends"
|
||||||
|
|
|
@ -108,8 +108,6 @@ def test_questions_device(args, monkeypatch):
|
||||||
# Prepare args
|
# Prepare args
|
||||||
args.aports = pmb_test.const.testdata + "/init_questions_device/aports"
|
args.aports = pmb_test.const.testdata + "/init_questions_device/aports"
|
||||||
args.device = "lg-mako"
|
args.device = "lg-mako"
|
||||||
args.nonfree_firmware = True
|
|
||||||
args.nonfree_userland = False
|
|
||||||
args.kernel = "downstream"
|
args.kernel = "downstream"
|
||||||
|
|
||||||
# Do not generate aports
|
# Do not generate aports
|
||||||
|
@ -119,26 +117,25 @@ def test_questions_device(args, monkeypatch):
|
||||||
|
|
||||||
# Existing device (without non-free components so we have defaults there)
|
# Existing device (without non-free components so we have defaults there)
|
||||||
func = pmb.config.init.ask_for_device
|
func = pmb.config.init.ask_for_device
|
||||||
nonfree = {"firmware": True, "userland": False}
|
|
||||||
fake_answers(monkeypatch, ["lg", "mako"])
|
fake_answers(monkeypatch, ["lg", "mako"])
|
||||||
kernel = args.kernel
|
kernel = args.kernel
|
||||||
assert func(args) == ("lg-mako", True, kernel, nonfree)
|
assert func(args) == ("lg-mako", True, kernel)
|
||||||
|
|
||||||
# Non-existing vendor, go back, existing vendor+device
|
# Non-existing vendor, go back, existing vendor+device
|
||||||
fake_answers(monkeypatch, ["whoops", "n", "lg", "mako"])
|
fake_answers(monkeypatch, ["whoops", "n", "lg", "mako"])
|
||||||
assert func(args) == ("lg-mako", True, kernel, nonfree)
|
assert func(args) == ("lg-mako", True, kernel)
|
||||||
|
|
||||||
# Existing vendor, new device, go back, existing vendor+device
|
# Existing vendor, new device, go back, existing vendor+device
|
||||||
fake_answers(monkeypatch, ["lg", "nonexistent", "n", "lg", "mako"])
|
fake_answers(monkeypatch, ["lg", "nonexistent", "n", "lg", "mako"])
|
||||||
assert func(args) == ("lg-mako", True, kernel, nonfree)
|
assert func(args) == ("lg-mako", True, kernel)
|
||||||
|
|
||||||
# New vendor and new device (new port)
|
# New vendor and new device (new port)
|
||||||
fake_answers(monkeypatch, ["new", "y", "device", "y"])
|
fake_answers(monkeypatch, ["new", "y", "device", "y"])
|
||||||
assert func(args) == ("new-device", False, kernel, nonfree)
|
assert func(args) == ("new-device", False, kernel)
|
||||||
|
|
||||||
# Existing vendor, new device (new port)
|
# Existing vendor, new device (new port)
|
||||||
fake_answers(monkeypatch, ["lg", "nonexistent", "y"])
|
fake_answers(monkeypatch, ["lg", "nonexistent", "y"])
|
||||||
assert func(args) == ("lg-nonexistent", False, kernel, nonfree)
|
assert func(args) == ("lg-nonexistent", False, kernel)
|
||||||
|
|
||||||
|
|
||||||
def test_questions_device_kernel(args, monkeypatch):
|
def test_questions_device_kernel(args, monkeypatch):
|
||||||
|
@ -161,39 +158,6 @@ def test_questions_device_kernel(args, monkeypatch):
|
||||||
assert func(args, device) == "downstream"
|
assert func(args, device) == "downstream"
|
||||||
|
|
||||||
|
|
||||||
def test_questions_device_nonfree(args, monkeypatch):
|
|
||||||
# Prepare args
|
|
||||||
args.aports = pmb_test.const.testdata + "/init_questions_device/aports"
|
|
||||||
args.nonfree_firmware = False
|
|
||||||
args.nonfree_userland = False
|
|
||||||
|
|
||||||
# APKBUILD with firmware and userland (all yes)
|
|
||||||
func = pmb.config.init.ask_for_device_nonfree
|
|
||||||
device = "nonfree-firmware-and-userland"
|
|
||||||
fake_answers(monkeypatch, ["y", "y"])
|
|
||||||
nonfree = {"firmware": True, "userland": True}
|
|
||||||
assert func(args, device) == nonfree
|
|
||||||
|
|
||||||
# APKBUILD with firmware and userland (all no)
|
|
||||||
fake_answers(monkeypatch, ["n", "n"])
|
|
||||||
nonfree = {"firmware": False, "userland": False}
|
|
||||||
assert func(args, device) == nonfree
|
|
||||||
|
|
||||||
# APKBUILD with firmware only
|
|
||||||
func = pmb.config.init.ask_for_device_nonfree
|
|
||||||
device = "nonfree-firmware"
|
|
||||||
fake_answers(monkeypatch, ["y"])
|
|
||||||
nonfree = {"firmware": True, "userland": False}
|
|
||||||
assert func(args, device) == nonfree
|
|
||||||
|
|
||||||
# APKBUILD with userland only
|
|
||||||
func = pmb.config.init.ask_for_device_nonfree
|
|
||||||
device = "nonfree-userland"
|
|
||||||
fake_answers(monkeypatch, ["y"])
|
|
||||||
nonfree = {"firmware": False, "userland": True}
|
|
||||||
assert func(args, device) == nonfree
|
|
||||||
|
|
||||||
|
|
||||||
def test_questions_flash_methods(args, monkeypatch):
|
def test_questions_flash_methods(args, monkeypatch):
|
||||||
func = pmb.aportgen.device.ask_for_flash_method
|
func = pmb.aportgen.device.ask_for_flash_method
|
||||||
fake_answers(monkeypatch, ["invalid_flash_method", "fastboot"])
|
fake_answers(monkeypatch, ["invalid_flash_method", "fastboot"])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue