-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path.go
executable file
·83 lines (68 loc) · 1.78 KB
/
.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -e
ROOT=$(dirname "$0")
if [ -z "$GO_VERSION" ]; then
source "$ROOT/go.version"
fi
if [ -z "$GO_VERSION" ]; then
echo "Missing \$GO_VERSION environment" >&2
exit 1
fi
GOROOT="$ROOT"/.goroot/$GO_VERSION
GOROOT_CURRENT="$ROOT"/.goroot/current
CACHE_DIR="$ROOT"/.cache
if [[ "$("$GOROOT"/bin/go version 2>&1 | cut -f3 -d\ )" != "go$GO_VERSION" ]]; then
# Make sure only one instance is executed at the same time
[ "$FLOCKER" != "$0" ] && exec env FLOCKER="$0" flock -e $0 $0 "$@"
rm -rf "$GOROOT"
case "$(uname -m)" in
"x86_64")
ARCH=amd64
;;
"arm64")
ARCH=arm64
;;
"aarch64")
ARCH=arm64
;;
*)
echo "Unsupported arch: $(uname -m)"
exit 1
esac
case "$(uname -s)" in
"Darwin")
OS=darwin
;;
"Linux")
OS=linux
;;
"FreeBSD")
OS=freebsd
;;
*)
echo "Unsupported OS: $(uname -s)"
exit 1
esac
GO_URL="https://dl.google.com/go/go$GO_VERSION.$OS-$ARCH.tar.gz"
# Download and install Go.
rm -rf "$GOROOT"
mkdir -p "$GOROOT"
mkdir -p "$CACHE_DIR"
cache_file="$CACHE_DIR"/${GO_URL##*/}
if [ ! -f "$cache_file" ]; then
echo "Installing $GO_URL" >&2
curl -sS -o "$cache_file" "$GO_URL"
else
echo "Installing $GO_URL (from cache)" >&2
fi
tar --strip-components 1 -C "$GOROOT" -zxf "$cache_file"
# Reset quilt state.
rm -rf "$ROOT"/.pc
# Update current symlink so quilt find the files.
rm -rf "$GOROOT_CURRENT"
ln -sf -T "$GO_VERSION" "$GOROOT_CURRENT"
else
# Update current symlink so quilt find the files, may be rolling back to previous version.
ln -sf -T "$GO_VERSION" "$GOROOT_CURRENT"
fi
"$GOROOT"/bin/go "$@"