diff options
author | Yang (Gabriel) Yu <Gabriel.yuyang@huawei.com> | 2018-08-09 13:07:31 +0800 |
---|---|---|
committer | Yang (Gabriel) Yu <Gabriel.yuyang@huawei.com> | 2018-08-11 10:32:08 +0800 |
commit | 13fd26c9dfdfbe70eba3da738cc932814b072b92 (patch) | |
tree | 3cf0eec9d6c7bd82e9fe856c220626ef353a4467 /utils/k8s_setup/golang_install.sh | |
parent | 09df92d801b68dc42d7b9e39e3c718988b0c01c6 (diff) |
add k8s test configs preparation
JIRA: BOTTLENECK-243
Change-Id: I994c71f03c4c2429d62618920cfc92fc1ed16abe
Signed-off-by: Yang (Gabriel) Yu <Gabriel.yuyang@huawei.com>
Diffstat (limited to 'utils/k8s_setup/golang_install.sh')
-rw-r--r-- | utils/k8s_setup/golang_install.sh | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/utils/k8s_setup/golang_install.sh b/utils/k8s_setup/golang_install.sh new file mode 100644 index 00000000..06c54cee --- /dev/null +++ b/utils/k8s_setup/golang_install.sh @@ -0,0 +1,100 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2018 Huawei Technologies Co.,Ltd and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +usage="Script to install and config golang of specific version. + +usage: + bash $(basename "$0") [-h|--help] [-v|--version <version>] [--debug] + +where: + -h|--help show the help text + -v|--version input the version of golang + --debug debug option switch +examples: + $(basename "$0") -v 1.10.3" + +# Debug option +redirect="/dev/null" + +# Process input variables +while [[ $# > 0 ]] + do + key="$1" + case $key in + -h|--help) + echo "$usage" + exit 0 + shift + ;; + -v|--version) + GOLANG_VERSION="$2" + shift + ;; + --debug) + redirect="/dev/stdout" + shift + ;; + *) + echo "unkown option $1 $2" + exit 1 + ;; + esac + shift +done + +#set -e + +echo "=======Downloading golang of version: ${GOLANG_VERSION}========" + +if [[ -f go${GOLANG_VERSION}.linux-amd64.tar.gz ]]; then + rm go${GOLANG_VERSION}.linux-amd64.tar.gz +fi +curl -O https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz >${redirect} + +echo "Installing golang of version: ${GOLANG_VERSION}" +if [[ -d /usr/local/go ]]; then + rm -rf /usr/local/go +fi + +tar -C /usr/local -xzf go${GOLANG_VERSION}.linux-amd64.tar.gz >${redirect} + +if [[ -d $HOME/go ]]; then + rm -rf ${HOME}/go + mkdir ${HOME}/go + mkdir ${HOME}/go/bin + mkdir ${HOME}/go/src +else + mkdir ${HOME}/go + mkdir ${HOME}/go/bin + mkdir ${HOME}/go/src +fi + +echo "Adding golang env to ~/.bashrc" +GOROOT=/usr/local/go +GOPATH=${HOME}/go + +if [[ $(cat ${HOME}/.bashrc | grep GOROOT) ]]; then + echo "golang env alreay in ${HOME}/.bashrc" +else + cat <<EOF >> ${HOME}/.bashrc + +export GOROOT=/usr/local/go +export GOPATH=${HOME}/go +export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin +EOF +fi + +export GOROOT=/usr/local/go +export GOPATH=${HOME}/go +export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin + +echo "Running go version command:" +go version + +echo "=======Installation of golang-${GOLANG_VERSION} complete=======" + |