更新 bin/ ZeroWrt.backup
Signed-off-by: zhao <zhao@noreply.localhost>
This commit is contained in:
parent
cf03e1d37e
commit
f06ef10e56
@ -914,29 +914,55 @@ firmware_update() {
|
||||
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_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=(
|
||||
["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"
|
||||
["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"
|
||||
)
|
||||
|
||||
color_output "\e[34m当前设备: $current_model\e[0m"
|
||||
color_output "\e[34m当前固件: $current_firmware\e[0m"
|
||||
color_output "\e[34m当前设备型号: $current_model\e[0m"
|
||||
color_output "\e[34m当前主板名称: $current_board\e[0m"
|
||||
color_output "\e[34m当前固件版本: $current_firmware\e[0m"
|
||||
|
||||
# 检测设备类型
|
||||
local device_type=""
|
||||
local device_name=""
|
||||
|
||||
# 先尝试通过主板名称匹配
|
||||
for dev in "${!supported_devices[@]}"; do
|
||||
if [[ $current_model == *"$dev"* ]]; then
|
||||
if [[ $current_board == *"$dev"* ]]; then
|
||||
device_type=$dev
|
||||
device_name=$current_board
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# 如果主板名称没匹配到,尝试通过型号匹配
|
||||
if [ -z "$device_type" ]; then
|
||||
for dev in "${!supported_devices[@]}"; do
|
||||
if [[ $current_model == *"$dev"* ]]; then
|
||||
device_type=$dev
|
||||
device_name=$current_model
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$device_type" ]; then
|
||||
color_output "\e[31m错误:当前设备不受支持\e[0m"
|
||||
color_output "\e[31m错误:无法识别设备类型\e[0m"
|
||||
color_output "\e[33m支持的设备类型:\e[0m"
|
||||
for dev in "${!supported_devices[@]}"; do
|
||||
color_output "- $dev"
|
||||
@ -947,15 +973,31 @@ firmware_update() {
|
||||
fi
|
||||
|
||||
color_output "\e[32m检测到设备类型: $device_type\e[0m"
|
||||
color_output "\e[32m设备识别名称: $device_name\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')
|
||||
color_output "\e[33m正在从GitHub获取最新固件信息...\e[0m"
|
||||
local release_info=$(curl -s "$api_url")
|
||||
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
|
||||
|
||||
while read -r line; do
|
||||
if [[ $line == *"download"* ]]; then
|
||||
if [[ $line =~ $search_pattern ]]; then
|
||||
latest_url=$line
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done <<< "$assets"
|
||||
|
||||
if [ -z "$latest_url" ]; then
|
||||
color_output "\e[31m无法获取最新固件信息\e[0m"
|
||||
color_output "\e[31m错误:找不到匹配的固件文件\e[0m"
|
||||
color_output "\e[33m搜索模式: $pattern\e[0m"
|
||||
read -p "按 Enter 键返回菜单..."
|
||||
show_menu
|
||||
return
|
||||
@ -966,10 +1008,10 @@ firmware_update() {
|
||||
|
||||
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"
|
||||
|
||||
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
|
||||
@ -981,7 +1023,7 @@ firmware_update() {
|
||||
|
||||
# 下载固件
|
||||
color_output "\e[33m正在下载固件...\e[0m"
|
||||
wget -O /tmp/firmware.bin "$latest_url"
|
||||
wget --show-progress -O /tmp/firmware.bin "$latest_url"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
color_output "\e[31m固件下载失败\e[0m"
|
||||
read -p "按 Enter 键返回菜单..."
|
||||
@ -1004,7 +1046,8 @@ firmware_update() {
|
||||
read -p "确定要继续刷写固件吗?(y/n): " flash_confirm
|
||||
if [[ "$flash_confirm" == "y" || "$flash_confirm" == "Y" ]]; then
|
||||
color_output "\e[33m开始刷写固件,设备将自动重启...\e[0m"
|
||||
sleep 3
|
||||
color_output "\e[33m更新过程可能需要几分钟,请勿断电!\e[0m"
|
||||
sleep 5
|
||||
sysupgrade -n /tmp/firmware.bin
|
||||
else
|
||||
color_output "\e[32m操作已取消\e[0m"
|
||||
@ -1012,6 +1055,7 @@ firmware_update() {
|
||||
fi
|
||||
else
|
||||
color_output "\e[32m当前已是最新固件\e[0m"
|
||||
color_output "\e[33m如需强制更新,请手动下载固件\e[0m"
|
||||
fi
|
||||
|
||||
read -p "按 Enter 键返回菜单..."
|
||||
|
Loading…
Reference in New Issue
Block a user