From 09f5445fbc51153860e8ff515d93a6f14adb232c Mon Sep 17 00:00:00 2001 From: zhao Date: Wed, 26 Mar 2025 01:54:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20bin/=20ZeroWrt.backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhao --- bin/ ZeroWrt.backup | 140 ++++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/bin/ ZeroWrt.backup b/bin/ ZeroWrt.backup index 82c5fd4..026a9bb 100644 --- a/bin/ ZeroWrt.backup +++ b/bin/ ZeroWrt.backup @@ -905,62 +905,53 @@ istore_style() { show_menu } -# 10. 固件更新 +# 10. 固件更新 (精确匹配版) firmware_update() { color_output "\e[34m[固件更新]\e[0m" color_output "\e[33m警告:此操作将下载并更新固件,可能导致设备重启!\e[0m" - # 定义固件信息 - local repo_url="https://github.com/oppen321/ZeroWrt-Action/releases/tag/OpenWrt-Rockchip-24.10" - local api_url="https://api.github.com/repos/oppen321/ZeroWrt-Action/releases/latest" + # 使用镜像源解决国内访问问题 + local api_url="https://ghproxy.com/https://api.github.com/repos/oppen321/ZeroWrt-Action/releases/latest" + + # 设备检测 local current_model=$(cat /tmp/sysinfo/model 2>/dev/null || echo "unknown") local current_board=$(cat /tmp/sysinfo/board_name 2>/dev/null || echo "unknown") local current_firmware=$(cat /etc/openwrt_release | grep "DISTRIB_DESCRIPTION" | cut -d"'" -f2) - - # 支持的设备映射表 (显示名称 => 固件匹配模式) + + # 精确的固件匹配规则 (基于您的命名格式) declare -A supported_devices=( - ["nanopi-r2c"]="ZeroWrt-Super-*-friendlyarm_nanopi-r2c-squashfs-sysupgrade.img.gz" - ["nanopi-r2c-plus"]="ZeroWrt-Super-*-friendlyarm_nanopi-r2c-plus-squashfs-sysupgrade.img.gz" - ["nanopi-r2s"]="ZeroWrt-Super-*-friendlyarm_nanopi-r2s-squashfs-sysupgrade.img.gz" - ["nanopi-r3s"]="ZeroWrt-Super-*-friendlyarm_nanopi-r3s-squashfs-sysupgrade.img.gz" - ["nanopi-r4s"]="ZeroWrt-Super-*-friendlyarm_nanopi-r4s-squashfs-sysupgrade.img.gz" - ["nanopi-r4se"]="ZeroWrt-Super-*-friendlyarm_nanopi-r4se-squashfs-sysupgrade.img.gz" - ["nanopi-r5c"]="ZeroWrt-Super-*-friendlyarm_nanopi-r5c-squashfs-sysupgrade.img.gz" - ["nanopi-r5s"]="ZeroWrt-Super-*-friendlyarm_nanopi-r5s-squashfs-sysupgrade.img.gz" - ["nanopi-r6c"]="ZeroWrt-Super-*-friendlyarm_nanopi-r6c-squashfs-sysupgrade.img.gz" - ["nanopi-r6"]="ZeroWrt-Super-*-friendlyarm_nanopi-r6-squashfs-sysupgrade.img.gz" - ["fastrhino-r66s"]="ZeroWrt-Super-*-lunzn_fastrhino-r66s-squashfs-sysupgrade.img.gz" - ["fastrhino-r68s"]="ZeroWrt-Super-*-lunzn_fastrhino-r68s-squashfs-sysupgrade.img.gz" + ["nanopi-r2c"]="ZeroWrt-Super-[0-9]*-[0-9.]*-friendlyarm_nanopi-r2c-squashfs-sysupgrade.img.gz" + ["nanopi-r2c-plus"]="ZeroWrt-Super-[0-9]*-[0-9.]*-friendlyarm_nanopi-r2c-plus-squashfs-sysupgrade.img.gz" + ["nanopi-r2s"]="ZeroWrt-Super-[0-9]*-[0-9.]*-friendlyarm_nanopi-r2s-squashfs-sysupgrade.img.gz" + ["nanopi-r3s"]="ZeroWrt-Super-[0-9]*-[0-9.]*-friendlyarm_nanopi-r3s-squashfs-sysupgrade.img.gz" + ["nanopi-r4s"]="ZeroWrt-Super-[0-9]*-[0-9.]*-friendlyarm_nanopi-r4s-squashfs-sysupgrade.img.gz" + ["nanopi-r4se"]="ZeroWrt-Super-[0-9]*-[0-9.]*-friendlyarm_nanopi-r4se-squashfs-sysupgrade.img.gz" + ["nanopi-r5c"]="ZeroWrt-Super-[0-9]*-[0-9.]*-friendlyarm_nanopi-r5c-squashfs-sysupgrade.img.gz" + ["nanopi-r5s"]="ZeroWrt-Super-[0-9]*-[0-9.]*-friendlyarm_nanopi-r5s-squashfs-sysupgrade.img.gz" + ["nanopi-r6c"]="ZeroWrt-Super-[0-9]*-[0-9.]*-friendlyarm_nanopi-r6c-squashfs-sysupgrade.img.gz" + ["nanopi-r6"]="ZeroWrt-Super-[0-9]*-[0-9.]*-friendlyarm_nanopi-r6-squashfs-sysupgrade.img.gz" + ["fastrhino-r66s"]="ZeroWrt-Super-[0-9]*-[0-9.]*-lunzn_fastrhino-r66s-squashfs-sysupgrade.img.gz" + ["fastrhino-r68s"]="ZeroWrt-Super-[0-9]*-[0-9.]*-lunzn_fastrhino-r68s-squashfs-sysupgrade.img.gz" ) - color_output "\e[34m当前设备型号: $current_model\e[0m" - color_output "\e[34m当前主板名称: $current_board\e[0m" - color_output "\e[34m当前固件版本: $current_firmware\e[0m" + # 显示设备信息 + color_output "\e[36m设备信息:\e[0m" + color_output " 型号: $current_model" + color_output " 主板: $current_board" + color_output " 当前固件: $current_firmware" - # 检测设备类型 - local device_type="" - local device_name="" - - # 先尝试通过主板名称匹配 - for dev in "${!supported_devices[@]}"; do - if [[ $current_board == *"$dev"* ]]; then - device_type=$dev - device_name=$current_board - break - fi - done - - # 如果主板名称没匹配到,尝试通过型号匹配 - if [ -z "$device_type" ]; then + # 设备检测函数 + detect_device() { for dev in "${!supported_devices[@]}"; do - if [[ $current_model == *"$dev"* ]]; then - device_type=$dev - device_name=$current_model - break + if [[ $current_board == *"$dev"* ]] || [[ $current_model == *"$dev"* ]]; then + echo "$dev" + return fi done - fi + echo "" + } + local device_type=$(detect_device) if [ -z "$device_type" ]; then color_output "\e[31m错误:无法识别设备类型\e[0m" color_output "\e[33m支持的设备类型:\e[0m" @@ -973,31 +964,34 @@ firmware_update() { fi color_output "\e[32m检测到设备类型: $device_type\e[0m" - color_output "\e[32m设备识别名称: $device_name\e[0m" - # 获取最新固件信息 - color_output "\e[33m正在从GitHub获取最新固件信息...\e[0m" - local release_info=$(curl -s "$api_url") + # 获取固件信息 + color_output "\e[33m正在获取固件信息...\e[0m" + local release_info=$(curl -s "$api_url" || { + color_output "\e[31m无法获取发布信息,尝试备用镜像...\e[0m" + curl -s "https://fastgit.xyz/https://api.github.com/repos/oppen321/ZeroWrt-Action/releases/latest" + }) + local latest_date=$(echo "$release_info" | grep "created_at" | head -1 | cut -d'"' -f4 | cut -d'T' -f1 | sed 's/-//g') local assets=$(echo "$release_info" | grep -E "browser_download_url|name" | awk -F'"' '{print $4}') - - # 查找匹配的固件 - local latest_url="" + + # 精确匹配固件文件 local pattern=${supported_devices[$device_type]} - local search_pattern=$(echo "$pattern" | sed 's/\*/.*/g') # 将*替换为.*用于grep - + local latest_url="" while read -r line; do - if [[ $line == *"download"* ]]; then - if [[ $line =~ $search_pattern ]]; then - latest_url=$line - break - fi + if [[ $line == *"download"* ]] && [[ $line =~ $pattern ]]; then + latest_url=$line + break fi done <<< "$assets" if [ -z "$latest_url" ]; then color_output "\e[31m错误:找不到匹配的固件文件\e[0m" color_output "\e[33m搜索模式: $pattern\e[0m" + color_output "\e[33m可用的下载文件:\e[0m" + echo "$assets" | grep "download" | sed 's/.*\///' | while read -r line; do + color_output " - $line" + done read -p "按 Enter 键返回菜单..." show_menu return @@ -1006,9 +1000,10 @@ firmware_update() { # 提取当前固件日期 local current_date=$(echo "$current_firmware" | grep -oE "202[0-9]{5}" || echo "0") + # 显示更新信息 color_output "\e[36m最新固件发布日期: ${latest_date:0:4}-${latest_date:4:2}-${latest_date:6:2}\e[0m" color_output "\e[36m当前固件发布日期: ${current_date:0:4}-${current_date:4:2}-${current_date:6:2}\e[0m" - color_output "\e[33m匹配到的固件URL: $latest_url\e[0m" + color_output "\e[33m下载文件: $(basename "$latest_url")\e[0m" if [ "$latest_date" -gt "$current_date" ]; then color_output "\e[32m发现新版本固件!\e[0m" @@ -1021,33 +1016,38 @@ firmware_update() { return fi - # 下载固件 + # 使用镜像源下载 color_output "\e[33m正在下载固件...\e[0m" - wget --show-progress -O /tmp/firmware.bin "$latest_url" - if [[ $? -ne 0 ]]; then - color_output "\e[31m固件下载失败\e[0m" - read -p "按 Enter 键返回菜单..." - show_menu - return + local mirror_url="https://ghproxy.com/$latest_url" + if ! wget --show-progress -O /tmp/firmware.bin "$mirror_url"; then + color_output "\e[31m镜像下载失败,尝试原始链接...\e[0m" + if ! wget --show-progress -O /tmp/firmware.bin "$latest_url"; then + color_output "\e[31m固件下载失败!\e[0m" + read -p "按 Enter 键返回菜单..." + show_menu + return + fi fi # 验证固件 color_output "\e[33m正在验证固件...\e[0m" if ! sysupgrade -v /tmp/firmware.bin; then - color_output "\e[31m固件验证失败,可能不兼容当前设备\e[0m" + color_output "\e[31m固件验证失败!\e[0m" + color_output "\e[33m可能原因:\e[0m" + color_output " 1. 文件下载不完整" + color_output " 2. 设备不兼容" + color_output " 3. 固件签名验证失败" rm -f /tmp/firmware.bin read -p "按 Enter 键返回菜单..." show_menu return fi - color_output "\e[31m警告:即将刷写新固件,此操作不可逆!\e[0m" - color_output "\e[31m请确保已备份重要配置!\e[0m" - read -p "确定要继续刷写固件吗?(y/n): " flash_confirm + color_output "\e[31m警告:此操作不可逆!\e[0m" + read -p "确认要刷写固件吗?(y/n): " flash_confirm if [[ "$flash_confirm" == "y" || "$flash_confirm" == "Y" ]]; then color_output "\e[33m开始刷写固件,设备将自动重启...\e[0m" - color_output "\e[33m更新过程可能需要几分钟,请勿断电!\e[0m" - sleep 5 + sleep 3 sysupgrade -n /tmp/firmware.bin else color_output "\e[32m操作已取消\e[0m" @@ -1055,7 +1055,7 @@ firmware_update() { fi else color_output "\e[32m当前已是最新固件\e[0m" - color_output "\e[33m如需强制更新,请手动下载固件\e[0m" + color_output "\e[33m当前版本: ${current_date:0:4}-${current_date:4:2}-${current_date:6:2}\e[0m" fi read -p "按 Enter 键返回菜单..."