summaryrefslogtreecommitdiffstats
path: root/meta/classes/useradd.bbclass
diff options
context:
space:
mode:
authorChen Qi <Qi.Chen@windriver.com>2013-07-19 09:52:25 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-07-24 11:35:35 +0100
commit50d2548f74322c130129cb2e7bb0b763c8774968 (patch)
tree6d4b2dfc7a6a7008f72287af08e0e6791ca639be /meta/classes/useradd.bbclass
parent18f39e545674d7405cbdf4486a911c577177706f (diff)
downloadpoky-50d2548f74322c130129cb2e7bb0b763c8774968.tar.gz
useradd.bbclass: add a new base class and code refactor
Add a new base class, useradd_base.bbclass, which is mainly a collection of basic functions for user/group settings. The useradd_base.bbclass is intended to be inherited by useradd.bbclass and the extrausers.bbclass to avoid code cuplication. [YOCTO #4074] (From OE-Core rev: 2a57bb7e9a7e154578aa7cb9aeebdf398a54ec00) Signed-off-by: Chen Qi <Qi.Chen@windriver.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/useradd.bbclass')
-rw-r--r--meta/classes/useradd.bbclass99
1 files changed, 8 insertions, 91 deletions
diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
index 3fe011d976..9b3ac258ae 100644
--- a/meta/classes/useradd.bbclass
+++ b/meta/classes/useradd.bbclass
@@ -1,3 +1,5 @@
1inherit useradd_base
2
1# base-passwd-cross provides the default passwd and group files in the 3# base-passwd-cross provides the default passwd and group files in the
2# target sysroot, and shadow -native and -sysroot provide the utilities 4# target sysroot, and shadow -native and -sysroot provide the utilities
3# and support files needed to add and modify user and group accounts 5# and support files needed to add and modify user and group accounts
@@ -44,30 +46,7 @@ if test "x$GROUPADD_PARAM" != "x"; then
44 opts=`echo "$GROUPADD_PARAM" | cut -d ';' -f 1` 46 opts=`echo "$GROUPADD_PARAM" | cut -d ';' -f 1`
45 remaining=`echo "$GROUPADD_PARAM" | cut -d ';' -f 2-` 47 remaining=`echo "$GROUPADD_PARAM" | cut -d ';' -f 2-`
46 while test "x$opts" != "x"; do 48 while test "x$opts" != "x"; do
47 groupname=`echo "$opts" | awk '{ print $NF }'` 49 perform_groupadd "$SYSROOT" "$OPT $opts" 10
48 group_exists=`grep "^$groupname:" $SYSROOT/etc/group || true`
49 if test "x$group_exists" = "x"; then
50 count=1
51 while true; do
52 eval $PSEUDO groupadd $OPT $opts || true
53 group_exists=`grep "^$groupname:" $SYSROOT/etc/group || true`
54 if test "x$group_exists" = "x"; then
55 # File locking issues can require us to retry the command
56 echo "WARNING: groupadd command did not succeed. Retrying..."
57 sleep 1
58 else
59 break
60 fi
61 count=`expr $count + 1`
62 if test $count = 11; then
63 echo "ERROR: tried running groupadd command 10 times without success, giving up"
64 exit 1
65 fi
66 done
67 else
68 echo "Note: group $groupname already exists, not re-creating it"
69 fi
70
71 if test "x$opts" = "x$remaining"; then 50 if test "x$opts" = "x$remaining"; then
72 break 51 break
73 fi 52 fi
@@ -83,32 +62,7 @@ if test "x$USERADD_PARAM" != "x"; then
83 opts=`echo "$USERADD_PARAM" | cut -d ';' -f 1` 62 opts=`echo "$USERADD_PARAM" | cut -d ';' -f 1`
84 remaining=`echo "$USERADD_PARAM" | cut -d ';' -f 2-` 63 remaining=`echo "$USERADD_PARAM" | cut -d ';' -f 2-`
85 while test "x$opts" != "x"; do 64 while test "x$opts" != "x"; do
86 # useradd does not have a -f option, so we have to check if the 65 perform_useradd "$SYSROOT" "$OPT $opts" 10
87 # username already exists manually
88 username=`echo "$opts" | awk '{ print $NF }'`
89 user_exists=`grep "^$username:" $SYSROOT/etc/passwd || true`
90 if test "x$user_exists" = "x"; then
91 count=1
92 while true; do
93 eval $PSEUDO useradd $OPT $opts || true
94 user_exists=`grep "^$username:" $SYSROOT/etc/passwd || true`
95 if test "x$user_exists" = "x"; then
96 # File locking issues can require us to retry the command
97 echo "WARNING: useradd command did not succeed. Retrying..."
98 sleep 1
99 else
100 break
101 fi
102 count=`expr $count + 1`
103 if test $count = 11; then
104 echo "ERROR: tried running useradd command 10 times without success, giving up"
105 exit 1
106 fi
107 done
108 else
109 echo "Note: username $username already exists, not re-creating it"
110 fi
111
112 if test "x$opts" = "x$remaining"; then 66 if test "x$opts" = "x$remaining"; then
113 break 67 break
114 fi 68 fi
@@ -119,58 +73,18 @@ fi
119 73
120if test "x$GROUPMEMS_PARAM" != "x"; then 74if test "x$GROUPMEMS_PARAM" != "x"; then
121 echo "Running groupmems commands..." 75 echo "Running groupmems commands..."
122 # groupmems fails if /etc/gshadow does not exist
123 if [ -f $SYSROOT${sysconfdir}/gshadow ]; then
124 gshadow="yes"
125 else
126 gshadow="no"
127 touch $SYSROOT${sysconfdir}/gshadow
128 fi
129 # Invoke multiple instances of groupmems for parameter lists 76 # Invoke multiple instances of groupmems for parameter lists
130 # separated by ';' 77 # separated by ';'
131 opts=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 1` 78 opts=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 1`
132 remaining=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 2-` 79 remaining=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 2-`
133 while test "x$opts" != "x"; do 80 while test "x$opts" != "x"; do
134 groupname=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-g" || $i == "--group") print $(i+1) }'` 81 perform_groupmems "$SYSROOT" "$OPT $opts" 10
135 username=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-a" || $i == "--add") print $(i+1) }'`
136 echo "$groupname $username"
137 mem_exists=`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $SYSROOT/etc/group || true`
138 if test "x$mem_exists" = "x"; then
139 count=1
140 while true; do
141 eval $PSEUDO groupmems $OPT $opts || true
142 mem_exists=`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $SYSROOT/etc/group || true`
143 if test "x$mem_exists" = "x"; then
144 # File locking issues can require us to retry the command
145 echo "WARNING: groupmems command did not succeed. Retrying..."
146 sleep 1
147 else
148 break
149 fi
150 count=`expr $count + 1`
151 if test $count = 11; then
152 echo "ERROR: tried running groupmems command 10 times without success, giving up"
153 if test "x$gshadow" = "xno"; then
154 rm -f $SYSROOT${sysconfdir}/gshadow
155 rm -f $SYSROOT${sysconfdir}/gshadow-
156 fi
157 exit 1
158 fi
159 done
160 else
161 echo "Note: group $groupname already contains $username, not re-adding it"
162 fi
163
164 if test "x$opts" = "x$remaining"; then 82 if test "x$opts" = "x$remaining"; then
165 break 83 break
166 fi 84 fi
167 opts=`echo "$remaining" | cut -d ';' -f 1` 85 opts=`echo "$remaining" | cut -d ';' -f 1`
168 remaining=`echo "$remaining" | cut -d ';' -f 2-` 86 remaining=`echo "$remaining" | cut -d ';' -f 2-`
169 done 87 done
170 if test "x$gshadow" = "xno"; then
171 rm -f $SYSROOT${sysconfdir}/gshadow
172 rm -f $SYSROOT${sysconfdir}/gshadow-
173 fi
174fi 88fi
175} 89}
176 90
@@ -254,6 +168,9 @@ fakeroot python populate_packages_prepend () {
254 preinst = d.getVar('pkg_preinst_%s' % pkg, True) or d.getVar('pkg_preinst', True) 168 preinst = d.getVar('pkg_preinst_%s' % pkg, True) or d.getVar('pkg_preinst', True)
255 if not preinst: 169 if not preinst:
256 preinst = '#!/bin/sh\n' 170 preinst = '#!/bin/sh\n'
171 preinst += 'perform_groupadd () {\n%s}\n' % d.getVar('perform_groupadd', True)
172 preinst += 'perform_useradd () {\n%s}\n' % d.getVar('perform_useradd', True)
173 preinst += 'perform_groupmems () {\n%s}\n' % d.getVar('perform_groupmems', True)
257 preinst += d.getVar('useradd_preinst', True) 174 preinst += d.getVar('useradd_preinst', True)
258 d.setVar('pkg_preinst_%s' % pkg, preinst) 175 d.setVar('pkg_preinst_%s' % pkg, preinst)
259 176