1#!/bin/bash 2 3# Copyright 2022 Google LLC 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16################################################################################ 17 18# This script installs a recent version of Go into a temporary directory. The Go 19# bin directory is then added to the PATH environment variable. 20# 21# NOTE: This script MUST be sourced to update the environment of the calling 22# script. 23# 24# Usage instructions: 25# 26# source ./kokoro/testutils/install_go.sh 27 28install_temp_go() { 29 local -r go_version="1.19.9" 30 31 local -r platform="$(uname | tr '[:upper:]' '[:lower:]')" 32 local go_platform 33 case "${platform}" in 34 'linux') 35 go_platform='linux-amd64' 36 ;; 37 'darwin') 38 go_platform='darwin-amd64' 39 ;; 40 *) 41 echo "Unsupported platform, unable to install Go." 42 exit 1 43 ;; 44 esac 45 readonly go_platform 46 47 local -r go_archive="go${go_version}.${go_platform}.tar.gz" 48 local -r go_url="https://go.dev/dl/${go_archive}" 49 50 local -r go_tmpdir=$(mktemp -dt tink-go.XXXXXX) 51 ( 52 cd "${go_tmpdir}" 53 curl -OLsS "${go_url}" 54 tar -xzf "${go_archive}" 55 ) 56 57 export GOROOT="${go_tmpdir}/go" 58 export PATH="${go_tmpdir}/go/bin:${PATH}" 59} 60 61if [[ -n "${KOKORO_ARTIFACTS_DIR:-}" ]] ; then 62 install_temp_go 63fi 64