From ea209fa575ec021edea6482832969a7fd6ec5f7b Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Mon, 25 Jan 2021 18:55:37 -0500 Subject: [PATCH] make permission chowning on docker start less fancy --- bin/docker_entrypoint.sh | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/bin/docker_entrypoint.sh b/bin/docker_entrypoint.sh index 29fcb646..865a9929 100755 --- a/bin/docker_entrypoint.sh +++ b/bin/docker_entrypoint.sh @@ -1,24 +1,25 @@ #!/usr/bin/env bash -# Autodetect UID,GID of host user based on ownership of files in the data volume DATA_DIR="${DATA_DIR:-/data}" ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}" -USID=$(stat --format="%u" "$DATA_DIR") -GRID=$(stat --format="%g" "$DATA_DIR") - -# If user is not root, modify the archivebox user+files to have the same uid,gid -if [[ "$USID" != 0 && "$GRID" != 0 ]]; then - usermod -u "$USID" "$ARCHIVEBOX_USER" > /dev/null 2>&1 - groupmod -g "$GRID" "$ARCHIVEBOX_USER" > /dev/null 2>&1 - chown -R "$USID":"$GRID" "/home/$ARCHIVEBOX_USER" - chown "$USID":"$GRID" "$DATA_DIR" - chown "$USID":"$GRID" "$DATA_DIR/*" > /dev/null 2>&1 || true +# Set the permissions of the data dir to match the archivebox user +if [[ -d "$DATA_DIR/archive" ]]; then + # check data directory permissions + if [[ ! "$(stat -c %u $DATA_DIR/archive)" = "$(id -u archivebox)" ]]; then + echo "Change in ownership detected, please be patient while we chown existing files" + echo "This could take some time..." + chown $ARCHIVEBOX_USER:$ARCHIVEBOX_USER -R "$DATA_DIR" + fi +else + # create data directory + mkdir -p "$DATA_DIR" + chown -R $ARCHIVEBOX_USER:$ARCHIVEBOX_USER "$DATA_DIR" fi +chown $ARCHIVEBOX_USER:$ARCHIVEBOX_USER "$DATA_DIR" -# Run commands as the new archivebox user in Docker. -# Any files touched will have the same uid & gid -# inside Docker and outside on the host machine. + +# Drop permissions to run commands as the archivebox user if [[ "$1" == /* || "$1" == "echo" || "$1" == "archivebox" ]]; then # arg 1 is a binary, execute it verbatim # e.g. "archivebox init"