|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -# Copyright 2021 The Kubernetes Authors. |
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. |
| 3 | +set -eux |
16 | 4 |
|
17 | | -set -o errexit |
18 | | -set -o nounset |
19 | | -set -o pipefail |
20 | | - |
21 | | -# Ensure the go tool exists and is a viable version. |
| 5 | +MINIMUM_GO_VERSION=go1.24.0 |
| 6 | +# Ensure the go tool exists and is a viable version, or installs it |
22 | 7 | verify_go_version() |
23 | 8 | { |
24 | | - if [[ -z "$(command -v go)" ]]; then |
25 | | - cat << EOF |
26 | | -Can't find 'go' in PATH, please fix and retry. |
27 | | -See http://golang.org/doc/install for installation instructions. |
28 | | -EOF |
29 | | - return 2 |
| 9 | + # If go is not available on the path, get it |
| 10 | + if ! [ -x "$(command -v go)" ]; then |
| 11 | + if [[ "${OSTYPE}" == "linux-gnu" ]]; then |
| 12 | + echo 'go not found, installing' |
| 13 | + curl -sLo "/tmp/${MINIMUM_GO_VERSION}.linux-amd64.tar.gz" "https://go.dev/dl/${MINIMUM_GO_VERSION}.linux-amd64.tar.gz" |
| 14 | + sudo tar -C /usr/local -xzf "/tmp/${MINIMUM_GO_VERSION}.linux-amd64.tar.gz" |
| 15 | + export PATH=/usr/local/go/bin:$PATH |
| 16 | + else |
| 17 | + echo "Missing required binary in path: go" |
| 18 | + return 2 |
| 19 | + fi |
30 | 20 | fi |
31 | 21 |
|
32 | 22 | local go_version |
|
36 | 26 | if [[ "${minimum_go_version}" != $(echo -e "${minimum_go_version}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) ]] && [[ "${go_version[2]}" != "devel" ]]; then |
37 | 27 | cat << EOF |
38 | 28 | Detected go version: ${go_version[*]}. |
39 | | -Kubernetes requires ${minimum_go_version} or greater. |
| 29 | +Requires ${minimum_go_version} or greater. |
40 | 30 | Please install ${minimum_go_version} or later. |
41 | 31 | EOF |
42 | 32 | return 2 |
|
0 commit comments