]> git.phdru.name Git - git-scripts.git/blob - sharedRepo
Feat: `sharedRepo [-a|-g] [group]`
[git-scripts.git] / sharedRepo
1 #! /bin/sh
2 # See https://stackoverflow.com/a/69193032/7976758
3
4 set -e
5 share=group
6
7 while getopts agh opt; do
8    case $opt in
9       a) share=all ;;
10       g) share=group ;;
11       h) ;;
12    esac
13 done
14 shift `expr $OPTIND - 1`
15
16 if [ $# -gt 1 -o "$1" = -h ]; then
17     echo "Usage: $0 [-a|-g] [group]"
18     if [ $# -gt 1 ]; then
19         exit 1
20     fi
21 fi
22
23 git config core.sharedRepository $share
24
25 # Fix group
26 if [ -n "$1" ]; then
27     chgrp -R $1 . # Use desired group name
28     # Make FS to inherit group on creating subdirectories or files
29     find . -type d -exec chmod g+s '{}' \+
30 fi
31
32 # Fix file/directory permissions throughout the entire tree
33 if [ $share = all ]; then
34     chmod -R ug=rwX,o=rX . # Please note **uppercase** X
35     # Git object DB files are read-only
36     find .git/objects -type f -exec chmod a=r '{}' \+
37 else # share = group
38     chmod -R ug=rwX,o= .
39     find .git/objects -type f -exec chmod ug=r '{}' \+
40 fi