don't fail if uid/gid exists
This commit is contained in:
+10
-16
@@ -5,30 +5,24 @@ set -e
|
|||||||
PUID="${PUID:-1000}"
|
PUID="${PUID:-1000}"
|
||||||
PGID="${PGID:-1000}"
|
PGID="${PGID:-1000}"
|
||||||
|
|
||||||
# Create group if it doesn't exist
|
# Use existing group if the GID is already taken, otherwise create one
|
||||||
if ! getent group sbv >/dev/null 2>&1; then
|
if ! getent group "${PGID}" >/dev/null 2>&1; then
|
||||||
addgroup -g "${PGID}" sbv
|
addgroup -g "${PGID}" sbv
|
||||||
fi
|
fi
|
||||||
|
SBV_GROUP="$(getent group "${PGID}" | cut -d: -f1)"
|
||||||
|
|
||||||
# Create user if it doesn't exist
|
# Use existing user if the UID is already taken, otherwise create one
|
||||||
if ! getent passwd sbv >/dev/null 2>&1; then
|
if ! getent passwd "${PUID}" >/dev/null 2>&1; then
|
||||||
adduser -D -u "${PUID}" -G sbv sbv
|
adduser -D -u "${PUID}" -G "${SBV_GROUP}" 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
|
|
||||||
fi
|
fi
|
||||||
|
SBV_USER="$(getent passwd "${PUID}" | cut -d: -f1)"
|
||||||
|
|
||||||
# Ensure data directory exists and has correct permissions
|
# Ensure data directory exists and has correct permissions
|
||||||
mkdir -p "${DB_PATH_PREFIX:-/data}"
|
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
|
# 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
|
# Switch to the sbv user and execute the application
|
||||||
exec su-exec sbv "$@"
|
exec su-exec "${SBV_USER}" "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user