From e111aec543e767feb6a909b8d8d713044a75c325 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Fri, 6 Sep 2013 12:06:53 -0700 Subject: [PATCH] fix(make_chroot): Fix support for new users with existing groups. When a user creates a chroot and as a common primary group such as 'users' the groupadd command fails. Instead treat this the same as users and only fail if the group exists but has a different (such as the 'users' group not using GID 100). Hopefully this works better. --- sdk_lib/make_chroot.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index c3c0c9fe62..72ee3f7753 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -150,12 +150,20 @@ init_users () { group_name=$(getent group "${SUDO_GID}" | cut -d: -f1) [[ -n "${group_name}" ]] || die "Looking up gid $SUDO_GID failed." + if grep -q "^${group_name}:[^:]*:${SUDO_GID}:" "${FLAGS_chroot}/etc/group" + then + true # group/gid exists, don't need to add it + elif grep -q "^${group_name}:" "${FLAGS_chroot}/etc/group"; then + die "Group ${group_name} exists in chroot with different GID" + else + bare_chroot groupadd -o -g "${SUDO_GID}" "${group_name}" + fi + # We need the UID to match the host user's. This can conflict with # a particular chroot UID. At the same time, the added user has to # be a primary user for the given UID for sudo to work, which is # determined by the order in /etc/passwd. Let's put ourselves on top # of the file. - bare_chroot groupadd -o -g "${SUDO_GID}" "${group_name}" bare_chroot useradd -o \ -G "${DEFGROUPS}" -g "${SUDO_GID}" -u "${SUDO_UID}" \ -s /bin/bash -m -c "${full_name}" "${SUDO_USER}"