Skip to content

Commit

Permalink
init: add users to sudo/wheel group if present
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Di Maio <[email protected]>
  • Loading branch information
89luca89 committed Jun 12, 2023
1 parent f24d34d commit 9bfac5c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions distrobox-init
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,14 @@ if [ -d "/run/host/var/kerberos" ] &&
EOF
fi

# If we have sudo/wheel groups, let's add the user to them.
additional_groups=""
if grep -q "^sudo" /etc/group; then
additional_groups="sudo"
elif grep -q "^wheel" /etc/group; then
additional_groups="wheel"
fi

# Let's add our user to the container. if the user already exists, enforce properties.
#
# In case of AD or LDAP usernames, it is possible we will have a backslach in the name.
Expand All @@ -1226,6 +1234,7 @@ if ! grep -q "^$(printf '%s' "${container_user_name}" | tr '\\' '.'):" /etc/pass
if ! useradd \
--home-dir "${container_user_home}" \
--no-create-home \
--groups "${additional_groups}" \
--shell "${SHELL:-"/bin/bash"}" \
--uid "${container_user_uid}" \
--gid "${container_user_gid}" \
Expand All @@ -1248,6 +1257,7 @@ elif [ ! -e /etc/passwd.done ]; then
if ! usermod \
--home "${container_user_home}" \
--shell "${SHELL:-"/bin/bash"}" \
--groups "${additional_groups}" \
--uid "${container_user_uid}" \
--gid "${container_user_gid}" \
"${container_user_name}"; then
Expand Down

0 comments on commit 9bfac5c

Please sign in to comment.