优化启动脚本对订阅地址的探测、下载逻辑。

This commit is contained in:
wanhebin 2023-02-16 18:21:55 +08:00
parent 9927b5b1aa
commit 947d8343fc

View File

@ -30,7 +30,8 @@ action() {
# 判断命令是否正常执行 函数
if_success() {
if [ $? -eq 0 ]; then
ReturnStatus=$3
if [ $ReturnStatus -eq 0 ]; then
action "$1" /bin/true
else
action "$2" /bin/false
@ -52,15 +53,33 @@ unset no_proxy
# 检查url是否有效
Text1="Clash订阅地址可访问"
Text2="Clash订阅地址不可访问"
for i in {1..10}
do
curl -o /dev/null -s -m 10 --connect-timeout 10 -w %{http_code} $URL | grep '[23][0-9][0-9]' &>/dev/null
if_success $Text1 $Text2
ReturnStatus=$?
if [ $ReturnStatus -eq 0 ]; then
break
else
continue
fi
done
if_success $Text1 $Text2 $ReturnStatus
# 拉取更新config.yml文件
Text3="配置文件config.yaml下载成功"
Text4="配置文件config.yaml下载失败退出启动"
for i in {1..10}
do
# wget -q -O $Temp_Dir/clash.yaml $URL
curl -s -o $Temp_Dir/clash.yaml $URL
if_success $Text3 $Text4
ReturnStatus=$?
if [ $ReturnStatus -eq 0 ]; then
break
else
continue
fi
done
if_success $Text3 $Text4 $ReturnStatus
# 取出代理相关配置
sed -n '/^proxies:/,$p' $Temp_Dir/clash.yaml > $Temp_Dir/proxy.txt
@ -84,10 +103,12 @@ Text6="服务启动失败!"
get_arch=`/bin/arch`
if [[ $get_arch =~ "x86_64" ]]; then
nohup $Server_Dir/bin/clash-linux-amd64 -d $Conf_Dir &> $Log_Dir/clash.log &
if_success $Text5 $Text6
ReturnStatus=$?
if_success $Text5 $Text6 $ReturnStatus
elif [[ $get_arch =~ "aarch64" ]]; then
nohup $Server_Dir/bin/clash-linux-armv7 -d $Conf_Dir &> $Log_Dir/clash.log &
if_success $Text5 $Text6
ReturnStatus=$?
if_success $Text5 $Text6 $ReturnStatus
else
echo -e "\033[31m[ERROR] Unsupported CPU Architecture\033[0m"
exit 1