Skip to content

Commit 35a5d93

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 d036296 commit 35a5d93

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
@@ -399,20 +399,32 @@ case "${ADJUSTED_ID}" in
399399
;;
400400
esac
401401

402-
# Source common helper functions
403-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
404-
source "${SCRIPT_DIR}/_lib/common-setup.sh"
405-
406402
# Handle the special "none" case for common-utils before user determination
407403
# The "none" case sets USER_UID and USER_GID to 0
408404
ORIGINAL_USERNAME="${USERNAME}"
409405
if [ "${ORIGINAL_USERNAME}" = "none" ]; then
410406
USERNAME="root"
411407
USER_UID=0
412408
USER_GID=0
413-
else
409+
elif [ "${ORIGINAL_USERNAME}" = "auto" ] || [ "${ORIGINAL_USERNAME}" = "automatic" ]; then
414410
# If in automatic mode, determine if a user already exists, if not use vscode (which will be created)
415-
USERNAME=$(determine_user_from_input "${USERNAME}" "vscode")
411+
# common-utils has special handling because it CREATES users, not just uses existing ones
412+
if [ "${_REMOTE_USER}" != "root" ]; then
413+
USERNAME="${_REMOTE_USER}"
414+
else
415+
# Try to find an existing user, or fall back to "vscode" which we'll create
416+
USERNAME=""
417+
POSSIBLE_USERS=("devcontainer" "vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
418+
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
419+
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
420+
USERNAME=${CURRENT_USER}
421+
break
422+
fi
423+
done
424+
if [ "${USERNAME}" = "" ]; then
425+
USERNAME=vscode
426+
fi
427+
fi
416428
fi
417429
# Create or update a non-root user to match UID/GID.
418430
group_name="${USERNAME}"

0 commit comments

Comments
 (0)