fix: false read-only detection in docker_init.bash (#1470 follow-up)

The read-only rootfs guard added in PR #1635 (issue #1470) checks
[ ! -w /etc/group ] as the current user (hermeswebuitoo, non-root).
On a normal writable rootfs this always fails because /etc/group is
owned by root — causing a false positive that crashes the container
with "Cannot modify /etc/group or /etc/passwd (read-only root fs)".

Fix: use sudo to test writability, since groupmod/usermod already
use sudo a few lines below. If sudo can write, the fs is not
read-only and the guard should not trigger.

Refs #1470
This commit is contained in:
bergeouss 2026-05-04 22:37:55 +00:00
parent e6cf801ef4
commit d4385f8aa2

View file

@ -189,10 +189,13 @@ if [ "A${whoami}" == "Ahermeswebuitoo" ]; then
# using usermod for the already create hermeswebui user, knowing it is not already in use
# per usermod manual: "You must make certain that the named user is not executing any processes when this command is being executed"
# Guard for read-only root filesystem (podman with read_only=true, issue #1470).
# The script runs as hermeswebuitoo (non-root), but groupmod/usermod use sudo.
# So we must check writability via sudo — a non-root user cannot write /etc/group
# even on a normal writable rootfs, which caused a false positive (issue #1658).
_readonly_root=false
if [ ! -w /etc/group ] || [ ! -w /etc/passwd ]; then
if ! sudo sh -c 'test -w /etc/group && test -w /etc/passwd' 2>/dev/null; then
_readonly_root=true
echo " !! Detected read-only root filesystem — /etc/group or /etc/passwd is not writable"
echo " !! Detected read-only root filesystem — /etc/group or /etc/passwd is not writable (even via sudo)"
fi
if [ "A${_readonly_root}" == "Atrue" ]; then
_current_hermeswebui_gid=$(id -g hermeswebui 2>/dev/null || echo "")