This repository was archived by the owner on Aug 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_permissions
More file actions
executable file
·57 lines (48 loc) · 1.58 KB
/
check_permissions
File metadata and controls
executable file
·57 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
usage() {
echo "Usage: $0 [ -b ] " 1>&2
echo " Options:"
echo " -b write all the details of the files with incorrect permissions to"
echo " 'incorrect_permissions' and a blame list with all the users"
echo " owning those file"
}
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
blame_list=false
while getopts "h?b" opt; do
case "$opt" in
h|\?)
usage
exit 0
;;
b) blame_list=true
;;
esac
done
# We check for incorrect permissions, writting the results to the "incorrect_permissions" file
if [ "$blame_list" = true ] ; then
rm -f incorrect_permissions
fi
check_dir() {
find $1 \( -not -group $2 -or -not -perm -g+rX \) -and \( -type d -or -name "*.nc" -or -name "*.yaml" \) -exec ls -ld '{}' \; 2>/dev/null
}
for group in ik11 hh5 cj50 jk72; do
for dir in $("$SCRIPT_DIR"/experiment_dirs $group); do
echo "Checking: $dir"
if [ "$blame_list" = true ] ; then
check_dir $dir $group | tee -a incorrect_permissions
else
check_dir $dir $group
fi
done
done
# Check which users own the files/directories that have incorrect permissions and build a blame list
if [ "$blame_list" = true ] ; then
users=()
for user in $(cat incorrect_permissions | awk '{print $3}'); do
if [[ ! " ${users[*]} " =~ " ${user} " ]]; then
users+=($user)
fi
done
printf -v emails '%s@nci.org.au, ' "${users[@]}"
echo "${emails%, }" > blame_list
fi