-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking change! Added the ability to change the user ID and group ID of the user running the server process via environment variables UID and GID, requiring a different configuration file location to avoid overriding the '/etc' directory inside the Docker container with the mounted directory.
- Loading branch information
Showing
5 changed files
with
123 additions
and
24 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
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
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 |
---|---|---|
@@ -1,2 +1,96 @@ | ||
#!/bin/sh | ||
exec uvicorn gallery-dl-server:app --host 0.0.0.0 --port $CONTAINER_PORT --log-level info --no-access-log | ||
#!/usr/bin/env bash | ||
|
||
check_etc () { | ||
if [[ ! -f /etc/passwd ]]; then | ||
exit 1 | ||
fi | ||
} | ||
|
||
get_ids () { | ||
UID_OG="$(id -u appuser)" | ||
GID_OG="$(id -g appuser)" | ||
|
||
UID="${UID:-$UID_OG}" | ||
GID="${GID:-$GID_OG}" | ||
} | ||
|
||
mod_ids () { | ||
groupmod --non-unique --gid "$GID" appgroup >/dev/null 2>&1 | ||
usermod --non-unique --gid "$GID" --uid "$UID" appuser >/dev/null 2>&1 | ||
|
||
chown --quiet -R "$UID:$GID" /usr/src/app /.cache/pip /.local | ||
} | ||
|
||
init () { | ||
if [[ $UID -eq $(id -u appuser) && $GID -eq $(id -g appuser) ]]; then | ||
log 0 | ||
if [[ $(id -u) -eq $(id -u root) ]]; then | ||
start 0 | ||
elif [[ $(id -u) -eq $(id -u appuser) ]]; then | ||
start 1 | ||
else | ||
exit 0 | ||
fi | ||
else | ||
log 1 | ||
if [[ $(id -u) -eq $(id -u root) ]]; then | ||
start 0 | ||
elif [[ $(id -u) -eq $(id -u appuser) ]]; then | ||
start 1 | ||
else | ||
exit 0 | ||
fi | ||
fi | ||
} | ||
|
||
log() { | ||
if [[ $1 -eq 0 ]]; then | ||
echo "INFO: Starting process with UID=$UID and GID=$GID ($(getent passwd $UID | cut -d: -f1))" | ||
elif [[ $1 -eq 1 ]]; then | ||
echo "INFO: Starting process with UID=$(id -u) and GID=$(id -g) ($(id -u -n))" | ||
else | ||
exit 0 | ||
fi | ||
} | ||
|
||
start() { | ||
if [[ $1 -eq 0 ]]; then | ||
exec su-exec appuser uvicorn gallery-dl-server:app --host 0.0.0.0 --port "$CONTAINER_PORT" --log-level info --no-access-log | ||
elif [[ $1 -eq 1 ]]; then | ||
exec uvicorn gallery-dl-server:app --host 0.0.0.0 --port "$CONTAINER_PORT" --log-level info --no-access-log | ||
else | ||
exit 0 | ||
fi | ||
} | ||
|
||
exit() { | ||
if [[ $1 -eq 0 ]]; then | ||
echo "error: fatal error" | ||
elif [[ $1 -eq 1 ]]; then | ||
echo "error: config mount location has changed from /etc to /config; please mount the directory containing gallery-dl.conf to /config" \ | ||
"and make sure to update any paths specified inside your config file, e.g. /etc/cookies.txt --> /config/cookies.txt" | ||
elif [[ $1 -eq 2 ]]; then | ||
echo "error: invalid permissions; use the environment variables UID and GID to set the user ID and group ID" \ | ||
"(defaults: UID=$UID_OG, GID=$GID_OG)" | ||
fi | ||
command exit 0 | ||
} | ||
|
||
check_etc | ||
get_ids | ||
if [[ $UID -ne $UID_OG || $GID -ne $GID_OG ]]; then | ||
if [[ $(id -u -n 2>/dev/null) == root ]]; then | ||
mod_ids | ||
init | ||
elif [[ $(id -u -n 2>/dev/null) == appuser ]]; then | ||
init | ||
else | ||
exit 2 | ||
fi | ||
elif [[ $(id -u -n 2>/dev/null) == root ]]; then | ||
init | ||
elif [[ $(id -u -n 2>/dev/null) == appuser ]]; then | ||
init | ||
else | ||
exit 2 | ||
fi |