From 4641c1aea2970b0ce43e7699caa5c9e1bea76fda Mon Sep 17 00:00:00 2001 From: Giovanni Fulco Date: Wed, 5 Jul 2023 14:17:12 +0200 Subject: [PATCH] [Maintenance] reuse use with uid=1000 from distro #194 (#211) --- Dockerfile | 8 ----- README.md | 1 + app/bin/run-upmpdcli.sh | 74 ++++++++++++++++++++++++++++------------- 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index c15776f..a20bd3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,14 +4,6 @@ ARG USE_PPA="${USE_PPA:-upnpp1}" ARG BUILD_MODE="${BUILD_MODE:-full}" ARG USE_APT_PROXY -RUN if $(grep -q 1000 /etc/passwd); then \ - userdel -r $(id -un 1000); \ -fi - -RUN if $(grep -q 1000 /etc/group); then \ - groupdel -r $(id -gn 1000); \ -fi - RUN mkdir -p /app/conf COPY app/conf/01proxy /app/conf/ diff --git a/README.md b/README.md index e9a7de5..5d3a43f 100644 --- a/README.md +++ b/README.md @@ -245,6 +245,7 @@ Just be careful to use the tag you have built. Change Date|Major Changes ---|--- +2023-07-05|Reuse existing user that should exist in the base image (see issue [#194](https://github.com/GioF71/upmpdcli-docker/issues/194)) 2023-07-04|Support for `lunar` for real this time (see issue [#209](https://github.com/GioF71/upmpdcli-docker/issues/209)) 2023-07-04|Install python packages only when needed (see issue [#206](https://github.com/GioF71/upmpdcli-docker/issues/206)) 2023-07-04|Set `latest` tag to `lunar` builds, leave `stable` to `jammy` (see issue [#204](https://github.com/GioF71/upmpdcli-docker/issues/204)) diff --git a/app/bin/run-upmpdcli.sh b/app/bin/run-upmpdcli.sh index 5f42ea5..5adb2cc 100644 --- a/app/bin/run-upmpdcli.sh +++ b/app/bin/run-upmpdcli.sh @@ -390,44 +390,71 @@ fi cat $CONFIG_FILE -USER_NAME=upmpd-user -GROUP_NAME=upmpd-user +DEFAULT_USER_NAME=upmpd-user +DEFAULT_GROUP_NAME=upmpd-user +DEFAULT_HOME_DIR=/home/$DEFAULT_USER_NAME + +USER_NAME=$DEFAULT_USER_NAME +GROUP_NAME=$DEFAULT_GROUP_NAME +HOME_DIR=$DEFAULT_HOME_DIR -echo "Creating user ..."; if [ -z "${PUID}" ]; then PUID=$DEFAULT_UID; echo "Setting default value for PUID: ["$PUID"]" fi + if [ -z "${PGID}" ]; then PGID=$DEFAULT_GID; echo "Setting default value for PGID: ["$PGID"]" fi -HOME_DIR=/home/$USER_NAME -### create home directory and ancillary directories -if [ ! -d "$HOME_DIR" ]; then - echo "Home directory [$HOME_DIR] not found, creating." - mkdir -p $HOME_DIR -fi -### create group -if [ ! $(getent group $GROUP_NAME) ]; then - echo "group $GROUP_NAME does not exist, creating..." + +echo "Ensuring user with uid:[$PUID] gid:[$PGID] exists ..."; + +### create group if it does not exist +if [ ! $(getent group $PGID) ]; then + echo "Group with gid [$PGID] does not exist, creating..." groupadd -g $PGID $GROUP_NAME + echo "Group [$GROUP_NAME] with gid [$PGID] created." else - echo "group $GROUP_NAME already exists." -fi -### create user -if [ ! $(getent passwd $USER_NAME) ]; then - echo "user $USER_NAME does not exist, creating..." - useradd -g $PGID -u $PUID -s /bin/bash -M -d $HOME_DIR $USER_NAME - id $USER_NAME - echo "user $USER_NAME created." + GROUP_NAME=$(getent group $PGID | cut -d: -f1) + echo "Group with gid [$PGID] name [$GROUP_NAME] already exists." +fi + +### create user if it does not exist +if [ ! $(getent passwd $PUID) ]; then + echo "User with uid [$PUID] does not exist, creating..." + useradd -g $PGID -u $PUID -M $USER_NAME + echo "User [$USER_NAME] with uid [$PUID] created." else - echo "user $USER_NAME already exists." + USER_NAME=$(getent passwd $PUID | cut -d: -f1) + echo "user with uid [$PUID] name [$USER_NAME] already exists." + HOME_DIR="/home/$USER_NAME" fi -echo "UPRCL is enabled, create $USER_NAME (group: $GROUP_NAME)"; -# set permission for home dir + +### create home directory +if [ ! -d "$HOME_DIR" ]; then + echo "Home directory [$HOME_DIR] not found, creating." + mkdir -p $HOME_DIR + echo ". done." +fi + +# set home to user +echo "Setting home directory to [$HOME_DIR] for user [$USER_NAME] ..." +usermod -d $HOME_DIR $USER_NAME +echo ". done." + +# set shell +echo "Setting shell to [/bin/bash] for user [$USER_NAME] ..." +usermod -s /bin/bash $USER_NAME +echo ". done." + +# set permission for home directory +echo "Setting home directory permissions ..." chown -R $USER_NAME:$GROUP_NAME $HOME_DIR +echo ". done." + # Permissions of writable volumes +echo "Setting permissions for writable volumes ..." chown -R $USER_NAME:$GROUP_NAME /cache # Fix permission errors on existing files find /cache -type d -exec chmod 755 {} \; @@ -435,6 +462,7 @@ find /cache -type f -exec chmod 644 {} \; chown -R $USER_NAME:$GROUP_NAME /uprcl/confdir chown -R $USER_NAME:$GROUP_NAME /user/config chown -R $USER_NAME:$GROUP_NAME /log +echo ". done." echo "About to sleep for $STARTUP_DELAY_SEC second(s)" sleep $STARTUP_DELAY_SEC