Skip to content

Commit 82f06f7

Browse files
authored
chore: add install-go.sh script (for local development) (#150)
Signed-off-by: Angelos Kolaitis <neoaggelos@gmail.com>
1 parent 665e13b commit 82f06f7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

hack/scripts/install-go.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash -e
2+
3+
# Usage:
4+
# $ install-go.sh # source Go version from go.mod
5+
# $ install-go.sh 1.24.7 # install specific Go version
6+
#
7+
# Description:
8+
# - Download go version and install under /usr/local/go
9+
# - Create symlinks for go and gofmt in /usr/local/bin
10+
11+
VERSION="${1:-}"
12+
if [ -z "${VERSION}" ]; then
13+
DIR="$(realpath "$(dirname "${0}")")"
14+
VERSION="$(cat "${DIR}/../../go.mod" | grep "^go" | sed "s,^go\s,,")"
15+
16+
echo "Will install Go version from go.mod : ${VERSION}"
17+
fi
18+
19+
# infer ARCH
20+
ARCH="$(uname -m)"
21+
if uname -m | grep -q x86_64; then ARCH=amd64; fi
22+
if uname -m | grep -q aarch64; then ARCH=arm64; fi
23+
24+
# infer OS
25+
OS="$(uname -s)"
26+
if uname -s | grep -q Linux; then OS=linux; fi
27+
if uname -s | grep -q Darwin; then OS=darwin; fi
28+
29+
fname="go${VERSION}.${OS}-${ARCH}.tar.gz"
30+
[ -f "$fname" ] || wget "https://go.dev/dl/go${VERSION}.${OS}-${ARCH}.tar.gz"
31+
sudo tar -C /usr/local -xvzf "${fname}"
32+
rm "${fname}"
33+
34+
sudo ln -sf /usr/local/go/bin/go /usr/local/bin/go
35+
sudo ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt

0 commit comments

Comments
 (0)