Update catwrt-update v2

This commit is contained in:
喵二
2024-07-17 19:58:25 +08:00
parent 439809cc55
commit 7467122858

View File

@@ -477,65 +477,62 @@ debug() {
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 version_remote=$(curl -s "$API_URL" | jq -r ".[\"$version_local\"].$arch_local.version")
version_remote=$(curl -s "$API_URL" | jq -r ".$arch_self.version") hash_remote=$(curl -s "$API_URL" | jq -r ".[\"$version_local\"].$arch_local.hash")
hash_remote=$(curl -s "$API_URL" | jq -r ".$arch_self.hash") releases_remote=$(curl -s "$API_URL" | jq -r ".[\"$version_local\"].$arch_local.releases")
channel_remote=$(curl -s "$API_URL" | jq -r ".$arch_self.channel") blog_remote=$(curl -s "$API_URL" | jq -r ".[\"$version_local\"].$arch_local.blogs")
blogs_remote=$(echo "$API_URL" | jq -r ".${arch}.blogs") channel_remote=$(curl -s "$API_URL" | jq -r ".[\"$version_local\"].$arch_local.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"
fi fi
} }
init() { init() {
if [ ! -f "$RELEASE" ]; then if [ ! -f "$RELEASE" ]; then
local_error "version file" local_error "version file"
fi fi
version_local=$(grep 'version' "$RELEASE" | cut -d '=' -f 2) version_local=$(grep 'version' "$RELEASE" | cut -d '=' -f 2)
hash_local=$(grep 'hash' "$RELEASE" | cut -d '=' -f 2) hash_local=$(grep 'hash' "$RELEASE" | cut -d '=' -f 2)
source_local=$(grep 'source' "$RELEASE" | cut -d '=' -f 2) source_local=$(grep 'source' "$RELEASE" | cut -d '=' -f 2)
arch_local=$(grep 'arch' "$RELEASE" | cut -d '=' -f 2) arch_local=$(grep 'arch' "$RELEASE" | cut -d '=' -f 2)
} }
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 up to date!"
echo "=======================================================" echo "======================================================="
else else
echo "=======================================================" echo "======================================================="
echo "Your CatWrt is outdated; you should upgrade it to the latest version!" echo "Your CatWrt is out of date, you should upgrade it!"
echo "Visit '$blogs_remote' for more information." echo "Visit the blog for more information"
echo "$blog_remote"
echo "=======================================================" echo "======================================================="
fi fi
} }
print_version() { print_version() {
echo "Remote Hash : $hash_remote" echo "Release : $releases_remote"
echo "Remote Version : $version_remote" echo "Channel : $channel_remote"
echo "Remote Current Channel : $channel_remote"
echo "Local Version : $version_local"
echo "Local Hash : $hash_local"
echo "=======================================================" echo "======================================================="
echo "" echo ""
} }
main() { main() {
init init
get_remote_hash "$arch_local" get_remote_info
contrast_version contrast_version
print_version print_version
} }