summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorMikhail Durnev <mikhail_durnev@mentor.com>2013-06-25 21:54:36 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-06-28 09:14:07 +0100
commitc62b1a33386439d0b4b51585fbc5b9198fd07068 (patch)
treedc37b5192588fd3960f9b6bdaeaac09549248742 /meta
parent1f7647c197929f5a8c633a93a02ac9f04b94b3ae (diff)
downloadast2050-yocto-poky-c62b1a33386439d0b4b51585fbc5b9198fd07068.zip
ast2050-yocto-poky-c62b1a33386439d0b4b51585fbc5b9198fd07068.tar.gz
useradd.bbclass: Add members to a group
useradd.bbclass supports adding new users and new groups. But it does not support adding existing users to existing groups. There is a need of adding users to some groups (e.g. audio). The class was extended to call groupmems utility with arguments passed via GROUPMEMS_PARAM. (From OE-Core rev: 6b3bd34bf8c5e511bccfbb64bdd1236e1e7576e3) Signed-off-by: Mikhail Durnev <mikhail_durnev@mentor.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/useradd.bbclass68
1 files changed, 63 insertions, 5 deletions
diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
index e50c889..3fe011d 100644
--- a/meta/classes/useradd.bbclass
+++ b/meta/classes/useradd.bbclass
@@ -24,13 +24,15 @@ if test "x$D" != "x"; then
OPT="--root $D"
# Add groups and users defined for all recipe packages
- GROUPADD_PARAM="${@get_all_cmd_params(d, 'group')}"
- USERADD_PARAM="${@get_all_cmd_params(d, 'user')}"
+ GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}"
+ USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}"
+ GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}"
else
# Installing onto a target
# Add groups and users defined only for this package
GROUPADD_PARAM="${GROUPADD_PARAM}"
USERADD_PARAM="${USERADD_PARAM}"
+ GROUPMEMS_PARAM="${GROUPMEMS_PARAM}"
fi
# Perform group additions first, since user additions may depend
@@ -114,6 +116,62 @@ if test "x$USERADD_PARAM" != "x"; then
remaining=`echo "$remaining" | cut -d ';' -f 2-`
done
fi
+
+if test "x$GROUPMEMS_PARAM" != "x"; then
+ echo "Running groupmems commands..."
+ # groupmems fails if /etc/gshadow does not exist
+ if [ -f $SYSROOT${sysconfdir}/gshadow ]; then
+ gshadow="yes"
+ else
+ gshadow="no"
+ touch $SYSROOT${sysconfdir}/gshadow
+ fi
+ # Invoke multiple instances of groupmems for parameter lists
+ # separated by ';'
+ opts=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 1`
+ remaining=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 2-`
+ while test "x$opts" != "x"; do
+ groupname=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-g" || $i == "--group") print $(i+1) }'`
+ username=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-a" || $i == "--add") print $(i+1) }'`
+ echo "$groupname $username"
+ mem_exists=`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $SYSROOT/etc/group || true`
+ if test "x$mem_exists" = "x"; then
+ count=1
+ while true; do
+ eval $PSEUDO groupmems $OPT $opts || true
+ mem_exists=`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $SYSROOT/etc/group || true`
+ if test "x$mem_exists" = "x"; then
+ # File locking issues can require us to retry the command
+ echo "WARNING: groupmems command did not succeed. Retrying..."
+ sleep 1
+ else
+ break
+ fi
+ count=`expr $count + 1`
+ if test $count = 11; then
+ echo "ERROR: tried running groupmems command 10 times without success, giving up"
+ if test "x$gshadow" = "xno"; then
+ rm -f $SYSROOT${sysconfdir}/gshadow
+ rm -f $SYSROOT${sysconfdir}/gshadow-
+ fi
+ exit 1
+ fi
+ done
+ else
+ echo "Note: group $groupname already contains $username, not re-adding it"
+ fi
+
+ if test "x$opts" = "x$remaining"; then
+ break
+ fi
+ opts=`echo "$remaining" | cut -d ';' -f 1`
+ remaining=`echo "$remaining" | cut -d ';' -f 2-`
+ done
+ if test "x$gshadow" = "xno"; then
+ rm -f $SYSROOT${sysconfdir}/gshadow
+ rm -f $SYSROOT${sysconfdir}/gshadow-
+ fi
+fi
}
useradd_sysroot () {
@@ -160,8 +218,8 @@ def update_useradd_after_parse(d):
raise bb.build.FuncFailed("%s inherits useradd but doesn't set USERADD_PACKAGES" % d.getVar('FILE'))
for pkg in useradd_packages.split():
- if not d.getVar('USERADD_PARAM_%s' % pkg, True) and not d.getVar('GROUPADD_PARAM_%s' % pkg, True):
- raise bb.build.FuncFailed("%s inherits useradd but doesn't set USERADD_PARAM or GROUPADD_PARAM for package %s" % (d.getVar('FILE'), pkg))
+ if not d.getVar('USERADD_PARAM_%s' % pkg, True) and not d.getVar('GROUPADD_PARAM_%s' % pkg, True) and not d.getVar('GROUPMEMS_PARAM_%s' % pkg, True):
+ raise bb.build.FuncFailed("%s inherits useradd but doesn't set USERADD_PARAM, GROUPADD_PARAM or GROUPMEMS_PARAM for package %s" % (d.getVar('FILE'), pkg))
python __anonymous() {
update_useradd_after_parse(d)
@@ -172,7 +230,7 @@ python __anonymous() {
def get_all_cmd_params(d, cmd_type):
import string
- param_type = cmd_type.upper() + "ADD_PARAM_%s"
+ param_type = cmd_type.upper() + "_PARAM_%s"
params = []
useradd_packages = d.getVar('USERADD_PACKAGES', True) or ""
OpenPOWER on IntegriCloud