Skip to content

Instantly share code, notes, and snippets.

@gossi
Last active June 9, 2017 16:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gossi/5722294 to your computer and use it in GitHub Desktop.
Save gossi/5722294 to your computer and use it in GitHub Desktop.
Shell script to pull git repositories in vendor/repo format
#!/bin/sh
###########################
## Shell script to clone a list of github repositories and run `mvn clean install` on each one of them
##
## Authors: Robert Gründler, Thomas Gossmann
## Usage: put a file called `repos.txt` in the folder of the script containing the repository URLs, line by line:
##
## https://github.com/pulse00/Composer-Eclipse-Plugin.git
## git@github.com:pulse00/Symfony-2-Eclipse-Plugin.git
##
###########################
cwd=`pwd`
while read line
do
projects+=( "$line" )
done < $cwd/repos.txt
for project in "${projects[@]}"
do
#:
# try git@github.com:username/repo-name.git first
replace=${project%/*/*}
name="${project#$replace/}"
# try https://github.com/username/repo-name.git
if [[ $name = *:* ]]; then
replace=${project%:*}
name="${project#$replace:}"
fi
# can't continue
if ! test -n "$name"; then
echo "Unable to parse directory for $project"
continue
fi
# cleanup name
name=${name%.git}
# create vendor dir if not present
vendor=${name%/*}
vendorpath="$cwd/$vendor"
if [ ! -d $vendorpath ]; then
mkdir $vendorpath
fi
# repo
repo=${name#$vendor/}
# if eclipse, prepend name with org.eclipse.
if [[ $vendor = "eclipse" ]]; then
repo="org.eclipse.$repo"
fi
# if the directory does not exist, clone the repos and run maven
fullpath="$cwd/$vendor/$repo"
if [ ! -d $fullpath ]; then
mkdir $fullpath
git clone $project $fullpath
cd $fullpath
mvn clean install
cd $cwd
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment