Skip to content

Instantly share code, notes, and snippets.

@lufia
Created December 20, 2017 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lufia/aabb7c64e472531b2e1a1e237994859b to your computer and use it in GitHub Desktop.
Save lufia/aabb7c64e472531b2e1a1e237994859b to your computer and use it in GitHub Desktop.
Install go-gettable packages with temporary GOPATH
#!/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