aboutsummaryrefslogtreecommitdiffstats
path: root/git-init-shared
blob: b0ffac58d4a6e7007b62d62d951f5ba30d549f37 (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
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh

set -e

usage() {
	printf "usage: git init-shared directory [user...]\n" >&2
	exit 1
}

acl_mask() {
	# Set the ACL mask for the directory. The default mask will be inherited by
	# new directories and files (where it will correctly be set to rw-)
	setfacl -m "d:m:rwx,m:rwx" "$1"
}

add_to_acl() {
	# Recursively apply all necessary ACL settings as we may be reinitializing
	# the git repository with additional authorised users.
	# Take care *not* to recalculate the ACL mask (-n), since rwX translates to
	# a mask of rwx even on non-directory files.
	setfacl -Rnm "d:u:$2:rwX,u:$2:rwX" "$1"
}

test $# -ge 1 || usage
dir=$1
shift

mkdir -p "$dir"

acl_mask "$dir"

for user in "$(id -un)" "$@"; do
	add_to_acl "$dir" "$user"
done

exec git init --bare "$dir"