commit: 9acc90f195babd6be689ea30a5b6dbdb42ba55a1 Author: Mike Gilbert <floppym <AT> gentoo <DOT> org> AuthorDate: Fri Jun 13 23:07:34 2025 +0000 Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org> CommitDate: Fri Jun 13 23:07:34 2025 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9acc90f1
user-info.eclass: fix egetgroups when ROOT is not empty Closes: https://bugs.gentoo.org/958022 Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org> eclass/user-info.eclass | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/eclass/user-info.eclass b/eclass/user-info.eclass index 1cc7b8250309..848622fe94e9 100644 --- a/eclass/user-info.eclass +++ b/eclass/user-info.eclass @@ -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 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) ) - - # Remove primary group from list - sgroups=${sgroups#${pgroup}} - egroups_arr=( ${pgroup} ${sgroups[@]} ) + 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
