Skip to content

Commit c55fc44

Browse files
committed
20-rootless-base.sh: Fix ownership of the user home directory when created by root.
When mount points exist in the user's home directory, both the home directory and the mount points are created by root before the user is created. This results in the home directory being owned by root. This change ensures that the ownership of the home directory and its contents (on the same filesystem) is updated to the correct user. If changing the owner of any mount points fails, the error is ignored. Signed-off-by: Norio Nomura <[email protected]>
1 parent 5a98e62 commit c55fc44

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/cidata/cidata.TEMPLATE.d/boot/20-rootless-base.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ set -eux
44
# This script does not work unless systemd is available
55
command -v systemctl >/dev/null 2>&1 || exit 0
66

7+
if [ -O "${LIMA_CIDATA_HOME}" ]; then
8+
# Fix ownership of the user home directory when created by root.
9+
# In cases where mount points exist in the user's home directory, the home directory and
10+
# the mount points are created by root before the user is created. This leads to the home
11+
# directory being owned by root.
12+
# Following commands fix the ownership of the home directory and its contents (on the same filesystem)
13+
# is updated to the correct user.
14+
# shellcheck disable=SC2046 # it fails if find results are quoted.
15+
chown "${LIMA_CIDATA_USER}" $(find "${LIMA_CIDATA_HOME}" -xdev) ||
16+
true # Ignore errors because changing owner of the mount points may fail but it is not critical.
17+
fi
18+
719
# Set up env
820
for f in .profile .bashrc .zshrc; do
921
if ! grep -q "# Lima BEGIN" "${LIMA_CIDATA_HOME}/$f"; then

0 commit comments

Comments
 (0)