diff --git a/entrypoint.sh b/entrypoint.sh index 7628926..f0ecc6d 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -51,6 +51,22 @@ fi # developer user can write to them. FINAL_UID="${TARGET_UID:-$CURRENT_UID}" FINAL_GID="${TARGET_GID:-$CURRENT_GID}" + +# First, fix parent dirs that Docker auto-creates as root:root when it +# materializes nested mount points (e.g. mounting a volume at +# .local/state/opencode creates .local/state as root). Non-recursive — +# we only need the dir node itself; children are handled below or were +# created by the user. +for parent in \ + /home/"$USER_NAME"/.local \ + /home/"$USER_NAME"/.local/share \ + /home/"$USER_NAME"/.local/state \ + /home/"$USER_NAME"/.config; do + if [ -d "$parent" ] && [ "$(stat -c '%u' "$parent" 2>/dev/null)" != "$FINAL_UID" ]; then + chown "$FINAL_UID":"$FINAL_GID" "$parent" 2>/dev/null || true + fi +done + for dir in \ /home/"$USER_NAME"/.local/share/opencode \ /home/"$USER_NAME"/.local/state/opencode \