#!/bin/bash export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH source <(curl -f -s --connect-timeout 10 --retry 3 https://dl.acepanel.net/public.sh) if [ $? -ne 0 ]; then echo "Download public.sh failed, please check the network or try again later." exit 1 fi slug=${1} version=${2} go_path="${setup_path}/server/go/${slug}" in_china=$(curl --retry 2 -m 10 -L -k https://www.qualcomm.cn/cdn-cgi/trace 2>/dev/null | grep -qx 'loc=CN' && echo "true" || echo "false") # 预检查 if [ ! -f "${go_path}/bin/go" ]; then error "Go ${slug} is not installed" fi # 架构映射 case ${ARCH} in x86_64) GO_ARCH="amd64" ;; aarch64) GO_ARCH="arm64" ;; esac # 下载Go安装包 GO_TARBALL="go${version}.linux-${GO_ARCH}.tar.gz" if ${in_china}; then GO_URL="https://mirrors.aliyun.com/golang/${GO_TARBALL}" echo "Downloading ${GO_TARBALL} from Aliyun mirror..." else GO_URL="https://dl.google.com/go/${GO_TARBALL}" echo "Downloading ${GO_TARBALL} from Google..." fi cd ${go_path} aria2c -x8 \ -U "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36" \ -o ${GO_TARBALL} \ ${GO_URL} if [ $? -ne 0 ]; then rm -f ${GO_TARBALL} error "Failed to download Go ${version}" fi # 删除旧文件 find ${go_path} -mindepth 1 ! -name "${GO_TARBALL}" -exec rm -rf {} + 2>/dev/null # 解压 tar -zxf ${GO_TARBALL} if [ $? -ne 0 ]; then rm -f ${GO_TARBALL} error "Failed to extract Go ${version}" fi # Go解压后移动到当前目录 mv go/* . rm -rf go rm -f ${GO_TARBALL} # 验证安装 if [ ! -f "${go_path}/bin/go" ]; then error "Go ${version} upgrade failed" fi echo -e $HR echo "Upgrade successful" echo -e $HR