]> rtime.felk.cvut.cz Git - sojka/gl-perm.git/blob - gl-perm
61bd2d2c5c6336bff9ac213230be5d5b88caca65
[sojka/gl-perm.git] / gl-perm
1 #!/bin/sh
2
3 # Gitolite permission manipulation helper script
4 # Copyright 2011, 2014, 2017, Michal Sojka <wsh@2x.cz>
5 # License: GNU GPLv2+
6
7 case "$1" in
8     -h|-help)
9 cat <<EOF
10 Usage: $0                     Print current permissions
11        $0 + READERS <user>    Allow <user> to read the repo (@all for all users)
12        $0 - READERS <user>    Remove <user> from the list of readers
13        $0 + WRITERS <user>    Allow <user> to write the repo
14 EOF
15         exit
16         ;;
17 esac
18 curr_branch=$(git symbolic-ref -q HEAD)
19 curr_branch_short=${curr_branch#refs/heads/}
20 remote=$(git config --get "branch.$curr_branch_short.remote")
21 url=$(git config --get "remote.$remote.url") || url=$remote
22
23 url_sans_ssh=${url#ssh://}
24 if [ x"$url_sans_ssh" != x"$url" ]; then
25     userhost=${url_sans_ssh%%/*}
26     repo=${url_sans_ssh#*/}
27 else
28     # scp-like syntax
29     userhost=${url%%:*}
30     repo=${url#*:}
31 fi
32 repo=${repo%.git}
33
34 case "$(basename "$0")" in
35     gl-perm|gl-perm-list)
36         set -- "$repo" -l;;
37     gl-perm-add-writer)
38         set -- "$repo" + WRITERS "${1?Missing user name}";;
39     gl-perm-add-reader)
40         set -- "$repo" + READERS "${1?Missing user name}";;
41     gl-perm-rm-writer)
42         set -- "$repo" - WRITERS "${1?Missing user name}";;
43     gl-perm-rm-reader)
44         set -- "$repo" - READERS "${1?Missing user name}";;
45 esac
46
47 (set -x; ssh "$userhost" perms "$@")