aboutsummaryrefslogtreecommitdiffstats
path: root/git-init-acl
diff options
context:
space:
mode:
authorWolfgang Müller2022-03-03 15:15:19 +0100
committerWolfgang Müller2022-03-03 15:15:19 +0100
commit92ba675e4bffaca19af1d354783c33b0d9dca069 (patch)
tree08e1d05dc899eb85829c555b4949ddaea79ac553 /git-init-acl
parent65e9587af04fcae23c9d0cf37f185b7555435256 (diff)
downloadgit-helpers-trunk.tar.gz
Rename git-init-shared(1) to git-init-acl(1)HEADtrunk
We have always felt that the name of this program was too close to the invocation of 'git init --shared' which does something similar. Make it clear in the name that we're working with POSIX ACLs instead of normal permission sets as 'git init --shared' does.
Diffstat (limited to 'git-init-acl')
-rwxr-xr-xgit-init-acl36
1 files changed, 36 insertions, 0 deletions
diff --git a/git-init-acl b/git-init-acl
new file mode 100755
index 0000000..50950b5
--- /dev/null
+++ b/git-init-acl
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+set -e
+
+usage() {
+ printf "usage: git init-acl 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"