Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docker): allow downgrade to regular user via environment variab…
…les (#89) * docker: Allowing to downgrade to regular user via environment variables (fixed issue #56) * docker: Use full relative path to entrypoint.sh Relative path as seen from repo-root Co-authored-by: Aaron Leopold <36278431+aaronleopold@users.noreply.github.com> --------- Co-authored-by: Aaron Leopold <36278431+aaronleopold@users.noreply.github.com>
- Loading branch information
1 parent
e50dd04
commit da20577
Showing
2 changed files
with
47 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/sh | ||
# Depending on the values passed for PUID/PGID via environment variables, | ||
# either starts the stump server daemon as root or as a regular user | ||
# | ||
# Also takes care of assigning proper attributes to the folders /data, /config and /app | ||
PUID=${PUID:-0} | ||
PGID=${PGID:-0} | ||
|
||
USER=stump | ||
GROUP=stump | ||
|
||
## Add stump group if it doesn't already exist | ||
if [[ -z "$(getent group "$PGID" | cut -d':' -f1)" ]]; then | ||
addgroup -g "$PGID" $GROUP | ||
fi | ||
|
||
## Add stump user if it doesn't already exist | ||
if [[ -z "$(getent passwd "$PUID" | cut -d':' -f1)" ]]; then | ||
adduser -D -s /bin/sh -u "$PUID" -G "$GROUP" $USER | ||
fi | ||
|
||
# Change current working directory | ||
cd /app | ||
|
||
if [[ "$PUID" -eq 0 ]]; then | ||
# Run as root | ||
./stump | ||
else | ||
# Set ownership on config, app and data dir | ||
chown -R "$PUID":"$PGID" /app | ||
chown -R "$PUID":"$PGID" /config | ||
# NOTE: Only change the directory itself, not recursively | ||
# We dont want to accidentally overwrite with incorrect | ||
# permissions if users provide wrong values for PUID/PGID | ||
chown "$PUID":"$PGID" /data | ||
|
||
# Run as non-root user | ||
# NOTE: Omit "-l" switch to keep env vars | ||
su $USER -c ./stump | ||
fi |