filebrowser.sh: fix DOCKER_DIR pointing to /root when run with sudo

DOCKER_DIR was computed before ACTUAL_HOME, so $HOME resolved to
/root (the root user's home) instead of the invoking user's home.
Files were created under /root/docker/ rather than ~/docker/.

Fix: compute ACTUAL_USER and ACTUAL_HOME first, then DOCKER_DIR.

https://claude.ai/code/session_01UZus2Q9gNTfUdqSMrhuX29
This commit is contained in:
Claude
2026-06-08 00:42:13 +00:00
parent 9641bebda8
commit c005e01156
+4 -3
View File
@@ -75,10 +75,11 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
}
fi
# Globals — use existing site config values if present, otherwise sensible defaults
DOCKER_DIR="${DOCKER_DIR:-$HOME/docker}"
# Globals — ACTUAL_USER/ACTUAL_HOME must come before DOCKER_DIR
# ($HOME under sudo is /root, not the real user's home)
ACTUAL_USER="${ACTUAL_USER:-${SUDO_USER:-$USER}}"
ACTUAL_HOME="$(getent passwd "$ACTUAL_USER" 2>/dev/null | cut -d: -f6 || echo "$HOME")"
ACTUAL_HOME="$(getent passwd "$ACTUAL_USER" 2>/dev/null | cut -d: -f6 || echo "${HOME:-/root}")"
DOCKER_DIR="${DOCKER_DIR:-$ACTUAL_HOME/docker}"
DRY_RUN="${DRY_RUN:-false}"
UNATTENDED="${UNATTENDED:-false}"
SITE_TZ="${SITE_TZ:-$(cat /etc/timezone 2>/dev/null || echo UTC)}"