Support host UID/GID for Docker runtime

This commit is contained in:
Dymas
2026-05-17 14:24:17 +02:00
parent 2734343904
commit 8ea43f1593
7 changed files with 64 additions and 4 deletions
+38
View File
@@ -8,6 +8,42 @@ is_true() {
esac
}
is_integer() {
case "${1:-}" in
'' | *[!0-9]*) return 1 ;;
*) return 0 ;;
esac
}
run_as_requested_user() {
uid="${USER_UID:-}"
gid="${USER_GID:-}"
if [ -z "$uid" ] && [ -z "$gid" ]; then
return 1
fi
if [ -z "$uid" ] || [ -z "$gid" ]; then
echo "Both USER_UID and USER_GID must be set together." >&2
exit 1
fi
if ! is_integer "$uid" || ! is_integer "$gid"; then
echo "USER_UID and USER_GID must be numeric." >&2
exit 1
fi
mkdir -p /app/.ani-cli-web/home
chown "$uid:$gid" /downloads /app/.ani-cli-web /app/.ani-cli-web/home
cd /app
exec setpriv \
--reuid "$uid" \
--regid "$gid" \
--clear-groups \
env HOME=/app/.ani-cli-web/home ./ani-cli-web "$@"
}
mkdir -p /downloads /app/.ani-cli-web
if is_true "${UPDATE_ON_START:-false}"; then
@@ -15,5 +51,7 @@ if is_true "${UPDATE_ON_START:-false}"; then
sudo ani-cli --update
fi
run_as_requested_user "$@" || true
cd /app
exec ./ani-cli-web "$@"