forked from Mirror/pmbootstrap
The provider selection for "pmbootstrap init" added in this commit is a flexible way to offer UI/device-specific configuration options in "pmbootstrap init", without hardcoding them in pmbootstrap. Instead, the options are defined entirely in pmaports using APK's virtual package provider mechanism. The code in pmbootstrap searches for available providers and displays them together with their pkgdesc. There are many possible use cases for this but I have tested two so far: 1. Selecting root provider (sudo vs doas). This can be defined entirely in postmarketos-base, without having to handle this specifically in pmbootstrap. $ pmbootstrap init [...] Available providers for postmarketos-root (2): * sudo: Use sudo to run root commands (**default**) * doas: Use doas (minimal replacement for sudo) to run root commands (Note: Does not support all functionality of sudo) Provider [default]: doas 2. Device-specific options. My main motivation for working on this feature is a new configuration option for the MSM8916-based devices. It allows more control about which firmware to enable: $ pmbootstrap init [...] Available providers for soc-qcom-msm8916-rproc (3): * all: Enable all remote processors (audio goes through modem) (default) * no-modem: Disable only modem (audio bypasses modem, ~80 MiB more RAM) * none: Disable all remote processors (no WiFi/BT/modem, ~90 MiB more RAM) Provider [default]: no-modem The configuration prompts show up dynamically by defining _pmb_select="<virtual packages>" in postmarketos-base, a UI PKGBUILD or the device APKBUILD. Selecting "default" (just pressing enter) means that no provider is selected. This allows APK to choose it automatically based on the "provider_priority". It also provides compatibility with existing installation; APK will just choose the default provider when upgrading. The selection can still be changed after installation by installing another provider using "apk". Note that at the end this is just a more convenient interface for the already existing "extra packages" prompt. When using pmbootstrap in automated scripts the providers (e.g. "postmarketos-root-doas") can be simply selected through the existing "extra_packages" option.
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
# Copyright 2021 Oliver Smith
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
import logging
|
|
import configparser
|
|
import os
|
|
import pmb.config
|
|
|
|
|
|
def load(args):
|
|
cfg = configparser.ConfigParser()
|
|
if os.path.isfile(args.config):
|
|
cfg.read(args.config)
|
|
|
|
if "pmbootstrap" not in cfg:
|
|
cfg["pmbootstrap"] = {}
|
|
if "providers" not in cfg:
|
|
cfg["providers"] = {}
|
|
|
|
for key in pmb.config.defaults:
|
|
if key in pmb.config.config_keys and key not in cfg["pmbootstrap"]:
|
|
cfg["pmbootstrap"][key] = str(pmb.config.defaults[key])
|
|
|
|
# We used to save default values in the config, which can *not* be
|
|
# configured in "pmbootstrap init". That doesn't make sense, we always
|
|
# want to use the defaults from pmb/config/__init__.py in that case,
|
|
# not some outdated version we saved some time back (eg. aports folder,
|
|
# postmarketOS binary packages mirror).
|
|
if key not in pmb.config.config_keys and key in cfg["pmbootstrap"]:
|
|
logging.debug("Ignored unconfigurable and possibly outdated"
|
|
" default value from config:"
|
|
f" {cfg['pmbootstrap'][key]}")
|
|
del cfg["pmbootstrap"][key]
|
|
|
|
return cfg
|