Skip to content

Instantly share code, notes, and snippets.

@donatello
Last active October 16, 2017 05:31
Show Gist options
  • Save donatello/a6b9ad00f1dc50c35555 to your computer and use it in GitHub Desktop.
Save donatello/a6b9ad00f1dc50c35555 to your computer and use it in GitHub Desktop.
Create a new custom Go environment in a specified directory
#!/bin/bash
GODOWNLOAD=go1.9.1.linux-amd64.tar.gz
GOURL=https://storage.googleapis.com/golang/$GODOWNLOAD
INSTALL_ARG=$1
if [ -z $INSTALL_ARG ]; then
echo "Please specify an install location on the command line."
exit 1
fi
if [ -d $INSTALL_ARG ]; then
echo "The directory \"$INSTALL_ARG\" already exists.. quitting!"
exit 1
fi
if [[ ${INSTALL_ARG:0:1} == "/" ]]; then
INSTALL_LOCATION=$INSTALL_ARG
else
INSTALL_LOCATION=$PWD/$INSTALL_ARG
fi
echo "Installing go environment to $INSTALL_LOCATION"
set -ex
wget -q -P $INSTALL_LOCATION $GOURL
tar -C $INSTALL_LOCATION -xf $INSTALL_LOCATION/$GODOWNLOAD
GOROOT=$INSTALL_LOCATION/go
GOPATH=$INSTALL_LOCATION/workspace
mkdir -p $GOPATH/{src,bin,pkg}
set +x
echo "Creating files to source:"
cat <<EOF > $INSTALL_LOCATION/activate
#!/bin/bash
export GOPATH=$GOPATH
export GOROOT=$GOROOT
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
EOF
chmod +x $INSTALL_LOCATION/activate
echo "Run \"source $INSTALL_LOCATION/activate\" to turn on the go environment at $INSTALL_LOCATION !"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment