ansible/files/scripts/fix-home-fedora-ownerships.sh
Nils Philippsen f710f4102a use script file instead of inline shell
Signed-off-by: Nils Philippsen <nils@redhat.com>
2021-03-24 15:19:37 +01:00

17 lines
470 B
Bash
Executable file

#!/bin/bash
for dname in */; do
dname="${dname%%/}"
downer="$(stat --format %U "$dname")"
# skip directories owned by root
if [ "$downer" = "root" ]; then
continue
fi
# verify that the directory actually is the home directory of the same-named user
IFS=":" read -r _ _ _ _ _ homedir _ < <(getent passwd "$dname")
if [ "$homedir" != "/home/fedora/$dname" ]; then
continue
fi
echo "fixing ownership: $dname"
chown -R "$dname:" "$dname"
done