Created
July 15, 2012 06:17
-
-
Save raws/3115343 to your computer and use it in GitHub Desktop.
Bash helper script for creating a Git repository on systems hosting them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# create-git-repo | |
# | |
# Create and publish a Git repository so that it is able to be | |
# cloned via `git clone git@host:repo.git'. | |
# | |
# Author: Ross Paffett <[email protected]> | |
GIT_DATA="/var/git" # Where to store the actual git repositories | |
GIT_USER="git" # The system git user | |
GIT_HOME="/home/${GIT_USER}" # Create symlinks to repositories here | |
if [ -n "$1" ]; then | |
export GIT_DIR="${GIT_DATA}/${1}.git" | |
# Initialize the repository in $GIT_DATA | |
if [ ! -d "$GIT_DIR" ]; then | |
git init --bare | |
else | |
echo "warning: ${GIT_DIR} already exists, skipping repository creation" | |
fi | |
# Correct permissions and create convenience symlink | |
if [ -d "$GIT_DIR" ]; then | |
chown -R "${GIT_USER}:${GIT_USER}" "${GIT_DIR}" | |
ln -s "$GIT_DIR" "${GIT_HOME}/$(basename $GIT_DIR)" | |
else | |
echo "error: ${GIT_DIR} was not created (\`git init' exited with code ${?})" | |
exit 1 | |
fi | |
else | |
echo "usage: create-git-repo NAME" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment