-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathgo.sh
More file actions
executable file
·63 lines (49 loc) · 1.99 KB
/
go.sh
File metadata and controls
executable file
·63 lines (49 loc) · 1.99 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# shellcheck disable=SC1091,SC2174
. /etc/environment
set -Eeuxo pipefail
printf "\n\t🐋 Installing Go(lang) 🐋\t\n"
wget -qO- "$(jq -r '.toolcache[] | select(.name == "go") | .url' "/imagegeneration/toolset.json")" > "/tmp/go-toolset.json"
go_arch() {
case "$(uname -m)" in
'x86_64') echo 'amd64' ;;
'aarch64') echo 'arm64' ;;
esac
}
toolcache_arch() {
case "$(uname -m)" in
'aarch64') echo 'arm64' ;;
'x86_64') echo 'x64' ;;
'armv7l') echo 'armv7l' ;;
*) exit 1 ;;
esac
}
DEFVER=$(jq -r '.toolcache[] | select(.name == "go") | .default' "/imagegeneration/toolset.json")
for V in $(jq -r '.toolcache[] | select(.name == "go") | .versions[]' "/imagegeneration/toolset.json"); do
printf "\n\t🐋 Installing GO=%s 🐋\t\n" "${V}"
VER=$(jq -r "[.[] | select(.version|test(\"^${V}\"))][0].version" "/tmp/go-toolset.json")
GOPATH="${ACT_TOOLSDIRECTORY}/go/${VER}/$(toolcache_arch)"
mkdir -v -m 0777 -p "$GOPATH"
DL_VER="${VER}"
# hack (1.21.0 has the 0 in it's url)
# TODO: i hate shell scripts, please can I have powershell on linux and no, python is not a solution, it should die
# TODO: write own thing to get links from go.dev and versions from actions/go-versions, mash it together, ?????, works
#if [[ "$(echo ${VER} | cut -d. -f3)" == "0" ]]; then
# DL_VER=$(echo "${VER}" | cut -d. -f-2)
#fi
wget -qO- "https://golang.org/dl/go${DL_VER}.linux-$(go_arch).tar.gz" | tar -zxf - --strip-components=1 -C "$GOPATH"
# ENVVAR="${V//\./_}"
# echo "${ENVVAR}=${GOPATH}" >>/etc/environment
# Create a complete file
touch "${GOPATH}.complete"
printf "\n\t🐋 Installed GO 🐋\t\n"
"$GOPATH/bin/go" version
if [[ "${V}" == "$DEFVER" ]]; then
ln -s "$GOPATH/bin"/* /usr/bin/
fi
done
sed "s|PATH=|PATH=$HOME/go/bin:|g" -i /etc/environment
printf "\n\t🐋 Cleaning image 🐋\t\n"
apt-get clean
rm -rf /var/cache/* /var/log/* /var/lib/apt/lists/* /tmp/* || echo 'Failed to delete directories'
printf "\n\t🐋 Cleaned up image 🐋\t\n"