diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 5e3c8c60..587b9d5a 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -93,6 +93,7 @@ config_keys = [ "ssh_key_glob", "ssh_keys", "sudo_timer", + "systemd", "timezone", "ui", "ui_extras", @@ -128,6 +129,7 @@ defaults = { "ssh_key_glob": "~/.ssh/id_*.pub", "ssh_keys": False, "sudo_timer": False, + "systemd": "default", "timezone": "GMT", "ui": "console", "ui_extras": False, @@ -792,6 +794,7 @@ apkbuild_custom_valid_options = [ "pmb:cross-native", "pmb:gpu-accel", "pmb:strict", + "pmb:systemd", ] # Variables from deviceinfo. Reference: diff --git a/pmb/config/init.py b/pmb/config/init.py index c047bd1f..2e43f88f 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -189,6 +189,24 @@ def ask_for_ui_extras(args, ui): default=args.ui_extras) +def ask_for_systemd(args, ui): + if "systemd" not in pmb.config.pmaports.read_config_repos(args): + return args.systemd + + default_is_systemd = pmb.helpers.ui.check_option(args, ui, "pmb:systemd") + not_str = " " if default_is_systemd else " not " + logging.info("Based on your UI selection, 'default' will result" + f" in{not_str}installing systemd.") + + choices = ["default", "always", "never"] + answer = pmb.helpers.cli.ask("Install systemd?", + choices, + args.systemd, + validation_regex=f"^({'|'.join(choices)})$", + complete=choices) + return answer + + def ask_for_keymaps(args, info): if "keymaps" not in info or info["keymaps"].strip() == "": return "" @@ -673,6 +691,10 @@ def frontend(args): ui = ask_for_ui(args, info) cfg["pmbootstrap"]["ui"] = ui cfg["pmbootstrap"]["ui_extras"] = str(ask_for_ui_extras(args, ui)) + + # systemd + cfg["pmbootstrap"]["systemd"] = ask_for_systemd(args, ui) + ask_for_provider_select_pkg(args, f"postmarketos-ui-{ui}", cfg["providers"]) ask_for_additional_options(args, cfg) diff --git a/pmb/config/pmaports.py b/pmb/config/pmaports.py index 29678964..4660ab71 100644 --- a/pmb/config/pmaports.py +++ b/pmb/config/pmaports.py @@ -81,6 +81,28 @@ def check_version_pmbootstrap(min): " of pmbootstrap from git.") +def read_config_repos(args): + """ Read the sections starting with "repo:" from pmaports.cfg. """ + # Try cache first + cache_key = "pmb.config.pmaports.read_config_repos" + if pmb.helpers.other.cache[cache_key]: + return pmb.helpers.other.cache[cache_key] + + cfg = configparser.ConfigParser() + cfg.read(f"{args.aports}/pmaports.cfg") + + ret = {} + for section in cfg.keys(): + if not section.startswith("repo:"): + continue + repo = section.split("repo:", 1)[1] + ret[repo] = cfg[section] + + # Cache and return + pmb.helpers.other.cache[cache_key] = ret + return ret + + def read_config(args): """ Read and verify pmaports.cfg. """ # Try cache first diff --git a/pmb/helpers/other.py b/pmb/helpers/other.py index 91d3345c..c0bec5f9 100644 --- a/pmb/helpers/other.py +++ b/pmb/helpers/other.py @@ -312,4 +312,5 @@ def init_cache(): "pmb.helpers.package.get": {}, "pmb.helpers.repo.update": repo_update, "pmb.helpers.git.parse_channels_cfg": {}, - "pmb.config.pmaports.read_config": None} + "pmb.config.pmaports.read_config": None, + "pmb.config.pmaports.read_config_repos": None} diff --git a/pmb/helpers/ui.py b/pmb/helpers/ui.py index 039be55d..7c618f17 100644 --- a/pmb/helpers/ui.py +++ b/pmb/helpers/ui.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later import os import glob +import pmb.helpers.pmaports import pmb.parse @@ -21,3 +22,12 @@ def list(args, arch): if pmb.helpers.package.check_arch(args, apkbuild["pkgname"], arch): ret.append((ui, apkbuild["pkgdesc"])) return ret + + +def check_option(args, ui, option): + """ + Check if an option, such as pmb:systemd, is inside an UI's APKBUILD. + """ + pkgname = f"postmarketos-ui-{ui}" + apkbuild = pmb.helpers.pmaports.get(args, pkgname, subpackages=False) + return option in apkbuild["options"]