2 ##############################################################################
3 # Copyright (c) 2018 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 usage="Script to install and config golang of specific version.
12 bash $(basename "$0") [-h|--help] [-v|--version <version>] [--debug]
15 -h|--help show the help text
16 -v|--version input the version of golang
17 --debug debug option switch
19 $(basename "$0") -v 1.10.3"
24 # Process input variables
39 redirect="/dev/stdout"
43 echo "unkown option $1 $2"
52 echo "=======Downloading golang of version: ${GOLANG_VERSION}========"
54 if [[ -f go${GOLANG_VERSION}.linux-amd64.tar.gz ]]; then
55 rm go${GOLANG_VERSION}.linux-amd64.tar.gz
57 curl -O https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz >${redirect}
59 echo "Installing golang of version: ${GOLANG_VERSION}"
60 if [[ -d /usr/local/go ]]; then
64 tar -C /usr/local -xzf go${GOLANG_VERSION}.linux-amd64.tar.gz >${redirect}
66 if [[ -d $HOME/go ]]; then
77 echo "Adding golang env to ~/.bashrc"
81 if [[ $(cat ${HOME}/.bashrc | grep GOROOT) ]]; then
82 echo "golang env alreay in ${HOME}/.bashrc"
84 cat <<EOF >> ${HOME}/.bashrc
86 export GOROOT=/usr/local/go
87 export GOPATH=${HOME}/go
88 export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin
92 export GOROOT=/usr/local/go
93 export GOPATH=${HOME}/go
94 export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin
96 echo "Running go version command:"
99 echo "=======Installation of golang-${GOLANG_VERSION} complete======="