user-info.eclass: fix egetgroups when ROOT is not empty

Closes: https://bugs.gentoo.org/958022
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
This commit is contained in:
Mike Gilbert
2025-06-13 19:07:34 -04:00
parent 2dfd9dca61
commit 9acc90f195

View File

@@ -1,4 +1,4 @@
# Copyright 1999-2023 Gentoo Authors
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: user-info.eclass
@@ -165,13 +165,18 @@ egetgroups() {
[[ $# -eq 1 ]] || die "usage: egetgroups <user>"
local egroups_arr
if [[ -n "${ROOT}" ]]; then
local pgroup=$(egetent passwd "$1" | cut -d: -f1)
local sgroups=( $(grep -E ":([^:]*,)?$1(,[^:]*)?$" "${ROOT}/etc/group" | cut -d: -f1) )
# Remove primary group from list
sgroups=${sgroups#${pgroup}}
egroups_arr=( ${pgroup} ${sgroups[@]} )
if [[ -n "${ROOT}" ]]; then
local pgid=$(egetent passwd "$1" | cut -d: -f4)
local pgroup=$(egetent group "${pgid}" | cut -d: -f1)
local sgroups=( $(grep -E ":([^:]*,)?$1(,[^:]*)?$" "${ROOT}/etc/group" | cut -d: -f1) )
egroups_arr=( "${pgroup}" )
local sg
for sg in "${sgroups[@]}"; do
if [[ ${sg} != ${pgroup} ]]; then
egroups_arr+=( "${sg}" )
fi
done
else
read -r -a egroups_arr < <(id -G -n "$1")
fi