diff --git a/bin/ ZeroWrt.backup b/bin/ ZeroWrt.backup index eab10d4..cac1169 100644 --- a/bin/ ZeroWrt.backup +++ b/bin/ ZeroWrt.backup @@ -48,8 +48,9 @@ show_menu() { color_output "\e[36m┃\e[0m 6. 一键设置 \e[36m┃\e[0m" color_output "\e[36m┃\e[0m 7. 一键部署 \e[36m┃\e[0m" color_output "\e[36m┃\e[0m 8. IPv6 开关 (仅适用于主路由) \e[36m┃\e[0m" - color_output "\e[36m┃\e[0m 9. iStoreOS 风格化 \e[36m┃\e[0m" - color_output "\e[36m┃\e[0m 10. 检测更新 \e[36m┃\e[0m" + color_output "\e[36m┃\e[0m 9. iStoreOS 风格化 \e[36m┃\e[0m" + color_output "\e[36m┃\e[0m 10. 固件更新 \e[36m┃\e[0m" + color_output "\e[36m┃\e[0m 11. 检测更新 \e[36m┃\e[0m" color_output "\e[36m┃\e[0m 0. 退出 \e[36m┃\e[0m" color_output "\e[36m┃ ┃\e[0m" color_output "\e[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\e[0m" @@ -64,7 +65,8 @@ show_menu() { 7) install_apps ;; 8) configure_ipv6 ;; 9) istore_style ;; - 10) check_update ;; + 10) firmware_update ;; + 11) check_update ;; 0) exit 0 ;; *) echo "无效选项,请重新输入"; show_menu ;; esac @@ -903,7 +905,120 @@ 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 current_model=$(cat /tmp/sysinfo/model 2>/dev/null || echo "unknown") + local current_firmware=$(cat /etc/openwrt_release | grep "DISTRIB_DESCRIPTION" | cut -d"'" -f2) + + # 支持的设备列表 + declare -A supported_devices=( + ["friendlyarm_nanopi-r2c-plus"]="ZeroWrt-Super-*-friendlyarm_nanopi-r2c-plus-squashfs-sysupgrade.img.gz" + ["x86_64"]="ZeroWrt-Super-*-x86-64-generic-squashfs-combined-efi.img.gz" + ["rockchip_rk3328"]="ZeroWrt-Super-*-rockchip_rk3328-squashfs-sysupgrade.img.gz" + ) + + color_output "\e[34m当前设备: $current_model\e[0m" + color_output "\e[34m当前固件: $current_firmware\e[0m" + + # 检测设备类型 + local device_type="" + for dev in "${!supported_devices[@]}"; do + if [[ $current_model == *"$dev"* ]]; then + device_type=$dev + break + fi + done + + if [ -z "$device_type" ]; then + color_output "\e[31m错误:当前设备不受支持\e[0m" + color_output "\e[33m支持的设备类型:\e[0m" + for dev in "${!supported_devices[@]}"; do + color_output "- $dev" + done + read -p "按 Enter 键返回菜单..." + show_menu + return + fi + + color_output "\e[32m检测到设备类型: $device_type\e[0m" + + # 获取最新固件信息 + color_output "\e[33m正在检查固件更新...\e[0m" + local latest_info=$(curl -s "$api_url" | grep -E "browser_download_url|created_at" | head -2) + local latest_url=$(echo "$latest_info" | grep "browser_download_url" | grep "$device_type" | cut -d'"' -f4) + local latest_date=$(echo "$latest_info" | grep "created_at" | cut -d'"' -f4 | cut -d'T' -f1 | sed 's/-//g') + + if [ -z "$latest_url" ]; then + color_output "\e[31m无法获取最新固件信息\e[0m" + read -p "按 Enter 键返回菜单..." + show_menu + return + fi + + # 提取当前固件日期 + 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" + + if [ "$latest_date" -gt "$current_date" ]; then + color_output "\e[32m发现新版本固件!\e[0m" + color_output "\e[33m下载URL: $latest_url\e[0m" + + read -p "是否下载并更新固件?(y/n): " confirm + if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then + color_output "\e[32m操作已取消\e[0m" + read -p "按 Enter 键返回菜单..." + show_menu + return + fi + + # 下载固件 + color_output "\e[33m正在下载固件...\e[0m" + wget -O /tmp/firmware.bin "$latest_url" + if [[ $? -ne 0 ]]; then + color_output "\e[31m固件下载失败\e[0m" + read -p "按 Enter 键返回菜单..." + show_menu + return + fi + + # 验证固件 + color_output "\e[33m正在验证固件...\e[0m" + if ! sysupgrade -v /tmp/firmware.bin; then + color_output "\e[31m固件验证失败,可能不兼容当前设备\e[0m" + 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 + if [[ "$flash_confirm" == "y" || "$flash_confirm" == "Y" ]]; then + color_output "\e[33m开始刷写固件,设备将自动重启...\e[0m" + sleep 3 + sysupgrade -n /tmp/firmware.bin + else + color_output "\e[32m操作已取消\e[0m" + rm -f /tmp/firmware.bin + fi + else + color_output "\e[32m当前已是最新固件\e[0m" + fi + + read -p "按 Enter 键返回菜单..." + show_menu +} + +# 11. 检测更新 check_update() { color_output "\e[34m[检测更新]\e[0m" color_output "正在检查更新..."