mirror of
https://github.com/juewuy/ShellCrash.git
synced 2024-11-16 11:42:18 +08:00
v1.0.0beta15.3
~优化脚本语句和结构 ~增加wget下载方式,统一下载逻辑 ~增加Gitee下载源 ~增加脚本日志以及查看日志功能 ~修复部分情况下开机自启显示错误的bug
This commit is contained in:
parent
f72bc273c7
commit
c642ca4b8c
|
@ -2,15 +2,19 @@
|
|||
# Copyright (C) Juewuy
|
||||
|
||||
webget(){
|
||||
[ -n "$(pidof clash)" ] && export http_proxy="http:/127.0.0.1:$mix_port" #设置临时http代理
|
||||
[ -n "$(pidof clash)" ] && export all_proxy="http://127.0.0.1:$mix_port" #设置临时http代理
|
||||
#参数【$1】代表下载目录,【$2】代表在线地址
|
||||
if curl --version > /dev/null 2>&1;then
|
||||
result=$(curl -w %{http_code} --connect-timeout 5 -# -kLo $1 $2)
|
||||
[ -z "$3" ] && progress='-#' || progress='-s'
|
||||
result=$(curl -w %{http_code} --connect-timeout 5 $progress -kLo $1 $2)
|
||||
elif wget --version > /dev/null 2>&1;then
|
||||
wget -q --show-progress --no-check-certificate --timeout=5 -O $1 $2
|
||||
[ -z "$3" ] && progress='--show-progress' || progress=''
|
||||
wget -Y on -q $progress --no-check-certificate --timeout=5 -O $1 $2
|
||||
[ $? -eq 0 ] && result="200"
|
||||
else
|
||||
echo 找不到curl或者wget,无法下载,请先安装相应依赖!
|
||||
fi
|
||||
export all_proxy=''
|
||||
}
|
||||
linkconfig(){
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -391,7 +395,7 @@ clashlink(){
|
|||
fi
|
||||
}
|
||||
gettar(){
|
||||
result=$(curl -w %{http_code} -skLo /tmp/clashfm.tar.gz $tarurl)
|
||||
webget /tmp/clashfm.tar.gz $tarurl
|
||||
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
|
||||
#解压
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -537,7 +541,7 @@ getcore(){
|
|||
echo -e "| \033[0m如长时间没有数据请用ctrl+c退出 |"
|
||||
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m"
|
||||
#获取在线clash核心文件
|
||||
result=$(curl -w %{http_code} -#kLo /tmp/clash.new $corelink)
|
||||
webget /tmp/clash.new $corelink
|
||||
if [ "$result" != "200" ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m核心文件下载失败!\033[0m"
|
||||
|
@ -565,7 +569,7 @@ getgeo(){
|
|||
if [ "$res" = '1' ]; then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo 正在从服务器获取数据库文件…………
|
||||
result=$(curl -w %{http_code} -#kLo /tmp/Country.mmdb $update_url/bin/Country.mmdb)
|
||||
webget /tmp/Country.mmdb $update_url/bin/Country.mmdb
|
||||
if [ "$result" != "200" ];then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo -e "\033[31m文件下载失败!\033[0m"
|
||||
|
@ -654,7 +658,7 @@ getdb(){
|
|||
dblink="${update_url}/bin/${db_type}.tar.gz"
|
||||
echo -----------------------------------------------
|
||||
echo 正在连接服务器获取安装文件…………
|
||||
result=$(curl -w %{http_code} -#kLo /tmp/clashdb.tar.gz $dblink)
|
||||
webget /tmp/clashdb.tar.gz $dblink
|
||||
if [ "$result" != "200" ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m文件下载失败!\033[0m"
|
||||
|
@ -736,22 +740,25 @@ setserver(){
|
|||
echo -e "\033[30;47m您可以在此处切换在线更新时使用的资源地址\033[0m"
|
||||
echo -e "当前源:\033[4;32m$update_url\033[0m"
|
||||
echo -----------------------------------------------
|
||||
echo -e " 1 Github源(直连美国服务器)"
|
||||
echo -e " 2 Jsdelivr-CDN源(仅同步最新release版本)"
|
||||
echo -e " 3 Github源+clash代理(需开启clash服务)"
|
||||
echo -e " 4 自定义输入(请务必确保路径正确)"
|
||||
echo -e " 1 Jsdelivr-CDN源(test版本)"
|
||||
echo -e " 2 Jsdelivr-CDN源(release版本)"
|
||||
echo -e " 3 Github源(test版本,需开启clash服务)"
|
||||
echo -e " 4 Gitee源(release版本,可能滞后)"
|
||||
echo -e " 5 自定义输入(请务必确保路径正确)"
|
||||
echo -e " 0 返回上级菜单"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
update
|
||||
elif [ "$num" = 1 ]; then
|
||||
update_url='--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master'
|
||||
update_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master'
|
||||
elif [ "$num" = 2 ]; then
|
||||
update_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash'
|
||||
elif [ "$num" = 3 ]; then
|
||||
update_url='-x '$authentication'@127.0.0.1:'$mix_port' https://raw.githubusercontent.com/juewuy/ShellClash/master'
|
||||
update_url='https://raw.githubusercontent.com/juewuy/ShellClash/master'
|
||||
elif [ "$num" = 4 ]; then
|
||||
update_url='https://gitee.com/juewuy/ShellClash/raw/master'
|
||||
elif [ "$num" = 5 ]; then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
read -p "请输入个人源路径 > " update_url
|
||||
if [ -z "$update_url" ];then
|
||||
|
@ -776,12 +783,15 @@ setserver(){
|
|||
checkupdate(){
|
||||
if [ -z "$release_new" ];then
|
||||
if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ];then
|
||||
release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 --connect-timeout 5 -m 5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
|
||||
webget /tmp/clashrelease https://api.github.com/repos/juewuy/ShellClash/releases/latest noprogress
|
||||
[ "$result" = "200" ] && release_new=$(cat /tmp/clashrelease | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') || release_new=master
|
||||
update_url=$update_url@$release_new
|
||||
fi
|
||||
curl -skL --connect-timeout 5 -m 5 $update_url/bin/version > /tmp/clashversion
|
||||
source /tmp/clashversion
|
||||
webget /tmp/clashversion $update_url/bin/version noprogress
|
||||
[ "$result" = "200" ] && source /tmp/clashversion || echo -e "\033[31m检查更新失败!\033[0m"
|
||||
[ -z "$release_new" ] && release_new=$versionsh
|
||||
rm -rf /tmp/clashversion
|
||||
rm -rf /tmp/clashrelease
|
||||
fi
|
||||
}
|
||||
update(){
|
||||
|
@ -887,6 +897,7 @@ testcommand(){
|
|||
echo " 5 查看config.yaml前40行"
|
||||
echo " 6 测试代理服务器连通性(google.tw)"
|
||||
echo " 7 重新进入新手引导"
|
||||
echo " 9 查看后台脚本运行日志"
|
||||
echo -----------------------------------------------
|
||||
echo " 0 返回上级目录!"
|
||||
read -p "请输入对应数字 > " num
|
||||
|
@ -927,7 +938,7 @@ testcommand(){
|
|||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
exit;
|
||||
elif [ "$num" = 6 ]; then
|
||||
echo 注意:测试结果不保证一定准确!
|
||||
echo 注意:依赖curl,且测试结果不保证一定准确!
|
||||
delay=`curl -kx ${authentication}@127.0.0.1:$mix_port -o /dev/null -s -w '%{time_starttransfer}' 'https://google.tw' & { sleep 3 ; kill $! & }` > /dev/null 2>&1
|
||||
delay=`echo |awk "{print $delay*1000}"` > /dev/null 2>&1
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -939,6 +950,10 @@ testcommand(){
|
|||
clashsh
|
||||
elif [ "$num" = 7 ]; then
|
||||
userguide
|
||||
elif [ "$num" = 9 ]; then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
cat $clashdir/log
|
||||
exit;
|
||||
else
|
||||
echoerrornum
|
||||
clashsh
|
||||
|
|
|
@ -24,37 +24,41 @@ getconfig(){
|
|||
#是否代理常用端口
|
||||
[ "$common_ports" = "已开启" ] && ports='-m multiport --dports 53,587,465,995,993,143,80,443 '
|
||||
}
|
||||
logger(){
|
||||
echo -e "\033[31m$1\033[0m"
|
||||
echo `date "+%G-%m-%d %H:%M:%S"` $1 >> $clashdir/log
|
||||
[ "$(wc -l $clashdir/log | awk '{print $1}')" -gt 30 ] && sed -i '1d' $clashdir/log
|
||||
}
|
||||
getyaml(){
|
||||
#前后端订阅服务器地址索引,可在此处添加!
|
||||
Server=`sed -n ""$server_link"p"<<EOF
|
||||
subcon.dlj.tf
|
||||
subconverter.herokuapp.com
|
||||
subcon.py6.pw
|
||||
api.dler.io
|
||||
api.wcc.best
|
||||
EOF`
|
||||
subcon.dlj.tf
|
||||
subconverter.herokuapp.com
|
||||
subcon.py6.pw
|
||||
api.dler.io
|
||||
api.wcc.best
|
||||
EOF`
|
||||
Config=`sed -n ""$rule_link"p"<<EOF
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoReject.ini
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiMode.ini
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_AdblockPlus.ini
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_AdblockPlus.ini
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_Netflix.ini
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_AdblockPlus.ini
|
||||
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_clash.ini
|
||||
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_dler.ini
|
||||
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/connershua_pro.ini
|
||||
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/connershua_backtocn.ini
|
||||
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/dlercloud_lige_platinum.ini
|
||||
https://subconverter.oss-ap-southeast-1.aliyuncs.com/Rules/RemoteConfig/special/basic.ini
|
||||
https://subconverter.oss-ap-southeast-1.aliyuncs.com/Rules/RemoteConfig/special/netease.ini
|
||||
EOF`
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoReject.ini
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiMode.ini
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_AdblockPlus.ini
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_AdblockPlus.ini
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_Netflix.ini
|
||||
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_AdblockPlus.ini
|
||||
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_clash.ini
|
||||
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_dler.ini
|
||||
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/connershua_pro.ini
|
||||
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/connershua_backtocn.ini
|
||||
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/dlercloud_lige_platinum.ini
|
||||
https://subconverter.oss-ap-southeast-1.aliyuncs.com/Rules/RemoteConfig/special/basic.ini
|
||||
https://subconverter.oss-ap-southeast-1.aliyuncs.com/Rules/RemoteConfig/special/netease.ini
|
||||
EOF`
|
||||
#如果传来的是Url链接则合成Https链接,否则直接使用Https链接
|
||||
if [ -z "$Https" ];then
|
||||
#echo $Url
|
||||
Https="https://$Server/sub?target=clash&insert=true&new_name=true&scv=true&exclude=$exclude&include=$include&url=$Url&config=$Config"
|
||||
markhttp=1
|
||||
fi
|
||||
#
|
||||
#输出
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo 正在连接服务器获取配置文件…………链接地址为:
|
||||
echo -e "\033[4;32m$Https\033[0m"
|
||||
|
@ -67,24 +71,23 @@ getyaml(){
|
|||
#获取在线yaml文件
|
||||
yaml=$clashdir/config.yaml
|
||||
yamlnew=/tmp/config.yaml
|
||||
rm -rf $yamlnew > /dev/null 2>&1
|
||||
result=$(curl -w %{http_code} -kLo $yamlnew $Https)
|
||||
rm -rf $yamlnew
|
||||
source $clashdir/getdate.sh && webget $yamlnew $Https
|
||||
if [ "$result" != "200" ];then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo -e "\033[31m配置文件获取失败!\033[0m"
|
||||
if [ -z "$markhttp" ];then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo -e "\033[31m请尝试使用【导入节点/链接】功能!\033[0m"
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo -----------------------------------------------
|
||||
logger "配置文件获取失败!"
|
||||
echo -e "\033[31m请尝试使用【导入订阅】功能!\033[0m"
|
||||
echo -----------------------------------------------
|
||||
exit 1
|
||||
else
|
||||
if [ "$retry" -ge 5 ];then
|
||||
echo -e "\033[32m无法获取配置文件,请检查链接格式以及网络连接状态!\033[0m"
|
||||
logger "无法获取配置文件,请检查链接格式以及网络连接状态!"
|
||||
exit 1
|
||||
else
|
||||
retry=$((retry+1))
|
||||
echo -e "\033[32m尝试使用其他服务器获取配置!\033[0m"
|
||||
echo -e "\033[33m正在尝试第$retry次/共5次!\033[0m"
|
||||
logger "正在尝试第$retry次/共5次!"
|
||||
sed -i '/server_link=*/'d $ccfg
|
||||
if [ "$server_link" -ge 5 ]; then
|
||||
server_link=0
|
||||
|
@ -100,7 +103,7 @@ getyaml(){
|
|||
#检测节点
|
||||
if [ -z "$(cat $yamlnew | grep 'server:' | grep -v 'nameserver')" ];then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo -e "\033[33m获取到了配置文件,但似乎并不包含正确的节点信息!\033[0m"
|
||||
logger "获取到了配置文件,但似乎并不包含正确的节点信息!"
|
||||
echo -----------------------------------------------
|
||||
sed -n '1,30p' $yamlnew
|
||||
echo -----------------------------------------------
|
||||
|
@ -111,7 +114,7 @@ getyaml(){
|
|||
#检测旧格式
|
||||
if cat $yamlnew | grep 'Proxy Group:' >/dev/null;then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo -e "\033[31m已经停止对旧格式配置文件的支持!!!\033[0m"
|
||||
logger "已经停止对旧格式配置文件的支持!!!"
|
||||
echo -e "请使用新格式或者使用【导入节点/链接】功能!"
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
exit 1
|
||||
|
@ -119,7 +122,7 @@ getyaml(){
|
|||
#检测不支持的加密协议
|
||||
if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo -e "\033[31m不支持chacha20加密,请更换节点加密协议!!!\033[0m"
|
||||
logger "不支持chacha20加密,请更换节点加密协议!!!"
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
exit 1
|
||||
fi
|
||||
|
@ -137,11 +140,11 @@ getyaml(){
|
|||
$clashdir/start.sh stop
|
||||
mv $yaml.bak $yaml
|
||||
$0 start
|
||||
echo -e "\033[31mclash服务启动失败!已还原配置文件并重启clash!\033[0m"
|
||||
logger "clash服务启动失败!已还原配置文件并重启clash!"
|
||||
sleep 1
|
||||
[ -n "$(pidof clash)" ] && exit 0
|
||||
fi
|
||||
echo -e "\033[31mclash服务启动失败!请查看报错信息!\033[0m"
|
||||
logger "clash服务启动失败!请查看报错信息!"
|
||||
$0 stop
|
||||
$clashdir/clash -t -d $clashdir
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -327,17 +330,19 @@ afstart(){
|
|||
#读取配置文件
|
||||
getconfig
|
||||
#修改iptables规则使流量进入clash
|
||||
stop_iptables
|
||||
[ "$redir_mod" != "纯净模式" ] && [ "$dns_no" != "true" ] && start_dns
|
||||
[ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir
|
||||
#标记启动时间
|
||||
mark_time
|
||||
#设置本机代理
|
||||
[ "$local_proxy" = "已开启" ] && $0 set_proxy $mix_port $hostdir
|
||||
#启用面板配置自动保存
|
||||
web_save_auto
|
||||
#后台还原面板配置
|
||||
[ -f $clashdir/web_save ] && web_restore &
|
||||
#还原面板配置相关
|
||||
if curl --version > /dev/null 2>&1;then
|
||||
web_save_auto #启用面板配置自动保存
|
||||
[ -f $clashdir/web_save ] && web_restore & #后台还原面板配置
|
||||
fi
|
||||
#clash启动校验
|
||||
[ -z "$(pidof clash)" ] && logger clash启动失败! && $0 stop && exit 0
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
|
@ -346,6 +351,7 @@ afstart)
|
|||
afstart
|
||||
;;
|
||||
start)
|
||||
[ -n "$(pidof clash)" ] && logger clash服务已经运行,请勿重复运行! && exit 0
|
||||
#读取配置文件
|
||||
getconfig
|
||||
#使用内置规则强行覆盖config配置文件
|
||||
|
@ -366,7 +372,9 @@ stop)
|
|||
#读取配置文件
|
||||
getconfig
|
||||
#保存面板配置
|
||||
if curl --version > /dev/null 2>&1;then
|
||||
web_save
|
||||
fi
|
||||
#删除守护进程&面板配置自动保存
|
||||
sed -i /clash保守模式守护进程/d $cronpath >/dev/null 2>&1
|
||||
sed -i /保存节点配置/d $cronpath >/dev/null 2>&1
|
||||
|
|
Loading…
Reference in New Issue
Block a user