From ce76c324a5b74024d6904ab5795de54fe3aebb20 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Mon, 30 Oct 2023 23:50:27 -0700 Subject: [PATCH] autodetect uid and gid from data dir contents --- bin/docker_entrypoint.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/docker_entrypoint.sh b/bin/docker_entrypoint.sh index 964a90f5..92fb46a6 100755 --- a/bin/docker_entrypoint.sh +++ b/bin/docker_entrypoint.sh @@ -2,13 +2,18 @@ export DATA_DIR="${DATA_DIR:-/data}" export ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}" -export PUID=${PUID:-911} -export PGID=${PGID:-911} -# Set the archivebox user UID & GID +# if data directory already exists, autodetect detect owner by looking at files within +DETECTED_UID="$(stat -c '%u' "$DATA_DIR/logs/errors.log" 2>/dev/null || echo 911)" +DETECTED_GID="$(stat -c '%g' "$DATA_DIR/logs/errors.log" 2>/dev/null || echo 911)" + +# prefer PUID and PGID passsed in explicitly as env vars to autodetected defaults +export PUID=${PUID:-$DETECTED_UID} +export PGID=${PGID:-$DETECTED_GID} + +# Set the archivebox user to use the configured UID & GID groupmod -o -g "$PGID" "$ARCHIVEBOX_USER" > /dev/null 2>&1 usermod -o -u "$PUID" "$ARCHIVEBOX_USER" > /dev/null 2>&1 - export PUID="$(id -u archivebox)" export PGID="$(id -g archivebox)"