Skip to content

Commit

Permalink
[Maintenance] reuse use with uid=1000 from distro #194 (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
GioF71 authored Jul 5, 2023
1 parent 1191e03 commit 4641c1a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
8 changes: 0 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
74 changes: 51 additions & 23 deletions app/bin/run-upmpdcli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -390,51 +390,79 @@ 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 {} \;
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
Expand Down

0 comments on commit 4641c1a

Please sign in to comment.