mirror of
https://github.com/mr0xb/dotfiles.git
synced 2026-08-27 19:34:57 -04:00
37 lines
949 B
Shell
37 lines
949 B
Shell
#!/usr/bin/env sh
|
|
|
|
TARGETDIR=${GO_TARGET_DIR:="/usr/local/"}
|
|
|
|
lookup_file() {
|
|
curl -sSL "https://go.dev/dl/?mode=json" |
|
|
jq -r '.[0].files[]
|
|
| select(.os == "'"$GOOS"'")
|
|
| select(.arch == "'"$GOARCH"'")
|
|
| .filename'
|
|
}
|
|
|
|
fetch() {
|
|
local filename
|
|
if [ $GO_VERS == "latest" ]; then
|
|
filename="$(lookup_file)"
|
|
else
|
|
filename="$GO_VERS.$GOOS-$GOARCH.tar.gz"
|
|
fi
|
|
[[ -z "$filename" ]] && echo "unable to fetch filename" 1>&2 && return 1
|
|
local path="/tmp/$filename"
|
|
[[ -n "$DOWNLOADS" ]] && [[ -d "$DOWNLOADS" ]] && path="$DOWNLOADS/$filename"
|
|
curl -L "https://go.dev/dl/$filename" -o "$path"
|
|
echo "$path"
|
|
}
|
|
|
|
install_latest_go() {
|
|
local dir="$1" path
|
|
[[ -z "$dir" ]] && dir="$TARGETDIR"
|
|
[[ -z "$dir" ]] && dir="$HOME/.local"
|
|
mkdir -p "$dir" 2>/dev/null
|
|
path="$(fetch)"
|
|
[[ -z "$path" ]] && echo "unable to fetch go tarball" 1>&2 && return 1
|
|
rm -rf "$dir/go" && tar -C "$dir" -xzf "$path"
|
|
}
|
|
|
|
install_latest_go "$@"
|