|
#!/bin/bash |
|
# |
|
# Create a new, shared, bare repo in a given directory. |
|
# Make it suitable for multiuser envs (assuming perms on that |
|
# directory are set properly, and all your git people are in |
|
# the group which owns that directory) |
|
# |
|
# (C) 2009 Ian Gallagher <[email protected]> |
|
# |
|
|
|
# Where the shared repositories live |
|
SHARED_REPO_DIR="/var/cache/git" |
|
|
|
# Umask to use - 002 makes files user/group writable, world readable. |
|
# This is suitable if you have your commiters in the group that owns |
|
# the repo dir, and want things like gitweb to be able to read the repos |
|
UMASK="002" |
|
|
|
# Ensure the first arg provided exists, it is the new repo name |
|
test -z "$1" \ |
|
&& echo 'Provide a repo name as the only argument!' \ |
|
&& exit 1 |
|
|
|
# Replace pesky spaces with underscores, silly windows users! |
|
project_name=$(echo "$1" | tr ' ' '_') |
|
|
|
# Absolute path for new repo |
|
project_dir="${SHARED_REPO_DIR}/${project_name}.git" |
|
|
|
# Make sure the path doesn't already exist |
|
test -d $project_dir \ |
|
&& echo "Directory '$project_dir' already exists, aborting" \ |
|
&& exit 1 |
|
|
|
# Create the directory and cd to it |
|
mkdir -p $project_dir |
|
cd $project_dir |
|
|
|
# Set the umask |
|
umask $UMASK |
|
|
|
# Initialize the repository with the --bare option |
|
git init --bare >/dev/null 2>&1 |
|
|
|
# Make sure it all worked, report failure |
|
test $? -ne 0 \ |
|
&& echo "Initialization of git repository in '$project_dir' failed :(" \ |
|
&& exit 1 |
|
|
|
# Set group writable flag on the new directory |
|
chmod g+rw $project_dir || exit 1 |
|
|
|
# We made it! Everything seems to have worked; report and exit cleanly |
|
echo "Successfully created bare git repo in '$project_dir' - add it like so to your distributed repo:" |
|
echo "git remote add share ssh://$(hostname -f)${project_dir}" |
|
|
|
exit 0 |