#!/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} node_path="${setup_path}/server/nodejs/${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 "${node_path}/bin/node" ]; then error "Node.js ${slug} is not installed" fi # 架构映射 case ${ARCH} in x86_64) NODE_ARCH="x64" ;; aarch64) NODE_ARCH="arm64" ;; esac # 下载Node.js安装包 NODE_TARBALL="node-v${version}-linux-${NODE_ARCH}.tar.xz" if ${in_china}; then NODE_URL="https://mirrors.cloud.tencent.com/nodejs-release/v${version}/${NODE_TARBALL}" echo "Downloading ${NODE_TARBALL} from Tencent mirror..." else NODE_URL="https://nodejs.org/dist/v${version}/${NODE_TARBALL}" echo "Downloading ${NODE_TARBALL} from nodejs.org..." fi cd ${node_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 ${NODE_TARBALL} \ ${NODE_URL} if [ $? -ne 0 ]; then rm -f ${NODE_TARBALL} error "Failed to download Node.js ${version}" fi # 删除旧文件 find ${node_path} -mindepth 1 ! -name "${NODE_TARBALL}" -exec rm -rf {} + 2>/dev/null # 解压 tar -xJf ${NODE_TARBALL} if [ $? -ne 0 ]; then rm -f ${NODE_TARBALL} error "Failed to extract Node.js ${version}" fi # Node.js解压后移动到当前目录 mv node-v${version}-linux-${NODE_ARCH}/* . rm -rf node-v${version}-linux-${NODE_ARCH} rm -f ${NODE_TARBALL} # 验证安装 if [ ! -f "${node_path}/bin/node" ]; then error "Node.js ${version} upgrade failed" fi echo -e $HR echo "Upgrade successful" echo -e $HR