-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_repo_rights
executable file
·98 lines (81 loc) · 1.73 KB
/
set_repo_rights
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
function usage()
{
cat <<EOF
Usage: set_repo_rights [OPTIONS] <REPOSITORY1> <REPOSITORY2> ...
Options:
--quiet do not give a report after setting permssions
--public give read access rights to others (e.g., the gitweb daemon)
EOF
}
function die()
{
echo "Error: $1"
usage
exit 1
}
QUIET=
PUBLIC=
PROJECT_GROUP=litmus
while true
do
case $1 in
--quiet)
shift
QUIET=yes
;;
--public)
shift
PUBLIC=yes
;;
--group)
shift
PROJECT_GROUP=$1
shift
;;
--help|-h)
usage
exit 0
;;
*) # unknown argument
break
;;
esac
done
function set_rights()
{
REPO=$1
if [ -z "$REPO" ]; then
die "You need to specify a repository!";
fi
# everything should belong the calling user
chown -R $USER:$PROJECT_GROUP "$REPO" || die "chown failed"
# setup group rights
find "$REPO" -type d -exec chmod g+s '{}' ';' || die "could not make directories sticky"
# owning group
setfacl -R -m g::rwx "$REPO" || die "setfacl failed"
# owning group, default entry
setfacl -d -R -m g::rwx "$REPO" || die "setfacl -d failed"
if [ -n "$PUBLIC" ]
then
# give access to others
find "$REPO" -type d -exec chmod g+rx '{}' ';' || die "could not make directories acessible"
find "$REPO" -type f -exec chmod g+r '{}' ';' || die "could not make files acessible"
# others, default entry
setfacl -d -R -m o::rx "$REPO" || die "setfacl -d failed"
else
# remove access
chmod -R o-rwx "$REPO" || die "chmod -R o-rwx failed"
fi
if [ -z "$QUIET" ]
then
echo "Repository $REPO is ready for use:"
ls -l "$REPO"
getfacl "$REPO"
fi
}
while [ ! -z "$1" ]
do
set_rights "$1"
shift
done