From 4397232f06704d5eb03eeff05632a6d6a30e4f71 Mon Sep 17 00:00:00 2001 From: lowcarbdev Date: Sat, 28 Mar 2026 22:37:56 -0600 Subject: [PATCH] don't fail if uid/gid exists --- docker-entrypoint.sh | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 3af2fc9..c555a50 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -5,30 +5,24 @@ set -e PUID="${PUID:-1000}" PGID="${PGID:-1000}" -# Create group if it doesn't exist -if ! getent group sbv >/dev/null 2>&1; then +# Use existing group if the GID is already taken, otherwise create one +if ! getent group "${PGID}" >/dev/null 2>&1; then addgroup -g "${PGID}" sbv fi +SBV_GROUP="$(getent group "${PGID}" | cut -d: -f1)" -# Create user if it doesn't exist -if ! getent passwd sbv >/dev/null 2>&1; then - adduser -D -u "${PUID}" -G sbv sbv -fi - -# Ensure the user has the correct UID/GID -if [ "$(id -u sbv)" != "${PUID}" ] || [ "$(id -g sbv)" != "${PGID}" ]; then - deluser sbv >/dev/null 2>&1 || true - delgroup sbv >/dev/null 2>&1 || true - addgroup -g "${PGID}" sbv - adduser -D -u "${PUID}" -G sbv sbv +# Use existing user if the UID is already taken, otherwise create one +if ! getent passwd "${PUID}" >/dev/null 2>&1; then + adduser -D -u "${PUID}" -G "${SBV_GROUP}" sbv fi +SBV_USER="$(getent passwd "${PUID}" | cut -d: -f1)" # Ensure data directory exists and has correct permissions mkdir -p "${DB_PATH_PREFIX:-/data}" -chown -R sbv:sbv "${DB_PATH_PREFIX:-/data}" +chown -R "${SBV_USER}:${SBV_GROUP}" "${DB_PATH_PREFIX:-/data}" # Log the user we're running as -echo "Running as UID=${PUID} GID=${PGID}" +echo "Running as UID=${PUID} GID=${PGID} (${SBV_USER}:${SBV_GROUP})" # Switch to the sbv user and execute the application -exec su-exec sbv "$@" +exec su-exec "${SBV_USER}" "$@"