]> rtime.felk.cvut.cz Git - sojka/gl-perm.git/blob - gl-perm
4c90add3b68b71f33837f52b4a5eab9f1bebc1b0
[sojka/gl-perm.git] / gl-perm
1 #!/bin/sh
2
3 # Gitolite permission manipulation helper script
4 # Copyright 2011, Michal Sojka <wsh@2x.cz>
5 # License: GNU GPLv2+
6
7 curr_branch=$(git symbolic-ref -q HEAD)
8 curr_branch_short="${curr_branch#refs/heads/}"
9 remote=$(git config --get branch.$curr_branch_short.remote)
10 url=$(git config --get remote.$remote.url) || url=$remote
11
12 url_sans_ssh=${url#ssh://}
13 if test x$url_sans_ssh != x$url; then
14     userhost=${url_sans_ssh%%/*}
15     repo=${url_sans_ssh#*/}
16 else
17     # scp-like syntax
18     userhost=${url%%:*}
19     repo=${url#*:}
20 fi
21
22 bn=$(basename $0)
23 if test x$bn = xgl-perm; then
24     cmd=$1; shift
25 else
26     cmd=$bn
27 fi
28
29 case $cmd in
30     gl-getperms|get)
31         ssh $userhost getperms $repo;;
32     gl-setperms|set)
33         ssh $userhost setperms $repo;;
34     gl-addperm|add)
35         perms=$(ssh $userhost getperms $repo)
36         ( test "$perms" && echo "$perms"; echo $* ) | ssh $userhost setperms $repo;;
37     gl-rmperm|rm)
38         user=$1
39         perms=$(ssh $userhost getperms $repo) # setperms does not work when executed in the same pipe with getperms
40         echo "$perms" | sed -e "s/[[:space:]]*\\b$user\\b//g" -e "/^[[:alnum:]]\+[[:space:]]*$/d" | ssh $userhost setperms $repo;;
41 esac