4 # homepage: https://golang.org
5 # tagline: The Go Programming Language tools
7 # Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
16 # cat << EOF >> main.go
24 # fmt.Println("Hello, World!")
40 # Use the script's first argument or the supplied WEBI_VERSION or ''
41 WEBI_VERSION=${1:-${WEBI_VERSION:-}}
43 # Set a temporary directory, if not already set
44 WEBI_TMP=${WEBI_TMP:-"$(mktemp -d -t webinstall-go.XXXXXXXX)"}
50 # The WEBI bootstrap will define these
51 # but each script should be testable in its own right
53 if [ -z "${WEBI_PKG_URL}" ]; then
54 release_tab="${WEBI_HOST}/api/releases/go@${WEBI_VERSION:-}.csv?os=$(uname -s)&arch=$(uname -m)&ext=tar&limit=1"
55 WEBI_CSV=$(curl -fsSL "$release_tab" -H "User-Agent: $(uname -a)")
56 WEBI_CHANNEL=$(echo $WEBI_TAB | cut -d ',' -f 3)
57 if [ "error" == "$WEBI_CHANNEL" ]; then
58 echo "could not find release for go v${WEBI_VERSION}"
61 WEBI_VERSION=$(echo $WEBI_TAB | cut -d ',' -f 1)
62 WEBI_PKG_URL=$(echo $WEBI_TAB | cut -d ',' -f 9)
63 WEBI_PKG_FILE="$WEBI_TMP/$(echo $WEBI_PKG_URL | sed s:.*/::)"
70 new_go_home="${HOME}/.local/opt/go-v${WEBI_VERSION}"
71 new_go="${HOME}/.local/opt/go-v${WEBI_VERSION}/bin/go"
73 # Test for existing version
75 cur_go="$(command -v go)"
77 if [ -n "$cur_go" ]; then
78 # TODO this is still sometimes wrong (i.e. 1.14 = 1.14.0)
79 cur_ver=$(go version | cut -d' ' -f3 | sed 's:go::')
80 if [ "$cur_ver" == "$(echo $WEBI_VERSION | sed 's:\.0::g')" ]; then
81 echo "go v$WEBI_VERSION already installed at $cur_go"
83 elif [ "$cur_go" != "$new_go" ]; then
84 echo "WARN: possible conflict with go v$WEBI_VERSION at $cur_go"
88 # TODO move download to the webi bootstrap
89 echo Downloading go v"${WEBI_VERSION}" from "${WEBI_PKG_URL}"
90 curl -fsSL "${WEBI_PKG_URL}" -o "${WEBI_PKG_FILE}"
91 pushd "${WEBI_TMP}" 2>&1 >/dev/null
92 echo Installing go v${WEBI_VERSION} as "$new_go"
93 tar xf "${WEBI_PKG_FILE}"
96 # simpler for single-binary commands
97 #mv ./example*/bin/example "$HOME/.local/bin"
99 # best for packages and toolchains
100 rm -rf "$new_go_home"
101 if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then
102 rsync -Krl ./go*/ "$new_go_home/" 2>/dev/null
104 cp -Hr ./go*/* "$new_go_home/" 2>/dev/null
105 cp -Hr ./go*/.* "$new_go_home/" 2>/dev/null
109 $new_go_home/bin/go get golang.org/x/tools/cmd/goimports > /dev/null 2>/dev/null
110 $new_go_home/bin/go get golang.org/x/tools/cmd/gorename > /dev/null 2>/dev/null
111 $new_go_home/bin/go get golang.org/x/tools/cmd/gotype > /dev/null 2>/dev/null
112 $new_go_home/bin/go get golang.org/x/tools/cmd/stringer > /dev/null 2>/dev/null
119 # TODO get better output from pathman / output the path to add as return to webi bootstrap
120 pathman add "$new_go_home"
121 pathman add "$HOME/go/bin/"
122 echo "Installed 'go' (and go tools)"