#!/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