Support running as alternative UID/GID (#74)

Because we use the Java user.home property to get the default
configuration directory, there needs to be an entry for the correct user
in /etc/passwd. For this to work with arbitrary UID/GID, that means
updating /etc/shadow dynamically based on the UID/GID in the container
before starting the application.

Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
This commit is contained in:
Chance Zibolski
2024-01-18 17:10:10 -08:00
committed by GitHub
parent 05c4fd32ab
commit fa96e50161
2 changed files with 33 additions and 4 deletions

View File

@@ -35,6 +35,26 @@ export BACKUP_INTERVAL="${BACKUP_INTERVAL:-1}"
export BACKUP_TTL="${BACKUP_TTL:-14}"
export EXTENSION_REPOS="${EXTENSION_REPOS:-"[]"}"
USERNAME="suwayomi"
HOME="/home/${USERNAME}"
# add UID/GID to /etc/passwd if missing, in order for Java's user.home property to work correctly with non default UIDs.
if ! whoami >/dev/null 2>&1; then
if [ -w /etc/passwd ]; then
echo "Adding user ${USERNAME} with current UID:GID $(id -u):$(id -g) to /etc/passwd"
# Remove existing entry with user first.
# cannot use sed -i because we do not have permission to write new
# files into /etc
sed "/${USERNAME}:x/d" /etc/passwd > /tmp/passwd
# add our user with our current user ID into passwd
echo "${USERNAME}:x:$(id -u):$(id -g):${USERNAME} user:${HOME}:/bin/bash" >> /tmp/passwd
# overwrite existing contents with new contents (cannot replace the
# file due to permissions)
cat /tmp/passwd > /etc/passwd
rm /tmp/passwd
fi
fi
envsubst < /home/suwayomi/server.conf.template > /home/suwayomi/.local/share/Tachidesk/server.conf
exec java -jar "/home/suwayomi/startup/tachidesk_latest.jar";