summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/classes/useradd.bbclass6
-rw-r--r--meta/classes/useradd_base.bbclass165
2 files changed, 46 insertions, 125 deletions
diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass
index c960656f02..0a6f2be0d4 100644
--- a/meta/classes/useradd.bbclass
+++ b/meta/classes/useradd.bbclass
@@ -57,7 +57,7 @@ if test "x`echo $GROUPADD_PARAM | tr -d '[:space:]'`" != "x"; then
57 opts=`echo "$GROUPADD_PARAM" | cut -d ';' -f 1` 57 opts=`echo "$GROUPADD_PARAM" | cut -d ';' -f 1`
58 remaining=`echo "$GROUPADD_PARAM" | cut -d ';' -f 2-` 58 remaining=`echo "$GROUPADD_PARAM" | cut -d ';' -f 2-`
59 while test "x$opts" != "x"; do 59 while test "x$opts" != "x"; do
60 perform_groupadd "$SYSROOT" "$OPT $opts" 10 60 perform_groupadd "$SYSROOT" "$OPT $opts"
61 if test "x$opts" = "x$remaining"; then 61 if test "x$opts" = "x$remaining"; then
62 break 62 break
63 fi 63 fi
@@ -73,7 +73,7 @@ if test "x`echo $USERADD_PARAM | tr -d '[:space:]'`" != "x"; then
73 opts=`echo "$USERADD_PARAM" | cut -d ';' -f 1` 73 opts=`echo "$USERADD_PARAM" | cut -d ';' -f 1`
74 remaining=`echo "$USERADD_PARAM" | cut -d ';' -f 2-` 74 remaining=`echo "$USERADD_PARAM" | cut -d ';' -f 2-`
75 while test "x$opts" != "x"; do 75 while test "x$opts" != "x"; do
76 perform_useradd "$SYSROOT" "$OPT $opts" 10 76 perform_useradd "$SYSROOT" "$OPT $opts"
77 if test "x$opts" = "x$remaining"; then 77 if test "x$opts" = "x$remaining"; then
78 break 78 break
79 fi 79 fi
@@ -89,7 +89,7 @@ if test "x`echo $GROUPMEMS_PARAM | tr -d '[:space:]'`" != "x"; then
89 opts=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 1` 89 opts=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 1`
90 remaining=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 2-` 90 remaining=`echo "$GROUPMEMS_PARAM" | cut -d ';' -f 2-`
91 while test "x$opts" != "x"; do 91 while test "x$opts" != "x"; do
92 perform_groupmems "$SYSROOT" "$OPT $opts" 10 92 perform_groupmems "$SYSROOT" "$OPT $opts"
93 if test "x$opts" = "x$remaining"; then 93 if test "x$opts" = "x$remaining"; then
94 break 94 break
95 fi 95 fi
diff --git a/meta/classes/useradd_base.bbclass b/meta/classes/useradd_base.bbclass
index ab3cd353f0..9b8f5c2207 100644
--- a/meta/classes/useradd_base.bbclass
+++ b/meta/classes/useradd_base.bbclass
@@ -4,7 +4,7 @@
4 4
5# The following functions basically have similar logic. 5# The following functions basically have similar logic.
6# *) Perform necessary checks before invoking the actual command 6# *) Perform necessary checks before invoking the actual command
7# *) Invoke the actual command, make retries if necessary 7# *) Invoke the actual command with flock
8# *) Error out if an error occurs. 8# *) Error out if an error occurs.
9 9
10# Note that before invoking these functions, make sure the global variable 10# Note that before invoking these functions, make sure the global variable
@@ -13,26 +13,16 @@
13perform_groupadd () { 13perform_groupadd () {
14 local rootdir="$1" 14 local rootdir="$1"
15 local opts="$2" 15 local opts="$2"
16 local retries="$3" 16 bbnote "${PN}: Performing groupadd with [$opts]"
17 bbnote "${PN}: Performing groupadd with [$opts] and $retries times of retry"
18 local groupname=`echo "$opts" | awk '{ print $NF }'` 17 local groupname=`echo "$opts" | awk '{ print $NF }'`
19 local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`" 18 local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
20 if test "x$group_exists" = "x"; then 19 if test "x$group_exists" = "x"; then
21 local count=0 20 opts=`echo $opts | sed s/\'/\"/g`
22 while true; do 21 eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO groupadd $opts\' || true
23 eval $PSEUDO groupadd $opts || true 22 group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
24 group_exists="`grep "^$groupname:" $rootdir/etc/group || true`" 23 if test "x$group_exists" = "x"; then
25 if test "x$group_exists" = "x"; then 24 bbfatal "${PN}: groupadd command did not succeed."
26 bbwarn "${PN}: groupadd command did not succeed. Retrying..." 25 fi
27 else
28 break
29 fi
30 count=`expr $count + 1`
31 if test $count = $retries; then
32 bbfatal "${PN}: Tried running groupadd command $retries times without success, giving up"
33 fi
34 sleep $count
35 done
36 else 26 else
37 bbnote "${PN}: group $groupname already exists, not re-creating it" 27 bbnote "${PN}: group $groupname already exists, not re-creating it"
38 fi 28 fi
@@ -41,26 +31,16 @@ perform_groupadd () {
41perform_useradd () { 31perform_useradd () {
42 local rootdir="$1" 32 local rootdir="$1"
43 local opts="$2" 33 local opts="$2"
44 local retries="$3" 34 bbnote "${PN}: Performing useradd with [$opts]"
45 bbnote "${PN}: Performing useradd with [$opts] and $retries times of retry"
46 local username=`echo "$opts" | awk '{ print $NF }'` 35 local username=`echo "$opts" | awk '{ print $NF }'`
47 local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`" 36 local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
48 if test "x$user_exists" = "x"; then 37 if test "x$user_exists" = "x"; then
49 local count=0 38 opts=`echo $opts | sed s/\'/\"/g`
50 while true; do 39 eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO useradd $opts\' || true
51 eval $PSEUDO useradd $opts || true 40 user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
52 user_exists="`grep "^$username:" $rootdir/etc/passwd || true`" 41 if test "x$user_exists" = "x"; then
53 if test "x$user_exists" = "x"; then 42 bbfatal "${PN}: useradd command did not succeed."
54 bbwarn "${PN}: useradd command did not succeed. Retrying..." 43 fi
55 else
56 break
57 fi
58 count=`expr $count + 1`
59 if test $count = $retries; then
60 bbfatal "${PN}: Tried running useradd command $retries times without success, giving up"
61 fi
62 sleep $count
63 done
64 else 44 else
65 bbnote "${PN}: user $username already exists, not re-creating it" 45 bbnote "${PN}: user $username already exists, not re-creating it"
66 fi 46 fi
@@ -69,8 +49,7 @@ perform_useradd () {
69perform_groupmems () { 49perform_groupmems () {
70 local rootdir="$1" 50 local rootdir="$1"
71 local opts="$2" 51 local opts="$2"
72 local retries="$3" 52 bbnote "${PN}: Performing groupmems with [$opts]"
73 bbnote "${PN}: Performing groupmems with [$opts] and $retries times of retry"
74 local groupname=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-g" || $i == "--group") print $(i+1) }'` 53 local groupname=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-g" || $i == "--group") print $(i+1) }'`
75 local username=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-a" || $i == "--add") print $(i+1) }'` 54 local username=`echo "$opts" | awk '{ for (i = 1; i < NF; i++) if ($i == "-a" || $i == "--add") print $(i+1) }'`
76 bbnote "${PN}: Running groupmems command with group $groupname and user $username" 55 bbnote "${PN}: Running groupmems command with group $groupname and user $username"
@@ -84,25 +63,11 @@ perform_groupmems () {
84 fi 63 fi
85 local mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group || true`" 64 local mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group || true`"
86 if test "x$mem_exists" = "x"; then 65 if test "x$mem_exists" = "x"; then
87 local count=0 66 eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO groupmems $opts\' || true
88 while true; do 67 mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group || true`"
89 eval $PSEUDO groupmems $opts || true 68 if test "x$mem_exists" = "x"; then
90 mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group || true`" 69 bbfatal "${PN}: groupmems command did not succeed."
91 if test "x$mem_exists" = "x"; then 70 fi
92 bbwarn "${PN}: groupmems command did not succeed. Retrying..."
93 else
94 break
95 fi
96 count=`expr $count + 1`
97 if test $count = $retries; then
98 if test "x$gshadow" = "xno"; then
99 rm -f $rootdir${sysconfdir}/gshadow
100 rm -f $rootdir${sysconfdir}/gshadow-
101 fi
102 bbfatal "${PN}: Tried running groupmems command $retries times without success, giving up"
103 fi
104 sleep $count
105 done
106 else 71 else
107 bbnote "${PN}: group $groupname already contains $username, not re-adding it" 72 bbnote "${PN}: group $groupname already contains $username, not re-adding it"
108 fi 73 fi
@@ -115,26 +80,15 @@ perform_groupmems () {
115perform_groupdel () { 80perform_groupdel () {
116 local rootdir="$1" 81 local rootdir="$1"
117 local opts="$2" 82 local opts="$2"
118 local retries="$3" 83 bbnote "${PN}: Performing groupdel with [$opts]"
119 bbnote "${PN}: Performing groupdel with [$opts] and $retries times of retry"
120 local groupname=`echo "$opts" | awk '{ print $NF }'` 84 local groupname=`echo "$opts" | awk '{ print $NF }'`
121 local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`" 85 local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
122 if test "x$group_exists" != "x"; then 86 if test "x$group_exists" != "x"; then
123 local count=0 87 eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO groupdel $opts\' || true
124 while true; do 88 group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
125 eval $PSEUDO groupdel $opts || true 89 if test "x$group_exists" != "x"; then
126 group_exists="`grep "^$groupname:" $rootdir/etc/group || true`" 90 bbfatal "${PN}: groupdel command did not succeed."
127 if test "x$group_exists" != "x"; then 91 fi
128 bbwarn "${PN}: groupdel command did not succeed. Retrying..."
129 else
130 break
131 fi
132 count=`expr $count + 1`
133 if test $count = $retries; then
134 bbfatal "${PN}: Tried running groupdel command $retries times without success, giving up"
135 fi
136 sleep $count
137 done
138 else 92 else
139 bbnote "${PN}: group $groupname doesn't exist, not removing it" 93 bbnote "${PN}: group $groupname doesn't exist, not removing it"
140 fi 94 fi
@@ -143,26 +97,15 @@ perform_groupdel () {
143perform_userdel () { 97perform_userdel () {
144 local rootdir="$1" 98 local rootdir="$1"
145 local opts="$2" 99 local opts="$2"
146 local retries="$3" 100 bbnote "${PN}: Performing userdel with [$opts]"
147 bbnote "${PN}: Performing userdel with [$opts] and $retries times of retry"
148 local username=`echo "$opts" | awk '{ print $NF }'` 101 local username=`echo "$opts" | awk '{ print $NF }'`
149 local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`" 102 local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
150 if test "x$user_exists" != "x"; then 103 if test "x$user_exists" != "x"; then
151 local count=0 104 eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO userdel $opts\' || true
152 while true; do 105 user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
153 eval $PSEUDO userdel $opts || true 106 if test "x$user_exists" != "x"; then
154 user_exists="`grep "^$username:" $rootdir/etc/passwd || true`" 107 bbfatal "${PN}: userdel command did not succeed."
155 if test "x$user_exists" != "x"; then 108 fi
156 bbwarn "${PN}: userdel command did not succeed. Retrying..."
157 else
158 break
159 fi
160 count=`expr $count + 1`
161 if test $count = $retries; then
162 bbfatal "${PN}: Tried running userdel command $retries times without success, giving up"
163 fi
164 sleep $count
165 done
166 else 109 else
167 bbnote "${PN}: user $username doesn't exist, not removing it" 110 bbnote "${PN}: user $username doesn't exist, not removing it"
168 fi 111 fi
@@ -174,25 +117,14 @@ perform_groupmod () {
174 set +e 117 set +e
175 local rootdir="$1" 118 local rootdir="$1"
176 local opts="$2" 119 local opts="$2"
177 local retries="$3" 120 bbnote "${PN}: Performing groupmod with [$opts]"
178 bbnote "${PN}: Performing groupmod with [$opts] and $retries times of retry"
179 local groupname=`echo "$opts" | awk '{ print $NF }'` 121 local groupname=`echo "$opts" | awk '{ print $NF }'`
180 local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`" 122 local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
181 if test "x$group_exists" != "x"; then 123 if test "x$group_exists" != "x"; then
182 local count=0 124 eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO groupmod $opts\'
183 while true; do 125 if test $? != 0; then
184 eval $PSEUDO groupmod $opts 126 bbwarn "${PN}: groupmod command did not succeed."
185 if test $? != 0; then 127 fi
186 bbwarn "${PN}: groupmod command did not succeed. Retrying..."
187 else
188 break
189 fi
190 count=`expr $count + 1`
191 if test $count = $retries; then
192 bbfatal "${PN}: Tried running groupmod command $retries times without success, giving up"
193 fi
194 sleep $count
195 done
196 else 128 else
197 bbwarn "${PN}: group $groupname doesn't exist, unable to modify it" 129 bbwarn "${PN}: group $groupname doesn't exist, unable to modify it"
198 fi 130 fi
@@ -204,25 +136,14 @@ perform_usermod () {
204 set +e 136 set +e
205 local rootdir="$1" 137 local rootdir="$1"
206 local opts="$2" 138 local opts="$2"
207 local retries="$3" 139 bbnote "${PN}: Performing usermod with [$opts]"
208 bbnote "${PN}: Performing usermod with [$opts] and $retries times of retry"
209 local username=`echo "$opts" | awk '{ print $NF }'` 140 local username=`echo "$opts" | awk '{ print $NF }'`
210 local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`" 141 local user_exists="`grep "^$username:" $rootdir/etc/passwd || true`"
211 if test "x$user_exists" != "x"; then 142 if test "x$user_exists" != "x"; then
212 local count=0 143 eval flock -x -w 100 $rootdir${sysconfdir} -c \'$PSEUDO usermod $opts\'
213 while true; do 144 if test $? != 0; then
214 eval $PSEUDO usermod $opts 145 bbfatal "${PN}: usermod command did not succeed."
215 if test $? != 0; then 146 fi
216 bbwarn "${PN}: usermod command did not succeed. Retrying..."
217 else
218 break
219 fi
220 count=`expr $count + 1`
221 if test $count = $retries; then
222 bbfatal "${PN}: Tried running usermod command $retries times without success, giving up"
223 fi
224 sleep $count
225 done
226 else 147 else
227 bbwarn "${PN}: user $username doesn't exist, unable to modify it" 148 bbwarn "${PN}: user $username doesn't exist, unable to modify it"
228 fi 149 fi