Last active
January 9, 2016 11:02
-
-
Save nicolas-grekas/a1d3058a95a65975e168 to your computer and use it in GitHub Desktop.
source ~/go/setup x.y.z
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
#!/bin/bash | |
go_version=$1 | |
go_arch=linux-amd64 | |
export GOPATH="$HOME/go" | |
if [ ! -e $GOPATH ] | |
then | |
mkdir $GOPATH | |
fi | |
if [ -e $GOPATH/current ] | |
then | |
cur_version=`cat $GOPATH/current` | |
if [[ "x" == "x$go_version" ]] | |
then | |
go_version=$cur_version | |
fi | |
export PATH=${PATH//:$GOPATH\/$cur_version\/bin:$GOPATH\/bin/} | |
fi | |
if [[ "x" == "x$go_version" ]] | |
then | |
echo 'Please specify the go version you want' | |
return | |
fi | |
if [ ! -e $GOPATH/$go_version.tar.gz ] | |
then | |
wget https://storage.googleapis.com/golang/go$go_version.$go_arch.tar.gz -O $GOPATH/$go_version.tar.gz | |
if [ ! $? ] | |
then | |
rm $GOPATH/$go_version.tar.gz | |
return | |
fi | |
tar -C $GOPATH -xzf $GOPATH/$go_version.tar.gz | |
if [ ! -e $GOPATH/$go_version ] | |
then | |
rm -Rf $GOPATH/$go_version | |
fi | |
mv $GOPATH/go $GOPATH/$go_version | |
fi | |
export GOROOT="$GOPATH/$go_version" | |
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin | |
if [[ "$go_version" != "$cur_version" ]] | |
then | |
rm -Rf $GOPATH/pkg | |
echo $go_version > $GOPATH/current | |
fi | |
go version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment