diff --git a/Nlbench_beta.sh b/Nlbench_beta.sh index 893ec20..3094d94 100644 --- a/Nlbench_beta.sh +++ b/Nlbench_beta.sh @@ -22,28 +22,33 @@ VERSION_URL="https://raw.githubusercontent.com/everett7623/nodeloc_vps_test/main # 更新脚本 update_scripts() { - REMOTE_VERSION=$(curl -s $VERSION_URL) + REMOTE_VERSION=$(curl -s $VERSION_URL | grep -oP '(?<=#\s)[\d-]+\sv[\d.]+(?=\s-)') if [ -z "$REMOTE_VERSION" ]; then echo -e "${RED}无法获取远程版本信息。请检查您的网络连接。${NC}" return 1 fi + if [ "$REMOTE_VERSION" != "$CURRENT_VERSION" ]; then echo -e "${BLUE}发现新版本 $REMOTE_VERSION,当前版本 $CURRENT_VERSION${NC}" echo -e "${BLUE}正在更新...${NC}" if curl -s -o /tmp/Nlbench.sh $SCRIPT_URL; then NEW_VERSION=$(grep '^CURRENT_VERSION=' /tmp/Nlbench.sh | cut -d'"' -f2) - sed -i "s/^CURRENT_VERSION=.*/CURRENT_VERSION=\"$NEW_VERSION\"/" "$0" - - if mv /tmp/Nlbench.sh "$0"; then - chmod +x "$0" - echo -e "${GREEN}脚本更新成功!新版本: $NEW_VERSION${NC}" - echo -e "${YELLOW}正在重新启动脚本以应用更新...${NC}" - sleep 3 - exec bash "$0" + if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then + sed -i "s/^CURRENT_VERSION=.*/CURRENT_VERSION=\"$NEW_VERSION\"/" "$0" + + if mv /tmp/Nlbench.sh "$0"; then + chmod +x "$0" + echo -e "${GREEN}脚本更新成功!新版本: $NEW_VERSION${NC}" + echo -e "${YELLOW}正在重新启动脚本以应用更新...${NC}" + sleep 3 + exec bash "$0" + else + echo -e "${RED}无法替换脚本文件。请检查权限。${NC}" + return 1 + fi else - echo -e "${RED}无法替换脚本文件。请检查权限。${NC}" - return 1 + echo -e "${GREEN}脚本已是最新版本。${NC}" fi else echo -e "${RED}下载新版本失败。请稍后重试。${NC}"