Sysup: support mt7621

This commit is contained in:
喵二
2024-08-26 23:36:50 +08:00
parent a40419ce6e
commit 78fb8fa11c
7 changed files with 101 additions and 31 deletions

View File

@@ -7,6 +7,7 @@ API_URL="https://api.miaoer.xyz/api/v2/snippets/catwrt/update"
BASE_URL="https://fastly.jsdelivr.net/gh/miaoermua/cattools@main/repo" BASE_URL="https://fastly.jsdelivr.net/gh/miaoermua/cattools@main/repo"
AMD64_EFI_SYSUP="https://raw.githubusercontent.com/miaoermua/cattools/main/sysupgrade/amd64/sysup_efi" AMD64_EFI_SYSUP="https://raw.githubusercontent.com/miaoermua/cattools/main/sysupgrade/amd64/sysup_efi"
AMD64_BIOS_SYSUP="https://raw.githubusercontent.com/miaoermua/cattools/main/sysupgrade/amd64/sysup_bios" AMD64_BIOS_SYSUP="https://raw.githubusercontent.com/miaoermua/cattools/main/sysupgrade/amd64/sysup_bios"
MT7621_SYSUP="https://raw.githubusercontent.com/miaoermua/cattools/main/sysupgrade/mt7621"
# Check ROOT & CatWrt/Lean's LEDE(QWRT) # Check ROOT & CatWrt/Lean's LEDE(QWRT)
if [ $(id -u) != "0" ]; then if [ $(id -u) != "0" ]; then
@@ -900,36 +901,68 @@ catnd() {
} }
# Sysupgrade # Sysupgrade
sysupgrade() { sysupgrade() {
if [ "$(uname -m)" != "x86_64" ]; then arch=$(cat /etc/catwrt_release | grep "^arch=" | cut -d'=' -f2)
echo "[Error] 仅有 x86_64 可以使用脚本进行系统升级。" board_name=$(cat /tmp/sysinfo/board_name)
if [ "$arch" != "mt7621" ] && [ "$arch" != "amd64" ]; then
echo "[Error] 不支持的架构: $arch"
exit 1 exit 1
fi fi
echo "" if [ "$arch" = "mt7621" ]; then
case "$board_name" in
disk_size=$(fdisk -l /dev/sda | grep "Disk /dev/sda:" | awk '{print $3}') *"newifi-d2")
tolerance=$(echo "200/1024/1024" | bc -l) base_fw_url="sysup_newifi-d2"
allowed_size=800.28 ;;
min_size=$(echo "$allowed_size - $tolerance" | bc -l) *"redmi-router-ac2100")
max_size=$(echo "$allowed_size + $tolerance" | bc -l) base_fw_url="sysup_redmi-router-ac2100"
;;
if (($(echo "$disk_size < $min_size" | bc -l))) || (($(echo "$disk_size > $max_size" | bc -l))); then *"mi-router-ac2100")
echo "[Error] 磁盘空间出现过修改或不匹配,无法继续升级。" base_fw_url="sysup_mi-router-ac2100"
exit 1 ;;
*)
echo "[Error] 该设备不支持通过此 Cattools 进行系统升级,请反馈给我们以支持!"
exit 1
;;
esac
fi fi
efi_mode=0
if [ -d /sys/firmware/efi ]; then if [ "$arch" = "amd64" ]; then
efi_mode=1 echo
disk_size=$(fdisk -l /dev/sda | grep "Disk /dev/sda:" | awk '{print $3}')
tolerance=$(echo "200/1024/1024" | bc -l)
allowed_size=800.28
min_size=$(echo "$allowed_size - $tolerance" | bc -l)
max_size=$(echo "$allowed_size + $tolerance" | bc -l)
if (($(echo "$disk_size < $min_size" | bc -l))) || (($(echo "$disk_size > $max_size" | bc -l))); then
echo "[Error] 磁盘空间出现过修改或不匹配,无法继续升级。"
exit 1
fi
efi_mode=0
if [ -d /sys/firmware/efi ]; then
efi_mode=1
fi
if [ -e /dev/sda128 ] || [ -e /dev/vda128 ] || [ -e /dev/nvme0n1p128 ] || [ $efi_mode -eq 1 ]; then
firmware_url=$AMD64_EFI_SYSUP
else
firmware_url=$AMD64_BIOS_SYSUP
fi
fi fi
if [ -e /dev/sda128 ] || [ -e /dev/vda128 ] || [ -e /dev/nvme0n1p128 ] || [ $efi_mode -eq 1 ]; then if [ "$arch" = "mt7621" ]; then
firmware_url=$AMD64_EFI_SYSUP firmware_url="$MT7621_SYSUP$base_fw_url"
else elif [ "$arch" = "amd64" ]; then
firmware_url=$AMD64_BIOS_SYSUP firmware_url=$firmware_url
fi fi
if [ -f /etc/catwrt_opkg_list_installed ]; then if [ -f /etc/catwrt_opkg_list_installed ]; then
rm /etc/catwrt_opkg_list_installed rm /etc/catwrt_opkg_list_installed
fi fi
@@ -955,18 +988,10 @@ sysupgrade() {
if [ -z "$confirm_upgrade" ] || [ "$confirm_upgrade" = "1" ]; then if [ -z "$confirm_upgrade" ] || [ "$confirm_upgrade" = "1" ]; then
read -t 5 -p "[INFO] 是否需要加速下载?按 ([1] 加速 5s 默认/[2] 跳过): " use_accel read -t 5 -p "[INFO] 是否需要加速下载?按 ([1] 加速 5s 默认/[2] 跳过): " use_accel
if [ -z "$use_accel" ] || [ "$use_accel" != "2" ]; then if [ -z "$use_accel" ] || [ "$use_accel" != "2" ]; then
if [ $efi_mode -eq 1 ]; then firmware_url="${firmware_url}_ghproxy"
curl https://mirror.ghproxy.com/https://raw.githubusercontent.com/miaoermua/cattools/main/sysupgrade/amd64/sysup_efi | bash
else
curl https://mirror.ghproxy.com/https://raw.githubusercontent.com/miaoermua/cattools/main/sysupgrade/amd64/sysup_bios | bash
fi
else
if [ $efi_mode -eq 1 ]; then
curl https://raw.githubusercontent.com/miaoermua/cattools/main/sysupgrade/amd64/sysup_efi | bash
else
curl https://raw.githubusercontent.com/miaoermua/cattools/main/sysupgrade/amd64/sysup_bios | bash
fi
fi fi
curl "$firmware_url" | bash
else else
echo "[INFO] 升级取消。" echo "[INFO] 升级取消。"
fi fi

View File

@@ -0,0 +1,7 @@
#!/bin/bash
## Dangerous! this operation does not allow normal users to bypass cattools!
MT7621_SYSUP="https://github.com/miaoermua/CatWrt/releases/download/v24.9.mt7621/CatWrt.v24.9.mt7621-xiaomi_mi-router-ac2100-squashfs-sysupgrade.bin"
sysupgrade -v $MT7621_SYSUP

View File

@@ -0,0 +1,8 @@
#!/bin/bash
## Dangerous! this operation does not allow normal users to bypass cattools!
MT7621_SYSUP="https://github.com/miaoermua/CatWrt/releases/download/v24.9.mt7621/CatWrt.v24.9.mt7621-xiaomi_mi-router-ac2100-squashfs-sysupgrade.bin"
GHPROXY="https://mirror.ghproxy.com/"
sysupgrade -v $GHPROXY$MT7621_SYSUP

View File

@@ -0,0 +1,7 @@
#!/bin/bash
## Dangerous! this operation does not allow normal users to bypass cattools!
MT7621_SYSUP="https://github.com/miaoermua/CatWrt/releases/download/v24.9.mt7621/CatWrt.v24.9.mt7621-d-team_newifi-d2-squashfs-sysupgrade.bin"
sysupgrade -v $MT7621_SYSUP

View File

@@ -0,0 +1,8 @@
#!/bin/bash
## Dangerous! this operation does not allow normal users to bypass cattools!
AMD64_EFI_SYSUP="https://github.com/miaoermua/CatWrt/releases/download/v24.9.mt7621/CatWrt.v24.9.mt7621-d-team_newifi-d2-squashfs-sysupgrade.bin"
GHPROXY="https://mirror.ghproxy.com/"
sysupgrade -v $GHPROXY$MT7621_SYSUP

View File

@@ -0,0 +1,7 @@
#!/bin/bash
## Dangerous! this operation does not allow normal users to bypass cattools!
MT7621_SYSUP="https://github.com/miaoermua/CatWrt/releases/download/v24.9.mt7621/CatWrt.v24.9.mt7621-xiaomi_redmi-router-ac2100-squashfs-sysupgrade.bin"
sysupgrade -v $MT7621_SYSUP

View File

@@ -0,0 +1,8 @@
#!/bin/bash
## Dangerous! this operation does not allow normal users to bypass cattools!
MT7621_SYSUP="https://github.com/miaoermua/CatWrt/releases/download/v24.9.mt7621/CatWrt.v24.9.mt7621-xiaomi_redmi-router-ac2100-squashfs-sysupgrade.bin"
GHPROXY="https://mirror.ghproxy.com/"
sysupgrade -v $GHPROXY$MT7621_SYSUP