]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
useradd_base.bbclass: Emulate the groupmems command using usermod
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>
Tue, 26 May 2026 12:44:18 +0000 (14:44 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 28 May 2026 10:21:19 +0000 (11:21 +0100)
The groupmems command does to support the --prefix option, which is
being used since commit a7b846ba7d6d63a5e59939d75d9c5fe3e4cbb0e9.
However, the groupmems command can easily be emulated using the usermod
command.

[YOCTO#16277]

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/useradd_base.bbclass

index 5e1c69911840922b9b1025dcd4fa30733827a6c3..5e12880b640b88fa2095d451055124f9c615a682 100644 (file)
@@ -56,13 +56,20 @@ perform_groupmems () {
        bbnote "${PN}: Performing groupmems with [$opts]"
        local groupname=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-g" || $i == "--group") print $(i+1) }'`
        local username=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-a" || $i == "--add") print $(i+1) }'`
-       bbnote "${PN}: Running groupmems command with group $groupname and user $username"
+       local prefix=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-P" || $i == "--prefix") print $(i+1) }'`
+       if test "x$groupname" = "x"; then
+               bbfatal "${PN}: groupmems: No user specified using --add."
+
+       elif test "x$username" = "x"; then
+               bbfatal "${PN}: groupmems: No group specified using --group."
+       fi
+       bbnote "${PN}: Emulating groupmems command using usermod with group $groupname and user $username"
        local mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*$" $rootdir/etc/group || true`"
        if test "x$mem_exists" = "x"; then
-               eval flock -x $rootdir${sysconfdir} -c \"$PSEUDO groupmems \$opts\" || true
+               eval flock -x $rootdir${sysconfdir} -c \"$PSEUDO usermod \${prefix:+--prefix \$prefix} --append --groups \$groupname \$username\" || true
                mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*$" $rootdir/etc/group || true`"
                if test "x$mem_exists" = "x"; then
-                       bbfatal "${PN}: groupmems command did not succeed."
+                       bbfatal "${PN}: groupmems command (emulated using usermod) did not succeed."
                fi
        else
                bbnote "${PN}: group $groupname already contains $username, not re-adding it"