init: ask whether to install systemd (MR 2273)

Add the following question to "pmbootstrap init":

[22:12:57] Based on your UI selection, 'default' will result in installing systemd.
[22:12:57] Install systemd? (default/always/never) [default]:

Determine whether the UI prefers to have systemd or not, based on
"pmb:systemd" in the UI package's APKBUILD.

Determine whether the currently selected branch supports systemd, by
checking for a "[repo:systemd]" section in pmaports.cfg. This section
will also contain bootstrap information, to be used in future patches.
This commit is contained in:
Oliver Smith 2024-02-23 01:20:23 +01:00
parent c6e8a89ea3
commit e96ca36376
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
5 changed files with 59 additions and 1 deletions

View File

@ -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: <https://postmarketos.org/deviceinfo>

View File

@ -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)

View File

@ -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

View File

@ -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}

View File

@ -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"]