forked from Mirror/pmbootstrap
pmbootstrap install: support _pmb_groups (MR 2010)
This commit is contained in:
parent
e357ee885e
commit
dd61d57b0e
5 changed files with 73 additions and 1 deletions
|
@ -296,6 +296,10 @@ apkbuild_package_attributes = {
|
|||
# removing the meta-package. (#1933). To disable this feature, use:
|
||||
# "pmbootstrap install --no-recommends".
|
||||
"_pmb_recommends": {"array": True},
|
||||
|
||||
# UI meta-packages can specify groups to which the user must be added
|
||||
# to access specific hardware such as LED indicators.
|
||||
"_pmb_groups": {"array": True},
|
||||
}
|
||||
|
||||
# Variables in APKBUILD files, that get parsed
|
||||
|
|
|
@ -195,7 +195,8 @@ def set_user(args):
|
|||
if not pmb.chroot.user_exists(args, args.user, suffix):
|
||||
pmb.chroot.root(args, ["adduser", "-D", "-u", "10000", args.user],
|
||||
suffix)
|
||||
for group in pmb.config.install_user_groups:
|
||||
groups = pmb.install.ui.get_groups(args) + pmb.config.install_user_groups
|
||||
for group in groups:
|
||||
pmb.chroot.root(args, ["addgroup", "-S", group], suffix,
|
||||
check=False)
|
||||
pmb.chroot.root(args, ["addgroup", args.user, group], suffix)
|
||||
|
|
|
@ -35,3 +35,32 @@ def get_recommends(args):
|
|||
return ret
|
||||
|
||||
|
||||
def get_groups(args):
|
||||
""" Get all groups to which the user additionally must be added.
|
||||
The list of groups are listed in _pmb_groups of the UI and
|
||||
UI-extras package.
|
||||
|
||||
:returns: list of groups, e.g. ["feedbackd", "udev"] """
|
||||
ret = []
|
||||
if args.ui == "none":
|
||||
return ret
|
||||
|
||||
# UI package
|
||||
meta = f"postmarketos-ui-{args.ui}"
|
||||
apkbuild = pmb.helpers.pmaports.get(args, meta)
|
||||
groups = apkbuild["_pmb_groups"]
|
||||
if groups:
|
||||
logging.debug(f"{meta}: install _pmb_groups:"
|
||||
f" {', '.join(groups)}")
|
||||
ret += groups
|
||||
|
||||
# UI-extras subpackage
|
||||
meta_extras = f"{meta}-extras"
|
||||
if args.ui_extras and meta_extras in apkbuild["subpackages"]:
|
||||
groups = apkbuild["subpackages"][meta_extras]["_pmb_groups"]
|
||||
if groups:
|
||||
logging.debug(f"{meta_extras}: install _pmb_groups:"
|
||||
f" {', '.join(groups)}")
|
||||
ret += groups
|
||||
|
||||
return ret
|
||||
|
|
|
@ -79,3 +79,28 @@ def test_get_recommends(args):
|
|||
with pytest.raises(RuntimeError) as e:
|
||||
func(args)
|
||||
assert str(e.value).startswith("Could not find aport for package")
|
||||
|
||||
|
||||
def test_get_groups(args):
|
||||
args.aports = f"{pmb_test.const.testdata}/pmb_groups"
|
||||
func = pmb.install.ui.get_groups
|
||||
|
||||
# UI: none:
|
||||
args.ui = "none"
|
||||
assert func(args) == []
|
||||
|
||||
# UI: test, without -extras
|
||||
args.ui = "test"
|
||||
args.ui_extras = False
|
||||
assert func(args) == ["feedbackd"]
|
||||
|
||||
# UI: test, with -extras
|
||||
args.ui = "test"
|
||||
args.ui_extras = True
|
||||
assert func(args) == ["feedbackd", "extra"]
|
||||
|
||||
# UI: invalid
|
||||
args.ui = "invalid"
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
func(args)
|
||||
assert str(e.value).startswith("Could not find aport for package")
|
||||
|
|
13
test/testdata/pmb_groups/main/postmarketos-ui-test/APKBUILD
vendored
Normal file
13
test/testdata/pmb_groups/main/postmarketos-ui-test/APKBUILD
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
pkgname=postmarketos-ui-test
|
||||
pkgver=1
|
||||
pkgrel=0
|
||||
license="GPL-3.0-or-later"
|
||||
depends=""
|
||||
subpackages="$pkgname-extras"
|
||||
arch="all"
|
||||
|
||||
_pmb_groups="feedbackd"
|
||||
|
||||
extras() {
|
||||
_pmb_groups="extra"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue