github.com/q2/git-lfs@v0.5.1-0.20150410234700-03a0d4cec40e/script/gpm (about) 1 #!/usr/bin/env bash 2 3 set -eu 4 5 ## Functions/ 6 usage() { 7 cat << EOF 8 SYNOPSIS 9 10 gpm leverages the power of the go get command and the underlying version 11 control systems used by it to set your Go dependencies to desired versions, 12 thus allowing easily reproducible builds in your Go projects. 13 14 A Godeps file in the root of your Go application is expected containing 15 the import paths of your packages and a specific tag or commit hash 16 from its version control system, an example Godeps file looks like this: 17 18 $ cat Godeps 19 # This is a comment 20 github.com/nu7hatch/gotrail v0.0.2 21 github.com/replicon/fast-archiver v1.02 #This is another comment! 22 github.com/nu7hatch/gotrail 2eb79d1f03ab24bacbc32b15b75769880629a865 23 24 gpm has a companion tool, called [gvp](https://github.com/pote/gvp) which 25 provides vendoring functionalities, it alters your GOPATH so every project 26 has its own isolated dependency directory, it's usage is recommended. 27 28 USAGE 29 $ gpm # Same as 'install'. 30 $ gpm install # Parses the Godeps file, installs dependencies and sets 31 # them to the appropriate version. 32 $ gpm version # Outputs version information 33 $ gpm help # Prints this message 34 EOF 35 } 36 37 # Iterates over Godep file dependencies and sets 38 # the specified version on each of them. 39 set_dependencies() { 40 deps=$(sed 's/#.*//;/^\s*$/d' < $1) || echo "" 41 42 while read package version; do 43 ( 44 install_path="${GOPATH%%:*}/src/${package%%/...}" 45 [[ -e "$install_path/.git/index.lock" || 46 -e "$install_path/.hg/store/lock" || 47 -e "$install_path/.bzr/checkout/lock" ]] && wait 48 echo ">> Getting package "$package"" 49 go get -u -d "$package" 50 echo ">> Setting $package to version $version" 51 cd $install_path 52 [ -d .hg ] && hg update -q "$version" 53 [ -d .git ] && git checkout -q "$version" 54 [ -d .bzr ] && bzr revert -q -r "$version" 55 [ -d .svn ] && svn update -r "$version" 56 ) & 57 done < <(echo "$deps") 58 wait 59 echo ">> All Done" 60 } 61 62 ## /Functions 63 case "${1:-"install"}" in 64 "version") 65 echo ">> gpm v1.2.0" 66 ;; 67 "install") 68 deps_file="Godeps" 69 [[ "$#" -eq 2 ]] && [[ -n "$2" ]] && deps_file="$2" 70 [[ -f "$deps_file" ]] || (echo ">> $deps_file file does not exist." && exit 1) 71 (which go > /dev/null) || 72 ( echo ">> Go is currently not installed or in your PATH" && exit 1) 73 set_dependencies $deps_file 74 ;; 75 "help") 76 usage 77 ;; 78 *) 79 ## Support for Plugins: if command is unknown search for a gpm-command executable. 80 if command -v "gpm-$1" > /dev/null 81 then 82 plugin=$1 && 83 shift && 84 gpm-$plugin $@ && 85 exit 86 else 87 usage && exit 1 88 fi 89 ;; 90 esac