@@ -19,7 +19,7 @@ PACKAGE_WRITE_DEPS += "shadow-native"
# c) As the preinst script in the target package at do_rootfs time
# d) As the preinst script in the target package on device as a package upgrade
#
-useradd_preinst () {
+useradd_preinst() {
OPT=""
SYSROOT=""
@@ -34,7 +34,7 @@ if test "x$D" != "x"; then
# shadow package, then while performing preinsts for packages that depend on
# shadow, there might only be /etc/login.def.dpkg-new there in root filesystem.
if [ ! -e $D${sysconfdir}/login.defs -a -e $D${sysconfdir}/login.defs.dpkg-new ]; then
- cp $D${sysconfdir}/login.defs.dpkg-new $D${sysconfdir}/login.defs
+ cp $D${sysconfdir}/login.defs.dpkg-new $D${sysconfdir}/login.defs
fi
# user/group lookups should match useradd/groupadd --prefix
@@ -102,19 +102,19 @@ if test "x`echo $GROUPMEMS_PARAM | tr -d '[:space:]'`" != "x"; then
fi
}
-useradd_sysroot () {
- user_group_groupmems_add_sysroot user
+groupadd_sysroot() {
+ common_useradd_sysroot groupadd
}
-groupadd_sysroot () {
- user_group_groupmems_add_sysroot group
+useradd_sysroot() {
+ common_useradd_sysroot useradd
}
-groupmemsadd_sysroot () {
- user_group_groupmems_add_sysroot groupmems
+groupmems_sysroot() {
+ common_useradd_sysroot groupmems
}
-user_group_groupmems_add_sysroot () {
+common_useradd_sysroot() {
# Pseudo may (do_prepare_recipe_sysroot) or may not (do_populate_sysroot_setscene) be running
# at this point so we're explicit about the environment so pseudo can load if
# not already present.
@@ -130,28 +130,24 @@ user_group_groupmems_add_sysroot () {
# Beware that in some cases we might see the fake pseudo passwd here, in which case we also must
# exit.
if [ ! -f $D${sysconfdir}/passwd ] ||
- grep -q this-is-the-pseudo-passwd $D${sysconfdir}/passwd; then
+ grep -q this-is-the-pseudo-passwd $D${sysconfdir}/passwd; then
exit 0
fi
# It is also possible we may be in a recipe which doesn't have useradd dependencies and hence the
# useradd/groupadd tools are unavailable. If there is no dependency, we assume we don't want to
# create users in the sysroot
- if ! command -v useradd; then
- bbwarn "command useradd not found!"
+ if ! command -v "$1"; then
+ bbwarn "The $1 command could not be found!"
exit 0
fi
# Add groups and users defined for all recipe packages
- if test "$1" = "group"; then
- GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}"
- elif test "$1" = "user"; then
- USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}"
- elif test "$1" = "groupmems"; then
- GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}"
- elif test "x$1" = "x"; then
- bbwarn "missing type of passwd db action"
- fi
+ case "$1" in
+ groupadd) GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}";;
+ useradd) USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}";;
+ groupmems) GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}";;
+ esac
# Tell the system to use the environment vars
UA_SYSROOT=1
@@ -159,36 +155,36 @@ user_group_groupmems_add_sysroot () {
useradd_preinst
}
-# The export of PSEUDO in useradd_sysroot() above contains references to
+# The export of PSEUDO in common_useradd_sysroot() above contains references to
# ${PSEUDO_SYSROOT} and ${PSEUDO_LOCALSTATEDIR}. Additionally, the logging
# shell functions use ${LOGFIFO}. These need to be handled when restoring
# postinst-useradd-${PN} from the sstate cache.
EXTRA_STAGING_FIXMES += "PSEUDO_SYSROOT PSEUDO_LOCALSTATEDIR LOGFIFO"
-python useradd_sysroot_sstate () {
- for type, sort_prefix in [("group", "01"), ("user", "02"), ("groupmems", "03")]:
+python useradd_sysroot_sstate() {
+ for cmd, sort_prefix in [("groupadd", "01"), ("useradd", "02"), ("groupmems", "03")]:
scriptfile = None
task = d.getVar("BB_CURRENTTASK")
if task == "package_setscene":
- bb.build.exec_func(type + "add_sysroot", d)
+ bb.build.exec_func(f"{cmd}_sysroot", d)
elif task == "prepare_recipe_sysroot":
# Used to update this recipe's own sysroot so the user/groups are available to do_install
# If do_populate_sysroot is triggered and we write the file here, there would be an overlapping
- # files. See usergrouptests.UserGroupTests.test_add_task_between_p_sysroot_and_package
- scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/postinst-useradd-" + sort_prefix + type + "-${PN}-recipedebug")
+ # file. See usergrouptests.UserGroupTests.test_add_task_between_p_sysroot_and_package
+ scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/postinst-useradd-" + sort_prefix + cmd + "-${PN}-recipedebug")
- bb.build.exec_func(type + "add_sysroot", d)
+ bb.build.exec_func(f"{cmd}_sysroot", d)
elif task == "populate_sysroot":
# Used when installed in dependent task sysroots
- scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/postinst-useradd-" + sort_prefix + type + "-${PN}")
+ scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/postinst-useradd-" + sort_prefix + cmd + "-${PN}")
if scriptfile:
bb.utils.mkdirhier(os.path.dirname(scriptfile))
with open(scriptfile, 'w') as script:
script.write("#!/bin/sh -e\n")
- bb.data.emit_func(type + "add_sysroot", script, d)
- script.write(type + "add_sysroot\n")
+ bb.data.emit_func(f"{cmd}_sysroot", script, d)
+ script.write(f"{cmd}_sysroot\n")
os.chmod(scriptfile, 0o755)
}
@@ -247,7 +243,7 @@ def get_all_cmd_params(d, cmd_type):
return "; ".join(params)
# Adds the preinst script into generated packages
-fakeroot python populate_packages:prepend () {
+fakeroot python populate_packages:prepend() {
def update_useradd_package(pkg):
bb.debug(1, 'adding user/group calls to preinst for %s' % pkg)
* Improve some odd function names, e.g., groupmemsadd_sysroot and user_group_groupmems_add_sysroot. These were introduced in commit 322ef726132a47d977d2c6ee41de5358f1e85994 (useradd.bbclass: Fix order of postinst-useradd-*). * Make common_useradd_sysroot() look for the actually used command instead of always looking for useradd. * Simplification of common_useradd_sysroot() by using case/esac. * A bit of whitespace clean-up. Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> --- meta/classes/useradd.bbclass | 60 +++++++++++++++++------------------- 1 file changed, 28 insertions(+), 32 deletions(-)