This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·54 lines (46 loc) · 1.8 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
. ~/.bashrc
LOG() {
echo "$(date +'%Y年%m月%d日%H:%M:%S'):" "$@"
}
# 更新新版本clash客户端可执行程序
update_clash_bin() {
for fn in "premium" "release"
do
if [ "$fn" = "premium" ] ; then
latest_url="https://github.com/Dreamacro/clash/releases/tag/premium"
else
latest_url="https://github.com/Dreamacro/clash/releases/latest"
fi
# Get latest binary download URL
tmpfile="tmp.list"
curl -L ${latest_url} | awk '/Dreamacro.clash.releases.download/ { gsub(/href=|["]/,""); print "https://github.com"$2 }' > ${tmpfile}
# Check latest binary version
cur_version=`cat ${fn}/version`
latest_version=`awk -F'-' '/clash-linux-amd64/{ sub(".gz",""); print $NF}' ${tmpfile}`
if [ "${cur_version}" != "${latest_version}" ] ; then
# 下载新版本
for dn in `cat ${tmpfile}`
do
out_file=`basename ${dn}`
latest_file=`echo ${out_file}|sed "s/${latest_version}/latest/g"`
# oldfile=`echo ${out_file}|sed "s/${latest_version}/${cur_version}/g"`
# 下载文件
LOG "正在下载: [$out_file],url:${dn}."
LOG "执行命令:wget -O ${out_file} -c ${dn}"
wget -O ${out_file} -c ${dn}
if [ "$?" = "0" ] ; then
# 下载成功
rm -f ${fn}/${latest_file}
mv ${out_file} ${fn}/${latest_file}
else
LOG "download file[$out_file] failed!"
fi
done
# 成功后,更新最新版本信息
echo ${latest_version} > ${fn}/version
fi
rm ${tmpfile}
done
}
update_clash_bin