Skip to content

Instantly share code, notes, and snippets.

@mixtmeta
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save mixtmeta/c2f7456c23d7be3d9cb2 to your computer and use it in GitHub Desktop.

Select an option

Save mixtmeta/c2f7456c23d7be3d9cb2 to your computer and use it in GitHub Desktop.
Script to create new Git repositories on DreamHost
#!/bin/bash
# this script is based on code from the following script:
# https://github.com/tmacam/private-git-on-dreamhost/blob/master/newgit.sh
set -e
# intial values
GIT_REPOS_ROOT="${HOME}/git/repos"
DESCRIPTION='A Git Repository'
# describe how the script works
usage()
{
echo "Usage: $0 [ -h ] [ -d description ] [ -n projectname ]"
echo ""
echo " -d description : description for gitweb"
echo " -h : print this screen"
echo " -n name : name of the project (should end in .git)"
echo ""
}
# evaluate the options passed on the command line
while getopts d:n:h option
do
case "${option}"
in
d) DESCRIPTION=${OPTARG};;
n) REPONAME=${OPTARG};;
h) usage
exit 1;;
esac
done
# check if name of repository is given. if not, exit
if [ -z $REPONAME ]; then
usage
exit 1
fi
# Add .git at and if needed
if ! ( echo $REPONAME | grep -q '\.git$'); then
REPONAME="${REPONAME}.git"
fi
REP_DIR="${GIT_REPOS_ROOT}/${REPONAME}"
mkdir ${REP_DIR}
pushd ${REP_DIR}
git --bare init
git --bare update-server-info
cp hooks/post-update.sample hooks/post-update
chmod a+x hooks/post-update
echo $DESCRIPTION > description
touch git-daemon-export-ok
popd
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment