Add golang installation 77/59877/8
authorYang (Gabriel) Yu <Gabriel.yuyang@huawei.com>
Tue, 17 Jul 2018 08:15:29 +0000 (16:15 +0800)
committerYu Yang (Gabriel) <Gabriel.yuyang@huawei.com>
Fri, 27 Jul 2018 04:02:31 +0000 (04:02 +0000)
Bottlenecks container does not have golang installed.
This patch is to add golang installation script for later
usage.

Change-Id: I1456bae1e0f0ab018014d0dc9ae6df334123bc9f
Signed-off-by: Yang (Gabriel) Yu <Gabriel.yuyang@huawei.com>
utils/kube_setup/install_golang.sh [new file with mode: 0644]
utils/kube_setup/kube_env.sh [new file with mode: 0644]

diff --git a/utils/kube_setup/install_golang.sh b/utils/kube_setup/install_golang.sh
new file mode 100644 (file)
index 0000000..06c54ce
--- /dev/null
@@ -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======="
+
diff --git a/utils/kube_setup/kube_env.sh b/utils/kube_setup/kube_env.sh
new file mode 100644 (file)
index 0000000..855dea2
--- /dev/null
@@ -0,0 +1,13 @@
+#!/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
+##############################################################################
+
+export GOROOT=/usr/local/go
+export GOPATH=${HOME}/go
+export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin
+