Created
March 3, 2014 20:47
-
-
Save mattetti/9334318 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
set -eu | |
## The Godeps file is expected to have lines like so: | |
# | |
# github.com/nu7hatch/gotrail v2.6 | |
# | |
## where the first element is the import path and the second is a tag | |
## or commit SHA in the project. | |
## Functions | |
# Iterates over Godep file dependencies and sets | |
# the specified version on each of them. | |
set_dependencies() { | |
while read package version; do | |
( | |
install_path="${GOPATH%%:*}/src/${package%%/...}" | |
[[ -e "$install_path/.git/index.lock" ]] && wait | |
if [ -d $install_path/.git ] && test "$(git --git-dir=$install_path/.git rev-parse HEAD)" = "$version"; then | |
echo ">> Checked $package already at $version" | |
exit 0 | |
fi | |
echo ">> Getting package "$package"" | |
go get -u -d "$package" | |
echo ">> Setting $package to version $version" | |
cd $install_path | |
[ -d .hg ] && hg update -q "$version" | |
[ -d .git ] && git checkout -q "$version" | |
[ -d .bzr ] && bzr revert -q -r "$version" | |
) & | |
done < <(echo "$deps") | |
wait | |
echo ">> All Done" | |
} | |
## Main execution | |
# Parse command line arguemnts | |
# Godeps default file is './Godeps' (can be overriden by -f) | |
godeps="Godeps" | |
while getopts “va:Hf:” OPTION | |
do | |
case $OPTION in | |
v) | |
echo "v0.4.1" | |
exit | |
;; | |
f) | |
godeps=$OPTARG | |
;; | |
esac | |
done | |
# Check if Godeps file exists | |
if [[ ! -f "$godeps" ]] | |
then | |
echo ">> $godeps file does not exist." | |
exit 1 | |
fi | |
# Get dependencies from Godeps file excluding comments | |
deps=$(sed 's/#.*//;/^\s*$/d' < "$godeps") || echo "" | |
set_dependencies |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment