~修复下载更新失败时不会正常报错的bug
~修复无法正确检查更新的bug
~适配移动ax18
This commit is contained in:
juewuy
2021-06-19 15:23:20 +08:00
parent 268e1d4823
commit c6623721d8
4 changed files with 56 additions and 63 deletions

Binary file not shown.

View File

@@ -1,4 +1,4 @@
clash_v=1.6.0 clash_v=1.6.0
clashpre_v=2021.05.08 clashpre_v=2021.05.08
GeoIP_v=20210611 GeoIP_v=20210611
versionsh=1.3.13 versionsh=1.3.14

View File

@@ -1,10 +1,6 @@
#!/bin/bash #!/bin/bash
# Copyright (C) Juewuy # Copyright (C) Juewuy
webget(){
$clashdir/start.sh webget $1 $2 $3 $4 $5 $6
[ "$?" = "0" ] && result=200
}
#导入订阅、配置文件相关 #导入订阅、配置文件相关
linkconfig(){ linkconfig(){
echo ----------------------------------------------- echo -----------------------------------------------
@@ -310,8 +306,8 @@ clashlink(){
} }
#下载更新相关 #下载更新相关
gettar(){ gettar(){
webget /tmp/clashfm.tar.gz $tarurl $clashdir/start.sh webget /tmp/clashfm.tar.gz $tarurl
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1 [ "$?" = "1" ] && echo "文件下载失败!" && exit 1
#解压 #解压
echo ----------------------------------------------- echo -----------------------------------------------
echo 开始解压文件! echo 开始解压文件!
@@ -424,8 +420,8 @@ getcore(){
#获取在线clash核心文件 #获取在线clash核心文件
echo ----------------------------------------------- echo -----------------------------------------------
echo 正在在线获取clash核心文件…… echo 正在在线获取clash核心文件……
webget /tmp/clash.new $corelink $clashdir/start.sh webget /tmp/clash.new $corelink
if [ "$result" != "200" ];then if [ "$?" = "1" ];then
echo -e "\033[31m核心文件下载失败\033[0m" echo -e "\033[31m核心文件下载失败\033[0m"
else else
echo -e "\033[32m$clashcore核心下载成功\033[0m" echo -e "\033[32m$clashcore核心下载成功\033[0m"
@@ -478,8 +474,8 @@ setcore(){
getgeo(){ getgeo(){
echo ----------------------------------------------- echo -----------------------------------------------
echo 正在从服务器获取数据库文件………… echo 正在从服务器获取数据库文件…………
webget /tmp/$geoname $update_url/bin/$geotype $clashdir/start.sh webget /tmp/$geoname $update_url/bin/$geotype
if [ "$result" != "200" ];then if [ "$?" = "1" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m文件下载失败\033[0m" echo -e "\033[31m文件下载失败\033[0m"
exit 1 exit 1
@@ -541,8 +537,8 @@ getdb(){
dblink="${update_url}/bin/${db_type}.tar.gz" dblink="${update_url}/bin/${db_type}.tar.gz"
echo ----------------------------------------------- echo -----------------------------------------------
echo 正在连接服务器获取安装文件………… echo 正在连接服务器获取安装文件…………
webget /tmp/clashdb.tar.gz $dblink $clashdir/start.sh webget /tmp/clashdb.tar.gz $dblink
if [ "$result" != "200" ];then if [ "$?" = "1" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m文件下载失败\033[0m" echo -e "\033[31m文件下载失败\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
@@ -638,15 +634,15 @@ getcrt(){
crtlink="${update_url}/bin/ca-certificates.crt" crtlink="${update_url}/bin/ca-certificates.crt"
echo ----------------------------------------------- echo -----------------------------------------------
echo 正在连接服务器获取安装文件………… echo 正在连接服务器获取安装文件…………
webget /tmp/ca-certificates.crt $crtlink $clashdir/start.sh webget /tmp/ca-certificates.crt $crtlink
if [ "$result" != "200" ];then if [ "$?" = "1" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m文件下载失败\033[0m" echo -e "\033[31m文件下载失败\033[0m"
else else
echo ----------------------------------------------- echo -----------------------------------------------
mv -f /tmp/ca-certificates.crt $crtdir mv -f /tmp/ca-certificates.crt $crtdir
webget /tmp/ssl_test https://baidu.com echooff rediron skipceroff $clashdir/start.sh webget /tmp/ssl_test https://baidu.com echooff rediron skipceroff
if [ "$result" != "200" ];then if [ "$?" = "1" ];then
export CURL_CA_BUNDLE=$crtdir export CURL_CA_BUNDLE=$crtdir
echo "export CURL_CA_BUNDLE=$crtdir" >> /etc/profile echo "export CURL_CA_BUNDLE=$crtdir" >> /etc/profile
fi fi
@@ -723,7 +719,7 @@ setserver(){
fi fi
elif [ "$num" = 6 ]; then elif [ "$num" = 6 ]; then
echo ----------------------------------------------- echo -----------------------------------------------
webget /tmp/clashrelease https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/bin/release_version echooff rediroff 2>/tmp/clashrelease $clashdir/start.sh webget /tmp/clashrelease https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/bin/release_version echooff rediroff 2>/tmp/clashrelease
echo -e "\033[32m请选择想要更新至的版本\033[0m" echo -e "\033[32m请选择想要更新至的版本\033[0m"
cat /tmp/clashrelease | awk '{print " "NR" "$1}' cat /tmp/clashrelease | awk '{print " "NR" "$1}'
echo -e " 0 返回上级菜单" echo -e " 0 返回上级菜单"
@@ -748,13 +744,13 @@ setserver(){
checkupdate(){ checkupdate(){
if [ -z "$release_new" ];then if [ -z "$release_new" ];then
if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ];then if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ];then
webget /tmp/clashrelease $update_url@master/bin/release_version echoon rediroff 2>/tmp/clashrelease $clashdir/start.sh webget /tmp/clashrelease $update_url@master/bin/release_version echoon rediroff 2>/tmp/clashrelease
[ "$result" = "200" ] && release_new=$(cat /tmp/clashrelease | head -1) [ "$?" = "0" ] && release_new=$(cat /tmp/clashrelease | head -1)
[ -z "$release_new" ] && release_new=master [ -z "$release_new" ] && release_new=master
update_url=$update_url@$release_new update_url=$update_url@$release_new
fi fi
webget /tmp/clashversion $update_url/bin/version echooff $clashdir/start.sh webget /tmp/clashversion $update_url/bin/version echooff
[ "$result" = "200" ] && source /tmp/clashversion || echo -e "\033[31m检查更新失败请检查网络连接或切换安装源\033[0m" [ "$?" = "0" ] && source /tmp/clashversion || echo -e "\033[31m检查更新失败请检查网络连接或切换安装源\033[0m"
[ -z "$release_new" ] && release_new=$versionsh [ -z "$release_new" ] && release_new=$versionsh
rm -rf /tmp/clashversion rm -rf /tmp/clashversion
rm -rf /tmp/clashrelease rm -rf /tmp/clashrelease
@@ -961,8 +957,8 @@ userguide(){
[ "$res" = 1 ] && checkupdate && getcrt [ "$res" = 1 ] && checkupdate && getcrt
fi fi
#设置加密DNS #设置加密DNS
webget /tmp/ssl_test https://baidu.com echooff rediron skipceroff $clashdir/start.sh webget /tmp/ssl_test https://baidu.com echooff rediron skipceroff
if [ "$result" = "200" ];then if [ "$?" = "0" ];then
dns_nameserver='https://223.5.5.5/dns-query, https://doh.pub/dns-query, tls://dns.rubyfish.cn:853' dns_nameserver='https://223.5.5.5/dns-query, https://doh.pub/dns-query, tls://dns.rubyfish.cn:853'
dns_fallback='https://1.0.0.1/dns-query, https://8.8.4.4/dns-query, https://doh.opendns.com/dns-query' dns_fallback='https://1.0.0.1/dns-query, https://8.8.4.4/dns-query, https://doh.opendns.com/dns-query'
setconfig dns_nameserver \'"$dns_nameserver"\' setconfig dns_nameserver \'"$dns_nameserver"\'

View File

@@ -47,39 +47,6 @@ compare(){
[ "$(cat $1)" = "$(cat $2)" ] && return 0 || return 1 [ "$(cat $1)" = "$(cat $2)" ] && return 0 || return 1
fi fi
} }
webget(){
#设置临时http代理
[ -n "$(pidof clash)" ] && getconfig && export all_proxy="http://$authentication@127.0.0.1:$mix_port"
#参数【$1】代表下载目录【$2】代表在线地址
#参数【$3】代表输出显示【$4】不启用重定向
#参数【$5】代表验证证书【$6】使用clash文件头
if curl --version > /dev/null 2>&1;then
[ "$3" = "echooff" ] && progress='-s' || progress='-#'
[ "$4" = "rediroff" ] && redirect='' || redirect='-L'
[ "$5" = "skipceroff" ] && certificate='' || certificate='-k'
[ -n "$6" ] && agent='-A "clash"'
result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$1" "$2")
[ "$result" != "200" ] && export all_proxy="" && result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$1" "$2")
else
if wget --version > /dev/null 2>&1;then
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
[ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
[ "$5" = "skipceroff" ] && certificate='' || certificate='--no-check-certificate'
timeout='--timeout=3 -t 2'
[ -n "$6" ] && agent='--user-agent="clash"'
fi
[ "$3" = "echoon" ] && progress=''
[ "$3" = "echooff" ] && progress='-q'
wget -Y on $agent $progress $redirect $certificate $timeout -O "$1" "$2"
if [ "$?" != "0" ];then
wget -Y off $agent $progress $redirect $certificate $timeout -O "$1" "$2"
[ "$?" = "0" ] && result="200"
else
result="200"
fi
fi
[ "$result" = "200" ] || exit 1
}
logger(){ logger(){
[ -n "$2" ] && echo -e "\033[$2m$1\033[0m" [ -n "$2" ] && echo -e "\033[$2m$1\033[0m"
echo `date "+%G-%m-%d %H:%M:%S"` $1 >> $clashdir/log echo `date "+%G-%m-%d %H:%M:%S"` $1 >> $clashdir/log
@@ -153,7 +120,7 @@ EOF`
yamlnew=/tmp/clash_config_$USER.yaml yamlnew=/tmp/clash_config_$USER.yaml
rm -rf $yamlnew rm -rf $yamlnew
$0 webget $yamlnew $Https 0 0 0 1 $0 webget $yamlnew $Https 0 0 0 1
if [ "$result" != "200" ];then if [ "$?" = "1" ];then
if [ -z "$markhttp" ];then if [ -z "$markhttp" ];then
echo ----------------------------------------------- echo -----------------------------------------------
logger "配置文件获取失败!" 31 logger "配置文件获取失败!" 31
@@ -168,7 +135,7 @@ EOF`
retry=$((retry+1)) retry=$((retry+1))
logger "配置文件获取失败!" 31 logger "配置文件获取失败!" 31
echo -e "\033[32m尝试使用其他服务器获取配置\033[0m" echo -e "\033[32m尝试使用其他服务器获取配置\033[0m"
logger "正在重试第$retry次/共5次" 32 logger "正在重试第$retry次/共5次" 33
sed -i '/server_link=*/'d $ccfg sed -i '/server_link=*/'d $ccfg
if [ "$server_link" -ge 5 ]; then if [ "$server_link" -ge 5 ]; then
server_link=0 server_link=0
@@ -314,7 +281,7 @@ cn_ip_route(){
else else
logger "未找到cn_ip列表正在下载" 33 logger "未找到cn_ip列表正在下载" 33
$0 webget $bindir/cn_ip.txt "$update_url/bin/china_ip_list.txt" $0 webget $bindir/cn_ip.txt "$update_url/bin/china_ip_list.txt"
[ "$result" != 200 ] && rm -rf $bindir/cn_ip.txt && logger "列表下载失败,已退出!" 31 && exit 1 [ "$?" = "1" ] && rm -rf $bindir/cn_ip.txt && logger "列表下载失败,已退出!" 31 && exit 1
fi fi
fi fi
if [ -f $bindir/cn_ip.txt ];then if [ -f $bindir/cn_ip.txt ];then
@@ -621,7 +588,7 @@ bfstart(){
[ -z "$cpucore" ] && source $clashdir/getdate.sh && getcpucore [ -z "$cpucore" ] && source $clashdir/getdate.sh && getcpucore
[ -z "$cpucore" ] && logger 找不到设备的CPU信息请手动指定处理器架构类型 31 && setcpucore [ -z "$cpucore" ] && logger 找不到设备的CPU信息请手动指定处理器架构类型 31 && setcpucore
$0 webget $bindir/clash "$update_url/bin/$clashcore/clash-linux-$cpucore" $0 webget $bindir/clash "$update_url/bin/$clashcore/clash-linux-$cpucore"
[ "$result" != 200 ] && rm -rf $bindir/clash && logger "核心下载失败,已退出!" 31 && exit 1 [ "$?" = "1" ] && rm -rf $bindir/clash && logger "核心下载失败,已退出!" 31 && exit 1
[ ! -x $bindir/clash ] && chmod +x $bindir/clash #检测可执行权限 [ ! -x $bindir/clash ] && chmod +x $bindir/clash #检测可执行权限
clashv=$($bindir/clash -v | awk '{print $2}') clashv=$($bindir/clash -v | awk '{print $2}')
setconfig clashv $clashv setconfig clashv $clashv
@@ -635,7 +602,7 @@ bfstart(){
logger "未找到GeoIP数据库正在下载" 33 logger "未找到GeoIP数据库正在下载" 33
[ -z "$geotype" ] && geotype=cn_mini.mmdb [ -z "$geotype" ] && geotype=cn_mini.mmdb
$0 webget $bindir/Country.mmdb $update_url/bin/$geotype $0 webget $bindir/Country.mmdb $update_url/bin/$geotype
[ "$result" != 200 ] && rm -rf $bindir/Country.mmdb && logger "数据库下载失败,已退出!" 31 && exit 1 [ "$?" = "1" ] && rm -rf $bindir/Country.mmdb && logger "数据库下载失败,已退出!" 31 && exit 1
Geo_v=$(date +"%Y%m%d") Geo_v=$(date +"%Y%m%d")
setconfig Geo_v $Geo_v setconfig Geo_v $Geo_v
fi fi
@@ -781,7 +748,37 @@ updateyaml)
$0 restart $0 restart
;; ;;
webget) webget)
webget $2 $3 $4 $5 $6 $7 #设置临时http代理
[ -n "$(pidof clash)" ] && getconfig && export all_proxy="http://$authentication@127.0.0.1:$mix_port"
#参数【$2】代表下载目录【$3】代表在线地址
#参数【$4】代表输出显示【$4】不启用重定向
#参数【$6】代表验证证书【$7】使用clash文件头
if curl --version > /dev/null 2>&1;then
[ "$4" = "echooff" ] && progress='-s' || progress='-#'
[ "$5" = "rediroff" ] && redirect='' || redirect='-L'
[ "$6" = "skipceroff" ] && certificate='' || certificate='-k'
[ -n "$7" ] && agent='-A "clash"'
result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$2" "$3")
[ "$?" != "0" ] && export all_proxy="" && result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$2" "$3")
else
if wget --version > /dev/null 2>&1;then
[ "$4" = "echooff" ] && progress='-q' || progress='-q --show-progress'
[ "$5" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
[ "$6" = "skipceroff" ] && certificate='' || certificate='--no-check-certificate'
timeout='--timeout=3 -t 2'
[ -n "$7" ] && agent='--user-agent="clash"'
fi
[ "$4" = "echoon" ] && progress=''
[ "$4" = "echooff" ] && progress='-q'
wget -Y on $agent $progress $redirect $certificate $timeout -O "$2" "$3"
if [ "$?" != "0" ];then
wget -Y off $agent $progress $redirect $certificate $timeout -O "$2" "$3"
[ "$?" = "0" ] && result="200"
else
result="200"
fi
fi
[ "$result" = "200" ] && exit 0 || exit 1
;; ;;
web_save) web_save)
getconfig getconfig