From 6123d0db2c010ab0d5ead00363f12169bff1870f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Sat, 15 Jul 2023 10:04:10 +0200 Subject: [PATCH] ci: Move install_go.sh as it was MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's move `.ci/install_go.sh` file from the tests repo to this one. The file has been moved as it is, it's not used, and in the following commits we'll clean it up before actually using it. Signed-off-by: Fabiano FidĂȘncio --- tests/install_go.sh | 98 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100755 tests/install_go.sh diff --git a/tests/install_go.sh b/tests/install_go.sh new file mode 100755 index 0000000000..2902778646 --- /dev/null +++ b/tests/install_go.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# +# Copyright (c) 2018 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + +set -o errexit +set -o nounset +set -o pipefail + +tmp_dir=$(mktemp -d -t install-go-tmp.XXXXXXXXXX) +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +script_name="$(basename "${BASH_SOURCE[0]}")" +force="" +USE_VERSIONS_FILE="" +PROJECT="Kata Containers" + +source "${script_dir}/lib.sh" + +install_dest="/usr/local/" + +finish() { + rm -rf "$tmp_dir" +} + +usage(){ + exit_code="$1" + cat < + +Args: + : Install a specific go version. + +Example: +${script_name} 1.10 + +Options +-d : destination path, path where go will be installed. +-f : Force remove old go version and install the specified one. +-h : Show this help +-p : Install go defined in ${PROJECT} versions file. + +EOF + + exit "$exit_code" +} + +trap finish EXIT + +pushd "${tmp_dir}" + +while getopts "d:fhp" opt +do + case $opt in + d) install_dest="${OPTARG}" ;; + f) force="true" ;; + h) usage 0 ;; + p) USE_VERSIONS_FILE="true" ;; + esac +done + +shift $(( $OPTIND - 1 )) + +go_version="${1:-""}" + +if [ -z "$go_version" ] && [ "${USE_VERSIONS_FILE}" = "true" ] ;then + go_version=$(get_from_kata_deps "languages.golang.meta.newest-version") +fi + +if [ -z "$go_version" ];then + echo "Missing go version or -p option" + usage 0 +fi + +if command -v go; then + [[ "$(go version)" == *"go${go_version}"* ]] && \ + info "Go ${go_version} already installed" && \ + exit + if [ "${force}" = "true" ]; then + info "removing $(go version)" + sudo rm -rf "${install_dest}/go" + else + die "$(go version) is installed, use -f or remove it before install go ${go_version}" + fi +fi + +goarch=$("${script_dir}/kata-arch.sh" --golang) + +info "Download go version ${go_version}" +kernel_name=$(uname -s) +curl -OL "https://storage.googleapis.com/golang/go${go_version}.${kernel_name,,}-${goarch}.tar.gz" +info "Install go" +mkdir -p "${install_dest}" +sudo tar -C "${install_dest}" -xzf "go${go_version}.${kernel_name,,}-${goarch}.tar.gz" +popd