note/tech/自动更新最新版本的github软件.md
2025-11-19 10:16:05 +08:00

31 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 自动更新最新版本的github软件
## 脚本
以v2rayNG为例
最新版本的链接形式是这样的:
https://github.com/2dust/v2rayNG/releases/download/1.7.20/v2rayNG_1.7.20.apk
先获取版本号、最新的链接地址:
```bash
# 获取版本号
tag_name=`curl -s https://api.github.com/repos/2dust/v2rayNG/releases/latest |grep tag_name |cut -f4 -d "\""`
# 对比本地版本与线上版本的不同
local_version=ls -l /var/www/download/v2/|grep v2rayNG|awk -F '_' '{print $2}'|awk -F '.a' '{print $1}'
if["$tag_name" = "$local_version"];then
echo "No updated.exit!"
exit 0
else
echo "Deleting old version..."
rm -rf /var/www/download/v2/v2rayNG_$local_version.apk
link=https://github.com/2dust/v2rayNG/releases/download/$tag_name/v2rayNG_$tag_name.apk
echo "Downloading New version..."
wget -P /var/www/download/v2 $link
new_version=ls -l /var/www/download/v2/|grep v2rayNG|awk -F '_' '{print $2}'|awk -F '.a' '{print $1}'
if["$new_version" = "$tag_name"] then
echo "downloaded new version of v2rayNG_$tag_name.apk"
else
echo "Error downloading!"
exit 2
fi
fi
```