Skip to content

Instantly share code, notes, and snippets.

@lpar
Created February 4, 2014 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lpar/8808597 to your computer and use it in GitHub Desktop.
Save lpar/8808597 to your computer and use it in GitHub Desktop.
Shell script to make a shared Git repository
#!/bin/sh
CMDNAME=`basename $0`
GROUP=$1
REPODIR=$2
if [ -z $REPODIR ]; then
echo "usage: $CMDNAME <group> <dir>"
echo "creates a shared Git repository for group <group> in the specified directory"
exit 0
fi
if [ -z `grep ^$GROUP /etc/group` ]; then
echo "no such group $GROUP"
exit 1
fi
if [ `id -u` != '0' ]; then
echo "this command must be run as root"
exit 2
fi
if [ -e $REPODIR ]; then
echo "destination directory already exists"
exit 3
fi
CWD=`pwd`
mkdir -p $REPODIR
cd $REPODIR
# At some point every copy of Git will be recent enough to have the
# --shared=group option in git-init
git --bare init
git config core.sharedRepository group
cd ..
chmod -R g+rwXs $REPODIR
chgrp -R $GROUP $REPODIR
cd $CWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment