]> rtime.felk.cvut.cz Git - sojka/gl-perm.git/blob - gl-perm
Complain if misused
[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         if test $# -gt 0; then echo >&2 "Command $cmd does not accept any arguments"; exit 1; fi
32         ssh $userhost getperms $repo;;
33     gl-setperms|set)
34         if test $# -gt 0; then echo >&2 "Command $cmd does not accept any arguments - it reads from stdin"; exit 1; fi
35         ssh $userhost setperms $repo;;
36     gl-addperm|add)
37         perms=$(ssh $userhost getperms $repo)
38         ( test "$perms" && echo "$perms"; echo $* ) | ssh $userhost setperms $repo;;
39     gl-rmperm|rm)
40         user=$1
41         perms=$(ssh $userhost getperms $repo) # setperms does not work when executed in the same pipe with getperms
42         echo "$perms" | sed -e "s/[[:space:]]*\\b$user\\b//g" -e "/^[[:alnum:]]\+[[:space:]]*$/d" | ssh $userhost setperms $repo;;
43 esac