Skip to content

Instantly share code, notes, and snippets.

@rotty3000
Created July 5, 2011 16:06
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 rotty3000/1065132 to your computer and use it in GitHub Desktop.
Save rotty3000/1065132 to your computer and use it in GitHub Desktop.
Clone Liferay Projects
#!/bin/bash
usage()
{
cat << EOF
SYNOPSIS
$0 <options>
DESCRIPTION
Clone a repo on github into a 'new' local folder.
OPTIONS
-h Show this message
-f Folder to clone into
-p Project name on github
-u Github username (if left out, try the current username)
-U Add an "upstream" remote reference
USAGE
Use clp to clone the project 'bar' into folder 'foo' with github username 'dave'
clp -f foo -p bar -u dave
EOF
}
FOLDER=
PROJECT=
GITHUB_USER=
ADD_UPSTREAM=0
while getopts “hf:p:u:U” OPTION
do
case $OPTION in
h)
usage
exit 1
;;
f)
FOLDER=$OPTARG
;;
p)
PROJECT=$OPTARG
;;
u)
GITHUB_USER=$OPTARG
;;
U)
ADD_UPSTREAM=1
;;
?)
usage
exit
;;
esac
done
if [[ -z $FOLDER ]] || [[ -z $PROJECT ]]
then
usage
exit 1
fi
if [[ -z $GITHUB_USER ]]
then
GITHUB_USER=$USER
fi
echo "Cloning ${PROJECT}.git into ${FOLDER}, username=${GITHUB_USER}"
if [[ -d $FOLDER ]]
then
echo "Folder ${FOLDER} exists."
exit 1
fi
mkdir $FOLDER
git clone --progress git@github.com:${GITHUB_USER}/${PROJECT}.git $FOLDER
if [[ $ADD_UPSTREAM -eq 1 ]]
then
echo "Adding upstream remote."
cd $FOLDER
git remote add upstream git@github.com:liferay/${PROJECT}.git
fi
echo "Clone complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment