From be2dcb477493520c021254acd59d9f3f2a4cc79d Mon Sep 17 00:00:00 2001 From: Arthur Joppart Date: Fri, 17 May 2024 01:33:28 +0200 Subject: [PATCH] alright: one more --- dl-downer/Dockerfile | 3 +-- dl-downer/entry.sh | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/dl-downer/Dockerfile b/dl-downer/Dockerfile index 9d44f07..114dc22 100644 --- a/dl-downer/Dockerfile +++ b/dl-downer/Dockerfile @@ -45,8 +45,7 @@ RUN pip install --no-cache-dir -r requirements.txt # RUN pip install playwright==@1.42.0 RUN playwright install --with-deps -RUN apt-get install -y sudo -RUN apt-get install -y gosu +RUN apt-get install -y sudo gosu RUN rm -rf /var/lib/apt/lists/ ENTRYPOINT [ "entry.sh" ] diff --git a/dl-downer/entry.sh b/dl-downer/entry.sh index e9086db..64b1e50 100644 --- a/dl-downer/entry.sh +++ b/dl-downer/entry.sh @@ -4,21 +4,32 @@ PUID=${PUID:-1000} PGID=${PGID:-1000} -# Check if group already exists -if ! getent group mygroup > /dev/null 2>&1; then - groupadd -g "$PGID" mygroup +# Create the group if it doesn't exist +if ! getent group "$PGID" > /dev/null 2>&1; then + groupadd -g "$PGID" mygroup +else + existing_group=$(getent group "$PGID" | cut -d: -f1) + echo "Using existing group: $existing_group" fi -# Check if user already exists -if ! id -u myuser > /dev/null 2>&1; then - useradd -u "$PUID" -g "$PGID" -m -s /bin/bash myuser +# Create the user if it doesn't exist +if ! id -u "$PUID" > /dev/null 2>&1; then + useradd -u "$PUID" -g "$PGID" -m -s /bin/bash myuser +else + existing_user=$(getent passwd "$PUID" | cut -d: -f1) + echo "Using existing user: $existing_user" +fi + +# Assign the user to the existing group if the group already existed +if getent passwd myuser > /dev/null 2>&1; then + usermod -aG "$PGID" myuser fi # Change ownership of the home directory -chown -R myuser:mygroup /home/myuser +chown -R "$PUID:$PGID" /home/myuser chown -R myuser:mygroup /downloads chown -R myuser:mygroup /storage_states # Run the command as the specified user -exec gosu myuser "$@" +exec gosu "$PUID:$PGID" "$@"