From c5feb3196db464892993a3a6ff24f557e2ca1610 Mon Sep 17 00:00:00 2001 From: BAK BYEONG JUN Date: Sat, 19 Apr 2025 00:15:59 +0900 Subject: [PATCH] init --- user/README.md | 26 +++++++++++++++++++++++ user/devcontainer-feature.json | 39 ++++++++++++++++++++++++++++++++++ user/install.sh | 29 +++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 user/README.md create mode 100644 user/devcontainer-feature.json create mode 100644 user/install.sh diff --git a/user/README.md b/user/README.md new file mode 100644 index 0000000..3102078 --- /dev/null +++ b/user/README.md @@ -0,0 +1,26 @@ + +# user (user) + +Create a user and group with the same id. + +## Example Usage + +```json +"features": { + "ghcr.io/davzucky/devcontainers-features-wolfi/user:1": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| username | Enter name of a non-root user to configure or none to skip | string | automatic | +| userUid | Enter UID for non-root user | string | automatic | +| userGid | Enter GID for non-root user | string | automatic | + + + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/davzucky/devcontainers-features-wolfi/blob/main/src/user/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ \ No newline at end of file diff --git a/user/devcontainer-feature.json b/user/devcontainer-feature.json new file mode 100644 index 0000000..1cdab56 --- /dev/null +++ b/user/devcontainer-feature.json @@ -0,0 +1,39 @@ +{ + "name": "user", + "id": "user", + "version": "0.0.1", + "description": "Create a user and group with the same id.", + "documentationURL": "https://github.com/davzucky/devcontainers-features-wolfi/tree/main/src/user", + "options": { + "username": { + "type": "string", + "proposals": [ + "devcontainer", + "vscode", + "codespace", + "none", + "automatic" + ], + "default": "automatic", + "description": "Enter name of a non-root user to configure or none to skip" + }, + "userUid": { + "type": "string", + "proposals": [ + "1001", + "automatic" + ], + "default": "automatic", + "description": "Enter UID for non-root user" + }, + "userGid": { + "type": "string", + "proposals": [ + "1001", + "automatic" + ], + "default": "automatic", + "description": "Enter GID for non-root user" + } + } +} \ No newline at end of file diff --git a/user/install.sh b/user/install.sh new file mode 100644 index 0000000..407729d --- /dev/null +++ b/user/install.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e + +USERNAME="${_BUILD_ARG_USERNAME:-"automatic"}" +USER_UID="${_BUILD_ARG_UID:-"automatic"}" +USER_GID="${_BUILD_ARG_GID:-"automatic"}" + +apt-get update +apt-get install -y sudo passwd + +if [ "$USERNAME" = "auto" ] || [ "$USERNAME" = "automatic" ]; then + for name in devcontainer vscode node codespace; do + if id -u "$name" >/dev/null 2>&1; then + USERNAME="$name" + break + fi + done + [ -z "$USERNAME" ] && USERNAME="vscode" +fi + +if id -u "$USERNAME" >/dev/null 2>&1; then + [ "$USER_GID" != "automatic" ] && groupmod -g "$USER_GID" "$(id -gn "$USERNAME")" + [ "$USER_UID" != "automatic" ] && usermod -u "$USER_UID" "$USERNAME" +else + [ "$USER_GID" = "automatic" ] && groupadd "$USERNAME" || groupadd -g "$USER_GID" "$USERNAME" + [ "$USER_UID" = "automatic" ] && useradd -m -s /bin/bash -g "$USERNAME" "$USERNAME" || useradd -m -s /bin/bash -u "$USER_UID" -g "$USERNAME" "$USERNAME" +fi + +[ "$USERNAME" != "root" ] && echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME && chmod 0440 /etc/sudoers.d/$USERNAME