Merge pull request #11 from miaoermua/compatible

Update Compatible More old versions
This commit is contained in:
喵二
2024-07-17 20:38:07 +08:00
committed by GitHub

View File

@@ -4,6 +4,7 @@ DEFAULT_IP="192.168.1.4"
RELEASE="/etc/catwrt_release" RELEASE="/etc/catwrt_release"
BACKUP_FILE="/etc/catwrt_opkg_list_installed" BACKUP_FILE="/etc/catwrt_opkg_list_installed"
API_URL="https://api.miaoer.xyz/api/v2/snippets/catwrt/update" API_URL="https://api.miaoer.xyz/api/v2/snippets/catwrt/update"
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"
@@ -61,16 +62,16 @@ menu() {
echo " CatTools " echo " CatTools "
echo " https://github.com/miaoermua/cattools " echo " https://github.com/miaoermua/cattools "
echo "----------------------------------------------------------" echo "----------------------------------------------------------"
echo "1. SetIP - 设置 IP" echo "1. SetIP - 设置 IP"
echo "2. network_wizard - 网络向导" echo "2. Network_Wizard - 网络向导"
echo "3. Debug - 抓取日志" echo "3. Apply_repo - 软件源配置"
echo "4. catwrt_update - 检查更新" echo "4. Diagnostics - 网络诊断"
echo "5. apply_repo - 软件源配置" echo "5. Debug - 抓取日志"
echo "6. diagnostics - 网络诊断" echo "6. Catwrt_update - 检查更新"
echo "7. sysupgrade - 系统更新" echo "7. Sysupgrade - 系统更新"
echo "8. restore - 恢复软件包" echo "8. Restore - 恢复软件包"
echo "9. enhancement - 实用增强" echo "9. Utilities(more) - 实用工具"
echo "0. Exit - 退出" echo "0. Exit - 退出"
echo "----------------------------------------------------------" echo "----------------------------------------------------------"
echo -n "请输入数字并回车(Please enter your choice): " echo -n "请输入数字并回车(Please enter your choice): "
} }
@@ -473,23 +474,25 @@ debug() {
} }
# catwrt_update # catwrt_update
catwrt_update() { catwrt_update() {
remote_error() { remote_error() {
echo "Remote $1 get failed for arch: $arch_self, please check your network!" echo "Remote $1 get failed for arch: $arch_local, please check your network!"
exit 1 exit 1
} }
local_error() { local_error() {
echo "Local $1 get failed, please check your /etc/catwrt-release!" echo "Local $1 get failed, please check your /etc/catwrt_release!"
exit 1 exit 1
} }
get_remote_hash() { get_remote_info() {
arch_self=$1 local arch_version_json=$(curl -s "$API_URL" | jq -r ".[\"$version_local\"].$arch_local")
version_remote=$(curl -s "$API_URL" | jq -r ".$arch_self.version") version_remote=$(echo "$arch_version_json" | jq -r '.version')
hash_remote=$(curl -s "$API_URL" | jq -r ".$arch_self.hash") hash_remote=$(echo "$arch_version_json" | jq -r '.hash')
channel_remote=$(curl -s "$API_URL" | jq -r ".$arch_self.channel") releases_remote=$(echo "$arch_version_json" | jq -r '.releases')
blogs_remote=$(echo "$API_URL" | jq -r ".${arch}.blogs") blog_remote=$(echo "$arch_version_json" | jq -r '.blogs')
channel_remote=$(echo "$arch_version_json" | jq -r '.channel')
if [ $? -ne 0 ] || [ -z "$version_remote" ] || [ -z "$hash_remote" ]; then if [ $? -ne 0 ] || [ -z "$version_remote" ] || [ -z "$hash_remote" ]; then
remote_error "version or hash" remote_error "version or hash"
@@ -510,144 +513,82 @@ catwrt_update() {
contrast_version() { contrast_version() {
if [ "$version_remote" == "$version_local" ] && [ "$hash_remote" == "$hash_local" ]; then if [ "$version_remote" == "$version_local" ] && [ "$hash_remote" == "$hash_local" ]; then
echo "=======================================================" echo "======================================================="
echo "Your CatWrt is latest version! Also, you are using $channel_remote channel." echo " Your CatWrt is $releases_remote"
echo "=======================================================" echo "======================================================="
else else
echo "=======================================================" if [ "$channel_remote" == "Stable" ] || ( [ "$channel_remote" == "Beta" ] && [ "$channel_local" == "Beta" ] ); then
echo "Your CatWrt is outdated; you should upgrade it to the latest version!" echo "======================================================="
echo "Visit '$blogs_remote' for more information." echo "Your CatWrt is $releases_remote, you should upgrade it!"
echo "=======================================================" echo "Visit the blog for more information"
echo "$blog_remote"
echo "======================================================="
else
echo "======================================================="
echo " Your CatWrt is up to date!"
echo "======================================================="
fi
fi fi
} }
print_version() { print_version() {
echo "Remote Hash : $hash_remote" echo "Local Version : $version_local"
echo "Remote Version : $version_remote" echo "Remote Version : $releases_remote"
echo "Remote Current Channel : $channel_remote" echo "Local Hash : $hash_local"
echo "Local Version : $version_local" echo "Remote Hash : $hash_remote"
echo "Local Hash : $hash_local" echo "Channel : $channel_remote"
echo "=======================================================" echo "======================================================="
echo "" echo ""
} }
main() { main() {
init init
get_remote_hash "$arch_local" get_remote_info
contrast_version contrast_version
print_version print_version
} }
main main
} }
# Repo # Apply_repo
apply_repo() { apply_repo() {
if [ -f /etc/catwrt_release ]; then arch=$(grep -o 'arch=[^ ]*' $RELEASE | cut -d= -f2)
source /etc/catwrt_release version=$(grep -o 'version=[^ ]*' $RELEASE | cut -d= -f2)
else
# If the `/etc/catwrt_release` file does not exist, the `/etc/openwrt_release` file is read.
if [ -f /etc/openwrt_release ]; then
openwrt_version=$(grep DISTRIB_RELEASE /etc/openwrt_release | cut -d"'" -f2)
arch=$(grep DISTRIB_TARGET /etc/openwrt_release | cut -d"/" -f1)
case "$arch" in
x86_64)
if grep -q "R22.11.11" /etc/openwrt_release; then
version="v22.12"
elif grep -q "R23.2" /etc/openwrt_release; then
version="v23.2"
else
echo "Unknown arch x86_64 /// 未知的 x86_64 版本"
exit 1
fi
;;
aarch64_generic)
if grep -q "R22.12.1" /etc/openwrt_release; then
version="v22.12"
arch="rkarm"
else
echo "Unknown arch aarch64_generic ///未知的 aarch64_generic 版本"
exit 1
fi
;;
mt7621)
if grep -q "R22.12.1" /etc/openwrt_release; then
version="v22.12"
arch="mt7621"
else
echo "Unknown arch mt7621 ///未知的 mt7621 版本"
exit 1
fi
;;
*)
echo "Unknown arch $arch /// 未知的架构: $arch"
exit 1
;;
esac
else
echo "$(/etc/catwrt_release) or $(/etc/openwrt_release) Files do not exist /// 文件不存在或者系统损坏!"
exit 1
fi
fi
BASE_URL="https://fastly.jsdelivr.net/gh/miaoermua/cattools@main/repo" case "$arch" in
amd64)
select_repo() { case "$version" in
case "$arch" in v22.12) REPO_URL="$BASE_URL/history/v22.12/amd64" ;;
amd64) v23.2) REPO_URL="$BASE_URL/history/v23.2/amd64" ;;
v23.8) REPO_URL="$BASE_URL/amd64" ;;
if [ "$version" == "v22.12" ]; then v24.3) REPO_URL="$BASE_URL/pr/v24.3/amd64" ;;
REPO_URL="$BASE_URL/history/v22.12/amd64" v24.8) REPO_URL="$BASE_URL/pr/v24.3/amd64" ;;
elif [ "$version" == "v23.2" ]; then *) echo "Unknown version" && exit 1 ;;
REPO_URL="$BASE_URL/history/v23.2/amd64"
elif [ "$version" == "v23.8" ]; then
REPO_URL="$BASE_URL/amd64"
elif [ "$version" == "v24.3" ]; then
REPO_URL="$BASE_URL/pr/v24.3/amd64"
elif [ "$version" == "v24.8" ]; then
REPO_URL="$BASE_URL/pr/v24.3/amd64"
else
echo "Unknown arch $arch /// 未知的架构: $arch"
exit 1
fi
;;
mt798x)
if [ "$version" == "v22.12" ]; then
REPO_URL="$BASE_URL/history/v22.12/aarch64_cortex-a53"
elif [ "$version" == "v23.2" ]; then
REPO_URL="$BASE_URL/history/v23.2/mt7986a"
elif [ "$version" == "v23.8" ]; then
REPO_URL="$BASE_URL/mt798x"
elif [ "$version" == "v24.3" ]; then
REPO_URL="$BASE_URL/pr/v24.3/mt798x"
else
echo "Unknown arch mt798x /// 未知的 mt798x 版本"
exit 1
fi
;;
rkarm)
if [ "$version" == "v22.12" ]; then
REPO_URL="$BASE_URL/rkarm"
elif [ "$version" == "v24.1" ]; then
REPO_URL="$BASE_URL/pr/v24.1/rkarm"
else
echo "Unknown arch rkarm /// 未知的 rkarm 版本"
exit 1
fi
;;
mt7621)
if [ "$version" == "v22.12" ]; then
REPO_URL="$BASE_URL/mt7621"
else
echo "Unknown arch mt7621 /// 未知的 mt7621 版本"
exit 1
fi
;;
*)
echo "Unknown arch $arch /// 未知的架构: $arch"
exit 1
;;
esac esac
} ;;
mt798x)
case "$version" in
v22.12) REPO_URL="$BASE_URL/history/v22.12/aarch64_cortex-a53" ;;
v23.2) REPO_URL="$BASE_URL/history/v23.2/mt7986a" ;;
v23.8) REPO_URL="$BASE_URL/mt798x" ;;
v24.3) REPO_URL="$BASE_URL/pr/v24.3/mt798x" ;;
*) echo "Unknown version" && exit 1 ;;
esac
;;
rkarm)
case "$version" in
v22.12) REPO_URL="$BASE_URL/rkarm" ;;
v24.1) REPO_URL="$BASE_URL/pr/v24.1/rkarm" ;;
*) echo "Unknown version" && exit 1 ;;
esac
;;
mt7621)
case "$version" in
v22.12) REPO_URL="$BASE_URL/mt7621" ;;
*) echo "Unknown version" && exit 1 ;;
esac
;;
*) echo "Unknown arch" && exit 1 ;;
esac
echo "" echo ""
echo "Warning:" echo "Warning:"
@@ -657,10 +598,7 @@ apply_repo() {
echo "你需要同意 CatWrt 软件源用户协议,请确认是否继续 (10 秒内按 [Ctrl]+[C] 取消操作)" echo "你需要同意 CatWrt 软件源用户协议,请确认是否继续 (10 秒内按 [Ctrl]+[C] 取消操作)"
echo "==============================================================================" echo "=============================================================================="
select_repo if { { [ "$arch" == "amd64" ] || [ "$arch" == "mt798x" ]; } && [ "$version" == "v24.3" ]; } || { [ "$arch" == "rkarm" ] && [ "$version" == "v24.1" ]; }; then
if { [ "$version" == "v24.3" ] && { [ "$arch" == "amd64" ] || [ "$arch" == "mt798x" ]; } } ||
{ [ "$version" == "v24.1" ] && [ "$arch" == "rkarm" ]; }; then
echo "你目前使用的 BETA 版本,只能临时镜像站的软件源,请注意关注 CatWrt 的更新情况!" echo "你目前使用的 BETA 版本,只能临时镜像站的软件源,请注意关注 CatWrt 的更新情况!"
echo "请选择要使用的软件源:" echo "请选择要使用的软件源:"
echo "1) netlify" echo "1) netlify"
@@ -670,9 +608,9 @@ apply_repo() {
choice=${choice:-2} choice=${choice:-2}
case $choice in case $choice in
1) conf_file="netlify.conf" ;; 1) conf_file="netlify.conf" ;;
2) conf_file="vercel.conf" ;; 2) conf_file="vercel.conf" ;;
*) conf_file="vercel.conf" ;; *) conf_file="vercel.conf" ;;
esac esac
else else
echo "请选择要使用的软件源:" echo "请选择要使用的软件源:"
@@ -686,12 +624,12 @@ apply_repo() {
choice=${choice:-5} choice=${choice:-5}
case $choice in case $choice in
1) conf_file="distfeeds.conf" ;; 1) conf_file="distfeeds.conf" ;;
2) conf_file="cfnetlify.conf" ;; 2) conf_file="cfnetlify.conf" ;;
3) conf_file="netlify.conf" ;; 3) conf_file="netlify.conf" ;;
4) conf_file="cfvercel.conf" ;; 4) conf_file="cfvercel.conf" ;;
5) conf_file="vercel.conf" ;; 5) conf_file="vercel.conf" ;;
*) conf_file="vercel.conf" ;; *) conf_file="vercel.conf" ;;
esac esac
fi fi
@@ -714,6 +652,7 @@ apply_repo() {
echo "完成" echo "完成"
} }
# catnd # catnd
catnd() { catnd() {
@@ -1128,20 +1067,20 @@ catwrt_opkg_list_installed() {
main main
} }
# Enhancement MENU # Utilities MENU
enhancement_menu() { utilities_menu() {
echo "" echo ""
echo "增强配置" echo " 从这里配置更多功能!"
echo "========================" echo "============================="
echo "" echo ""
echo "1. Mihomo 配置" echo "1. Mihomo 配置"
echo "2. Tailscale 配置" echo "2. Tailscale 配置"
echo "3. TTYD 配置免密(危险)" echo "3. TTYD 配置免密(危险)"
echo "4. SSL/TLS 证书上传配置" echo "4. SSL/TLS 证书上传配置"
echo "5. 重置 root 密码" echo "5. 重置 root 密码"
echo "6. 重置系统" echo "6. 重置系统"
echo "" echo ""
echo "0. 返回 Cattools 主菜单" echo "0. 返回 Cattools 主菜单"
echo echo
read -p "请输入数字并回车(Please enter your choice): " choice read -p "请输入数字并回车(Please enter your choice): " choice
case $choice in case $choice in
@@ -1152,7 +1091,7 @@ enhancement_menu() {
5) openwrt_firstboot ;; 5) openwrt_firstboot ;;
6) reset_root_password ;; 6) reset_root_password ;;
0) menu ;; 0) menu ;;
*) echo "无效选项,请重试" && enhancement_menu ;; *) echo "无效选项,请重试" && utilities_menu ;;
esac esac
} }
@@ -1529,6 +1468,46 @@ reset_root_password() {
exit exit
} }
patch_catwrt_release() {
if [ -f $RELEASE ]; then
if grep -q "version=v23.7" $RELEASE && grep -q "arch=amd64" $RELEASE && grep -q "source=lean" $RELEASE; then
echo "Already patched for x86_64 v23.7"
elif grep -q "version=v23.8" $RELEASE && grep -q "arch=amd64" $RELEASE && grep -q "source=lean" $RELEASE; then
echo "Already patched for x86_64 v23.8"
elif grep -q "version=v23.8" $RELEASE && grep -q "arch=mt798x" $RELEASE && grep -q "source=lean" $RELEASE; then
echo "Already patched for aarch64 v23.8"
fi
else
if [ "$(uname -m)" == "mips" ] || [ "$(uname -m)" == "mipsel" ] && grep -q "R22.12.1" /etc/openwrt_release && grep -q "miaoer.xyz" /etc/banner; then
echo "version=v22.12" > $RELEASE
echo "arch=mt7621" >> $RELEASE
echo "source=lean" >> $RELEASE
echo "hash=a1682a48834efdc6c5e2c3c62921b3195d306c8c" >> $RELEASE
echo "The patch file has been installed!"
elif [ "$(uname -m)" == "aarch64" ] && grep -q "R22.12.1" /etc/openwrt_release && grep -q "miaoer.xyz" /etc/banner; then
echo "version=v22.12" > $RELEASE
echo "arch=rkarm" >> $RELEASE
echo "source=lean" >> $RELEASE
echo "hash=3fd4930e781e40e3f85e2c6c082d6fcdd544e9ce" >> $RELEASE
echo "The patch file has been installed!"
elif [ "$(uname -m)" == "x86_64" ] && grep -q "R23.2" /etc/openwrt_release && grep -q "miaoer.xyz" /etc/banner; then
echo "version=v23.2" > $RELEASE
echo "arch=amd64" >> $RELEASE
echo "source=lean" >> $RELEASE
echo "hash=0239fab82eb640b55d4f4050cbc227ffd22087f3" >> $RELEASE
echo "The patch file has been installed!"
elif [ "$(uname -m)" == "x86_64" ] && grep -q "R22.11.11" /etc/openwrt_release && grep -q "miaoer.xyz" /etc/banner; then
echo "version=v22.12" > $RELEASE
echo "arch=amd64" >> $RELEASE
echo "source=lean" >> $RELEASE
echo "hash=4d6877d960c5c3bdc01b8e47679d923b475bea82" >> $RELEASE
echo "The patch file has been installed!"
fi
fi
}
patch_catwrt_release
while true; do while true; do
menu menu
read choice read choice
@@ -1540,17 +1519,17 @@ while true; do
network_wizard network_wizard
;; ;;
3) 3)
debug
;;
4)
catwrt_update
;;
5)
apply_repo apply_repo
;; ;;
6) 4)
catnd catnd
;; ;;
5)
debug
;;
6)
catwrt_update
;;
7) 7)
sysupgrade sysupgrade
;; ;;
@@ -1558,7 +1537,7 @@ while true; do
catwrt_opkg_list_installed catwrt_opkg_list_installed
;; ;;
9) 9)
enhancement_menu utilities_menu
;; ;;
0) 0)
echo "Exiting..." echo "Exiting..."