Merge pull request #12 from ttimochan/main

fix: catwrt-update
This commit is contained in:
喵二
2024-07-18 22:30:31 +08:00
committed by GitHub

View File

@@ -487,12 +487,23 @@ catwrt_update() {
} }
get_remote_info() { get_remote_info() {
local arch_version_json=$(curl -s "$API_URL" | jq -r ".[\"$version_local\"].$arch_local") json_data=$(curl -s "$API_URL")
version_remote=$(echo "$arch_version_json" | jq -r '.version') result=$(echo "$json_data" | jq --arg hash "$hash_local" '
hash_remote=$(echo "$arch_version_json" | jq -r '.hash') . as $root |
releases_remote=$(echo "$arch_version_json" | jq -r '.releases') paths(scalars) as $p |
blog_remote=$(echo "$arch_version_json" | jq -r '.blogs') if getpath($p) == $hash then
channel_remote=$(echo "$arch_version_json" | jq -r '.channel') $p[0] as $version |
$p[1] as $device |
{version: $version, device: $device} + $root[$version][$device]
else empty end
| select(.version != null)
')
version_remote=$(echo "$result" | jq -r '.version')
channel_remote=$(echo "$result" | jq -r '.channel')
blog_remote=$(echo "$result" | jq -r '.blogs')
hash_remote=$(echo "$result" | jq -r '.hash')
latest=$(echo "$result" | jq -r '.latest')
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"
@@ -511,23 +522,24 @@ catwrt_update() {
} }
contrast_version() { contrast_version() {
if [ "$version_remote" == "$version_local" ] && [ "$hash_remote" == "$hash_local" ]; then if [ "$latest" == "true" ]; then
echo "=======================================================" echo "======================================================="
echo " Your CatWrt is $releases_remote" echo " Your CatWrt is up to date!"
echo " Remote Channel: $channel_remote"
if [ "$channel_remote" == "Beta" ]; then
echo " Please watch the latest version changes"
else
echo " You are on the stable version."
fi
echo "=======================================================" echo "======================================================="
else else
if [ "$channel_remote" == "Stable" ] || ( [ "$channel_remote" == "Beta" ] && [ "$channel_local" == "Beta" ] ); then echo "======================================================="
echo "=======================================================" echo "Your CatWrt is $version_local, the latest version is $version_remote,you should upgrade it!"
echo "Your CatWrt is $releases_remote, you should upgrade it!" echo "Visit the blog for more information"
echo "Visit the blog for more information" echo "$blog_remote"
echo "$blog_remote" echo "======================================================="
echo "======================================================="
else
echo "======================================================="
echo " Your CatWrt is up to date!"
echo "======================================================="
fi
fi fi
} }
print_version() { print_version() {
@@ -608,9 +620,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 "请选择要使用的软件源:"
@@ -624,12 +636,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
@@ -1009,17 +1021,17 @@ catwrt_opkg_list_installed() {
backup_installed_packages() { backup_installed_packages() {
echo "名单中已安装软件包列表..." echo "名单中已安装软件包列表..."
> "$BACKUP_FILE" >"$BACKUP_FILE"
for package in "${PACKAGES[@]}"; do for package in "${PACKAGES[@]}"; do
if opkg list_installed | grep -q "^$package "; then if opkg list_installed | grep -q "^$package "; then
echo "$package" >> "$BACKUP_FILE" echo "$package" >>"$BACKUP_FILE"
fi fi
done done
echo "备份完成" echo "备份完成"
} }
restore_installed_packages() { restore_installed_packages() {
opkg list_installed | awk '{print \$1}' > /tmp/default_installed_packages opkg list_installed | awk '{print \$1}' >/tmp/default_installed_packages
if [ -f "$BACKUP_FILE" ]; then if [ -f "$BACKUP_FILE" ]; then
while IFS= read -r package; do while IFS= read -r package; do
if grep -q "^$package$" "$DEFAULT_PACKAGES_FILE"; then if grep -q "^$package$" "$DEFAULT_PACKAGES_FILE"; then
@@ -1030,7 +1042,7 @@ catwrt_opkg_list_installed() {
echo "安装固件默认缺失的软件包: $package" echo "安装固件默认缺失的软件包: $package"
opkg install "$package" opkg install "$package"
fi fi
done < "$BACKUP_FILE" done <"$BACKUP_FILE"
echo "安装完成" echo "安装完成"
else else
echo "未检测到备份文件!寄了!" echo "未检测到备份文件!寄了!"
@@ -1055,12 +1067,12 @@ catwrt_opkg_list_installed() {
echo "" echo ""
read -p "检测到备份文件,是否需要恢复软件包?([ENTER] 确认 / [0] 取消) " choice read -p "检测到备份文件,是否需要恢复软件包?([ENTER] 确认 / [0] 取消) " choice
case "$choice" in case "$choice" in
0) 0)
echo "你选择了不恢复,打算重新开始!如果你有需要请回来找我!" echo "你选择了不恢复,打算重新开始!如果你有需要请回来找我!"
;; ;;
*) *)
restore_installed_packages restore_installed_packages
;; ;;
esac esac
else else
backup_installed_packages backup_installed_packages
@@ -1069,7 +1081,7 @@ catwrt_opkg_list_installed() {
rm -f /tmp/default_installed_packages rm -f /tmp/default_installed_packages
} }
main main
} }
# Utilities MENU # Utilities MENU
utilities_menu() { utilities_menu() {
@@ -1474,39 +1486,39 @@ reset_root_password() {
patch_catwrt_release() { patch_catwrt_release() {
if [ -f $RELEASE ]; then if [ -f $RELEASE ]; then
if grep -q "version=v23.7" $RELEASE && grep -q "arch=amd64" $RELEASE && grep -q "source=lean" $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" 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 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" 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 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" echo "Already patched for aarch64 v23.8"
fi fi
else else
if [ "$(uname -m)" == "mips" ] || [ "$(uname -m)" == "mipsel" ] && grep -q "R22.12.1" /etc/openwrt_release && grep -q "miaoer.xyz" /etc/banner; then 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 "version=v22.12" >$RELEASE
echo "arch=mt7621" >> $RELEASE echo "arch=mt7621" >>$RELEASE
echo "source=lean" >> $RELEASE echo "source=lean" >>$RELEASE
echo "hash=a1682a48834efdc6c5e2c3c62921b3195d306c8c" >> $RELEASE echo "hash=a1682a48834efdc6c5e2c3c62921b3195d306c8c" >>$RELEASE
echo "The patch file has been installed!" 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 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 "version=v22.12" >$RELEASE
echo "arch=rkarm" >> $RELEASE echo "arch=rkarm" >>$RELEASE
echo "source=lean" >> $RELEASE echo "source=lean" >>$RELEASE
echo "hash=3fd4930e781e40e3f85e2c6c082d6fcdd544e9ce" >> $RELEASE echo "hash=3fd4930e781e40e3f85e2c6c082d6fcdd544e9ce" >>$RELEASE
echo "The patch file has been installed!" 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 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 "version=v23.2" >$RELEASE
echo "arch=amd64" >> $RELEASE echo "arch=amd64" >>$RELEASE
echo "source=lean" >> $RELEASE echo "source=lean" >>$RELEASE
echo "hash=0239fab82eb640b55d4f4050cbc227ffd22087f3" >> $RELEASE echo "hash=0239fab82eb640b55d4f4050cbc227ffd22087f3" >>$RELEASE
echo "The patch file has been installed!" 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 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 "version=v22.12" >$RELEASE
echo "arch=amd64" >> $RELEASE echo "arch=amd64" >>$RELEASE
echo "source=lean" >> $RELEASE echo "source=lean" >>$RELEASE
echo "hash=4d6877d960c5c3bdc01b8e47679d923b475bea82" >> $RELEASE echo "hash=4d6877d960c5c3bdc01b8e47679d923b475bea82" >>$RELEASE
echo "The patch file has been installed!" echo "The patch file has been installed!"
fi fi
fi fi
} }
@@ -1516,41 +1528,41 @@ while true; do
menu menu
read choice read choice
case $choice in case $choice in
1) 1)
setip setip
;; ;;
2) 2)
network_wizard network_wizard
;; ;;
3) 3)
apply_repo apply_repo
;; ;;
4) 4)
catnd catnd
;; ;;
5) 5)
debug debug
;; ;;
6) 6)
catwrt_update catwrt_update
;; ;;
7) 7)
sysupgrade sysupgrade
;; ;;
8) 8)
catwrt_opkg_list_installed catwrt_opkg_list_installed
;; ;;
9) 9)
utilities_menu utilities_menu
;; ;;
0) 0)
echo "Exiting..." echo "Exiting..."
break break
;; ;;
*) *)
echo "Invalid choice, please try again /// 错误的数字请重试,[ENTER] 回车后重新输入" echo "Invalid choice, please try again /// 错误的数字请重试,[ENTER] 回车后重新输入"
read -p "Press [Enter] key to continue..." read -p "Press [Enter] key to continue..."
;; ;;
esac esac
done done