Created
December 20, 2017 08:42
-
-
Save lufia/aabb7c64e472531b2e1a1e237994859b to your computer and use it in GitHub Desktop.
Install go-gettable packages with temporary GOPATH
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 | |
# usage: goinstall [pkg ...] | |
if [[ -z $GOPATH ]] | |
then | |
echo $(basename $0): requires GOPATH >&2 | |
exit 1 | |
fi | |
IFS=: paths=($GOPATH) | |
dir=$(mktemp -d -t $(basename $0)) | |
trap 'rm -rf $dir; exit 2' 1 2 3 15 EXIT | |
export GOPATH=$dir | |
go get -u -- $* || exit 1 | |
for i in "${paths[@]}" | |
do | |
if ! [[ -d "$i/bin" ]] || ! [[ -w "$i/bin" ]] | |
then | |
continue | |
fi | |
cp -p $GOPATH/bin/* "$i/bin" || exit 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment