lxc: Handle symlinks in rempa-uid-and-gid-for-lv

I previously thought that handling symlinks would not be necessary and
also not possible. Then, I found out about the `--no-dereference` option
for `chown` ...
This commit is contained in:
MasterofJOKers 2023-06-28 18:25:29 +02:00
parent 73fdc6b27a
commit e09ee60593
1 changed files with 15 additions and 3 deletions

View File

@ -42,7 +42,19 @@ printf "uid: %s gid: %s\n" $ROOT_USER_ID $ROOT_GROUP_ID
# We ignore links here, because they might not point to a valid location and would make our program fail. They are also # We ignore links here, because they might not point to a valid location and would make our program fail. They are also
# owned by whoever mounted the filesystem it seems, so don't need a chown. # owned by whoever mounted the filesystem it seems, so don't need a chown.
find . -xdev -not -type l -printf "%U %G %p\n" | \ # Funny enough, the above statement is not true. I see symlinks in the container that are not owned by a valid user
# inside the container ...
# chown
# -h, --no-dereference
# affect symbolic links instead of any referenced file (useful only on systems
# that can change the ownership of a symlink)
#
# --from=CURRENT_OWNER:CURRENT_GROUP
# change the owner and/or group of each file only if its current owner and/or
# group match those specified here. Either may be omitted, in which case a
# match is not required for the omitted attribute
#
find . -xdev -printf "%U %G %p\n" | \
while read F; do while read F; do
U=$(echo $F | cut -d ' ' -f 1) U=$(echo $F | cut -d ' ' -f 1)
if [ ${U} -lt ${ROOT_USER_ID} ] || [ ${U} -gt $(( ${ROOT_USER_ID} + 65535 )) ]; then if [ ${U} -lt ${ROOT_USER_ID} ] || [ ${U} -gt $(( ${ROOT_USER_ID} + 65535 )) ]; then
@ -63,8 +75,8 @@ find . -xdev -not -type l -printf "%U %G %p\n" | \
fi fi
P=$(echo $F | cut -d ' ' -f 3-) P=$(echo $F | cut -d ' ' -f 3-)
printf "chown %s:%s %s\n" ${NEW_U} ${NEW_G} "${P}" printf "chown --no-dereference %s:%s %s\n" ${NEW_U} ${NEW_G} "${P}"
# chown ${NEW_U}:${NEW_G} "${P}" # chown --no-dereference ${NEW_U}:${NEW_G} "${P}"
done done
cd / cd /