Skip to content

Commit

Permalink
Merge pull request #2724 from norio-nomura/fix-owership-of-the-user-h…
Browse files Browse the repository at this point in the history
…ome-directory

20-rootless-base.sh: Fix ownership of the user home directory when created by root.
  • Loading branch information
AkihiroSuda authored Oct 11, 2024
2 parents fa4d0d8 + c55fc44 commit 5d41ca2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/cidata/cidata.TEMPLATE.d/boot/20-rootless-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ set -eux
# This script does not work unless systemd is available
command -v systemctl >/dev/null 2>&1 || exit 0

if [ -O "${LIMA_CIDATA_HOME}" ]; then
# Fix ownership of the user home directory when created by root.
# In cases where mount points exist in the user's home directory, the home directory and
# the mount points are created by root before the user is created. This leads to the home
# directory being owned by root.
# Following commands fix the ownership of the home directory and its contents (on the same filesystem)
# is updated to the correct user.
# shellcheck disable=SC2046 # it fails if find results are quoted.
chown "${LIMA_CIDATA_USER}" $(find "${LIMA_CIDATA_HOME}" -xdev) ||
true # Ignore errors because changing owner of the mount points may fail but it is not critical.
fi

# Set up env
for f in .profile .bashrc .zshrc; do
if ! grep -q "# Lima BEGIN" "${LIMA_CIDATA_HOME}/$f"; then
Expand Down

0 comments on commit 5d41ca2

Please sign in to comment.