-
-
Save rotty3000/1065132 to your computer and use it in GitHub Desktop.
Clone Liferay Projects
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 | |
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 [email protected]:${GITHUB_USER}/${PROJECT}.git $FOLDER | |
if [[ $ADD_UPSTREAM -eq 1 ]] | |
then | |
echo "Adding upstream remote." | |
cd $FOLDER | |
git remote add upstream [email protected]: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