Update flash_catwrt.sh

This commit is contained in:
喵二
2024-09-29 20:35:33 +08:00
committed by GitHub
parent bc283fdd9a
commit 70c0fb50ac

View File

@@ -11,9 +11,9 @@ disk_count=$(echo "$disks" | wc -l)
if [ "$disk_count" -eq 1 ]; then if [ "$disk_count" -eq 1 ]; then
target_disk=$(echo "$disks" | awk '{print $1}') target_disk=$(echo "$disks" | awk '{print $1}')
echo "检测到一个磁盘:/dev/$target_disk" echo "[INFO] 检测到一个磁盘:/dev/$target_disk"
else else
echo "检测到多个磁盘,请选择目标磁盘:" echo "[INFO] 检测到多个磁盘,请选择目标磁盘:"
index=1 index=1
@@ -22,28 +22,29 @@ else
index=$((index + 1)) index=$((index + 1))
done done
read -p "请输入目标磁盘的数字编号: " disk_choice read -p "[INFO] 请输入目标磁盘的数字编号: " disk_choice
if ! echo "$disk_choice" | grep -qE '^[0-9]+$'; then if ! echo "$disk_choice" | grep -qE '^[0-9]+$'; then
echo "无效输入,必须为数字" echo "[ERROR] 无效输入,必须为数字"
exit 1 exit 1
fi fi
target_disk=$(echo "$disks" | sed -n "${disk_choice}p" | awk '{print $1}') target_disk=$(echo "$disks" | sed -n "${disk_choice}p" | awk '{print $1}')
if [ -z "$target_disk" ]; then if [ -z "$target_disk" ]; then
echo "无效的选择" echo "[ERROR] 无效的选择"
exit 1 exit 1
fi fi
echo "你选择的目标磁盘是:/dev/$target_disk" echo
echo "[INFO] 你选择的目标磁盘是:/dev/$target_disk"
fi fi
# 是否使用 ghproxy 加速 # 是否使用 ghproxy 加速
read -p "是否使用 ghproxy 加速下载固件? (y/n): " use_ghproxy read -p "[INFO] 是否使用 ghproxy 加速下载固件? (y/n): " use_ghproxy
if [ "$use_ghproxy" = "y" ] || [ "$use_ghproxy" = "Y" ]; then if [ "$use_ghproxy" = "y" ] || [ "$use_ghproxy" = "Y" ]; then
echo "将使用 ghproxy 进行下载加速" echo "[INFO] 将使用 ghproxy 进行下载加速"
GH_PROXY_PREFIX="https://mirror.ghproxy.com/" GH_PROXY_PREFIX="https://mirror.ghproxy.com/"
else else
echo "不使用 ghproxy 加速" echo "[INFO] 不使用 ghproxy 加速"
GH_PROXY_PREFIX="" GH_PROXY_PREFIX=""
fi fi
@@ -51,6 +52,7 @@ fi
efi_mode=0 efi_mode=0
if [ -d /sys/firmware/efi ]; then if [ -d /sys/firmware/efi ]; then
efi_mode=1 efi_mode=1
echo "[INFO] 你的固件支持 efi"
fi fi
# 添加 ghproxy # 添加 ghproxy
@@ -63,20 +65,20 @@ firmware_url=$([ "$efi_mode" -eq 1 ] && echo "$AMD64_EFI_SYSUP" || echo "$AMD64_
firmware_file="/tmp/catwrt_sysupgrade.img.gz" firmware_file="/tmp/catwrt_sysupgrade.img.gz"
wget --timeout=30 --tries=3 -O "$firmware_file" "$firmware_url" wget --timeout=30 --tries=3 -O "$firmware_file" "$firmware_url"
if [ $? -ne 0 ] || [ ! -f "$firmware_file" ]; then if [ $? -ne 0 ] || [ ! -f "$firmware_file" ]; then
echo "固件下载失败" echo "[ERROR] 固件下载失败"
exit 1 exit 1
fi fi
echo "固件已下载到 $firmware_file。即将使用 dd 命令覆写 /dev/$target_disk。" echo "[INFO] 固件已下载到 $firmware_file 即将使用 dd 命令覆写 /dev/$target_disk"
echo "此操作将永久删除所有数据,无法恢复。按回车键继续,或按 Ctrl+C 取消操作" echo "[INFO] 此操作将永久删除所有数据,无法恢复。按 [ENTER] 回车键继续,或按 [Ctrl]+[C] 终止操作"
read -r read -r
# 写入固件 # 写入固件
dd if="$firmware_file" of="/dev/$target_disk" bs=4M status=progress dd if="$firmware_file" of="/dev/$target_disk" bs=4096k status=progress
echo "固件更新完成。重启后使用 cattools 配置 CatWrt。"
echo "固件更新完成" echo "固件覆写成功,重启后使用 cattools 配置 CatWrt。"
echo "" echo ""
echo "重启后可使用 cattools 命令配置 CatWrt,或者自行配置" echo "重启后可使用 cattools 命令配置 CatWrt,或者自行配置"
echo "IP: 192.168.1.4" echo "IP: 192.168.1.4"