Skip to content

Commit 5d41ca2

Browse files
authored
Merge pull request #2724 from norio-nomura/fix-owership-of-the-user-home-directory
20-rootless-base.sh: Fix ownership of the user home directory when created by root.
2 parents fa4d0d8 + c55fc44 commit 5d41ca2

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)