]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
useradd.bbclass: Add support for USERMOD_PARAM
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>
Tue, 12 May 2026 19:04:12 +0000 (21:04 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 28 May 2026 10:21:19 +0000 (11:21 +0100)
The groupmems command will be removed in shadow 4.20. The same
functionality as provided by groupmems can be achieved with the usermod
command. Add support for USERMOD_PARAM variables to specify the options
to use.

The following GROUPMEMS_PARAM:

GROUPMEMS_PARAM:${PN} = "--add user --group group1; \
                         --add user --group group2"

would be directly converted to the following USERMOD_PARAM:

USERMOD_PARAM:${PN} = "--append --groups group1 user; \
                       --append --groups group2 user"

It can also be simplified to:

USERMOD_PARAM:${PN} = "--append --groups group1,group2 user"

Add USERMOD_PARAM to PACKAGEVARS similarly to the USERADD_PARAM and
GROUPADD_PARAM variables.

[YOCTO#16277]

Co-authored-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-global/package.bbclass
meta/classes/useradd.bbclass
meta/conf/documentation.conf

index 67148fc1acbdd2ea371b4d7fe40ec05d8b5a68c3..30accaeaa9176795d9eb4269ddc695f4271c4783 100644 (file)
@@ -438,7 +438,7 @@ python package_depchains() {
 
 # Since bitbake can't determine which variables are accessed during package
 # iteration, we need to list them here:
-PACKAGEVARS = "FILES RDEPENDS RRECOMMENDS SUMMARY DESCRIPTION RSUGGESTS RPROVIDES RCONFLICTS PKG ALLOW_EMPTY pkg_postinst pkg_postrm pkg_postinst_ontarget INITSCRIPT_NAME INITSCRIPT_PARAMS DEBIAN_NOAUTONAME ALTERNATIVE PKGE PKGV PKGR USERADD_PARAM GROUPADD_PARAM CONFFILES SYSTEMD_SERVICE LICENSE SECTION pkg_preinst pkg_prerm RREPLACES GROUPMEMS_PARAM SYSTEMD_AUTO_ENABLE SKIP_FILEDEPS PRIVATE_LIBS PACKAGE_ADD_METADATA"
+PACKAGEVARS = "FILES RDEPENDS RRECOMMENDS SUMMARY DESCRIPTION RSUGGESTS RPROVIDES RCONFLICTS PKG ALLOW_EMPTY pkg_postinst pkg_postrm pkg_postinst_ontarget INITSCRIPT_NAME INITSCRIPT_PARAMS DEBIAN_NOAUTONAME ALTERNATIVE PKGE PKGV PKGR USERADD_PARAM GROUPADD_PARAM USERMOD_PARAM CONFFILES SYSTEMD_SERVICE LICENSE SECTION pkg_preinst pkg_prerm RREPLACES GROUPMEMS_PARAM SYSTEMD_AUTO_ENABLE SKIP_FILEDEPS PRIVATE_LIBS PACKAGE_ADD_METADATA"
 
 def gen_packagevar(d, pkgvars="PACKAGEVARS"):
     ret = []
index 1080008b3fa44b600508ab2f337523cde0b01fe3..55393d38f7cc581ce46d9d635a57c01aa491a8bc 100644 (file)
@@ -48,6 +48,7 @@ if test "x$UA_SYSROOT" = "x"; then
        # Add groups and users defined only for this package
        GROUPADD_PARAM="${GROUPADD_PARAM}"
        USERADD_PARAM="${USERADD_PARAM}"
+       USERMOD_PARAM="${USERMOD_PARAM}"
        GROUPMEMS_PARAM="${GROUPMEMS_PARAM}"
 fi
 
@@ -85,6 +86,22 @@ if test "x`echo $USERADD_PARAM | tr -d '[:space:]'`" != "x"; then
        done
 fi
 
+if test "x`echo $USERMOD_PARAM | tr -d '[:space:]'`" != "x"; then
+       echo "Running usermod commands..."
+       # Invoke multiple instances of usermod for parameter lists
+       # separated by ';'
+       opts=`echo "$USERMOD_PARAM" | cut -d ';' -f 1 | sed -e 's#[ \t]*$##'`
+       remaining=`echo "$USERMOD_PARAM" | cut -d ';' -f 2- | sed -e 's#[ \t]*$##'`
+       while test "x$opts" != "x"; do
+               perform_usermod "$SYSROOT" "$OPT $opts"
+               if test "x$opts" = "x$remaining"; then
+                       break
+               fi
+               opts=`echo "$remaining" | cut -d ';' -f 1 | sed -e 's#[ \t]*$##'`
+               remaining=`echo "$remaining" | cut -d ';' -f 2- | sed -e 's#[ \t]*$##'`
+       done
+fi
+
 if test "x`echo $GROUPMEMS_PARAM | tr -d '[:space:]'`" != "x"; then
        echo "Running groupmems commands..."
        # Invoke multiple instances of groupmems for parameter lists
@@ -103,13 +120,17 @@ fi
 }
 
 groupadd_sysroot() {
-        common_useradd_sysroot groupadd
+       common_useradd_sysroot groupadd
 }
 
 useradd_sysroot() {
        common_useradd_sysroot useradd
 }
 
+usermod_sysroot() {
+       common_useradd_sysroot usermod
+}
+
 groupmems_sysroot() {
        common_useradd_sysroot groupmems
 }
@@ -146,6 +167,7 @@ common_useradd_sysroot() {
        case "$1" in
                groupadd) GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}";;
                useradd) USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}";;
+               usermod) USERMOD_PARAM="${@get_all_cmd_params(d, 'usermod')}";;
                groupmems) GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}";;
        esac
 
@@ -162,7 +184,7 @@ common_useradd_sysroot() {
 EXTRA_STAGING_FIXMES += "PSEUDO_SYSROOT PSEUDO_LOCALSTATEDIR LOGFIFO"
 
 python useradd_sysroot_sstate() {
-    for cmd, sort_prefix in [("groupadd", "01"), ("useradd", "02"), ("groupmems", "03")]:
+    for cmd, sort_prefix in [("groupadd", "01"), ("useradd", "02"), ("usermod", "03"), ("groupmems", "04")]:
         scriptfile = None
         task = d.getVar("BB_CURRENTTASK")
         if task == "package_setscene":
@@ -216,9 +238,9 @@ def update_useradd_after_parse(d):
         bb.fatal("%s inherits useradd but doesn't set USERADD_PACKAGES" % d.getVar('FILE', False))
 
     for pkg in useradd_packages.split():
-        d.appendVarFlag("do_populate_sysroot", "vardeps", " USERADD_PARAM:%s GROUPADD_PARAM:%s GROUPMEMS_PARAM:%s" % (pkg, pkg, pkg))
-        if not d.getVar('USERADD_PARAM:%s' % pkg) and not d.getVar('GROUPADD_PARAM:%s' % pkg) and not d.getVar('GROUPMEMS_PARAM:%s' % pkg):
-            bb.fatal("%s inherits useradd but doesn't set USERADD_PARAM, GROUPADD_PARAM or GROUPMEMS_PARAM for package %s" % (d.getVar('FILE', False), pkg))
+        d.appendVarFlag("do_populate_sysroot", "vardeps", f" USERADD_PARAM:{pkg} GROUPADD_PARAM:{pkg} USERMOD_PARAM:{pkg} GROUPMEMS_PARAM:{pkg}")
+        if not any(d.getVar(f"{name}_PARAM:{pkg}") for name in ["USERADD", "GROUPADD", "USERMOD", "GROUPMEMS"]):
+            bb.fatal("%s inherits useradd but doesn't set USERADD_PARAM, GROUPADD_PARAM, USERMOD_PARAM or GROUPMEMS_PARAM for package %s" % (d.getVar('FILE', False), pkg))
 
 python __anonymous() {
     if not bb.data.inherits_class('nativesdk', d) \
@@ -226,8 +248,8 @@ python __anonymous() {
         update_useradd_after_parse(d)
 }
 
-# Return a single [GROUP|USER]ADD_PARAM formatted string which includes the
-# [group|user]add parameters for all USERADD_PACKAGES in this recipe
+# Return a single (GROUPADD|USERADD|USERMOD)_PARAM formatted string which includes the
+# (groupadd|useradd|usermod) parameters for all USERADD_PACKAGES in this recipe
 def get_all_cmd_params(d, cmd_type):
     import string
     
@@ -260,10 +282,11 @@ fakeroot python populate_packages:prepend() {
         preinst += 'bbfatal () {\n\techo "ERROR: $*"\n\texit 1\n}\n'
         preinst += 'perform_groupadd () {\n%s}\n' % d.getVar('perform_groupadd')
         preinst += 'perform_useradd () {\n%s}\n' % d.getVar('perform_useradd')
+        preinst += 'perform_usermod () {\n%s}\n' % d.getVar('perform_usermod')
         preinst += 'perform_groupmems () {\n%s}\n' % d.getVar('perform_groupmems')
         preinst += d.getVar('useradd_preinst')
         # Expand out the *_PARAM variables to the package specific versions
-        for rep in ["GROUPADD_PARAM", "USERADD_PARAM", "GROUPMEMS_PARAM"]:
+        for rep in ["GROUPADD_PARAM", "USERADD_PARAM", "USERMOD_PARAM", "GROUPMEMS_PARAM"]:
             val = d.getVar(rep + ":" + pkg) or ""
             preinst = preinst.replace("${" + rep + "}", val)
         d.setVar('pkg_preinst:%s' % pkg, preinst)
index 94368d5c2be66354d10ff222ec86171118f3b5e2..41e67d336597897e1704c6ec5d1ea0de0f9ce38b 100644 (file)
@@ -451,6 +451,7 @@ USERADD_PACKAGES[doc] = "When a recipe inherits the useradd class, this variable
 USERADD_PARAM[doc] = "When a recipe inherits the useradd class, this variable specifies for a package what parameters should be passed to the useradd command if you wish to add a user to the system when the package is installed."
 USERADD_UID_TABLES[doc] = "Specifies a password file to use for obtaining static user identification (uid) values when the OpenEmbedded build system adds a user to the system during package installation."
 USERADDEXTENSION[doc] = "When set to 'useradd-staticids', causes the OpenEmbedded build system to base all user and group additions on files listed in USERADD_UID_TABLES and USERADD_GID_TABLES."
+USERMOD_PARAM[doc] = "When a recipe inherits the useradd class, this variable specifies for a package what parameters should be passed to the usermod command if you wish to modify a user when the package is installed. Typically used to add the user to one or more groups."
 
 #W