use script file instead of inline shell
Signed-off-by: Nils Philippsen <nils@redhat.com>
This commit is contained in:
parent
97e389f73f
commit
f710f4102a
2 changed files with 31 additions and 16 deletions
17
files/scripts/fix-home-fedora-ownerships.sh
Executable file
17
files/scripts/fix-home-fedora-ownerships.sh
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/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
|
|
@ -15,26 +15,24 @@
|
||||||
follow: yes
|
follow: yes
|
||||||
register: home_fedora_res
|
register: home_fedora_res
|
||||||
|
|
||||||
|
- name: Copy the script to the host
|
||||||
|
copy:
|
||||||
|
src: scripts/fix-home-fedora-ownerships.sh
|
||||||
|
dest: /usr/local/sbin/fix-home-fedora-ownerships.sh
|
||||||
|
mode: 0755
|
||||||
|
when: home_fedora_res.stat.isdir
|
||||||
|
|
||||||
- name: Fix ownership of home directories in /home/fedora
|
- name: Fix ownership of home directories in /home/fedora
|
||||||
# assumes that directory name == user name
|
# assumes that directory name == user name
|
||||||
shell:
|
shell:
|
||||||
chdir: /home/fedora
|
chdir: /home/fedora
|
||||||
# skip directories owned by root and verify that the directory actually is the home directory
|
cmd: /usr/local/sbin/fix-home-fedora-ownerships.sh
|
||||||
# of the same-named user
|
|
||||||
cmd: >-
|
|
||||||
for dname in */; do
|
|
||||||
dname="${dname%%/}";
|
|
||||||
downer="$(stat --format %U "$dname")";
|
|
||||||
if [ "$downer" = "root" ]; then
|
|
||||||
continue
|
|
||||||
fi;
|
|
||||||
IFS=":" read -r _ _ _ _ _ homedir _ < <(getent passwd "$dname");
|
|
||||||
if [ "$homedir" != "/home/fedora/$dname" ]; then
|
|
||||||
continue
|
|
||||||
fi;
|
|
||||||
echo "fixing ownership: $dname";
|
|
||||||
chown -R "$dname:" "$dname";
|
|
||||||
done
|
|
||||||
register: chown_res
|
register: chown_res
|
||||||
changed_when: "'fixing ownership:' in chown_res.stdout"
|
changed_when: "'fixing ownership:' in chown_res.stdout"
|
||||||
when: home_fedora_res.stat.isdir
|
when: home_fedora_res.stat.isdir
|
||||||
|
|
||||||
|
- name: Delete the script from the host
|
||||||
|
file:
|
||||||
|
path: /usr/local/sbin/fix-home-fedora-ownerships.sh
|
||||||
|
state: absent
|
||||||
|
when: home_fedora_res.stat.isdir
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue