]> rtime.felk.cvut.cz Git - sojka/gl-perm.git/commitdiff
Initial commit
authorMichal Sojka <sojka@os.inf.tu-dresden.de>
Tue, 20 Sep 2011 21:35:13 +0000 (23:35 +0200)
committerMichal Sojka <sojka@os.inf.tu-dresden.de>
Tue, 20 Sep 2011 21:35:13 +0000 (23:35 +0200)
gl-addperm [new symlink]
gl-getperms [new symlink]
gl-perm [new file with mode: 0755]
gl-rmperm [new symlink]
gl-setperms [new symlink]

diff --git a/gl-addperm b/gl-addperm
new file mode 120000 (symlink)
index 0000000..d92ca59
--- /dev/null
@@ -0,0 +1 @@
+gl-getperms
\ No newline at end of file
diff --git a/gl-getperms b/gl-getperms
new file mode 120000 (symlink)
index 0000000..a73817c
--- /dev/null
@@ -0,0 +1 @@
+gl-perm
\ No newline at end of file
diff --git a/gl-perm b/gl-perm
new file mode 100755 (executable)
index 0000000..4c90add
--- /dev/null
+++ b/gl-perm
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# Gitolite permission manipulation helper script
+# Copyright 2011, Michal Sojka <wsh@2x.cz>
+# License: GNU GPLv2+
+
+curr_branch=$(git symbolic-ref -q HEAD)
+curr_branch_short="${curr_branch#refs/heads/}"
+remote=$(git config --get branch.$curr_branch_short.remote)
+url=$(git config --get remote.$remote.url) || url=$remote
+
+url_sans_ssh=${url#ssh://}
+if test x$url_sans_ssh != x$url; then
+    userhost=${url_sans_ssh%%/*}
+    repo=${url_sans_ssh#*/}
+else
+    # scp-like syntax
+    userhost=${url%%:*}
+    repo=${url#*:}
+fi
+
+bn=$(basename $0)
+if test x$bn = xgl-perm; then
+    cmd=$1; shift
+else
+    cmd=$bn
+fi
+
+case $cmd in
+    gl-getperms|get)
+       ssh $userhost getperms $repo;;
+    gl-setperms|set)
+       ssh $userhost setperms $repo;;
+    gl-addperm|add)
+       perms=$(ssh $userhost getperms $repo)
+       ( test "$perms" && echo "$perms"; echo $* ) | ssh $userhost setperms $repo;;
+    gl-rmperm|rm)
+       user=$1
+       perms=$(ssh $userhost getperms $repo) # setperms does not work when executed in the same pipe with getperms
+       echo "$perms" | sed -e "s/[[:space:]]*\\b$user\\b//g" -e "/^[[:alnum:]]\+[[:space:]]*$/d" | ssh $userhost setperms $repo;;
+esac
diff --git a/gl-rmperm b/gl-rmperm
new file mode 120000 (symlink)
index 0000000..d92ca59
--- /dev/null
+++ b/gl-rmperm
@@ -0,0 +1 @@
+gl-getperms
\ No newline at end of file
diff --git a/gl-setperms b/gl-setperms
new file mode 120000 (symlink)
index 0000000..d92ca59
--- /dev/null
@@ -0,0 +1 @@
+gl-getperms
\ No newline at end of file