#!/bin/sh set -eu is_true() { case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in 1 | true | yes | on) return 0 ;; *) return 1 ;; 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 python3 /app/app.py "$@" } mkdir -p /downloads /app/.ani-cli-web if is_true "${UPDATE_ON_START:-false}"; then echo "Checking for ani-cli updates with sudo ani-cli --update" sudo ani-cli --update fi run_as_requested_user "$@" || true cd /app exec python3 /app/app.py "$@"