Patchwork [CONSOLIDATED,PULL,07/27] useradd.bbclass: check if a group already exists manually

login
register
mail settings
Submitter Saul Wold
Date Oct. 23, 2011, 6:26 p.m.
Message ID <fa014e1258eb26983a258ab8dcedfadfdb7685d8.1319394187.git.sgw@linux.intel.com>
Download mbox | patch
Permalink /patch/13763/
State New, archived
Headers show

Comments

Saul Wold - Oct. 23, 2011, 6:26 p.m.
From: Otavio Salvador <otavio@ossystems.com.br>

The use of groupadd -f makes much more difficult to figure when a
group is not add. This was the case of the class not working for our
usage and this being caused by the lack of '/etc/group' file but
unnoticed as groupadd wasn't failing according.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 meta/classes/useradd.bbclass |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

Patch

diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
index 1e03a04..fb70b3e 100644
--- a/meta/classes/useradd.bbclass
+++ b/meta/classes/useradd.bbclass
@@ -37,7 +37,13 @@  if test "x$GROUPADD_PARAM" != "x"; then
 	opts=`echo "$GROUPADD_PARAM" | cut -d ';' -f 1`
 	remaining=`echo "$GROUPADD_PARAM" | cut -d ';' -f 2-`
 	while test "x$opts" != "x"; do
-		eval $PSEUDO groupadd -f $OPT $opts
+		groupname=`echo "$opts" | awk '{ print $NF }'`
+		group_exists=`grep "^$groupname:" $SYSROOT/etc/group || true`
+		if test "x$group_exists" = "x"; then
+			eval $PSEUDO groupadd  $OPT $opts
+		else
+			echo "Note: group $groupname already exists, not re-creating it"
+		fi
 
 		if test "x$opts" = "x$remaining"; then
 			break