aboutsummaryrefslogtreecommitdiffstats
path: root/gitcmd
diff options
context:
space:
mode:
Diffstat (limited to 'gitcmd')
-rwxr-xr-xgitcmd47
1 files changed, 47 insertions, 0 deletions
diff --git a/gitcmd b/gitcmd
new file mode 100755
index 0000000..53cd3d8
--- /dev/null
+++ b/gitcmd
@@ -0,0 +1,47 @@
+#!/usr/bin/python3
+
+import sys
+import os
+
+def printerr(*l, **d): return print(*l, **d, file=sys.stderr)
+def fail(*l, **d): printerr(*l, **d); raise SystemExit(1)
+
+try:
+ user = sys.argv[1]
+except IndexError:
+ fail('Bad adminsys, he forgot to set user associated with this key.')
+
+try:
+ with open(user + '.listro', 'r', encoding='utf8') as f:
+ repositories_ro = f.read().splitlines()
+except FileNotFoundError:
+ repositories_ro = []
+
+try:
+ with open(user + '.listrw', 'r', encoding='utf8') as f:
+ repositories_rw = f.read().splitlines()
+except FileNotFoundError:
+ repositories_rw = []
+
+try:
+ ssh_original_command = os.environ['SSH_ORIGINAL_COMMAND'].split()
+ command = ssh_original_command[0]
+ repository = ssh_original_command[1].split('.git')[0].strip("'")
+except IndexError:
+ if command == 'ls':
+ print('\n'.join(repositories_ro + repositories_rw or ['Empty list']))
+ raise SystemExit(0)
+ fail('Invalid repository name or git usage')
+except KeyError:
+ fail('Bad boy, git only access authorized.')
+
+repositories_ro = repositories_ro + repositories_rw
+if command == 'git-upload-pack' and repository in repositories_ro:
+ os.execv('/usr/bin/git-upload-pack',
+ ['/usr/bin/git-upload-pack', '--strict', '--timeout=600',
+ repository])
+elif command == 'git-receive-pack' and repository in repositories_rw:
+ os.execv('/usr/bin/git-receive-pack',
+ ['/usr/bin/git-receive-pack', repository])
+else:
+ fail('Bad git command or inexistant repository or access denied')