mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-25 20:26:34 +00:00
support/scripts/mkusers: preserve group members
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> Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr> [Thomas: add curly braces when referencing ${members}, as suggested by Yann.] Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
parent
04d7572a85
commit
497f7134fc
@ -75,6 +75,14 @@ get_gid() {
|
|||||||
'$1 == group { printf( "%d\n", $3 ); }' "${GROUP}"
|
'$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() {
|
get_username() {
|
||||||
local uid="${1}"
|
local uid="${1}"
|
||||||
@ -211,16 +219,17 @@ generate_gid() {
|
|||||||
add_one_group() {
|
add_one_group() {
|
||||||
local group="${1}"
|
local group="${1}"
|
||||||
local gid="${2}"
|
local gid="${2}"
|
||||||
local _f
|
local members
|
||||||
|
|
||||||
# Generate a new GID if needed
|
# Generate a new GID if needed
|
||||||
if [ ${gid} -eq -1 ]; then
|
if [ ${gid} -eq -1 ]; then
|
||||||
gid="$( generate_gid "${group}" )"
|
gid="$( generate_gid "${group}" )"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
members=$(get_members "$group")
|
||||||
# Remove any previous instance of this group, and re-add the new one
|
# Remove any previous instance of this group, and re-add the new one
|
||||||
sed -i --follow-symlinks -e '/^'"${group}"':.*/d;' "${GROUP}"
|
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
|
# Ditto for /etc/gshadow if it exists
|
||||||
if [ -f "${GSHADOW}" ]; then
|
if [ -f "${GSHADOW}" ]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user