Skip to content

Commit

Permalink
feat(set-user): add a debug option to show detailed logs
Browse files Browse the repository at this point in the history
  • Loading branch information
zydou committed Sep 1, 2023
1 parent 5e6a4b9 commit 96c653d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/set-user/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "set-user",
"version": "1.1.6",
"version": "1.2.0",
"name": "Set up username and UID:GID",
"documentationURL": "https://github.com/zydou/devcontainer-features/tree/main/src/set-user",
"description": "Set up a non-root user with UID and GID",
Expand Down Expand Up @@ -32,6 +32,11 @@
],
"default": "automatic",
"description": "Enter gid for non-root user"
},
"debug": {
"type": "boolean",
"default": false,
"description": "Enable detailed logging of this feature"
}
}
}
22 changes: 13 additions & 9 deletions src/set-user/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set -e
USERNAME="${USERNAME:-"${_REMOTE_USER:-"vscode"}"}"
USER_UID="${UID:-"automatic"}"
USER_GID="${GID:-"automatic"}"
DEBUG="${DEBUG:-"false"}"

if [ "$(id -u)" -ne 0 ]; then
echo 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
Expand Down Expand Up @@ -45,11 +46,12 @@ else
exit 1
fi

echo "content of /etc/passwd before setup:"
cat /etc/passwd
echo "content of /etc/group before setup:"
cat /etc/group

if [ "${DEBUG}" = "true" ]; then
echo "content of /etc/passwd before setup:"
cat /etc/passwd
echo "content of /etc/group before setup:"
cat /etc/group
fi

# Create or update a non-root user to match UID/GID.
group_name="${USERNAME}"
Expand Down Expand Up @@ -91,7 +93,9 @@ if [ "${USERNAME}" != "root" ]; then
chmod 0440 "/etc/sudoers.d/${USERNAME}"
fi

echo "content of /etc/passwd after setup:"
cat /etc/passwd
echo "content of /etc/group after setup:"
cat /etc/group
if [ "${DEBUG}" = "true" ]; then
echo "content of /etc/passwd after setup:"
cat /etc/passwd
echo "content of /etc/group after setup:"
cat /etc/group
fi

0 comments on commit 96c653d

Please sign in to comment.