Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] support/mkusers: Preserve group members
@ 2018-09-03 13:11 Johan Oudinet
  2018-09-10 15:22 ` Yann E. MORIN
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Johan Oudinet @ 2018-09-03 13:11 UTC (permalink / raw)
  To: buildroot

When the function add_one_group is called on an existing group,
make sure the members of this group are not removed in the process of
deleting then re-adding the group.

Signed-off-by: Johan Oudinet <johan.oudinet@gmail.com>
---
 support/scripts/mkusers | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/support/scripts/mkusers b/support/scripts/mkusers
index 5bbec3e10f..ec75c02dac 100755
--- a/support/scripts/mkusers
+++ b/support/scripts/mkusers
@@ -75,6 +75,14 @@ get_gid() {
         '$1 == group { printf( "%d\n", $3 ); }' "${GROUP}"
 }
 
+#----------------------------------------------------------------------------
+get_members() {
+    local group="${1}"
+
+    awk -F: -v group="${group}"                             \
+        '$1 == group { printf( "%s\n", $4 ); }' "${GROUP}"
+}
+
 #----------------------------------------------------------------------------
 get_username() {
     local uid="${1}"
@@ -211,16 +219,17 @@ generate_gid() {
 add_one_group() {
     local group="${1}"
     local gid="${2}"
-    local _f
+    local members
 
     # Generate a new GID if needed
     if [ ${gid} -eq -1 ]; then
         gid="$( generate_gid "${group}" )"
     fi
 
+    members=$(get_members "$group")
     # Remove any previous instance of this group, and re-add the new one
     sed -i --follow-symlinks -e '/^'"${group}"':.*/d;' "${GROUP}"
-    printf "%s:x:%d:\n" "${group}" "${gid}" >>"${GROUP}"
+    printf "%s:x:%d:%s\n" "${group}" "${gid}" "$members" >>"${GROUP}"
 
     # Ditto for /etc/gshadow if it exists
     if [ -f "${GSHADOW}" ]; then
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-10-01 19:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-03 13:11 [Buildroot] [PATCH] support/mkusers: Preserve group members Johan Oudinet
2018-09-10 15:22 ` Yann E. MORIN
2018-09-10 15:24 ` Yann E. MORIN
2018-09-12 19:33 ` Thomas Petazzoni
2018-10-01 19:21 ` Peter Korsgaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox