-
Notifications
You must be signed in to change notification settings - Fork 79
/
setup-go.sh
executable file
·29 lines (26 loc) · 1.09 KB
/
setup-go.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash -eux
TEMP="$(mktemp -d)"
trap 'rm -rf $TEMP' EXIT ERR INT
ARCH=$(dpkg --print-architecture)
GO_LINUX_PACKAGE_URL="https://go.dev/dl/$(curl https://go.dev/VERSION?m=text | head -n1).linux-${ARCH}.tar.gz"
if [[ "${INPUT_GOVERSION##*/}" == "go.mod" ]]; then
INPUT_GOVERSION=$(grep -e '^go' -m 1 ${INPUT_GOVERSION} | sed -e 's/go //g')
fi
if [[ ${INPUT_GOVERSION} =~ ^1\.[0-9]+$ ]]; then
LATEST_MINOR_GOVERSION=$(curl -s https://go.dev/dl/ | grep -oP "go${INPUT_GOVERSION}\.\d+" | head -n 1 | cut -c 3-)
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go${LATEST_MINOR_GOVERSION}.linux-${ARCH}.tar.gz"
elif [[ ${INPUT_GOVERSION} == http* ]]; then
GO_LINUX_PACKAGE_URL=${INPUT_GOVERSION}
elif [[ -n ${INPUT_GOVERSION} ]]; then
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go${INPUT_GOVERSION}.linux-${ARCH}.tar.gz"
fi
wget --progress=dot:mega ${GO_LINUX_PACKAGE_URL} -O "$TEMP/go-linux.tar.gz"
(
cd "$TEMP" || exit 1
tar -zxf go-linux.tar.gz
mv go /usr/local/
)
mkdir -p /go/bin /go/src /go/pkg
export GO_HOME=/usr/local/go
export GOPATH=/go
export PATH=${GOPATH}/bin:${GO_HOME}/bin/:$PATH