]> rtime.felk.cvut.cz Git - sojka/gl-perm.git/commitdiff
Rewrite
authorMichal Sojka <michal.sojka@cvut.cz>
Sat, 2 Dec 2017 13:21:08 +0000 (14:21 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Sat, 2 Dec 2017 13:21:08 +0000 (14:21 +0100)
Makefile [new file with mode: 0644]
gl-addperm [deleted symlink]
gl-getperms [deleted symlink]
gl-perm
gl-rmperm [deleted symlink]
gl-setperms [deleted symlink]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..d0d9065
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+PREFIX=$(HOME)/bin
+
+gl-perm=$(shell realpath gl-perm)
+ln=ln -sf "$(gl-perm)" "$(PREFIX)/gl-perm-$1"
+
+install:
+       $(call ln,list)
+       $(call ln,add-writer)
+       $(call ln,add-reader)
+       $(call ln,del-writer)
+       $(call ln,del-reader)
diff --git a/gl-addperm b/gl-addperm
deleted file mode 120000 (symlink)
index d92ca59..0000000
+++ /dev/null
@@ -1 +0,0 @@
-gl-getperms
\ No newline at end of file
diff --git a/gl-getperms b/gl-getperms
deleted file mode 120000 (symlink)
index a73817c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-gl-perm
\ No newline at end of file
diff --git a/gl-perm b/gl-perm
index a9c522c135cc6f4cc6e3ddc6a5f32774ec39e858..61bd2d2c5c6336bff9ac213230be5d5b88caca65 100755 (executable)
--- a/gl-perm
+++ b/gl-perm
@@ -1,16 +1,27 @@
 #!/bin/sh
 
 # Gitolite permission manipulation helper script
-# Copyright 2011, Michal Sojka <wsh@2x.cz>
+# Copyright 2011, 2014, 2017, Michal Sojka <wsh@2x.cz>
 # License: GNU GPLv2+
 
+case "$1" in
+    -h|-help)
+cat <<EOF
+Usage: $0                     Print current permissions
+       $0 + READERS <user>    Allow <user> to read the repo (@all for all users)
+       $0 - READERS <user>    Remove <user> from the list of readers
+       $0 + WRITERS <user>    Allow <user> to write the repo
+EOF
+       exit
+       ;;
+esac
 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
+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
+if [ x"$url_sans_ssh" != x"$url" ]; then
     userhost=${url_sans_ssh%%/*}
     repo=${url_sans_ssh#*/}
 else
@@ -18,26 +29,19 @@ else
     userhost=${url%%:*}
     repo=${url#*:}
 fi
+repo=${repo%.git}
 
-bn=$(basename $0)
-if test x$bn = xgl-perm; then
-    cmd=$1; shift
-else
-    cmd=$bn
-fi
-
-case $cmd in
-    gl-getperms|get)
-       if test $# -gt 0; then echo >&2 "Command $cmd does not accept any arguments"; exit 1; fi
-       ssh $userhost getperms $repo;;
-    gl-setperms|set)
-       if test $# -gt 0; then echo >&2 "Command $cmd does not accept any arguments - it reads from stdin"; exit 1; fi
-       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;;
+case "$(basename "$0")" in
+    gl-perm|gl-perm-list)
+       set -- "$repo" -l;;
+    gl-perm-add-writer)
+       set -- "$repo" + WRITERS "${1?Missing user name}";;
+    gl-perm-add-reader)
+       set -- "$repo" + READERS "${1?Missing user name}";;
+    gl-perm-rm-writer)
+       set -- "$repo" - WRITERS "${1?Missing user name}";;
+    gl-perm-rm-reader)
+       set -- "$repo" - READERS "${1?Missing user name}";;
 esac
+
+(set -x; ssh "$userhost" perms "$@")
diff --git a/gl-rmperm b/gl-rmperm
deleted file mode 120000 (symlink)
index d92ca59..0000000
--- a/gl-rmperm
+++ /dev/null
@@ -1 +0,0 @@
-gl-getperms
\ No newline at end of file
diff --git a/gl-setperms b/gl-setperms
deleted file mode 120000 (symlink)
index d92ca59..0000000
+++ /dev/null
@@ -1 +0,0 @@
-gl-getperms
\ No newline at end of file