This commit is contained in:
2026-07-10 15:11:51 +08:00
parent 8bfcf23bc2
commit da17239d7d
148 changed files with 2542 additions and 4873 deletions
+31 -6
View File
@@ -7,6 +7,8 @@
set -eo pipefail
installed() { command -v "$1" >/dev/null 2>&1; }
doRemove() {
[ -d "/usr/local/go" ] && sudo rm -rf "/usr/local/go"
}
@@ -20,22 +22,42 @@ install() {
echo "Installing golang v$version"
echo "==============================================="
echo
latestJson=$(echo "$json" | jq -r '.[0].files.[] | select (.kind == "archive" and .os == "linux" and .arch == "amd64")')
local os="linux"
[ "$(uname -s)" = "Darwin" ] && os="darwin"
latestJson=$(echo "$json" | jq -r ".[0].files.[] | select (.kind == \"archive\" and .os == \"$os\" 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
if [ ! -f "$archivePath" ]; then
if installed wget; then
wget -q --show-progress "$fileUrl" -O "$archivePath"
else
curl -fsSL "$fileUrl" -o "$archivePath"
fi
fi
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"
if ! grep -q '/usr/local/go/bin' "$HOME/.profile" 2>/dev/null; then
echo 'export PATH="/usr/local/go/bin:$PATH"' >> "$HOME/.profile"
echo "export GOPATH=\"\$HOME/.go\"" >> "$HOME/.profile"
fi
# shellcheck source=/dev/null
source "$HOME/.profile"
echo
go version
go install github.com/go-delve/delve/cmd/dlv@latest
go install
echo "Finish!"
echo
}
upgrade() {
install
}
remove() {
@@ -45,12 +67,15 @@ remove() {
echo "==============================================="
echo
doRemove
sed -i '/\/usr\/local\/go\/bin/d' "$HOME/.profile"
sed -i '/GOPATH/d' "$HOME/.profile"
echo
echo "Finish!"
echo
}
case "$1" in
u|upgrade|update) upgrade ;;
r|remove|d|delete|p|purge) remove ;;
*) install ;;
esac