From 1970ec9aec7a86cbf506a3ae9345a34fc1b127a4 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Thu, 20 Mar 2025 18:09:12 +0100 Subject: [PATCH] Check directory permission in docker-entrypoint.sh with `test -w` --- docker-entrypoint.sh | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 787dd13fb..1a7126b9d 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,15 +2,12 @@ set -e -# Get UID/GID from volume dir -VOLUME_UID=$(stat -c '%u' $VOLUME_DIR) -VOLUME_GID=$(stat -c '%g' $VOLUME_DIR) - -MY_UID=$(id -u) -MY_GID=$(id -g) - # Run as custom user -if [ "$MY_GID" != "$VOLUME_GID" ] || [ "$MY_UID" != "$VOLUME_UID" ]; then +if ! [ -w $VOLUME_DIR ]; then + # Get UID/GID from volume dir + VOLUME_UID=$(stat -c '%u' $VOLUME_DIR) + VOLUME_GID=$(stat -c '%g' $VOLUME_DIR) + # create or modify user and group to match expected uid/gid groupadd --gid $VOLUME_GID archivist || groupmod -o --gid $VOLUME_GID archivist useradd -ms /bin/bash -u $VOLUME_UID -g $VOLUME_GID archivist || usermod -o -u $VOLUME_UID archivist @@ -36,4 +33,3 @@ else # run process directly exec $@ fi -