-
Notifications
You must be signed in to change notification settings - Fork 0
/
chgrpacl
executable file
·77 lines (69 loc) · 2.23 KB
/
chgrpacl
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#
# chgrpacl -R oldgrp newgrp file
#
# Update ACLs on files/directories to change ACEs from one group name to
# another. Only changes ACEs for the old group name, it doesn't create new ACEs.
#
# Requires 'aclfind'.
#
# v0.1 - 2013-03-05 - Morgan Aldridge <[email protected]>
# Initial version.
#
function main () {
# do we have 'findacl'
if ! which findacl 1>/dev/null; then
echo "$0 requires findacl!" 1>&2
exit 1
fi
# are we recursive?
local depth="-depth 0"
if [ "$1" = "-R" ]; then
depth=""
shift
fi
# were we given enough parameters?
if [ $# -ne 3 ]; then
echo "An invalid number of parameters was specified!" 1>&2
exit 1
fi
local old_group="$1"
local new_group="$2"
local path="$3"
# get all the filenames & their ACLs for file that have ACEs for the specified old group name
local line
local file
while IFS= read -r line; do
# parse the ACEs or filename
if [[ "$line" =~ ^\ ([0-9]+):\ ((user|group):)?([A-Za-z0-9._-]+)\ ((local|inherited)\ )?(allow|deny)\ ([a-z_,]+)$ ]]; then
local num="${BASH_REMATCH[1]}"
local type="${BASH_REMATCH[3]}"
local name="${BASH_REMATCH[4]}"
local inherited="${BASH_REMATCH[6]}"
local grant="${BASH_REMATCH[7]}"
local permissions="${BASH_REMATCH[8]}"
#echo "#: $num; TYPE: $type; NAME: $name; GRANT: $grant; PERMISSIONS: $permissions"
# rewrite the ACL with the new group name
local tmp_old_group="$old_group"
local tmp_new_group="$new_group"
if [ -n "$type" ]; then
tmp_old_group="${type}:${tmp_old_group}"
tmp_new_group="${type}:${tmp_new_group}"
fi
if [ "$inherited" = "inherited" ]; then
chmod =ai# ${num} "${tmp_new_group} ${grant} ${permissions}" "$file"
else
chmod =a# ${num} "${tmp_new_group} ${grant} ${permissions}" "$file"
fi
if [ $? -eq 0 ]; then
echo " ${num}: ${tmp_old_group} ${inherited} ${grant} ${permissions} --> ${num}: ${tmp_new_group} ${inherited} ${grant} ${permissions}"
else
echo " ERROR! Unable to change ACE '${num}: ${tmp_old_group} ${inherited} ${grant} ${permissions}'!" 1>&2
fi
elif [[ "$line" =~ ^[^\ ] ]]; then
file="$line"
echo "$file"
fi
done <<< "$(findacl "$path" $depth -acegroup "$old_group" -printacl)"
}
main "$@"