Skip to content

Commit 3f37648

Browse files
Copilotabdurriq
andcommitted
Fix common-utils to restore original user creation logic
common-utils has different semantics than other features - it CREATES users rather than just using existing ones. Restored the original inline logic that uses _REMOTE_USER without validation since the user will be created. Co-authored-by: abdurriq <[email protected]>
1 parent 5358fa3 commit 3f37648

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

src/common-utils/main.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,20 +391,32 @@ case "${ADJUSTED_ID}" in
391391
;;
392392
esac
393393

394-
# Source common helper functions
395-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
396-
source "${SCRIPT_DIR}/_lib/common-setup.sh"
397-
398394
# Handle the special "none" case for common-utils before user determination
399395
# The "none" case sets USER_UID and USER_GID to 0
400396
ORIGINAL_USERNAME="${USERNAME}"
401397
if [ "${ORIGINAL_USERNAME}" = "none" ]; then
402398
USERNAME="root"
403399
USER_UID=0
404400
USER_GID=0
405-
else
401+
elif [ "${ORIGINAL_USERNAME}" = "auto" ] || [ "${ORIGINAL_USERNAME}" = "automatic" ]; then
406402
# If in automatic mode, determine if a user already exists, if not use vscode (which will be created)
407-
USERNAME=$(determine_user_from_input "${USERNAME}" "vscode")
403+
# common-utils has special handling because it CREATES users, not just uses existing ones
404+
if [ "${_REMOTE_USER}" != "root" ]; then
405+
USERNAME="${_REMOTE_USER}"
406+
else
407+
# Try to find an existing user, or fall back to "vscode" which we'll create
408+
USERNAME=""
409+
POSSIBLE_USERS=("devcontainer" "vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
410+
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
411+
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
412+
USERNAME=${CURRENT_USER}
413+
break
414+
fi
415+
done
416+
if [ "${USERNAME}" = "" ]; then
417+
USERNAME=vscode
418+
fi
419+
fi
408420
fi
409421
# Create or update a non-root user to match UID/GID.
410422
group_name="${USERNAME}"

0 commit comments

Comments
 (0)