Skip to content

Instantly share code, notes, and snippets.

@nu7hatch
Created August 26, 2010 14:17
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 nu7hatch/551458 to your computer and use it in GitHub Desktop.
Save nu7hatch/551458 to your computer and use it in GitHub Desktop.
Git repos management helpers
#!/bin/bash
# usage: git-setup-home PATH
#
# It creates 'git' user and group, and prepares given home directory.
# By default git home dir is '/var/git'.
if [ $1 ] ; then
export GIT_HOME=$1
else
export GIT_HOME=/var/git
fi
useradd -r -U -d $GIT_HOME -m git && chmod g+rx $GIT_HOME
echo "Home for git repositories has been succesfuly created!"
#!/bin/bash
# usage: git-setup-project NAME [DESCRIPTION]
#
# It creates bare, shared git repository in git home dir. When given project
# already exists then you are able to reinitialize it.
if [ -n $GIT_HOME ] ; then
GIT_HOME=/var/git
fi
if [ -d $GIT_HOME ] ; then
REPO_DIR=$GIT_HOME/$1.git
if [ -d $REPO_DIR ] ; then
echo -ne "Directory $REPO_DIR already exists. Do you want to overwrite it? [Yn]: "
while read line ; do
case $line in
""|y) break ;;
n) echo "Aborting..." ; exit 0 ;;
*) echo -ne "Type 'y' or 'n': " ;;
esac
done
else
mkdir $REPO_DIR
fi
cd $REPO_DIR
git --bare init --shared=group && \
chown -R git:git $REPO_DIR && \
chmod -R g+ws $REPO_DIR
if [ $# -gt 1 ] ; then
echo $2 > description
fi
else
echo "Git home directory $GIT_HOME doesn't exists!"
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment