Skip to content

Instantly share code, notes, and snippets.

@venj
Created August 9, 2012 08:13
Show Gist options
  • Save venj/3302249 to your computer and use it in GitHub Desktop.
Save venj/3302249 to your computer and use it in GitHub Desktop.
script to quick add a repo on local server.
#!/bin/bash
REPO_HOME=/home/git
CWDDIR=`pwd`
function usage() {
echo -e "Usage: \e[1;34m`basename $0`\e[0m RepoName1 [RepoName2 ...]"
}
function createrepo() {
repo_path=$REPO_HOME/$1.git
if [ -d $repo_path ];then
echo -e "\e[1;31mError:\e[0m Git repository \e[1;32m$1\e[0m already exists!"
else
mkdir $repo_path
cd $repo_path
git init --bare > /dev/null 2>&1
chown -R git:git $repo_path
chmod 755 $repo_path
cd $CWDDIR
echo -e "Git repository \e[1;32m$1\e[0m successfully created."
echo Use following command to use this repository:
#echo $ git remote add origin [email protected]
echo
echo -e "$ \e[1;31mgit remote add origin [email protected]:$1.git\e[0m"
echo
fi
}
if [ $UID -ne 0 ];then
echo You should run this script as root!
exit 1
fi
if [ -z $1 ]; then
usage
exit 0
fi
for repo in $@;do
createrepo $repo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment