This commit is contained in:
2025-11-14 10:45:09 +08:00
parent c7449f4acb
commit 66aff98afd
16 changed files with 527 additions and 306 deletions

View File

@@ -1,28 +1,55 @@
#!/usr/bin/env bash
##makedesc: Install golang v1.21.0
source "$( dirname $(readlink -e -- "${BASH_SOURCE}"))/../helpers.sh" || exit 255
##makedesc: Install golang
# https://go.dev/dl/
# https://golang.org/doc/install
# https://www.vultr.com/docs/install-the-latest-version-of-golang-on-ubuntu
# https://github.com/udhos/update-golang/blob/master/update-golang.sh
[ $1 ] && VERSION="$1" || VERSION="1.23.0"
title "Installing golang v$VERSION..."
set -eo pipefail
FILE="go$VERSION.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go && \
download "https://golang.org/dl/$FILE" "/tmp/$FILE" && \
sudo tar -xzf "/tmp/$FILE" -C /usr/local && \
rm -rf "/tmp/$FILE" && \
sudo chown $USER: -R /usr/local/go && \
echo 'export PATH="/usr/local/go/bin:$PATH"' >> "$HOME/.profile" && \
echo "export GOPATH=\"\$HOME/.go\"" >> "$HOME/.profile" && \
source ~/.profile
doRemove() {
[ -d "/usr/local/go" ] && sudo rm -rf "/usr/local/go"
}
[ $? = 0 ] && {
install() {
dlUrl="https://go.dev/dl"
json=$(curl -sSL "$dlUrl/?mode=json")
version=$(echo "$json" | jq -r '.[0].version')
echo
success "golang installed!"
info "NOTE: now run 'source ~/.profile' to apply new env vars"
echo "==============================================="
echo "Installing golang v$version"
echo "==============================================="
echo
latestJson=$(echo "$json" | jq -r '.[0].files.[] | select (.kind == "archive" and .os == "linux" and .arch == "amd64")')
fileName=$(echo "$latestJson" | jq -r '.filename')
fileUrl="$dlUrl/$fileName"
downloadPath="$HOME/install"
archivePath="$downloadPath/$fileName"
doRemove
[ -f "$archivePath" ] || wget "$fileUrl" -O "$archivePath"
[ -f "$archivePath" ] && sudo tar -xzf "$archivePath" -C /usr/local
sudo chown "$USER": -R /usr/local/go
echo 'export PATH="/usr/local/go/bin:$PATH"' >> "$HOME/.profile"
echo "export GOPATH=\"\$HOME/.go\"" >> "$HOME/.profile"
echo
echo "Finish!"
go version
}
remove() {
echo
echo "==============================================="
echo "Removing golang"
echo "==============================================="
echo
doRemove
echo
echo "Finish!"
echo
}
case "$1" in
r|remove|d|delete|p|purge) remove ;;
*) install ;;
esac