blob: 10d69c863ae0be4ea4fd74979567b6d2e8aeb0d9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#!/usr/bin/env fish
set _REPO_PERMISSIONS_FILE /etc/repo-permissions
# unify repo regex somehow
set _GIT_VALIDATION_REGEX "^(git-(?:upload-pack|receive-pack|upload-archive)) '((?:\/[a-zA-Z-]+)+.git)'\$"
# check given git command
set -l matcher (string match -r -g $_GIT_VALIDATION_REGEX "$argv")
if test (count $matcher) -ne 2
# there should be two groups otherwise something is wrong
exit 1
end
# echo check for permissions
set -l checkUser (whoami)
set -l gitCommand $matcher[1]
set -l repo $matcher[2]
# adjust repo path to /srv/repos
set -l repoDir srv repos
set -l repoDir /(string join -n '/' $repoDir (string split '/' $repo))
cat $_REPO_PERMISSIONS_FILE | grep -q -E "^$repoDir:$checkUser\$"
or exit 1;
# execute parsed git command
/usr/bin/sudo -u git /usr/bin/git-shell -c "$gitCommand '$repoDir'"
|