-
Notifications
You must be signed in to change notification settings - Fork 3
/
fixup
executable file
·62 lines (53 loc) · 2.08 KB
/
fixup
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
#!/bin/bash
# Fix up the permissions and group ownership of installation directories. Sets
# group to 'sw' unless -G is given, setgid's directories unless -g is given, and
# makes all files group writable and other unwritable.
function fixup()
{
# NOTE: Gnu xargs assumed, providing --no-run-if-empty
local GROUP=sw
local PERM='u+rwX,g+rwX,o+rX-w'
local GROUPPERM='u+rwX,g+rX-w,o-rxw'
local SETGID_DIRS=yes
local SETX
local HELP
local OPTIND
while getopts "gG:pP:xh" o; do
case $o in
g) unset SETGID_DIRS ;;
G) GROUP=${OPTARG} ;;
p) PERM=${GROUPPERM} ;;
P) PERM=${OPTARG} ;;
x) SETX=yes ;;
h) HELP=yes ;;
esac
done
shift $((OPTIND-1))
#[[ $# == 0 || $HELP ]] && { echo -e "USAGE: $0 [ -g, to NOT setgid g+s on dirs ] [ -G group, default '$GROUP' ] [ -p, set group-restrictive permissions '$GROUPPERM' ] [ -x, show commands as they are executed ] [ -h, for help ] dir-or-file ..." ; return; }
[[ $# == 0 || $HELP ]] && {
echo "USAGE: fixup [ -g ] [ -G group ] [ -p ] [ -P permissions ] [ -x ] [ -h ] dir-or-file ..."
echo
echo " -g do NOT setgid g+s on dirs"
echo " -G group change to group 'group', default '$GROUP'"
echo " -p set group-restrictive permissions '$GROUPPERM'"
echo " -P perms set permissions to 'perms', default '$PERM'"
echo " -x show commands as they are executed, via shell 'set -x'"
echo " -h help"
return;
}
[[ $SETX ]] && set -x
args=("$@")
for arg in ${args[@]} ; do
echo "fixup: '$arg'"
echo " Changing permissions to $PERM ..."
chmod -R "$PERM" "$arg"
echo " Changing group to $GROUP ..."
chgrp -hR $GROUP "$arg"
if [[ $SETGID_DIRS ]] ; then
echo " Adding g+s to directory permissions ..."
find "$arg" -type d -print0 | xargs -0 --no-run-if-empty chmod g+s
fi
done
[[ $SETX ]] && set +x
}
fixup "$@"