v1.0.0beta15.3
~优化脚本语句和结构 ~完美适配支持wget!!! ~增加Gitee下载源 ~增加脚本日志以及查看日志功能 ~修复部分情况下开机自启显示错误的bug
This commit is contained in:
@@ -278,15 +278,13 @@ clashstart(){
|
||||
if [ ! -f $clashdir/clash ];then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo -e "\033[31m没有找到核心文件,请先下载clash核心!\033[0m"
|
||||
checkupdate
|
||||
source $clashdir/getdate.sh && getcore
|
||||
source $clashdir/getdate.sh && checkupdate && getcore
|
||||
fi
|
||||
#检查GeoIP数据库
|
||||
if [ ! -f $clashdir/Country.mmdb ];then
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
echo -e "\033[31m没有找到GeoIP数据库文件,请下载数据库文件!\033[0m"
|
||||
checkupdate
|
||||
source $clashdir/getdate.sh && getgeo
|
||||
source $clashdir/getdate.sh && checkupdate && getgeo
|
||||
fi
|
||||
#检查yaml配置文件
|
||||
if [ ! -f "$yaml" ];then
|
||||
|
||||
@@ -4,15 +4,17 @@
|
||||
webget(){
|
||||
[ -n "$(pidof clash)" ] && export all_proxy="http://127.0.0.1:$mix_port" #设置临时http代理
|
||||
#参数【$1】代表下载目录,【$2】代表在线地址
|
||||
#参数【$3】代表输出显示,【$4】不启用重定向
|
||||
if curl --version > /dev/null 2>&1;then
|
||||
[ -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
|
||||
[ -z "$3" ] && progress='--show-progress' || progress=''
|
||||
wget -Y on -q $progress --no-check-certificate --timeout=5 -O $1 $2
|
||||
[ $? -eq 0 ] && result="200"
|
||||
[ "$3" = "echooff" ] && progress='-s' || progress='-#'
|
||||
[ -z "$4" ] && redirect='-L' || redirect=''
|
||||
result=$(curl -w %{http_code} --connect-timeout 5 $progress $redirect -ko $1 $2)
|
||||
else
|
||||
echo 找不到curl或者wget,无法下载,请先安装相应依赖!
|
||||
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
|
||||
[ "$3" = "echoon" ] && progress=''
|
||||
[ -z "$4" ] && redirect='' || redirect='--max-redirect=0'
|
||||
wget -Y on $progress $redirect --no-check-certificate --timeout=5 -O $1 $2
|
||||
[ $? -eq 0 ] && result="200"
|
||||
fi
|
||||
export all_proxy=''
|
||||
}
|
||||
@@ -783,15 +785,14 @@ setserver(){
|
||||
checkupdate(){
|
||||
if [ -z "$release_new" ];then
|
||||
if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ];then
|
||||
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
|
||||
release_new=$(webget /dev/null https://github.com.cnpmjs.org/juewuy/ShellClash/releases/latest echoon rediroff 2>&1 | grep -oE "releases/tag/.*" | awk -F '[/" ]' '{print $3}')
|
||||
[ -z "$release_new" ] && release_new=master
|
||||
update_url=$update_url@$release_new
|
||||
fi
|
||||
webget /tmp/clashversion $update_url/bin/version noprogress
|
||||
webget /tmp/clashversion $update_url/bin/version echooff
|
||||
[ "$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(){
|
||||
@@ -820,16 +821,18 @@ update(){
|
||||
clashsh
|
||||
elif [ "$num" = 1 ]; then
|
||||
getsh
|
||||
|
||||
|
||||
elif [ "$num" = 2 ]; then
|
||||
getcore
|
||||
|
||||
update
|
||||
|
||||
elif [ "$num" = 3 ]; then
|
||||
getgeo
|
||||
update
|
||||
|
||||
elif [ "$num" = 4 ]; then
|
||||
getdb
|
||||
update
|
||||
|
||||
elif [ "$num" = 5 ]; then
|
||||
setpac
|
||||
|
||||
@@ -291,8 +291,19 @@ daemon(){
|
||||
fi
|
||||
}
|
||||
web_save(){
|
||||
#使用curl获取面板节点设置
|
||||
curl -s -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" http://localhost:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g'| sed 's/"//g' > /tmp/clash_web_save
|
||||
get_save(){
|
||||
if curl --version > /dev/null 2>&1;then
|
||||
curl -s -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" "$1"
|
||||
elif [ -n "$(wget --help 2>&1|grep '\-\-method')" ];then
|
||||
wget -q --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" -O - "$1"
|
||||
else
|
||||
logger 当前系统未安装curl且wget的版本太低,无法保存节点配置!
|
||||
getconfig
|
||||
sed -i /保存节点配置/d $cronpath >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
#使用get_save获取面板节点设置
|
||||
get_save http://localhost:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g'| sed 's/"//g' > /tmp/clash_web_save
|
||||
#对比文件,如果有变动则写入磁盘,否则清除缓存
|
||||
if [ "$(cat /tmp/clash_web_save)" = "$(cat $clashdir/web_save 2>/dev/null)" ];then
|
||||
rm -rf /tmp/clash_web_save
|
||||
@@ -301,12 +312,24 @@ web_save(){
|
||||
fi
|
||||
}
|
||||
web_restore(){
|
||||
put_save(){
|
||||
if curl --version > /dev/null 2>&1;then
|
||||
curl -sS -X PUT -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" "$1" -d "$2" >/dev/null
|
||||
else
|
||||
wget --method=PUT --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" --body-data="$2" "$1" >/dev/null
|
||||
fi
|
||||
}
|
||||
#设置循环检测clash面板端口
|
||||
i=1
|
||||
while [ $i -lt 10 ]
|
||||
do
|
||||
sleep 1
|
||||
[ -n "$(curl -s http://localhost:${db_port})" ] && i=10
|
||||
if curl --version > /dev/null 2>&1;then
|
||||
test=$(curl -s http://localhost:${db_port})
|
||||
else
|
||||
test=$(wget -q -O - http://localhost:${db_port})
|
||||
fi
|
||||
[ -n "$test" ] && i=10
|
||||
done
|
||||
#发送数据
|
||||
num=$(cat $clashdir/web_save | wc -l)
|
||||
@@ -314,7 +337,7 @@ web_restore(){
|
||||
do
|
||||
group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' $clashdir/web_save | sed 's/ /%20/g')
|
||||
now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' $clashdir/web_save)
|
||||
curl -sS -X PUT -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" http://localhost:${db_port}/proxies/"${group_name}" -d "{\"name\":\"${now_name}\"}" >/dev/null
|
||||
put_save http://localhost:${db_port}/proxies/${group_name} "{\"name\":\"${now_name}\"}"
|
||||
done
|
||||
exit 0
|
||||
}
|
||||
@@ -336,13 +359,9 @@ afstart(){
|
||||
mark_time
|
||||
#设置本机代理
|
||||
[ "$local_proxy" = "已开启" ] && $0 set_proxy $mix_port $hostdir
|
||||
#还原面板配置相关
|
||||
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
|
||||
#还原面板配置
|
||||
web_save_auto #启用面板配置自动保存
|
||||
[ -f $clashdir/web_save ] && web_restore & #后台还原面板配置
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
@@ -351,7 +370,6 @@ afstart)
|
||||
afstart
|
||||
;;
|
||||
start)
|
||||
[ -n "$(pidof clash)" ] && logger clash服务已经运行,请勿重复运行! && exit 0
|
||||
#读取配置文件
|
||||
getconfig
|
||||
#使用内置规则强行覆盖config配置文件
|
||||
@@ -372,9 +390,7 @@ stop)
|
||||
#读取配置文件
|
||||
getconfig
|
||||
#保存面板配置
|
||||
if curl --version > /dev/null 2>&1;then
|
||||
web_save
|
||||
fi
|
||||
web_save
|
||||
#删除守护进程&面板配置自动保存
|
||||
sed -i /clash保守模式守护进程/d $cronpath >/dev/null 2>&1
|
||||
sed -i /保存节点配置/d $cronpath >/dev/null 2>&1
|
||||
|
||||
Reference in New Issue
Block a user