aboutsummaryrefslogtreecommitdiffstats
path: root/package
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2021-10-26 13:02:37 +0100
committerDaniel Golle <daniel@makrotopia.org>2021-10-28 16:27:21 +0100
commitb2aca61360c33ad3161f8ef35a1c28ebb2507600 (patch)
tree8e90b642ae1038f94085ad53531ab9467524ab90 /package
parentdb639238f202ef7a71ad7f85693463fd8a3810cd (diff)
downloadupstream-b2aca61360c33ad3161f8ef35a1c28ebb2507600.tar.gz
upstream-b2aca61360c33ad3161f8ef35a1c28ebb2507600.tar.bz2
upstream-b2aca61360c33ad3161f8ef35a1c28ebb2507600.zip
base-files, metadata: support additional group membership
Some packages may require additional group membership for the system user added by that package. Allow defining additional groups as third member of the ':'-separated tuple, allowing to specify multiple ','-separated groups with optional GID. Example: USERID:=foouser=1000:foogroup=1000:addg1=1001,addg2=1002,addg3 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'package')
-rw-r--r--package/base-files/files/lib/functions.sh23
1 files changed, 20 insertions, 3 deletions
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh
index d8604415cc..a5b23eb135 100644
--- a/package/base-files/files/lib/functions.sh
+++ b/package/base-files/files/lib/functions.sh
@@ -209,10 +209,10 @@ add_group_and_user() {
if [ -n "$rusers" ]; then
local tuple oIFS="$IFS"
for tuple in $rusers; do
- local uid gid uname gname
+ local uid gid uname gname addngroups addngroup addngname addngid
IFS=":"
- set -- $tuple; uname="$1"; gname="$2"
+ set -- $tuple; uname="$1"; gname="$2"; addngroups="$3"
IFS="="
set -- $uname; uname="$1"; uid="$2"
set -- $gname; gname="$1"; gid="$2"
@@ -232,7 +232,24 @@ add_group_and_user() {
group_add_user "$gname" "$uname"
fi
- unset uid gid uname gname
+ if [ -n "$uname" ] && [ -n "$addngroups" ]; then
+ oIFS="$IFS"
+ IFS=","
+ for addngroup in $addngroups ; do
+ IFS="="
+ set -- $addngroup; addngname="$1"; addngid="$2"
+ if [ -n "$addngid" ]; then
+ group_exists "$addngname" || group_add "$addngname" "$addngid"
+ else
+ group_add_next "$addngname"
+ fi
+
+ group_add_user "$addngname" "$uname"
+ done
+ IFS="$oIFS"
+ fi
+
+ unset uid gid uname gname addngroups addngroup addngname addngid
done
fi
}