From ce907f5a6dacec53cac8b70e53964f835e6faa99 Mon Sep 17 00:00:00 2001 From: juewuy Date: Wed, 10 Jan 2024 22:02:15 +0800 Subject: [PATCH] =?UTF-8?q?v1.8.5d=20~=E5=85=A8=E9=9D=A2=E9=80=82=E9=85=8D?= =?UTF-8?q?singbox=E5=86=85=E6=A0=B8(=E8=87=AA=E5=AE=9A=E4=B9=89=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=92=8C=E8=A7=84=E5=88=99=E7=9B=B8=E5=85=B3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E9=99=A4=E5=A4=96)=20=20=20=C2=B7=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86singbox=E4=B8=93=E5=B1=9Edns=E6=A8=A1=E5=BC=8F-mix?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=20=20=20=C2=B7=E5=A2=9E=E5=8A=A0=E4=BA=86sin?= =?UTF-8?q?gbox=E6=95=B0=E6=8D=AE=E5=BA=93=E6=96=87=E4=BB=B6=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=20=20=20=C2=B7=E5=A2=9E=E5=8A=A0=E4=BB=8E/tmp?= =?UTF-8?q?=E5=AF=BC=E5=85=A5singbox=E5=86=85=E6=A0=B8=E5=8F=8Asingbox?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=9A=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20~=E6=AD=A3=E5=BC=8F=E6=94=B9=E5=90=8D=E4=B8=BAShellCrash?= =?UTF-8?q?=E5=B9=B6=E8=B0=83=E6=95=B4=E8=84=9A=E6=9C=AC=E5=86=85=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E8=AF=B4=E6=98=8E=20~=E9=87=8D=E5=86=99systemd?= =?UTF-8?q?=E5=92=8Cprocd=E5=90=AF=E5=8A=A8=E8=84=9A=E6=9C=AC=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=AF=E5=8A=A8=E6=B5=81=E7=A8=8B=E5=92=8C?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=97=A5=E5=BF=97=20~=E9=87=8D=E5=86=99?= =?UTF-8?q?=E4=BF=9D=E5=AE=88=E6=A8=A1=E5=BC=8F=E5=8F=8A=E6=9C=AC=E6=9C=BA?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E9=80=82=E9=85=8Dsingbox=E5=86=85=E6=A0=B8=20~=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=AC=AC=E4=B8=89=E6=96=B9Geo=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD=20~=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=97=A7=E7=89=88=E4=BB=BB=E5=8A=A1=E7=AE=A1=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=8F=AF=E5=AE=9A=E6=97=B6=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E9=87=8D=E5=90=AF=E7=9A=84=E4=BB=BB=E5=8A=A1=20~?= =?UTF-8?q?=E4=BF=9D=E5=AE=88=E6=A8=A1=E5=BC=8F=E5=90=AF=E5=8A=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20~=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E7=94=9F=E6=88=90=E6=9C=8D=E5=8A=A1=E5=99=A8=E4=BB=A5?= =?UTF-8?q?=E9=80=82=E9=85=8Dsingbox=E9=85=8D=E7=BD=AE=E7=94=9F=E6=88=90?= =?UTF-8?q?=20~=E8=87=AA=E5=AE=9A=E4=B9=89clash=E8=8A=82=E7=82=B9=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=8F=90=E7=A4=BA=E4=BC=98=E5=8C=96=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E7=9B=B8=E5=85=B3bug=20~=E4=BF=AE=E5=A4=8D=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E4=BB=BB=E5=8A=A1=E6=AF=8F10=E5=88=86=E9=92=9F?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E8=8A=82=E7=82=B9=E9=85=8D=E7=BD=AE=E6=9C=AA?= =?UTF-8?q?=E7=94=9F=E6=95=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 14 +- public/servers.list | 34 +- public/task.list | 8 +- scripts/getdate.sh | 874 +++++++------ scripts/init.sh | 97 +- scripts/menu.sh | 434 +++---- scripts/misnap_init.sh | 4 +- scripts/{shellcrash.rc => shellcrash.procd} | 14 +- scripts/shellcrash.service | 8 +- scripts/start.sh | 1239 ++++++++++--------- scripts/task.sh | 229 ++-- 11 files changed, 1536 insertions(+), 1419 deletions(-) rename scripts/{shellcrash.rc => shellcrash.procd} (74%) diff --git a/install.sh b/install.sh index b6712f7..9c434db 100644 --- a/install.sh +++ b/install.sh @@ -174,7 +174,7 @@ if [ ! -w $dir ];then else $echo "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)" read -p "确认安装?(1/0) > " res - [ "$res" = "1" ] && CRASHDIR=$dir/clash || setdir + [ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir fi } install(){ @@ -225,20 +225,20 @@ read -p "请输入相应数字 > " num if [ -z $num ];then echo 安装已取消! && exit 1; elif [ "$num" = "2" ];then - webget /tmp/clashrelease $url_cdn@master/bin/release_version echoon rediroff 2>/tmp/clashrelease + webget /tmp/release_version $url_cdn@master/bin/release_version echoon rediroff 2>/tmp/release_version if [ "$result" = "200" ];then - release_new=$(cat /tmp/clashrelease | head -1) + release_new=$(cat /tmp/release_version | head -1) url_dl="$url_cdn@$release_new" else $echo "\033[33m无法获取稳定版安装地址,将尝试安装公测版!\033[0m" fi fi [ -z "$url_dl" ] && url_dl=$url -webget /tmp/clashversion "$url_dl/bin/version" echooff -[ "$result" = "200" ] && versionsh=$(cat /tmp/clashversion | grep "versionsh" | awk -F "=" '{print $2}') +webget /tmp/test_version "$url_dl/bin/version" echooff +[ "$result" = "200" ] && versionsh=$(cat /tmp/test_version | grep "versionsh" | awk -F "=" '{print $2}') [ -z "$release_new" ] && release_new=$versionsh -rm -rf /tmp/clashversion -rm -rf /tmp/clashrelease +rm -rf /tmp/test_version +rm -rf /tmp/release_version tarurl=$url_dl/bin/ShellCrash.tar.gz #输出 diff --git a/public/servers.list b/public/servers.list index 2f59494..01d0298 100644 --- a/public/servers.list +++ b/public/servers.list @@ -1,32 +1,32 @@ # ID&类型 说明 地址 其他说明 (类型:100-稳定源;200-测试源;300-基础sub;400-meta_sub;500-规则地址) -101 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellClash 稳定版 -102 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellClash 稳定版 +101 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellCrash 稳定版 +102 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellCrash 稳定版 -201 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellClash@master 公测版 +201 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master 公测版 202 ShellClash自建源 https://gh.jwsc.eu.org/master 公测版 -203 ShellClash-cfworkers源 https://gh.shellclash.workers.dev/https://raw.githubusercontent.com/juewuy/ShellClash 公测版 -204 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellClash/master 公测版 +203 ShellClash-cfworkers源 https://gh.shellclash.workers.dev/https://raw.githubusercontent.com/juewuy/ShellCrash 公测版 +204 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellCrash/master 公测版 205 (请加讨论组-https://t.me/ShellClash) http://t.jwsc.eu.org 内测版 206 wwng2333自建CN源 https://mirrors.csgo.ovh/ShellClash 公测版 -301 墙洞提供 https://api.dler.io -302 SUB作者提供 https://sub.xeton.dev -303 猫熊提供 https://sub.maoxiongnet.com +301 墙洞提供,不支持vless|hy https://api.dler.io +302 SUB作者提供,不支持vless|hy https://sub.xeton.dev +303 品云提供,不支持vless|hy https://sub.id9.cc -401 肥羊提供(有广告),支持vless|hy https://sub.d1.mk -402 品云提供,支持vless|hy https://v.id9.cc -403 作者提供,支持vless|hy https://sub.jwsc.eu.org +401 肥羊提供(有广告),支持vless|hy2 https://sub.d1.mk +402 肥羊提供(有广告),支持vless|hy2 https://api.v1.mk +403 作者提供,支持vless|hy2 https://sub.jwsc.eu.org 497 作者提供,未加密仅备用 http://sub2.jwsc.eu.org 498 本地服务器 http://127.0.0.1:25500 -501 Acl4SSR全能优化版 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash.ini (推荐) -502 Acl4SSR精简优化版 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Mini.ini (推荐) -503 Acl4SSR全能优化+去广告增强 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Block.ini -504 Acl4SSR极简版 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Nano.ini (适合自建节点) -505 Acl4SSR分流&游戏增强 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Full.ini -506 Acl4SSR分流&游戏&去广告增强 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Full_Block.ini (低性能设备慎用) +501 Acl4SSR全能优化版 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash.ini (推荐) +502 Acl4SSR精简优化版 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash_Mini.ini (推荐) +503 Acl4SSR全能优化+去广告增强 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash_Block.ini +504 Acl4SSR极简版 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash_Nano.ini (适合自建节点) +505 Acl4SSR分流&游戏增强 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash_Full.ini +506 Acl4SSR分流&游戏&去广告增强 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash_Full_Block.ini (低性能设备慎用) 507 洞主规则精简版 https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_clash.ini 508 洞主规则重度完整版 https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_dler.ini 509 Acl4SSR多国精简 https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiCountry.ini diff --git a/public/task.list b/public/task.list index 14d00a4..9ec771f 100644 --- a/public/task.list +++ b/public/task.list @@ -3,14 +3,16 @@ 101#$CRASHDIR/start.sh start#启动clash服务 102#$CRASHDIR/start.sh stop#停止clash服务 103#$CRASHDIR/start.sh restart#重启clash服务 -104#$CRASHDIR/start.sh getyaml && $CRASHDIR/start.sh restart#更新订阅并重启服务 -105#$CRASHDIR/start.sh updateyaml#热更新订阅 +104#$CRASHDIR/start.sh update_config#更新订阅并重启服务 +105#$CRASHDIR/start.sh hotupdate#热更新订阅 106#$CRASHDIR/start.sh web_save#自动保存面板配置 -107#$CRASHDIR/start.sh ntp#自动同步ntp时间 +107#$CRASHDIR/task/task.sh ntp#自动同步ntp时间 111#$CRASHDIR/task/task.sh update_core#自动更新内核 112#$CRASHDIR/task/task.sh update_shellclash#自动更新脚本 113#$CRASHDIR/task/task.sh update_mmdb#自动更新数据库文件 121#$CRASHDIR/task/task.sh reset_firewall#重设透明路由防火墙 +122#reboot#重启路由设备(慎用) + diff --git a/scripts/getdate.sh b/scripts/getdate.sh index 1345213..8170121 100644 --- a/scripts/getdate.sh +++ b/scripts/getdate.sh @@ -4,219 +4,13 @@ error_down(){ echo -e "\033[33m请尝试切换至其他安装源后重新下载!\033[0m" sleep 1 - setserver } dir_avail(){ - df $2 $1 |awk '{ for(i=1;i<=NF;i++){ if(NR==1){ arr[i]=$i; }else{ arr[i]=arr[i]" "$i; } } } END{ for(i=1;i<=NF;i++){ print arr[i]; } }' |grep -E 'Ava|可用' |awk '{print $2}' + df -h &>/dev/null && h=$2 + df $h $1 |awk '{ for(i=1;i<=NF;i++){ if(NR==1){ arr[i]=$i; }else{ arr[i]=arr[i]" "$i; } } } END{ for(i=1;i<=NF;i++){ print arr[i]; } }' |grep -E 'Ava|可用' |awk '{print $2}' } #导入订阅、配置文件相关 -linkconfig(){ - echo ----------------------------------------------- - echo 当前使用规则为:$(grep -aE '^5' $CRASHDIR/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $2}') - grep -aE '^5' $CRASHDIR/configs/servers.list | awk '{print " "NR" "$2$4}' - echo ----------------------------------------------- - echo 0 返回上级菜单 - read -p "请输入对应数字 > " num - totalnum=$(grep -acE '^5' $CRASHDIR/configs/servers.list ) - if [ -z "$num" ] || [ "$num" -gt "$totalnum" ];then - errornum - elif [ "$num" = 0 ];then - echo - elif [ "$num" -le "$totalnum" ];then - #将对应标记值写入配置 - rule_link=$num - setconfig rule_link $rule_link - echo ----------------------------------------------- - echo -e "\033[32m设置成功!返回上级菜单\033[0m" - fi -} -linkserver(){ - echo ----------------------------------------------- - echo -e "\033[36m以下为互联网采集的第三方服务器,具体安全性请自行斟酌!\033[0m" - echo -e "\033[32m感谢以下作者的无私奉献!!!\033[0m" - echo 当前使用后端为:$(grep -aE '^3|^4' $CRASHDIR/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}') - grep -aE '^3|^4' $CRASHDIR/configs/servers.list | awk '{print " "NR" "$3" "$2}' - echo ----------------------------------------------- - echo 0 返回上级菜单 - read -p "请输入对应数字 > " num - totalnum=$(grep -acE '^3|^4' $CRASHDIR/configs/servers.list ) - if [ -z "$num" ] || [ "$num" -gt "$totalnum" ];then - errornum - elif [ "$num" = 0 ];then - echo - elif [ "$num" -le "$totalnum" ];then - #将对应标记值写入配置 - server_link=$num - setconfig server_link $server_link - echo ----------------------------------------------- - echo -e "\033[32m设置成功!返回上级菜单\033[0m" - fi -} -linkfilter(){ - [ -z "$exclude" ] && exclude="未设置" - echo ----------------------------------------------- - echo -e "\033[33m当前过滤关键字:\033[47;30m$exclude\033[0m" - echo ----------------------------------------------- - echo -e "\033[33m匹配关键字的节点会在导入时被【屏蔽】!!!\033[0m" - echo -e "多个关键字可以用\033[30;47m | \033[0m号分隔" - echo -e "\033[32m支持正则表达式\033[0m,空格请使用\033[30;47m + \033[0m号替代" - echo ----------------------------------------------- - echo -e " 000 \033[31m删除\033[0m关键字" - echo -e " 回车 取消输入并返回上级菜单" - echo ----------------------------------------------- - read -p "请输入关键字 > " exclude - if [ "$exclude" = '000' ]; then - echo ----------------------------------------------- - exclude='' - echo -e "\033[31m 已删除节点过滤关键字!!!\033[0m" - fi - setconfig exclude \'$exclude\' -} -linkfilter2(){ - [ -z "$include" ] && include="未设置" - echo ----------------------------------------------- - echo -e "\033[33m当前筛选关键字:\033[47;30m$include\033[0m" - echo ----------------------------------------------- - echo -e "\033[33m仅有匹配关键字的节点才会被【导入】!!!\033[0m" - echo -e "多个关键字可以用\033[30;47m | \033[0m号分隔" - echo -e "\033[32m支持正则表达式\033[0m,空格请使用\033[30;47m + \033[0m号替代" - echo ----------------------------------------------- - echo -e " 000 \033[31m删除\033[0m关键字" - echo -e " 回车 取消输入并返回上级菜单" - echo ----------------------------------------------- - read -p "请输入关键字 > " include - if [ "$include" = '000' ]; then - echo ----------------------------------------------- - include='' - echo -e "\033[31m 已删除节点匹配关键字!!!\033[0m" - fi - setconfig include \'$include\' -} -getyaml(){ - $CRASHDIR/start.sh getyaml - if [ "$?" = 0 ];then - if [ "$inuserguide" != 1 ];then - read -p "是否启动服务以使配置文件生效?(1/0) > " res - [ "$res" = 1 ] && clashstart || clashsh - exit; - fi - fi -} -getlink(){ - echo ----------------------------------------------- - echo -e "\033[30;47m 欢迎使用在线生成配置文件功能!\033[0m" - echo ----------------------------------------------- - #设置输入循环 - i=1 - while [ $i -le 99 ] - do - echo ----------------------------------------------- - echo -e "\033[33m本功能依赖第三方在线subconverter服务实现,脚本本身不提供任何代理服务!\033[0m" - echo -e "\033[31m严禁使用本脚本从事任何非法活动,否则一切后果请自负!\033[0m" - echo ----------------------------------------------- - echo -e "支持批量(<=99)导入订阅链接、分享链接" - echo ----------------------------------------------- - echo -e " 1 \033[36m开始生成配置文件\033[0m(原文件将被备份)" - echo -e " 2 设置\033[31m节点过滤\033[0m关键字 \033[47;30m$exclude\033[0m" - echo -e " 3 设置\033[32m节点筛选\033[0m关键字 \033[47;30m$include\033[0m" - echo -e " 4 选取在线\033[33m配置规则模版\033[0m" - echo -e " 5 \033[0m选取在线生成服务器\033[0m" - echo -e " 0 \033[31m撤销输入并返回上级菜单\033[0m" - echo ----------------------------------------------- - read -p "请直接输入第${i}个链接或对应数字选项 > " link - link=$(echo $link | sed 's/\&/%26/g') #处理分隔符 - test=$(echo $link | grep "://") - link=`echo ${link/\#*/''}` #删除链接附带的注释内容 - link=`echo ${link/\ \(*\)/''}` #删除恶心的超链接内容 - link=`echo ${link/*\&url\=/""}` #将clash完整链接还原成单一链接 - link=`echo ${link/\&config\=*/""}` #将clash完整链接还原成单一链接 - - if [ -n "$test" ];then - if [ -z "$Url_link" ];then - Url_link="$link" - else - Url_link="$Url_link"\|"$link" - fi - i=$((i+1)) - - elif [ "$link" = '1' ]; then - if [ -n "$Url_link" ];then - i=100 - #将用户链接写入配置 - setconfig Https - setconfig Url \'$Url_link\' - #获取在线yaml文件 - getyaml - else - echo ----------------------------------------------- - echo -e "\033[31m请先输入订阅或分享链接!\033[0m" - sleep 1 - fi - - elif [ "$link" = '2' ]; then - linkfilter - - elif [ "$link" = '3' ]; then - linkfilter2 - - elif [ "$link" = '4' ]; then - linkconfig - - elif [ "$link" = '5' ]; then - linkserver - - elif [ "$link" = 0 ];then - Url_link="" - i=100 - - else - echo ----------------------------------------------- - echo -e "\033[31m请输入正确的链接或者数字!\033[0m" - sleep 1 - fi - done -} -getlink2(){ - echo ----------------------------------------------- - echo -e "\033[32m仅限导入完整clash配置文件链接!!!\033[0m" - echo ----------------------------------------------- - echo -e "\033[33m有流媒体需求,请使用\033[32m6-1在线生成配置文件功能!!!\033[0m" - echo -e "\033[33m如不了解机制,请使用\033[32m6-1在线生成配置文件功能!!!\033[0m" - echo -e "\033[33m如遇任何问题,请使用\033[32m6-1在线生成配置文件功能!!!\033[0m" - echo -e "\033[31m此功能可能会导致部分节点无法连接或者规则覆盖不完整!!!\033[0m" - echo ----------------------------------------------- - echo -e "\033[33m0 返回上级菜单\033[0m" - echo ----------------------------------------------- - read -p "请输入完整链接 > " link - test=$(echo $link | grep -iE "tp.*://" ) - link=`echo ${link/\ \(*\)/''}` #删除恶心的超链接内容 - link=`echo ${link//\&/\\\&}` #处理分隔符 - if [ -n "$link" -a -n "$test" ];then - echo ----------------------------------------------- - echo -e 请检查输入的链接是否正确: - echo -e "\033[4;32m$link\033[0m" - read -p "确认导入配置文件?原配置文件将被更名为config.yaml.bak![1/0] > " res - if [ "$res" = '1' ]; then - #将用户链接写入配置 - sed -i '/Url=*/'d $CFG_PATH - setconfig Https \'$link\' - setconfig Url - #获取在线yaml文件 - getyaml - else - getlink2 - fi - elif [ "$link" = 0 ];then - i= - else - echo ----------------------------------------------- - echo -e "\033[31m请输入正确的配置文件链接地址!!!\033[0m" - echo -e "\033[33m仅支持http、https、ftp以及ftps链接!\033[0m" - sleep 1 - getlink2 - fi -} -setrules(){ +setrules(){ #自定义clash规则 set_rule_type(){ echo ----------------------------------------------- echo -e "\033[33m请选择规则类型\033[0m" @@ -340,13 +134,13 @@ setrules(){ ;; esac } -setgroups(){ +setgroups(){ #自定义clash策略组 set_group_type(){ echo ----------------------------------------------- echo -e "\033[33m注意策略组名称必须和【自定义规则】或【自定义节点】功能中指定的策略组一致!\033[0m" echo -e "\033[33m建议先创建策略组,之后可在【自定义规则】或【自定义节点】功能中智能指定\033[0m" echo -e "\033[33m如需在当前策略组下添加节点,请手动编辑$YAMLSDIR/proxy-groups.yaml\033[0m" - read -p "请输入自定义策略组名称(不支持纯数字) > " new_group_name + read -p "请输入自定义策略组名称(不支持纯数字且不要包含特殊字符!) > " new_group_name echo ----------------------------------------------- echo -e "\033[32m请选择策略组【$new_group_name】的类型!\033[0m" echo $group_type_cn | awk '{for(i=1;i<=NF;i++){print i" "$i}}' @@ -432,14 +226,20 @@ EOF ;; esac } -setproxies(){ +setproxies(){ #自定义clash节点 set_proxy_type(){ echo ----------------------------------------------- echo -e "\033[33m注意节点格式必须是单行,不包括括号,name:必须写在最前,例如:\033[0m" echo -e "\033[36m【name: \"test\", server: 192.168.1.1, port: 12345, type: socks5, udp: true】\033[0m" echo -e "更多写法请参考:\033[32m https://juewuy.github.io/ \033[0m" read -p "请输入节点 > " proxy_state_set - [ -n "$(echo $proxy_state_set | grep -E "^name:")" ] && set_group_add || errornum + if [ -n "$(echo $proxy_state_set | grep "#" )" ];then + echo -e "\033[33m绝对禁止包含【#】号!!!\033[0m" + elif [ -n "$(echo $proxy_state_set | grep -E "^name:" )" ];then + set_group_add + else + errornum + fi } set_group_add(){ echo ----------------------------------------------- @@ -530,50 +330,7 @@ setproxies(){ ;; esac } -override(){ - [ -z "$rule_link" ] && rule_link=1 - [ -z "$server_link" ] && server_link=1 - echo ----------------------------------------------- - echo -e "\033[30;47m 欢迎使用配置文件覆写功能!\033[0m" - echo ----------------------------------------------- - echo -e " 1 自定义\033[32m端口及秘钥\033[0m" - echo -e " 2 管理\033[36m自定义规则\033[0m" - echo -e " 3 管理\033[33m自定义节点\033[0m" - echo -e " 4 管理\033[36m自定义策略组\033[0m" - echo -e " 5 \033[32m自定义\033[0m高级功能" - [ "$disoverride" != 1 ] && echo -e " 9 \033[33m禁用\033[0m配置文件覆写" - echo ----------------------------------------------- - [ "$inuserguide" = 1 ] || echo -e " 0 返回上级菜单" - read -p "请输入对应数字 > " num - case "$num" in - 1) - source $CFG_PATH - if [ -n "$(pidof CrashCore)" ];then - echo ----------------------------------------------- - echo -e "\033[33m检测到服务正在运行,需要先停止服务!\033[0m" - read -p "是否停止服务?(1/0) > " res - if [ "$res" = "1" ];then - $CRASHDIR/start.sh stop - setport - fi - else - setport - fi - override - ;; - 2) - setrules - override - ;; - 3) - setproxies - override - ;; - 4) - setgroups - override - ;; - 5) +set_clash_adv(){ #自定义clash高级规则 [ ! -f $YAMLSDIR/user.yaml ] && cat > $YAMLSDIR/user.yaml < " num + case "$num" in + 1) + source $CFG_PATH + if [ -n "$(pidof CrashCore)" ];then + echo ----------------------------------------------- + echo -e "\033[33m检测到服务正在运行,需要先停止服务!\033[0m" + read -p "是否停止服务?(1/0) > " res + if [ "$res" = "1" ];then + ${CRASHDIR}/start.sh stop + setport + fi + else + setport + fi + override + ;; + 2) + setrules + override + ;; + 3) + setproxies + override + ;; + 4) + setgroups + override + ;; + 5) + [ "$crashcore" = singbox ] && set_singbox_adv || set_clash_adv sleep 3 override ;; @@ -626,14 +446,221 @@ EOF esac } -clashlink(){ +gen_link_config(){ #选择在线规则 + echo ----------------------------------------------- + echo 当前使用规则为:$(grep -aE '^5' ${CRASHDIR}/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $2}') + grep -aE '^5' ${CRASHDIR}/configs/servers.list | awk '{print " "NR" "$2$4}' + echo ----------------------------------------------- + echo 0 返回上级菜单 + read -p "请输入对应数字 > " num + totalnum=$(grep -acE '^5' ${CRASHDIR}/configs/servers.list ) + if [ -z "$num" ] || [ "$num" -gt "$totalnum" ];then + errornum + elif [ "$num" = 0 ];then + echo + elif [ "$num" -le "$totalnum" ];then + #将对应标记值写入配置 + rule_link=$num + setconfig rule_link $rule_link + echo ----------------------------------------------- + echo -e "\033[32m设置成功!返回上级菜单\033[0m" + fi +} +gen_link_server(){ #选择在线服务器 + echo ----------------------------------------------- + echo -e "\033[36m以下为互联网采集的第三方服务器,具体安全性请自行斟酌!\033[0m" + echo -e "\033[32m感谢以下作者的无私奉献!!!\033[0m" + echo 当前使用后端为:$(grep -aE '^3|^4' ${CRASHDIR}/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}') + grep -aE '^3|^4' ${CRASHDIR}/configs/servers.list | awk '{print " "NR" "$3" "$2}' + echo ----------------------------------------------- + echo 0 返回上级菜单 + read -p "请输入对应数字 > " num + totalnum=$(grep -acE '^3|^4' ${CRASHDIR}/configs/servers.list ) + if [ -z "$num" ] || [ "$num" -gt "$totalnum" ];then + errornum + elif [ "$num" = 0 ];then + echo + elif [ "$num" -le "$totalnum" ];then + #将对应标记值写入配置 + server_link=$num + setconfig server_link $server_link + echo ----------------------------------------------- + echo -e "\033[32m设置成功!返回上级菜单\033[0m" + fi +} +gen_link_flt(){ #在线生成节点过滤 + [ -z "$exclude" ] && exclude="未设置" + echo ----------------------------------------------- + echo -e "\033[33m当前过滤关键字:\033[47;30m$exclude\033[0m" + echo ----------------------------------------------- + echo -e "\033[33m匹配关键字的节点会在导入时被【屏蔽】!!!\033[0m" + echo -e "多个关键字可以用\033[30;47m | \033[0m号分隔" + echo -e "\033[32m支持正则表达式\033[0m,空格请使用\033[30;47m + \033[0m号替代" + echo ----------------------------------------------- + echo -e " 000 \033[31m删除\033[0m关键字" + echo -e " 回车 取消输入并返回上级菜单" + echo ----------------------------------------------- + read -p "请输入关键字 > " exclude + if [ "$exclude" = '000' ]; then + echo ----------------------------------------------- + exclude='' + echo -e "\033[31m 已删除节点过滤关键字!!!\033[0m" + fi + setconfig exclude \'$exclude\' +} +gen_link_ele(){ #在线生成节点筛选 + [ -z "$include" ] && include="未设置" + echo ----------------------------------------------- + echo -e "\033[33m当前筛选关键字:\033[47;30m$include\033[0m" + echo ----------------------------------------------- + echo -e "\033[33m仅有匹配关键字的节点才会被【导入】!!!\033[0m" + echo -e "多个关键字可以用\033[30;47m | \033[0m号分隔" + echo -e "\033[32m支持正则表达式\033[0m,空格请使用\033[30;47m + \033[0m号替代" + echo ----------------------------------------------- + echo -e " 000 \033[31m删除\033[0m关键字" + echo -e " 回车 取消输入并返回上级菜单" + echo ----------------------------------------------- + read -p "请输入关键字 > " include + if [ "$include" = '000' ]; then + echo ----------------------------------------------- + include='' + echo -e "\033[31m 已删除节点匹配关键字!!!\033[0m" + fi + setconfig include \'$include\' +} +get_core_config(){ #调用工具下载 + ${CRASHDIR}/start.sh get_core_config + if [ "$?" = 0 ];then + if [ "$inuserguide" != 1 ];then + read -p "是否启动服务以使配置文件生效?(1/0) > " res + [ "$res" = 1 ] && start_core || main_menu + exit; + fi + fi +} +gen_core_config_link(){ #在线生成工具 + echo ----------------------------------------------- + echo -e "\033[30;47m 欢迎使用在线生成配置文件功能!\033[0m" + echo ----------------------------------------------- + #设置输入循环 + i=1 + while [ $i -le 99 ] + do + echo ----------------------------------------------- + echo -e "\033[33m本功能依赖第三方在线subconverter服务实现,脚本本身不提供任何代理服务!\033[0m" + echo -e "\033[31m严禁使用本脚本从事任何非法活动,否则一切后果请自负!\033[0m" + echo ----------------------------------------------- + echo -e "支持批量(<=99)导入订阅链接、分享链接" + echo ----------------------------------------------- + echo -e " 1 \033[36m开始生成配置文件\033[0m(原文件将被备份)" + echo -e " 2 设置\033[31m节点过滤\033[0m关键字 \033[47;30m$exclude\033[0m" + echo -e " 3 设置\033[32m节点筛选\033[0m关键字 \033[47;30m$include\033[0m" + echo -e " 4 选取在线\033[33m配置规则模版\033[0m" + echo -e " 5 \033[0m选取在线生成服务器\033[0m" + echo -e " 0 \033[31m撤销输入并返回上级菜单\033[0m" + echo ----------------------------------------------- + read -p "请直接输入第${i}个链接或对应数字选项 > " link + link=$(echo $link | sed 's/\&/%26/g') #处理分隔符 + test=$(echo $link | grep "://") + link=`echo ${link/\#*/''}` #删除链接附带的注释内容 + link=`echo ${link/\ \(*\)/''}` #删除恶心的超链接内容 + link=`echo ${link/*\&url\=/""}` #将完整链接还原成单一链接 + link=`echo ${link/\&config\=*/""}` #将完整链接还原成单一链接 + + if [ -n "$test" ];then + if [ -z "$Url_link" ];then + Url_link="$link" + else + Url_link="$Url_link"\|"$link" + fi + i=$((i+1)) + + elif [ "$link" = '1' ]; then + if [ -n "$Url_link" ];then + i=100 + #将用户链接写入配置 + setconfig Https + setconfig Url \'$Url_link\' + #获取在线yaml文件 + get_core_config + else + echo ----------------------------------------------- + echo -e "\033[31m请先输入订阅或分享链接!\033[0m" + sleep 1 + fi + + elif [ "$link" = '2' ]; then + gen_link_flt + + elif [ "$link" = '3' ]; then + gen_link_ele + + elif [ "$link" = '4' ]; then + gen_link_config + + elif [ "$link" = '5' ]; then + gen_link_server + + elif [ "$link" = 0 ];then + Url_link="" + i=100 + + else + echo ----------------------------------------------- + echo -e "\033[31m请输入正确的链接或者数字!\033[0m" + sleep 1 + fi + done +} +set_core_config_link(){ #直接导入配置 + echo ----------------------------------------------- + echo -e "\033[32m仅限导入完整的配置文件链接!!!\033[0m" + echo ----------------------------------------------- + echo -e "\033[33m有流媒体需求,请使用\033[32m6-1在线生成配置文件功能!!!\033[0m" + echo -e "\033[33m如不了解机制,请使用\033[32m6-1在线生成配置文件功能!!!\033[0m" + echo -e "\033[33m如遇任何问题,请使用\033[32m6-1在线生成配置文件功能!!!\033[0m" + echo -e "\033[31m此功能可能会导致部分节点无法连接或者规则覆盖不完整!!!\033[0m" + echo ----------------------------------------------- + echo -e "\033[33m0 返回上级菜单\033[0m" + echo ----------------------------------------------- + read -p "请输入完整链接 > " link + test=$(echo $link | grep -iE "tp.*://" ) + link=`echo ${link/\ \(*\)/''}` #删除恶心的超链接内容 + link=`echo ${link//\&/\\\&}` #处理分隔符 + if [ -n "$link" -a -n "$test" ];then + echo ----------------------------------------------- + echo -e 请检查输入的链接是否正确: + echo -e "\033[4;32m$link\033[0m" + read -p "确认导入配置文件?原配置文件将被备份![1/0] > " res + if [ "$res" = '1' ]; then + #将用户链接写入配置 + sed -i '/Url=*/'d $CFG_PATH + setconfig Https \'$link\' + setconfig Url + #获取在线yaml文件 + get_core_config + else + set_core_config_link + fi + elif [ "$link" = 0 ];then + i= + else + echo ----------------------------------------------- + echo -e "\033[31m请输入正确的配置文件链接地址!!!\033[0m" + echo -e "\033[33m仅支持http、https、ftp以及ftps链接!\033[0m" + sleep 1 + set_core_config_link + fi +} +set_core_config(){ #配置文件功能 [ -z "$rule_link" ] && rule_link=1 [ -z "$server_link" ] && server_link=1 + [ "$crashcore" = singbox ] && config_path=${JSONSDIR}/config.json || config_path=${YAMLSDIR}/config.yaml echo ----------------------------------------------- - echo -e "\033[30;47m 欢迎使用导入配置文件功能!\033[0m" + echo -e "\033[30;47m ShellCrash配置文件管理\033[0m" echo ----------------------------------------------- - echo -e " 1 在线\033[32m生成Clash配置文件\033[0m" - echo -e " 2 导入\033[33mClash配置文件链接\033[0m" + echo -e " 1 在线\033[32m生成内核配置文件\033[0m" + echo -e " 2 导入\033[33m外部配置文件链接\033[0m" echo -e " 3 \033[36m管理\033[0m配置文件" echo -e " 4 \033[33m更新\033[0m配置文件" echo -e " 5 设置\033[36m自动更新\033[0m" @@ -657,7 +684,7 @@ clashlink(){ Url_link=$Url fi fi - getlink + gen_core_config_link ;; 2) echo ----------------------------------------------- @@ -668,32 +695,32 @@ clashlink(){ sleep 1 read -p "我确认遇到问题可以自行解决[1/0] > " res if [ "$res" = '1' ]; then - getlink2 + set_core_config_link else echo ----------------------------------------------- echo -e "\033[32m正在跳转……\033[0m" sleep 1 - getlink + gen_core_config_link fi ;; 3) - if [ ! -f $YAMLSDIR/config.yaml.bak ];then + if [ ! -f ${config_path}.bak ];then echo ----------------------------------------------- echo -e "\033[31m没有找到配置文件的备份!\033[0m" - clashlink + set_core_config else echo ----------------------------------------------- - echo -e 备份文件共有"\033[32m`wc -l < $YAMLSDIR/config.yaml.bak`\033[0m"行内容,当前文件共有"\033[32m`wc -l < $YAMLSDIR/config.yaml`\033[0m"行内容 + echo -e 备份文件共有"\033[32m`wc -l < ${config_path}.bak`\033[0m"行内容,当前文件共有"\033[32m`wc -l < ${config_path}`\033[0m"行内容 read -p "确认还原配置文件?此操作不可逆![1/0] > " res if [ "$res" = '1' ]; then - mv $YAMLSDIR/config.yaml.bak $YAMLSDIR/config.yaml + mv ${config_path}.bak ${config_path} echo ----------------------------------------------- echo -e "\033[32m配置文件已还原!请手动重启服务!\033[0m" sleep 1 else echo ----------------------------------------------- echo -e "\033[31m操作已取消!返回上级菜单!\033[0m" - clashlink + set_core_config fi fi ;; @@ -702,7 +729,7 @@ clashlink(){ echo ----------------------------------------------- echo -e "\033[31m没有找到你的配置文件/订阅链接!请先输入链接!\033[0m" sleep 1 - clashlink + set_core_config else echo ----------------------------------------------- echo -e "\033[33m当前系统记录的链接为:\033[0m" @@ -710,15 +737,15 @@ clashlink(){ echo ----------------------------------------------- read -p "确认更新配置文件?[1/0] > " res if [ "$res" = '1' ]; then - getyaml + get_core_config else - clashlink + set_core_config fi fi ;; 5) - source $CRASHDIR/task/task.sh && task_add - clashlink + source ${CRASHDIR}/task/task.sh && task_add + set_core_config ;; 6) checkcfg=$(cat $CFG_PATH) @@ -734,26 +761,26 @@ clashlink(){ } #下载更新相关 gettar(){ - $CRASHDIR/start.sh webget $TMPDIR/clashfm.tar.gz $tarurl + ${CRASHDIR}/start.sh webget ${TMPDIR}/clashfm.tar.gz $tarurl if [ "$?" != "0" ];then echo -e "\033[33m文件下载失败!\033[0m" error_down else - $CRASHDIR/start.sh stop 2>/dev/null + ${CRASHDIR}/start.sh stop 2>/dev/null #解压 echo ----------------------------------------------- echo 开始解压文件! - mkdir -p $CRASHDIR > /dev/null - tar -zxvf "$TMPDIR/clashfm.tar.gz" -C $CRASHDIR/ || tar -zxvf "$TMPDIR/clashfm.tar.gz" --no-same-owner -C $CRASHDIR/ + mkdir -p ${CRASHDIR} > /dev/null + tar -zxvf "${TMPDIR}/clashfm.tar.gz" -C ${CRASHDIR}/ || tar -zxvf "${TMPDIR}/clashfm.tar.gz" --no-same-owner -C ${CRASHDIR}/ if [ $? -ne 0 ];then echo -e "\033[33m文件解压失败!\033[0m" error_down else - source $CRASHDIR/init.sh >/dev/null + source ${CRASHDIR}/init.sh >/dev/null echo -e "\033[32m脚本更新成功!\033[0m" fi fi - rm -rf $TMPDIR/clashfm.tar.gz + rm -rf ${TMPDIR}/clashfm.tar.gz exit } getsh(){ @@ -778,7 +805,7 @@ getsh(){ getcpucore(){ cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]') [ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="armv5" - [ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && [ ! -d /jffs/clash ] && cpucore="armv7" + [ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && [ ! -d /jffs/CrashCore ] && cpucore="armv7" [ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="armv8" [ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386" [ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64" @@ -830,31 +857,28 @@ switch_core(){ echo -e "\033[33m二者Geo数据库及yaml/json配置文件不通用\033[0m" read -p "是否保留相关数据库文件?(1/0) > " res [ "$res" = '0' ] && [ "$core_old" = "clash" ] && { - rm -rf $CRASHDIR/Country.mmdb - rm -rf $CRASHDIR/GeoSite.dat + rm -rf ${CRASHDIR}/Country.mmdb + rm -rf ${CRASHDIR}/GeoSite.dat setconfig Country_v setconfig cn_mini_v setconfig geosite_v } [ "$res" = '0' ] && [ "$core_old" = "singbox" ] && { - rm -rf $CRASHDIR/geoip.db - rm -rf $CRASHDIR/geosite.db + rm -rf ${CRASHDIR}/geoip.db + rm -rf ${CRASHDIR}/geosite.db setconfig geoip_cn_v setconfig geosite_cn_v } read -p "是否保留$core_old相关配置文件?(1/0) > " res - [ "$res" = '0' ] && [ "$core_old" = "clash" ] && rm -rf $CRASHDIR/yamls - [ "$res" = '0' ] && [ "$core_old" = "singbox" ] && rm -rf $CRASHDIR/jsons + [ "$res" = '0' ] && [ "$core_old" = "clash" ] && rm -rf ${CRASHDIR}/yamls + [ "$res" = '0' ] && [ "$core_old" = "singbox" ] && rm -rf ${CRASHDIR}/jsons } if [ "$crashcore" = singbox ];then - COMMAND="$bindir/CrashCore run -D $bindir -c $TMPDIR/config.json >/dev/null" - COMMAND_T="$bindir/CrashCore check -D $bindir -c $TMPDIR/config.json" + COMMAND='"$BINDIR/CrashCore run -D $BINDIR -c $TMPDIR/config.json"' else - COMMAND="$bindir/CrashCore -d $bindir -f $TMPDIR/config.yaml >/dev/null" - COMMAND_T="$bindir/CrashCore -t -d $bindir -f $TMPDIR/config.yaml" + COMMAND='"$BINDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"' fi - setconfig COMMAND $COMMAND $CRASHDIR/configs/service.env - setconfig COMMAND_T $COMMAND_T $CRASHDIR/configs/service.env + setconfig COMMAND "$COMMAND" ${CRASHDIR}/configs/command.env } getcore(){ [ -z "$crashcore" ] && crashcore=clashpre @@ -865,28 +889,28 @@ getcore(){ #获取在线内核文件 echo ----------------------------------------------- echo 正在在线获取$crashcore核心文件…… - $CRASHDIR/start.sh webget $TMPDIR/core.new $corelink + ${CRASHDIR}/start.sh webget ${TMPDIR}/core.new $corelink if [ "$?" = "1" ];then echo -e "\033[31m核心文件下载失败!\033[0m" - rm -rf $TMPDIR/core.new + rm -rf ${TMPDIR}/core.new [ -z "$custcorelink" ] && error_down else - chmod +x $TMPDIR/core.new - $CRASHDIR/start.sh stop + chmod +x ${TMPDIR}/core.new + ${CRASHDIR}/start.sh stop [ "$crashcore" = unknow ] && setcoretype if [ "$crashcore" = singbox ];then - core_v=$($TMPDIR/core.new version 2>/dev/null | grep version | awk '{print $3}') + core_v=$(${TMPDIR}/core.new version 2>/dev/null | grep version | awk '{print $3}') else - core_v=$($TMPDIR/core.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //') + core_v=$(${TMPDIR}/core.new -v 2>/dev/null | grep linux | sed 's/ linux.*//;s/.* //') fi if [ -z "$core_v" ];then echo -e "\033[31m核心文件下载成功但校验失败!请尝试手动指定CPU版本\033[0m" - rm -rf $TMPDIR/core.new + rm -rf ${TMPDIR}/core.new setcpucore else echo -e "\033[32m$crashcore核心下载成功!\033[0m" - mv -f $TMPDIR/core.new $bindir/CrashCore - chmod +x $bindir/CrashCore + mv -f ${TMPDIR}/core.new ${BINDIR}/CrashCore + chmod +x ${BINDIR}/CrashCore setconfig crashcore $crashcore setconfig core_v $core_v switch_core @@ -941,7 +965,7 @@ setcustcore(){ setcore(){ #获取核心及版本信息 [ -z "$crashcore" ] && crashcore="unknow" - [ ! -f $CRASHDIR/CrashCore ] && crashcore="未安装核心" + [ ! -f ${CRASHDIR}/CrashCore ] && crashcore="未安装核心" [ "$crashcore" = singbox ] && core_old=singbox || core_old=clash ### echo ----------------------------------------------- @@ -999,16 +1023,16 @@ setcore(){ getgeo(){ #生成链接 - [ -z "$custcorelink" ] && geolink="$update_url/bin/geodata/$geotype" || geolink="$custcorelink" + [ -z "$custgeolink" ] && geolink="$update_url/bin/geodata/$geotype" || geolink="$custgeolink" echo ----------------------------------------------- echo 正在从服务器获取数据库文件………… - $CRASHDIR/start.sh webget $TMPDIR/$geoname $geolink + ${CRASHDIR}/start.sh webget ${TMPDIR}/$geoname $geolink if [ "$?" = "1" ];then echo ----------------------------------------------- echo -e "\033[31m文件下载失败!\033[0m" error_down else - mv -f $TMPDIR/$geoname $bindir/$geoname + mv -f ${TMPDIR}/$geoname ${BINDIR}/$geoname echo ----------------------------------------------- echo -e "\033[32m$geotype数据库文件下载成功!\033[0m" #全球版GeoIP和精简版CN-IP数据库不共存 @@ -1022,28 +1046,50 @@ getgeo(){ sleep 1 } setcustgeo(){ - checkcustgeo(){ - echo -e "\033[32m正在查找可更新的数据库文件!\033[0m" - $CRASHDIR/start.sh webget $TMPDIR/github_api https://api.github.com/repos/$project/releases/latest - cat $TMPDIR/github_api | grep "browser_download_url" | grep -oiE 'geosite.*\.dat"$|country.*\.mmdb"$|geosite.*\.db"$|geoip.*\.db"$' | sed 's/"//' > $TMPDIR/github_api - if [ -s $TMPDIR/github_api ];then + getcustgeo(){ + echo ----------------------------------------------- + echo 正在从服务器获取数据库文件………… + ${CRASHDIR}/start.sh webget ${TMPDIR}/$geoname $custgeolink + if [ "$?" = "1" ];then echo ----------------------------------------------- - cat $TMPDIR/github_api | awk '{print " "NR" "$3,$2,$4}' - echo -e "0 返回上级菜单" + echo -e "\033[31m文件下载失败!\033[0m" + error_down + else + mv -f ${TMPDIR}/$geoname ${BINDIR}/$geoname + echo ----------------------------------------------- + echo -e "\033[32m$geotype数据库文件下载成功!\033[0m" + fi + sleep 1 + } + checkcustgeo(){ + [ ! -s ${TMPDIR}/geo.list ] && { + echo -e "\033[32m正在查找可更新的数据库文件!\033[0m" + ${CRASHDIR}/start.sh webget ${TMPDIR}/github_api https://api.github.com/repos/$project/releases/latest + cat ${TMPDIR}/github_api | grep "browser_download_url" | grep -oE 'releases/download.*' | grep -oiE 'geosite.*\.dat"$|country.*\.mmdb"$|geosite.*\.db"$|geoip.*\.db"$' | sed 's/"//' > ${TMPDIR}/geo.list + rm -rf ${TMPDIR}/github_api + } + if [ -s ${TMPDIR}/geo.list ];then + echo -e "请选择需要更新的数据库文件:" + echo ----------------------------------------------- + cat ${TMPDIR}/geo.list | awk '{print " "NR" "$1}' + echo -e " 0 返回上级菜单" echo ----------------------------------------------- read -p "请输入对应数字 > " num case "$num" in 0) ;; [1-99]) - if [ "$num" -le "$(wc -l $TMPDIR/github_api)" ];then - geotype=$(sed -n "$num"p $TMPDIR/github_api) - [ -n "$(echo $geo_api | grep -oiE 'GeoSite.*dat')" ] && geoname=GeoSite.dat - [ -n "$(echo $geo_api | grep -oiE 'Country.*mmdb')" ] && geoname=Country.mmdb - [ -n "$(echo $geo_api | grep -oiE 'geosite.*db')" ] && geoname=geosite.db - [ -n "$(echo $geo_api | grep -oiE 'geoip.*db')" ] && geoname=geoip.db - custgeolink=https://raw.githubusercontent.com/$project/release/$geotype - getgeo + if [ "$num" -le "$(wc -l < ${TMPDIR}/geo.list)" ];then + geotype=$(sed -n "$num"p ${TMPDIR}/geo.list) + [ -n "$(echo $geotype | grep -oiE 'GeoSite.*dat')" ] && geoname=GeoSite.dat + [ -n "$(echo $geotype | grep -oiE 'Country.*mmdb')" ] && geoname=Country.mmdb + [ -n "$(echo $geotype | grep -oiE 'geosite.*db')" ] && geoname=geosite.db + [ -n "$(echo $geotype | grep -oiE 'geoip.*db')" ] && geoname=geoip.db + [ -n "$(pidof CrashCore)" ] && \ + custgeolink=https://raw.githubusercontent.com/${project}/release/$geotype || \ + custgeolink=https://fastly.jsdelivr.net/gh/${project}@release/$geotype + getcustgeo + checkcustgeo else errornum fi @@ -1052,55 +1098,61 @@ setcustgeo(){ errornum ;; esac - rm -rf $TMPDIR/github_api else echo -e "\033[31m查找失败,请检查网络连接!\033[0m" sleep 1 fi } + rm -rf ${TMPDIR}/geo.list echo ----------------------------------------------- echo -e "\033[36m自定义数据库需要调用第三方地址,请尽量在服务启动后更新!\033[0m" echo -e "\033[36m自定义数据库不兼容小闪存模式,也不支持自动更新!\033[0m" echo -e "\033[33m继续后如出现任何问题,请务必自行解决,一切提问恕不受理!\033[0m" echo ----------------------------------------------- - sleep 1 read -p "我确认遇到问题可以自行解决[1/0] > " res [ "$res" = '1' ] && { - echo -e "\033[33m此处数据库均源自互联网采集,此处致谢各位作者!\033[0m" - echo -e "\033[33m请点击或复制链接前往项目页面查看具体说明!\033[0m" - echo -e "\033[33m请选择需要更新的数据库项目来源!\033[0m" echo ----------------------------------------------- - echo -e "1 \033[36;4mhttps://github.com/MetaCubeX/meta-rules-dat\033[0m (Clash及SingBox)" - echo -e "2 \033[36;4mhttps://github.com/DustinWin/clash-geosite\033[0m (Clash及SingBox)" - echo -e "3 \033[36;4mhttps://github.com/lyc8503/sing-box-rules\033[0m (仅限SingBox)" - echo -e "4 \033[36;4mhttps://github.com/Loyalsoldier/geoip\033[0m (仅限Clash-GeoIP)" + echo -e "\033[36m此处数据库均源自互联网采集,此处致谢各位作者!\033[0m" + echo -e "\033[32m请点击或复制链接前往项目页面查看具体说明!\033[0m" + echo -e "\033[33m如遇到网络错误请先启动ShellCrash服务!\033[0m" + echo -e "\033[0m请选择需要更新的数据库项目来源:\033[0m" echo ----------------------------------------------- - echo -e "9 \033[33m 自定义数据库链接 \033[0m" - echo -e "0 返回上级菜单" + echo -e " 1 \033[36;4mhttps://github.com/MetaCubeX/meta-rules-dat\033[0m (Clash及SingBox)" + echo -e " 2 \033[36;4mhttps://github.com/DustinWin/clash-geosite\033[0m (Clash及SingBox)" + echo -e " 3 \033[36;4mhttps://github.com/lyc8503/sing-box-rules\033[0m (仅限SingBox)" + echo -e " 4 \033[36;4mhttps://github.com/Loyalsoldier/geoip\033[0m (仅限Clash-GeoIP)" + echo ----------------------------------------------- + echo -e " 9 \033[33m自定义数据库链接 \033[0m" + echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num case "$num" in 0) ;; 1) project=MetaCubeX/meta-rules-dat - checkcustgeo + checkcustgeo + setcustgeo ;; 2) project=DustinWin/clash-geosite - checkcustgeo + checkcustgeo + setcustgeo ;; 3) project=lyc8503/sing-box-rules - checkcustgeo + checkcustgeo + setcustgeo ;; 4) project=Loyalsoldier/geoip - checkcustgeo + checkcustgeo + setcustgeo ;; 9) read -p "请输入自定义数据库的链接地址 > " link [ -n "$link" ] && custgeolink="$link" getgeo + setcustgeo ;; *) errornum @@ -1122,8 +1174,8 @@ setgeo(){ echo -e " 3 Clash全球版GeoIP数据库(约6mb) \033[33m$Country_v\033[0m" echo -e " 4 Clash精简版GeoIP_cn数据库(约0.1mb) \033[33m$cn_mini_v\033[0m" echo -e " 5 Meta完整版GeoSite数据库(约5mb) \033[33m$geosite_v\033[0m" - echo -e " 6 SingBox精简版GeoIP_cn数据库(约0.3mb) \033[33m$Country_v\033[0m" - echo -e " 7 SingBox精简版GeoSite数据库(约0.8mb) \033[33m$cn_mini_v\033[0m" + echo -e " 6 SingBox精简版GeoIP_cn数据库(约0.3mb) \033[33m$geoip_cn_v\033[0m" + echo -e " 7 SingBox精简版GeoSite数据库(约0.8mb) \033[33m$geosite_cn_v\033[0m" echo -e " 9 \033[32m自定义数据库\033[0m: \033[33m仅限专业用户使用\033[0m" echo " 0 返回上级菜单" echo ----------------------------------------------- @@ -1228,7 +1280,7 @@ getdb(){ dblink="${update_url}/bin/dashboard/${db_type}.tar.gz" echo ----------------------------------------------- echo 正在连接服务器获取安装文件………… - $CRASHDIR/start.sh webget $TMPDIR/clashdb.tar.gz $dblink + ${CRASHDIR}/start.sh webget ${TMPDIR}/clashdb.tar.gz $dblink if [ "$?" = "1" ];then echo ----------------------------------------------- echo -e "\033[31m文件下载失败!\033[0m" @@ -1238,10 +1290,10 @@ getdb(){ else echo -e "\033[33m下载成功,正在解压文件!\033[0m" mkdir -p $dbdir > /dev/null - tar -zxvf "$TMPDIR/clashdb.tar.gz" -C $dbdir > /dev/null + tar -zxvf "${TMPDIR}/clashdb.tar.gz" -C $dbdir > /dev/null if [ $? -ne 0 ];then - tar -zxvf "$TMPDIR/clashdb.tar.gz" --no-same-permissions -C $dbdir > /dev/null - [ $? -ne 0 ] && echo "文件解压失败!" && rm -rf $TMPDIR/clashfm.tar.gz && exit 1 + tar -zxvf "${TMPDIR}/clashdb.tar.gz" --no-same-permissions -C $dbdir > /dev/null + [ $? -ne 0 ] && echo "文件解压失败!" && rm -rf ${TMPDIR}/clashfm.tar.gz && exit 1 fi #修改默认host和端口 if [ "$db_type" = "clashdb" -o "$db_type" = "meta_db" -o "$db_type" = "meta_xd" ];then @@ -1255,21 +1307,21 @@ getdb(){ setconfig hostdir \'$hostdir\' echo ----------------------------------------------- echo -e "\033[32m面板安装成功!\033[0m" - rm -rf $TMPDIR/clashdb.tar.gz + rm -rf ${TMPDIR}/clashdb.tar.gz fi sleep 1 } setdb(){ dbdir(){ - if [ -f /www/clash/CNAME -o -f $CRASHDIR/ui/CNAME ];then + if [ -f /www/clash/CNAME -o -f ${CRASHDIR}/ui/CNAME ];then echo ----------------------------------------------- echo -e "\033[31m检测到您已经安装过本地面板了!\033[0m" echo ----------------------------------------------- read -p "是否覆盖安装?[1/0] > " res if [ "$res" = 1 ]; then - rm -rf $bindir/ui + rm -rf ${BINDIR}/ui [ -f /www/clash/CNAME ] && rm -rf /www/clash && dbdir=/www/clash - [ -f $CRASHDIR/ui/CNAME ] && rm -rf $CRASHDIR/ui && dbdir=$CRASHDIR/ui + [ -f ${CRASHDIR}/ui/CNAME ] && rm -rf ${CRASHDIR}/ui && dbdir=${CRASHDIR}/ui getdb else setdb @@ -1279,14 +1331,14 @@ setdb(){ echo ----------------------------------------------- echo -e "请选择面板\033[33m安装目录:\033[0m" echo ----------------------------------------------- - echo -e " 1 在$CRASHDIR/ui目录安装" + echo -e " 1 在${CRASHDIR}/ui目录安装" echo -e " 2 在/www/clash目录安装" echo ----------------------------------------------- echo " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ "$num" = '1' ]; then - dbdir=$CRASHDIR/ui + dbdir=${CRASHDIR}/ui hostdir=":$db_port/ui" getdb elif [ "$num" = '2' ]; then @@ -1298,7 +1350,7 @@ setdb(){ echo -e "\033[33m安装已取消!\033[0m" fi else - dbdir=$CRASHDIR/ui + dbdir=${CRASHDIR}/ui hostdir=":$db_port/ui" getdb fi @@ -1338,8 +1390,8 @@ setdb(){ read -p "确认卸载本地面板?(1/0) > " res if [ "$res" = 1 ];then rm -rf /www/clash - rm -rf $CRASHDIR/ui - rm -rf $bindir/ui + rm -rf ${CRASHDIR}/ui + rm -rf ${BINDIR}/ui echo ----------------------------------------------- echo -e "\033[31m面板已经卸载!\033[0m" sleep 1 @@ -1353,7 +1405,7 @@ getcrt(){ crtlink="${update_url}/bin/fix/ca-certificates.crt" echo ----------------------------------------------- echo 正在连接服务器获取安装文件………… - $CRASHDIR/start.sh webget $TMPDIR/ca-certificates.crt $crtlink + ${CRASHDIR}/start.sh webget ${TMPDIR}/ca-certificates.crt $crtlink if [ "$?" = "1" ];then echo ----------------------------------------------- echo -e "\033[31m文件下载失败!\033[0m" @@ -1361,13 +1413,13 @@ getcrt(){ else echo ----------------------------------------------- mkdir -p $openssldir - mv -f $TMPDIR/ca-certificates.crt $crtdir - $CRASHDIR/start.sh webget $TMPDIR/ssl_test https://baidu.com echooff rediron skipceroff + mv -f ${TMPDIR}/ca-certificates.crt $crtdir + ${CRASHDIR}/start.sh webget ${TMPDIR}/ssl_test https://baidu.com echooff rediron skipceroff if [ "$?" = "1" ];then export CURL_CA_BUNDLE=$crtdir echo "export CURL_CA_BUNDLE=$crtdir" >> /etc/profile fi - rm -rf $TMPDIR/ssl_test + rm -rf ${TMPDIR}/ssl_test echo -e "\033[32m证书安装成功!\033[0m" sleep 1 fi @@ -1414,7 +1466,7 @@ setserver(){ echo -e "\033[30;47m切换ShellCrash版本及更新源地址\033[0m" echo -e "当前源地址:\033[4;32m$update_url\033[0m" echo ----------------------------------------------- - grep -aE '^1|^2' $CRASHDIR/configs/servers.list | awk '{print " "NR" "$4" "$2}' + grep -aE '^1|^2' ${CRASHDIR}/configs/servers.list | awk '{print " "NR" "$4" "$2}' echo ----------------------------------------------- echo -e " a 自定义源地址(用于本地源或自建源)" echo -e " b \033[31m版本回退\033[0m" @@ -1424,11 +1476,11 @@ setserver(){ 0) ;; [1-99]) - release_type=$(grep -aE '^1|^2' $CRASHDIR/configs/servers.list | sed -n ""$num"p" | awk '{print $4}') + release_type=$(grep -aE '^1|^2' ${CRASHDIR}/configs/servers.list | sed -n ""$num"p" | awk '{print $4}') if [ "release_type" = "稳定版" ];then - release_url=$(grep -aE '^1' $CRASHDIR/configs/servers.list | sed -n ""$num"p" | awk '{print $3}') + release_url=$(grep -aE '^1' ${CRASHDIR}/configs/servers.list | sed -n ""$num"p" | awk '{print $3}') else - update_url=$(grep -aE '^1|^2' $CRASHDIR/configs/servers.list | sed -n ""$num"p" | awk '{print $3}') + update_url=$(grep -aE '^1|^2' ${CRASHDIR}/configs/servers.list | sed -n ""$num"p" | awk '{print $3}') unset release_url fi saveserver @@ -1447,15 +1499,15 @@ setserver(){ b) echo ----------------------------------------------- echo -e "\033[33m如无法连接,请务必先启用服务!!!\033[0m" - $CRASHDIR/start.sh webget $TMPDIR/clashrelease https://raw.githubusercontent.com/juewuy/ShellCrash/master/bin/release_version echooff rediroff 2>$TMPDIR/clashrelease + ${CRASHDIR}/start.sh webget ${TMPDIR}/release_new https://raw.githubusercontent.com/juewuy/ShellCrash/master/bin/release_version echooff rediroff 2>${TMPDIR}/release_new echo -e "\033[31m请选择想要回退至的release版本:\033[0m" - cat $TMPDIR/clashrelease | awk '{print " "NR" "$1}' + cat ${TMPDIR}/release_new | awk '{print " "NR" "$1}' echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" -o "$num" = 0 ]; then setserver - elif [ $num -le $(cat $TMPDIR/clashrelease 2>/dev/null | awk 'END{print NR}') ]; then - release_version=$(cat $TMPDIR/clashrelease | awk '{print $1}' | sed -n "$num"p) + elif [ $num -le $(cat ${TMPDIR}/release_new 2>/dev/null | awk 'END{print NR}') ]; then + release_version=$(cat ${TMPDIR}/release_new | awk '{print $1}' | sed -n "$num"p) update_url="https://raw.githubusercontent.com/juewuy/ShellCrash/$release_version" saveserver unset release_url @@ -1463,7 +1515,7 @@ setserver(){ echo ----------------------------------------------- echo -e "\033[31m输入有误,请重新输入!\033[0m" fi - rm -rf $TMPDIR/clashrelease + rm -rf ${TMPDIR}/release_new ;; *) errornum @@ -1475,25 +1527,25 @@ checkupdate(){ if [ -z "$release_new" ];then if [ -n "$release_url" ];then [ -n "$(echo $release_url|grep 'jsdelivr')" ] && check_url=$release_url@master || check_url=$release_url/master - $CRASHDIR/start.sh webget $TMPDIR/clashversion $check_url/bin/release_version echoon rediroff 2>$TMPDIR/clashversion - release_new=$(cat $TMPDIR/clashversion | head -1) + ${CRASHDIR}/start.sh webget ${TMPDIR}/version_new $check_url/bin/release_version echoon rediroff 2>${TMPDIR}/version_new + release_new=$(cat ${TMPDIR}/version_new | head -1) [ -n "$(echo $release_url|grep 'jsdelivr')" ] && update_url=$release_url@$release_new || update_url=$release_url/$release_new setconfig update_url \'$update_url\' release_type=正式版 else release_type=测试版 fi - $CRASHDIR/start.sh webget $TMPDIR/clashversion $update_url/bin/version echooff - [ "$?" = "0" ] && release_new=$(cat $TMPDIR/clashversion | grep -oE 'versionsh=.*' | awk -F'=' '{ print $2 }') + ${CRASHDIR}/start.sh webget ${TMPDIR}/version_new $update_url/bin/version echooff + [ "$?" = "0" ] && release_new=$(cat ${TMPDIR}/version_new | grep -oE 'versionsh=.*' | awk -F'=' '{ print $2 }') if [ -n "$release_new" ];then - source $TMPDIR/clashversion 2>/dev/null + source ${TMPDIR}/version_new 2>/dev/null else echo -e "\033[31m检查更新失败!请切换其他安装源!\033[0m" echo -e "\033[36m如全部安装源都无法使用,请先运行服务后再使用更新功能!\033[0m" sleep 1 setserver fi - rm -rf $TMPDIR/clashversion + rm -rf ${TMPDIR}/version_new fi } update(){ @@ -1504,8 +1556,8 @@ update(){ core_v_new=$(eval echo \$${crashcore}_v) echo -e "\033[30;47m欢迎使用更新功能:\033[0m" echo ----------------------------------------------- - echo -e "当前目录(\033[32m$CRASHDIR\033[0m)剩余空间:\033[36m$(dir_avail $CRASHDIR -h)\033[0m" - [ "$(dir_avail $CRASHDIR)" -le 5120 ] && { + echo -e "当前目录(\033[32m${CRASHDIR}\033[0m)剩余空间:\033[36m$(dir_avail ${CRASHDIR} -h)\033[0m" + [ "$(dir_avail ${CRASHDIR})" -le 5120 ] && { echo -e "\033[33m当前目录剩余空间较低,建议开启小闪存模式!\033[0m" sleep 1 } @@ -1559,7 +1611,7 @@ update(){ setserver update elif [ "$num" = 8 ]; then - source $CRASHDIR/task/task.sh && task_add + source ${CRASHDIR}/task/task.sh && task_add update elif [ "$num" = 9 ]; then @@ -1616,9 +1668,9 @@ userguide(){ setconfig ipv6_dns 已开启 } #设置开机启动 - [ -f /etc/rc.common ] && /etc/init.d/clash enable + [ -f /etc/rc.common ] && /etc/init.d/CrashCore enable ckcmd systemctl && systemctl enable shellcrash.service > /dev/null 2>&1 - rm -rf $CRASHDIR/.dis_startup + rm -rf ${CRASHDIR}/.dis_startup autostart=enable #检测IP转发 if [ "$(cat /proc/sys/net/ipv4/ip_forward)" = "0" ];then @@ -1646,15 +1698,15 @@ userguide(){ } forwhat #检测小内存模式 - dir_size=$(df $CRASHDIR | awk '{print $4}' | sed 1d) + dir_size=$(dir_avail ${CRASHDIR}) if [ "$dir_size" -lt 10240 ];then echo ----------------------------------------------- echo -e "\033[33m检测到你的安装目录空间不足10M,是否开启小闪存模式?\033[0m" echo -e "\033[0m开启后核心及数据库文件将被下载到内存中,这将占用一部分内存空间\033[0m" - echo -e "\033[0m每次开机后首次运行clash时都会自动的重新下载相关文件\033[0m" + echo -e "\033[0m每次开机后首次运行服务时都会自动的重新下载相关文件\033[0m" echo ----------------------------------------------- read -p "是否开启?(1/0) > " res - [ "$res" = 1 ] && setconfig bindir "/tmp/clash_$USER" + [ "$res" = 1 ] && setconfig BINDIR /tmp/ShellCrash ${CRASHDIR}/configs/command.env fi #下载本地面板 # echo ----------------------------------------------- @@ -1671,14 +1723,14 @@ userguide(){ [ "$res" = 1 ] && checkupdate && getcrt fi #设置加密DNS - $CRASHDIR/start.sh webget $TMPDIR/ssl_test https://doh.pub echooff rediron + ${CRASHDIR}/start.sh webget ${TMPDIR}/ssl_test https://doh.pub echooff rediron if [ "$?" = "0" ];then 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' setconfig dns_nameserver \'"$dns_nameserver"\' setconfig dns_fallback \'"$dns_fallback"\' fi - rm -rf $TMPDIR/ssl_test + rm -rf ${TMPDIR}/ssl_test #开启公网访问 sethost(){ read -p "请输入你的公网IP地址 > " host @@ -1698,8 +1750,8 @@ userguide(){ if [ "$res" = 1 ];then read -p "请先设置面板访问秘钥 > " secret read -p "请先修改Socks服务端口(1-65535) > " mix_port - read -p "请先设置Socks服务密码(账号默认为clash) > " sec - [ -z "$sec" ] && authentication=clash:$sec + read -p "请先设置Socks服务密码(账号默认为crash) > " sec + [ -z "$sec" ] && authentication=crash:$sec host=$(curl ip.sb 2>/dev/null | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') if [ -z "$host" ];then sethost @@ -1713,7 +1765,7 @@ userguide(){ fi fi #启用推荐的自动任务配置 - source $CRASHDIR/task/task.sh && task_recom + source ${CRASHDIR}/task/task.sh && task_recom #小米设备软固化 if [ "$systype" = "mi_snapshot" ];then echo ----------------------------------------------- @@ -1727,49 +1779,47 @@ userguide(){ echo -e "\033[0m你必须拥有一份yaml格式的配置文件才能运行服务!\033[0m" echo ----------------------------------------------- read -p "现在开始导入?(1/0) > " res - [ "$res" = 1 ] && inuserguide=1 && clashlink && inuserguide="" + [ "$res" = 1 ] && inuserguide=1 && set_core_config && inuserguide="" #回到主界面 echo ----------------------------------------------- echo -e "\033[36m很好!现在只需要执行启动就可以愉快的使用了!\033[0m" echo ----------------------------------------------- read -p "立即启动服务?(1/0) > " res - [ "$res" = 1 ] && clashstart && sleep 2 - clashsh + [ "$res" = 1 ] && start_core && sleep 2 + main_menu } #测试菜单 testcommand(){ + [ "$crashcore" = singbox ] && config_path=${JSONSDIR}/config.json || config_path=${YAMLSDIR}/config.yaml echo ----------------------------------------------- echo -e "\033[30;47m这里是测试命令菜单\033[0m" echo -e "\033[33m如遇问题尽量运行相应命令后截图提交issue或TG讨论组\033[0m" echo ----------------------------------------------- - echo " 1 查看Clash运行时的报错信息(会停止服务)" + echo " 1 查看内核运行时的报错信息" echo " 2 查看系统DNS端口(:53)占用 " echo " 3 测试ssl加密(aes-128-gcm)跑分" - echo " 4 查看clash相关路由规则" - echo " 5 查看config.yaml前40行" + echo " 4 查看ShellCrash相关路由规则" + echo " 5 查看内核配置文件前40行" echo " 6 测试代理服务器连通性(google.tw)" echo ----------------------------------------------- echo " 0 返回上级目录!" read -p "请输入对应数字 > " num if [ -z "$num" ]; then errornum - clashsh + main_menu elif [ "$num" = 0 ]; then - clashsh + main_menu elif [ "$num" = 1 ]; then - $CRASHDIR/start.sh stop echo ----------------------------------------------- - if $CRASHDIR/clash -v &>/dev/null;then - clash -s modify_yaml &>/dev/null - $CRASHDIR/clash -t -d $CRASHDIR -f $TMPDIR/config.yaml - [ "$?" = 0 ] && testover=32m测试通过!|| testover=31m出现错误!请截图后到TG群询问!!! - echo -e "\033[$testover\033[0m" + ckcmd journalctl && error=$(journalctl -u shellcrash | grep -Eo 'error.*=.*|.*ERROR.*|.*FATAL.*') + [ -z "$error" ] && error=$(cat $TMPDIR/core_test.log | grep -Eo 'error.*=.*|.*ERROR.*|.*FATAL.*') + if [ -n "$error" ];then + echo $error + exit; else - echo -e "\033[31m你没有安装clash内核或内核不完整,请先前往更新界面安装内核!\033[0m" - update - testcommand + echo -e "\033[31m未找到因内核运行错误所产生的日志文件!\033[0m" + sleep 1 fi - exit; elif [ "$num" = 2 ]; then echo ----------------------------------------------- netstat -ntulp |grep 53 @@ -1788,41 +1838,41 @@ testcommand(){ else echo -------------------Redir--------------------- iptables -t nat -L PREROUTING --line-numbers - iptables -t nat -L clash_dns --line-numbers - iptables -t nat -L clash --line-numbers + iptables -t nat -L shellcrash_dns --line-numbers + iptables -t nat -L shellcrash --line-numbers [ -n "$(echo $redir_mod | grep -E 'Tproxy模式|混合模式|Tun模式')" ] && { echo ----------------Tun/Tproxy------------------- iptables -t mangle -L PREROUTING --line-numbers - iptables -t mangle -L clash --line-numbers + iptables -t mangle -L shellcrash --line-numbers } [ "$local_proxy" = "已开启" ] && [ "$local_type" = "iptables增强模式" ] && { echo ----------------OUTPUT------------------- iptables -t nat -L OUTPUT --line-numbers - iptables -t nat -L clash_out --line-numbers + iptables -t nat -L shellcrash_out --line-numbers } [ "$ipv6_redir" = "已开启" ] && { [ -n "$(lsmod | grep 'ip6table_nat')" ] && { echo -------------------Redir--------------------- ip6tables -t nat -L PREROUTING --line-numbers - ip6tables -t nat -L clashv6_dns --line-numbers - ip6tables -t nat -L clashv6 --line-numbers + ip6tables -t nat -L shellcrashv6_dns --line-numbers + ip6tables -t nat -L shellcrashv6 --line-numbers } [ -n "$(echo $redir_mod | grep -E 'Tproxy模式|混合模式|Tun模式')" ] && { echo ----------------Tun/Tproxy------------------- ip6tables -t mangle -L PREROUTING --line-numbers - ip6tables -t mangle -L clashv6 --line-numbers + ip6tables -t mangle -L shellcrashv6 --line-numbers } } fi exit; elif [ "$num" = 5 ]; then echo ----------------------------------------------- - sed -n '1,40p' $CRASHDIR/config.yaml + sed -n '1,40p' ${config_path} echo ----------------------------------------------- exit; elif [ "$num" = 6 ]; then echo "注意:依赖curl(不支持wget),且测试结果不保证一定准确!" - 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=`curl -kx ${authentication}@127.0.0.1:$mix_port -o /dev/null -s -w '%{time_starttransfer}' 'https://google.tw' & { sleep 3 ; kill $! &>/dev/null & }` > /dev/null 2>&1 delay=`echo |awk "{print $delay*1000}"` > /dev/null 2>&1 echo ----------------------------------------------- if [ `echo ${#delay}` -gt 1 ];then @@ -1830,11 +1880,11 @@ testcommand(){ else echo -e "\033[31m连接超时!请重试或检查节点配置!\033[0m" fi - clashsh + main_menu else errornum - clashsh + main_menu fi } diff --git a/scripts/init.sh b/scripts/init.sh index ba86a60..f4d078c 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,7 +1,7 @@ #!/bin/sh # Copyright (C) Juewuy -version=1.8.3e +version=1.8.5d setdir(){ dir_avail(){ @@ -119,16 +119,16 @@ if [ ! -w $dir ];then else echo -e "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)" read -p "确认安装?(1/0) > " res - [ "$res" = "1" ] && CRASHDIR=$dir/clash || setdir + [ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir fi } -setconfig(){ +setconfig(){ #参数1代表变量名,参数2代表变量值,参数3即文件路径 - [ -z "$3" ] && configpath=$CRASHDIR/configs/ShellCrash.cfg || configpath=$3 - [ -n "$(grep -E "^${1}=" $configpath)" ] && sed -i "s#^${1}=\(.*\)#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath + [ -z "$3" ] && configpath=${CRASHDIR}/configs/ShellCrash.cfg || configpath="${3}" + [ -n "$(grep "${1}=" "$configpath")" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath } -$CRASHDIR/start.sh stop 2>/dev/null #防止进程冲突 +${CRASHDIR}/start.sh stop 2>/dev/null #防止进程冲突 #特殊固件识别及标记 [ -f "/etc/storage/started_script.sh" ] && { systype=Padavan #老毛子固件 @@ -144,30 +144,29 @@ $CRASHDIR/start.sh stop 2>/dev/null #防止进程冲突 #检查环境变量 [ -z "$CRASHDIR" -a -n "$clashdir" ] && CRASHDIR=$clashdir -[ -z "$CRASHDIR" -a -d /tmp/SC_tmp ] && { - setdir -} +[ -z "$CRASHDIR" -a -d /tmp/SC_tmp ] && setdir #移动文件 -mkdir -p $CRASHDIR -mv -f /tmp/SC_tmp/* $CRASHDIR 2>/dev/null +mkdir -p ${CRASHDIR} +mv -f /tmp/SC_tmp/* ${CRASHDIR} 2>/dev/null #初始化 -mkdir -p $CRASHDIR/configs -[ -f "$CRASHDIR/configs/ShellCrash.cfg" ] || echo '#ShellCrash配置文件,不明勿动!' > $CRASHDIR/configs/ShellCrash.cfg +mkdir -p ${CRASHDIR}/configs +[ -f "${CRASHDIR}/configs/ShellCrash.cfg" ] || echo '#ShellCrash配置文件,不明勿动!' > ${CRASHDIR}/configs/ShellCrash.cfg #本地安装跳过新手引导 #[ -z "$url" ] && setconfig userguide 1 #判断系统类型写入不同的启动文件 -if [ -f /etc/rc.common ] && [ -n "$(pidof procd)" ];then +if [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ];then #设为init.d方式启动 - cp -f $CRASHDIR/crash.rc /etc/init.d/shellcrash + cp -f ${CRASHDIR}/shellcrash.procd /etc/init.d/shellcrash chmod 755 /etc/init.d/shellcrash else - [ -w /etc/systemd/system ] && sysdir=/etc/systemd/system [ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system - if [ -n "$sysdir" -a -z "$WSL_DISTRO_NAME" ];then #wsl环境不使用systemd + [ -w /etc/systemd/system ] && sysdir=/etc/systemd/system + if [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ];then #设为systemd方式启动 - mv -f $CRASHDIR/shellcrash.service $sysdir/shellcrash.service 2>/dev/null + mv -f ${CRASHDIR}/shellcrash.service $sysdir/shellcrash.service 2>/dev/null sed -i "s%/etc/ShellCrash%$CRASHDIR%g" $sysdir/shellcrash.service + rm -rf $sysdir/clash.service #旧版文件清理 systemctl daemon-reload else #设为保守模式启动 @@ -176,9 +175,23 @@ else fi #修饰文件及版本号 type bash &>/dev/null && shtype=bash || shtype=sh -sed -i "s|/bin/sh|/bin/$shtype|" $CRASHDIR/start.sh -chmod 755 $CRASHDIR/start.sh +for file in start.sh task.sh ;do + sed -i "s|/bin/sh|/bin/$shtype|" ${CRASHDIR}/${file} + chmod 755 ${CRASHDIR}/${file} +done setconfig versionsh_l $version +#生成用于执行systemd及procd服务的变量文件 +TMPDIR='/tmp/ShellCrash' +BINDIR=${CRASHDIR} +touch ${CRASHDIR}/configs/command.env +setconfig TMPDIR ${TMPDIR} ${CRASHDIR}/configs/command.env +setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env +if [ -x ${CRASHDIR}/CrashCore ] && ${CRASHDIR}/CrashCore version &>/dev/null ;then + COMMAND='"$BINDIR/CrashCore run -D $BINDIR -c $TMPDIR/config.json"' +else + COMMAND='"$BINDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"' +fi +setconfig COMMAND "$COMMAND" ${CRASHDIR}/configs/command.env #设置更新地址 [ -n "$url" ] && setconfig update_url $url #设置环境变量 @@ -212,7 +225,7 @@ fi } #镜像化OpenWrt(snapshot)额外设置 if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ];then - chmod 755 $CRASHDIR/misnap_init.sh + chmod 755 ${CRASHDIR}/misnap_init.sh uci delete firewall.ShellClash 2>/dev/null uci delete firewall.ShellCrash 2>/dev/null uci set firewall.ShellCrash=include @@ -222,11 +235,11 @@ if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ];then uci commit firewall setconfig systype $systype else - rm -rf $CRASHDIR/misnap_init.sh + rm -rf ${CRASHDIR}/misnap_init.sh fi #华硕USB启动额外设置 [ "$usb_status" = "1" ] && { - echo "$CRASHDIR/start.sh init #ShellCrash初始化脚本" > $CRASHDIR/asus_usb_mount.sh + echo "$CRASHDIR/start.sh init #ShellCrash初始化脚本" > ${CRASHDIR}/asus_usb_mount.sh nvram set script_usbmount="$CRASHDIR/asus_usb_mount.sh" nvram commit } @@ -234,39 +247,43 @@ fi rm -rf /tmp/*rash*gz rm -rf /tmp/SC_tmp #转换&清理旧版本文件 -mkdir -p $CRASHDIR/yamls -mkdir -p $CRASHDIR/tools -mkdir -p $CRASHDIR/task +mkdir -p ${CRASHDIR}/yamls +mkdir -p ${CRASHDIR}/jsons +mkdir -p ${CRASHDIR}/tools +mkdir -p ${CRASHDIR}/task for file in config.yaml.bak user.yaml proxies.yaml proxy-groups.yaml rules.yaml others.yaml ;do - mv -f $CRASHDIR/$file $CRASHDIR/yamls/$file 2>/dev/null + mv -f ${CRASHDIR}/$file ${CRASHDIR}/yamls/$file 2>/dev/null done - [ ! -L $CRASHDIR/config.yaml ] && mv -f $CRASHDIR/config.yaml $CRASHDIR/yamls/config.yaml 2>/dev/null + [ ! -L ${CRASHDIR}/config.yaml ] && mv -f ${CRASHDIR}/config.yaml ${CRASHDIR}/yamls/config.yaml 2>/dev/null for file in fake_ip_filter mac web_save servers.list fake_ip_filter.list fallback_filter.list;do - mv -f $CRASHDIR/$file $CRASHDIR/configs/$file 2>/dev/null + mv -f ${CRASHDIR}/$file ${CRASHDIR}/configs/$file 2>/dev/null done #配置文件改名 - mv -f $CRASHDIR/mark $CRASHDIR/configs/ShellCrash.cfg 2>/dev/null - mv -f $CRASHDIR/configs/ShellClash.cfg $CRASHDIR/configs/ShellCrash.cfg 2>/dev/null + mv -f ${CRASHDIR}/mark ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null + mv -f ${CRASHDIR}/configs/ShellClash.cfg ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null #内核改名 - mv -f $CRASHDIR/clash $CRASHDIR/CrashCore 2>/dev/null + mv -f ${CRASHDIR}/clash ${CRASHDIR}/CrashCore 2>/dev/null for file in dropbear_rsa_host_key authorized_keys tun.ko ShellDDNS.sh;do - mv -f $CRASHDIR/$file $CRASHDIR/tools/$file 2>/dev/null + mv -f ${CRASHDIR}/$file ${CRASHDIR}/tools/$file 2>/dev/null done for file in cron task.sh task.list;do - mv -f $CRASHDIR/$file $CRASHDIR/task/$file 2>/dev/null + mv -f ${CRASHDIR}/$file ${CRASHDIR}/task/$file 2>/dev/null done -chmod 755 $CRASHDIR/task/task.sh +chmod 755 ${CRASHDIR}/task/task.sh #旧版文件清理 -rm -rf $sysdir/shellcrash.service + +rm -rf /etc/init.d/clash +rm -rf $CRASHDIR/clash.sh for file in log shellcrash.service mark? mark.bak;do - rm -rf $CRASHDIR/$file + rm -rf ${CRASHDIR}/$file done #旧版变量改名 sed -i "s/clashcore/crashcore/g" $configpath +sed -i "s/clash.meta/meta/g" $configpath sed -i "s/ShellClash/ShellCrash/g" $configpath #旧版任务清理 -$CRASHDIR/start.sh cronset "clash服务" 2>/dev/null -$CRASHDIR/start.sh cronset "订阅链接" 2>/dev/null -$CRASHDIR/start.sh cronset "ShellCrash初始化" 2>/dev/null +${CRASHDIR}/start.sh cronset "clash服务" 2>/dev/null +${CRASHDIR}/start.sh cronset "订阅链接" 2>/dev/null +${CRASHDIR}/start.sh cronset "ShellCrash初始化" 2>/dev/null sleep 1 echo -e "\033[32m脚本初始化完成,请输入\033[30;47m crash \033[0;33m命令开始使用!\033[0m" diff --git a/scripts/menu.sh b/scripts/menu.sh index 792be0c..555cc3e 100644 --- a/scripts/menu.sh +++ b/scripts/menu.sh @@ -1,38 +1,35 @@ #!/bin/sh # Copyright (C) Juewuy -CFG_PATH=$CRASHDIR/configs/ShellCrash.cfg -YAMLSDIR=$CRASHDIR/yamls -TMPDIR=/tmp/ShellCrash && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR +CFG_PATH=${CRASHDIR}/configs/ShellCrash.cfg +YAMLSDIR=${CRASHDIR}/yamls +JSONSDIR=${CRASHDIR}/jsons +#加载执行目录,失败则初始化 +source ${CRASHDIR}/configs/command.env &>/dev/null +[ -z "$BINDIR" -o -z "$TMPDIR" -o -z "$COMMAND" ] && source ${CRASHDIR}/init.sh &>/dev/null +[ ! -f ${TMPDIR} ] && mkdir -p ${TMPDIR} + #读取配置相关 setconfig(){ #参数1代表变量名,参数2代表变量值,参数3即文件路径 - [ -z "$3" ] && configpath=$CFG_PATH || configpath=$3 - [ -n "$(grep -E "^${1}=" $configpath)" ] && sed -i "s#^${1}=\(.*\)#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath + [ -z "$3" ] && configpath=${CFG_PATH} || configpath="${3}" + [ -n "$(grep "${1}=" "$configpath")" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath } ckcmd(){ command -v sh &>/dev/null && command -v $1 &>/dev/null || type $1 &>/dev/null } ckstatus(){ - - #服务器缺省地址 - [ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellCrash #检查/读取脚本配置文件 if [ -f $CFG_PATH ];then - #检查重复行并去除 - [ -n "$(awk 'a[$0]++' $CFG_PATH)" ] && awk '!a[$0]++' $CFG_PATH > $CFG_PATH - #检查时间戳 - touch $TMPDIR/crash_start_time - #使用source加载配置文件 - source $CFG_PATH > /dev/null + [ -n "$(awk 'a[$0]++' $CFG_PATH)" ] && awk '!a[$0]++' $CFG_PATH > $CFG_PATH #检查重复行并去除 + source $CFG_PATH &>/dev/null else - mkdir -p $CRASHDIR/configs - echo '#标识ShellCrash运行状态的文件,不明勿动!' > $CFG_PATH + source ${CRASHDIR}/init.sh &>/dev/null fi - versionsh=$(cat $CRASHDIR/init.sh | grep -E ^version= | head -n 1 | sed 's/version=//') + versionsh=$(cat ${CRASHDIR}/init.sh | grep -E ^version= | head -n 1 | sed 's/version=//') [ -n "$versionsh" ] && versionsh_l=$versionsh - #设置默认核心资源目录 - [ -z "$bindir" ] && bindir=$CRASHDIR + #服务器缺省地址 + [ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellCrash #设置默认端口及变量 [ -z "$mix_port" ] && mix_port=7890 [ -z "$redir_port" ] && redir_port=7892 @@ -42,22 +39,22 @@ ckstatus(){ [ -z "$local_proxy" ] && local_proxy=未开启 [ -z "$redir_mod" ] && redir_mod=纯净模式 #检查mac地址记录 - [ ! -f $CRASHDIR/configs/mac ] && touch $CRASHDIR/configs/mac + [ ! -f ${CRASHDIR}/configs/mac ] && touch ${CRASHDIR}/configs/mac #获取本机host地址 [ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'lan' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host" ] && host='设备IP地址' #dashboard目录位置 - [ -f $CRASHDIR/ui/index.html ] && dbdir=$CRASHDIR/ui && hostdir=":$db_port/ui" + [ -f ${CRASHDIR}/ui/index.html ] && dbdir=${CRASHDIR}/ui && hostdir=":$db_port/ui" [ -f /www/clash/index.html ] && dbdir=/www/clash && hostdir=/clash #开机自启检测 if [ -f /etc/rc.common ];then - [ -n "$(find /etc/rc.d -name '*clash')" ] && autostart=enable || autostart=disable - elif [ -w /etc/systemd/system -o -w /usr/lib/systemd/system ];then - [ -n "$(systemctl is-enabled shellcrash.service 2>&1 | grep enable)" ] && autostart=enable || autostart=disable + [ -n "$(find /etc/rc.d -name '*shellcrash')" ] && autostart=enable || autostart=disable + elif ckcmd systemctl;then + [ "$(systemctl is-enabled shellcrash.service 2>&1)" = enabled ] && autostart=enable || autostart=disable else - [ -f $CRASHDIR/.dis_startup ] && autostart=disable || autostart=enable + [ -f ${CRASHDIR}/.dis_startup ] && autostart=disable || autostart=enable fi #开机自启描述 if [ "$autostart" = "enable" ]; then @@ -73,8 +70,8 @@ ckstatus(){ run="\033[32m正在运行($redir_mod)\033[0m" VmRSS=`cat /proc/$PID/status|grep -w VmRSS|awk '{print $2,$3}'` #获取运行时长 - touch $TMPDIR/crash_start_time #用于延迟启动的校验 - start_time=$(cat $TMPDIR/crash_start_time) + touch ${TMPDIR}/crash_start_time #用于延迟启动的校验 + start_time=$(cat ${TMPDIR}/crash_start_time) if [ -n "$start_time" ]; then time=$((`date +%s`-start_time)) day=$((time/86400)) @@ -86,10 +83,11 @@ ckstatus(){ #检测系统端口占用 checkport fi + [ "$crashcore" = singbox ] && corename=Sing-Box || corename=Clash #输出状态 echo ----------------------------------------------- echo -e "\033[30;46m欢迎使用ShellCrash!\033[0m 版本:$versionsh_l" - echo -e "Clash服务"$run","$auto"" + echo -e "$corename服务"$run","$auto"" if [ -n "$PID" ];then echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m,已运行:\033[46;30m"$day"\033[44;37m"$time"\033[0m" fi @@ -98,53 +96,50 @@ ckstatus(){ #检查新手引导 if [ -z "$userguide" ];then setconfig userguide 1 - source $CRASHDIR/getdate.sh && userguide + source ${CRASHDIR}/getdate.sh && userguide fi #检查执行权限 - [ ! -x $CRASHDIR/start.sh ] && chmod +x $CRASHDIR/start.sh + [ ! -x ${CRASHDIR}/start.sh ] && chmod +x ${CRASHDIR}/start.sh #检查/tmp内核文件 - for file in `ls -F /tmp | grep -v [/\$] | grep -v '\ ' | grep -Ev ".*[(gz)(zip)(7z)(tar)(xz)]$" | grep -iE '^clash$|^clash-linux*|^mihomo*|^clash.meta*'` ; do + for file in `ls -F /tmp | grep -v [/\$] | grep -v '\ ' | grep -Ev ".*[(gz)(zip)(7z)(tar)(xz)]$" | grep -iE '^clash$|^clash-linux.*|^mihomo.*|^sing.*box|^clash.meta.*'` ; do file=/tmp/$file chmod +x $file - tmp_version=$($file -v 2>/dev/null) - if [ -n "$tmp_version" ];then - echo -e "发现可用的内核文件: \033[36m$file\033[0m " - read -p "是否加载?(1/0) > " res + echo -e "发现可用的内核文件: \033[36m$file\033[0m " + read -p "是否加载(会停止当前服务)?(1/0) > " res [ "$res" = 1 ] && { - source $CRASHDIR/getdate.sh && setcoretype && \ - mv -f $file $CRASHDIR/CrashCore && \ - echo -e "\033[32m内核加载完成!\033[0m " && \ - setconfig crashcore $crashcore && \ - switch_core - sleep 1 + ${CRASHDIR}/start.sh stop + $file -v &>/dev/null || $file version &>/dev/null + if [ "$?" = 0 ];then + source ${CRASHDIR}/getdate.sh && setcoretype && \ + mv -f $file ${CRASHDIR}/CrashCore && \ + echo -e "\033[32m内核加载完成!\033[0m " && \ + setconfig crashcore $crashcore && \ + switch_core + sleep 1 + else + echo -e "\033[33m检测到不可用的内核文件!可能是文件受损或CPU架构不匹配!\033[0m" + rm -rf $file + echo -e "\033[33m内核文件已移除,请认真检查后重新上传!\033[0m" + sleep 2 + fi } - else - echo -e "\033[33m检测到不可用的内核文件!可能是文件受损或CPU架构不匹配!\033[0m" - rm -rf $file - echo -e "\033[33m内核文件已移除,请认真检查后重新上传!\033[0m" - sleep 2 - fi echo ----------------------------------------------- done #检查/tmp配置文件 - [ -x $bindir/clash ] && \ - for file in `ls -F /tmp | grep -v [/\$] | grep -v '\ ' | grep -iE '.yaml$|.yml$'` ; do + [ -x ${BINDIR}/CrashCore ] && \ + for file in `ls -F /tmp | grep -v [/\$] | grep -v '\ ' | grep -iE '.yaml$|.yml$|.json$'` ; do file=/tmp/$file - $bindir/clash -t -d $bindir -f $file &>/dev/null && { - echo -e "发现可用的YAML配置文件: \033[36m$file\033[0m " - read -p "加载为yaml配置文件/或者移除该文件?(1/0) > " res + echo -e "发现内核配置文件: \033[36m$file\033[0m " + read -p "是否加载为$crashcore的配置文件?(1/0) > " res [ "$res" = 1 ] && { - mv -f $file $CRASHDIR/yamls/config.yaml + if [ -n "$(echo $file | grep -iE '.json$')" ];then + mv -f $file ${CRASHDIR}/jsons/config.json + else + mv -f $file ${CRASHDIR}/yamls/config.yaml + fi echo -e "\033[32m配置文件加载完成!\033[0m " sleep 1 } - [ "$res" = 0 ] && { - rm -rf $file - echo -e "\033[32m配置文件已移除!\033[0m " - sleep 1 - } - echo ----------------------------------------------- - } done #检查禁用配置覆写 [ "$disoverride" = "1" ] && { @@ -161,7 +156,8 @@ errornum(){ echo -e "\033[31m请输入正确的字母或数字!\033[0m" } startover(){ - echo -e "\033[32m服务已启动!\033[0m" + [ "$crashcore" = singbox ] && corename=Singbox || corename=Clash + echo -e "\033[32m$corename服务已启动!\033[0m" echo -e "请使用 \033[4;32mhttp://$host$hostdir\033[0m 管理内置规则" if [ "$redir_mod" = "纯净模式" ];then echo ----------------------------------------------- @@ -169,16 +165,28 @@ startover(){ echo -e "或者使用HTTP/SOCK5方式连接:IP{\033[36m$host\033[0m}端口{\033[36m$mix_port\033[0m}" fi } -clashstart(){ - #检查yaml配置文件 - echo ----------------------------------------------- - if [ -s $CRASHDIR/yamls/config.yaml -o -n "$Url" -o -n "$Https" ];then - $CRASHDIR/start.sh start - sleep 1 - [ -n "$(pidof CrashCore)" ] && startover +start_core(){ + if [ "$crashcore" = singbox ];then + core_config=${CRASHDIR}/jsons/config.json else - echo -e "\033[31m没有找到配置文件,请先导入配置文件!\033[0m" - source $CRASHDIR/getdate.sh && clashlink + core_config=${CRASHDIR}/yamls/config.yaml + fi + echo ----------------------------------------------- + if [ -s $core_config -o -n "$Url" -o -n "$Https" ];then + ${CRASHDIR}/start.sh start + sleep 2 + if [ -n "$(pidof CrashCore)" ];then + startover + else + ${COMMAND} &>${TMPDIR}/core_test.log & + sleep 1 ; kill $! &>/dev/null + ${CRASHDIR}/start.sh start_error + ${CRASHDIR}/start.sh stop + exit 1 + fi + else + echo -e "\033[31m没有找到${crashcore}配置文件,请先导入配置文件!\033[0m" + source ${CRASHDIR}/getdate.sh && set_core_config fi } checkrestart(){ @@ -186,7 +194,7 @@ checkrestart(){ echo -e "\033[32m检测到已变更的内容,请重启服务!\033[0m" echo ----------------------------------------------- read -p "是否现在重启服务?(1/0) > " res - [ "$res" = 1 ] && clashstart + [ "$res" = 1 ] && start_core } #功能相关 log_pusher(){ #日志菜单 @@ -209,9 +217,9 @@ log_pusher(){ #日志菜单 read -p "请输入对应数字 > " num case $num in 1) - if [ -s $TMPDIR/ShellCrash.log ];then + if [ -s ${TMPDIR}/ShellCrash.log ];then echo ----------------------------------------------- - cat $TMPDIR/ShellCrash.log + cat ${TMPDIR}/ShellCrash.log exit 0 else echo -e "\033[31m未找到相关日志!\033[0m" @@ -251,7 +259,7 @@ log_pusher(){ #日志菜单 push_TG=$TOKEN setconfig push_TG $TOKEN setconfig chat_ID $chat_ID - $CRASHDIR/start.sh logger "已完成Telegram日志推送设置!" 32 + ${CRASHDIR}/start.sh logger "已完成Telegram日志推送设置!" 32 else echo -e "\033[31m无法获取对话ID,请重新配置!\033[0m" fi @@ -279,7 +287,7 @@ log_pusher(){ #日志菜单 if [ -n "$url" ];then push_Deer=$url setconfig push_Deer $url - $CRASHDIR/start.sh logger "已完成PushDeer日志推送设置!" 32 + ${CRASHDIR}/start.sh logger "已完成PushDeer日志推送设置!" 32 else echo -e "\033[31m输入错误,请重新输入!\033[0m" fi @@ -314,7 +322,7 @@ log_pusher(){ #日志菜单 bark_param=$param setconfig bark_param \'$param\' fi - $CRASHDIR/start.sh logger "已完成Bark日志推送设置!" 32 + ${CRASHDIR}/start.sh logger "已完成Bark日志推送设置!" 32 else echo -e "\033[31m输入错误,请重新输入!\033[0m" fi @@ -350,7 +358,7 @@ log_pusher(){ #日志菜单 push_Po_key=$key setconfig push_Po $Token setconfig push_Po_key $key - $CRASHDIR/start.sh logger "已完成Passover日志推送设置!" 32 + ${CRASHDIR}/start.sh logger "已完成Passover日志推送设置!" 32 else echo -e "\033[31m输入错误,请重新输入!\033[0m" fi @@ -377,7 +385,7 @@ log_pusher(){ #日志菜单 ;; 9) echo -e "\033[33m运行日志及任务日志均已清空!\033[0m" - rm -rf $TMPDIR/ShellCrash.log + rm -rf ${TMPDIR}/ShellCrash.log sleep 1 log_pusher ;; @@ -515,6 +523,7 @@ setdns(){ echo -e "FallbackDNS:\033[36m$dns_fallback\033[0m" echo -e "多个DNS地址请用\033[30;47m“|”\033[0m或者\033[30;47m“, ”\033[0m分隔输入" echo -e "\033[33m必须拥有本地根证书文件才能使用dot/doh类型的加密dns\033[0m" + echo -e "\033[33m注意singbox内核只有首个dns会被加载!\033[0m" echo ----------------------------------------------- echo -e " 1 修改\033[32m基础DNS\033[0m" echo -e " 2 修改\033[36mFallback_DNS\033[0m" @@ -522,7 +531,7 @@ setdns(){ echo -e " 4 一键配置\033[32m加密DNS\033[0m" echo -e " 5 hosts优化: \033[36m$hosts_opt\033[0m ————调用本机hosts并劫持NTP服务" echo -e " 6 Dnsmasq转发: \033[36m$dns_redir\033[0m ————不推荐使用" - echo -e " 7 禁用DNS劫持: \033[36m$dns_no\033[0m ————取消劫持局域网53端口" + echo -e " 7 禁用DNS劫持: \033[36m$dns_no\033[0m ————搭配第三方DNS使用" echo -e " 0 返回上级菜单" echo ----------------------------------------------- read -p "请输入对应数字 > " num @@ -770,7 +779,7 @@ macfilter(){ add_mac(){ echo ----------------------------------------------- echo 已添加的mac地址: - cat $CRASHDIR/configs/mac + cat ${CRASHDIR}/configs/mac echo ----------------------------------------------- echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[32m" cat $dhcpdir | awk '{print " "NR" "$3,$2,$4}' @@ -782,8 +791,8 @@ macfilter(){ if [ -z "$num" -o "$num" = 0 ]; then i= elif [ -n "$(echo $num | grep -aE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')" ];then - if [ -z "$(cat $CRASHDIR/configs/mac | grep -E "$num")" ];then - echo $num | grep -oE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$' >> $CRASHDIR/configs/mac + if [ -z "$(cat ${CRASHDIR}/configs/mac | grep -E "$num")" ];then + echo $num | grep -oE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$' >> ${CRASHDIR}/configs/mac else echo ----------------------------------------------- echo -e "\033[31m已添加的设备,请勿重复添加!\033[0m" @@ -791,8 +800,8 @@ macfilter(){ add_mac elif [ $num -le $(cat $dhcpdir 2>/dev/null | awk 'END{print NR}') ]; then macadd=$(cat $dhcpdir | awk '{print $2}' | sed -n "$num"p) - if [ -z "$(cat $CRASHDIR/configs/mac | grep -E "$macadd")" ];then - echo $macadd >> $CRASHDIR/configs/mac + if [ -z "$(cat ${CRASHDIR}/configs/mac | grep -E "$macadd")" ];then + echo $macadd >> ${CRASHDIR}/configs/mac else echo ----------------------------------------------- echo -e "\033[31m已添加的设备,请勿重复添加!\033[0m" @@ -806,12 +815,12 @@ macfilter(){ } del_mac(){ echo ----------------------------------------------- - if [ -z "$(cat $CRASHDIR/configs/mac)" ];then + if [ -z "$(cat ${CRASHDIR}/configs/mac)" ];then echo -e "\033[31m列表中没有需要移除的设备!\033[0m" else echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[0m" i=1 - for mac in $(cat $CRASHDIR/configs/mac); do + for mac in $(cat ${CRASHDIR}/configs/mac); do dev_ip=$(cat $dhcpdir | grep $mac | awk '{print $3}') && [ -z "$dev_ip" ] && dev_ip='000.000.00.00' dev_mac=$(cat $dhcpdir | grep $mac | awk '{print $2}') && [ -z "$dev_mac" ] && dev_mac=$mac dev_name=$(cat $dhcpdir | grep $mac | awk '{print $4}') && [ -z "$dev_name" ] && dev_name='未知设备' @@ -823,8 +832,8 @@ macfilter(){ read -p "请输入需要移除的设备的对应序号 > " num if [ -z "$num" ]||[ "$num" -le 0 ]; then n= - elif [ $num -le $(cat $CRASHDIR/configs/mac | wc -l) ];then - sed -i "${num}d" $CRASHDIR/configs/mac + elif [ $num -le $(cat ${CRASHDIR}/configs/mac | wc -l) ];then + sed -i "${num}d" ${CRASHDIR}/configs/mac echo ----------------------------------------------- echo -e "\033[32m对应设备已移除!\033[0m" del_mac @@ -853,11 +862,11 @@ macfilter(){ echo -e "\033[30;47m请在此添加或移除设备\033[0m" echo -e "当前过滤方式为:\033[33m$macfilter_type模式\033[0m" echo -e "仅列表内设备\033[36m$macfilter_scrip经过\033[0mClash内核" - if [ -n "$(cat $CRASHDIR/configs/mac)" ]; then + if [ -n "$(cat ${CRASHDIR}/configs/mac)" ]; then echo ----------------------------------------------- echo -e "当前已过滤设备为:\033[36m" echo -e "\033[33m 设备IP 设备mac地址 设备名称\033[0m" - for mac in $(cat $CRASHDIR/configs/mac); do + for mac in $(cat ${CRASHDIR}/configs/mac); do dev_ip=$(cat $dhcpdir | grep $mac | awk '{print $3}') && [ -z "$dev_ip" ] && dev_ip='000.000.00.00' dev_mac=$(cat $dhcpdir | grep $mac | awk '{print $2}') && [ -z "$dev_mac" ] && dev_mac=$mac dev_name=$(cat $dhcpdir | grep $mac | awk '{print $4}') && [ -z "$dev_name" ] && dev_name='未知设备' @@ -888,7 +897,7 @@ macfilter(){ del_mac macfilter elif [ "$num" = 4 ]; then - :>$CRASHDIR/configs/mac + :>${CRASHDIR}/configs/mac echo ----------------------------------------------- echo -e "\033[31m设备列表已清空!\033[0m" macfilter @@ -942,7 +951,7 @@ setboot(){ [ -z "$start_old" ] && start_old=未开启 [ -z "$start_delay" -o "$start_delay" = 0 ] && delay=未设置 || delay=${start_delay}秒 [ "$autostart" = "enable" ] && auto_set="\033[33m禁止" || auto_set="\033[32m允许" - [ "$bindir" = "$CRASHDIR" ] && mini_clash=未开启 || mini_clash=已开启 + [ "${BINDIR}" = "${CRASHDIR}" ] && mini_clash=未开启 || mini_clash=已开启 echo ----------------------------------------------- echo -e "\033[30;47m欢迎使用启动设置菜单:\033[0m" echo ----------------------------------------------- @@ -950,7 +959,7 @@ setboot(){ echo -e " 2 使用保守模式: \033[36m$start_old\033[0m ————基于定时任务(每分钟检测)" echo -e " 3 设置自启延时: \033[36m$delay\033[0m ————用于解决自启后服务受限" echo -e " 4 启用小闪存模式: \033[36m$mini_clash\033[0m ————用于闪存空间不足的设备" - [ "$bindir" != "$CRASHDIR" ] && echo -e " 5 设置小闪存目录: \033[36m$bindir\033[0m" + [ "${BINDIR}" != "${CRASHDIR}" ] && echo -e " 5 设置小闪存目录: \033[36m${BINDIR}\033[0m" echo ----------------------------------------------- echo -e " 0 \033[0m返回上级菜单\033[0m" read -p "请输入对应数字 > " num @@ -958,15 +967,15 @@ setboot(){ case "$num" in 1) if [ "$autostart" = "enable" ]; then - [ -d /etc/rc.d ] && cd /etc/rc.d && rm -rf *clash > /dev/null 2>&1 && cd - >/dev/null + [ -d /etc/rc.d ] && cd /etc/rc.d && rm -rf *shellcrash > /dev/null 2>&1 && cd - >/dev/null ckcmd systemctl && systemctl disable shellcrash.service > /dev/null 2>&1 - touch $CRASHDIR/.dis_startup + touch ${CRASHDIR}/.dis_startup autostart=disable echo -e "\033[33m已禁止Clash开机启动!\033[0m" elif [ "$autostart" = "disable" ]; then - [ -f /etc/rc.common ] && /etc/init.d/clash enable + [ -f /etc/rc.common ] && /etc/init.d/shellcrash enable ckcmd systemctl && systemctl enable shellcrash.service > /dev/null 2>&1 - rm -rf $CRASHDIR/.dis_startup + rm -rf ${CRASHDIR}/.dis_startup autostart=enable echo -e "\033[32m已设置Clash开机启动!\033[0m" fi @@ -977,14 +986,14 @@ setboot(){ echo -e "\033[33m改为使用保守模式启动服务!!\033[0m" start_old=已开启 setconfig start_old $start_old - $CRASHDIR/start.sh stop + ${CRASHDIR}/start.sh stop else if [ -n "$(pidof procd)" -o -w /etc/systemd/system -o -w /usr/lib/systemd/system ];then echo -e "\033[32m改为使用系统守护进程启动服务!!\033[0m" - $CRASHDIR/start.sh cronset "ShellCrash初始化" + ${CRASHDIR}/start.sh cronset "ShellCrash初始化" start_old=未开启 setconfig start_old $start_old - $CRASHDIR/start.sh stop + ${CRASHDIR}/start.sh stop else echo -e "\033[31m当前设备不支持以其他模式启动!!\033[0m" @@ -1011,12 +1020,12 @@ setboot(){ setboot ;; 4) - dir_size=$(df $CRASHDIR |awk '{ for(i=1;i<=NF;i++){ if(NR==1){ arr[i]=$i; }else{ arr[i]=arr[i]" "$i; } } } END{ for(i=1;i<=NF;i++){ print arr[i]; } }' |grep Ava |awk '{print $2}') + dir_size=$(df ${CRASHDIR} |awk '{ for(i=1;i<=NF;i++){ if(NR==1){ arr[i]=$i; }else{ arr[i]=arr[i]" "$i; } } } END{ for(i=1;i<=NF;i++){ print arr[i]; } }' |grep Ava |awk '{print $2}') if [ "$mini_clash" = "未开启" ]; then if [ "$dir_size" -gt 20480 ];then echo -e "\033[33m您的设备空间充足(>20M),无需开启!\033[0m" else - [ "$bindir" = "$CRASHDIR" ] && bindir="/tmp/clash_$USER" + [ "$BINDIR" = "$CRASHDIR" ] && BINDIR="$TMPDIR" echo -e "\033[32m已经启用小闪存功能!\033[0m" echo -e "如需更换目录,请使用【设置小闪存目录】功能\033[0m" fi @@ -1024,14 +1033,14 @@ setboot(){ if [ "$dir_size" -lt 8192 ];then echo -e "\033[31m您的设备剩余空间不足8M,停用后可能无法正常运行!\033[0m" read -p "确认停用此功能?(1/0) > " res - [ "$res" = 1 ] && bindir="$CRASHDIR" && echo -e "\033[33m已经停用小闪存功能!\033[0m" + [ "$res" = 1 ] && BINDIR="$CRASHDIR" && echo -e "\033[33m已经停用小闪存功能!\033[0m" else - rm -rf /tmp/clash_$USER - bindir="$CRASHDIR" + rm -rf /tmp/ShellCrash + BINDIR="$CRASHDIR" echo -e "\033[33m已经停用小闪存功能!\033[0m" fi fi - setconfig bindir $bindir + setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env sleep 1 setboot ;; @@ -1044,14 +1053,14 @@ setboot(){ read -p "请输入相应数字 > " num case "$num" in 1) - bindir="/tmp/clash_$USER" ;; + BINDIR="$TMPDIR" ;; 2) set_usb_dir(){ echo "请选择安装目录" du -hL /mnt | awk '{print " "NR" "$2" "$1}' read -p "请输入相应数字 > " num - bindir=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p) - if [ -z "$bindir" ];then + BINDIR=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p) + if [ -z "$BINDIR" ];then echo "\033[31m输入错误!请重新设置!\033[0m" set_usb_dir fi @@ -1060,8 +1069,8 @@ setboot(){ ;; 3) input_dir(){ - read -p "请输入自定义目录 > " bindir - if [ ! -d "$bindir" ];then + read -p "请输入自定义目录 > " BINDIR + if [ ! -d "$BINDIR" ];then echo "\033[31m输入错误!请重新设置!\033[0m" input_dir fi @@ -1072,7 +1081,7 @@ setboot(){ errornum ;; esac - setconfig bindir $bindir + setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env setboot ;; *) @@ -1085,14 +1094,14 @@ metacfg(){ echo ----------------------------------------------- } -clashcfg(){ +normal_set(){ set_redir_mod(){ set_redir_config(){ setconfig redir_mod $redir_mod setconfig dns_mod $dns_mod if [ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ] && [ "$crashcore" = "clash" ];then - rm -rf $bindir/clash - rm -rf $CRASHDIR/clash + rm -rf ${BINDIR}/clash + rm -rf ${CRASHDIR}/clash setconfig crashcore meta fi echo ----------------------------------------------- @@ -1135,7 +1144,7 @@ clashcfg(){ elif [ "$num" = 3 ]; then if [ -f /etc/init.d/qca-nss-ecm -a "$systype" = "mi_snapshot" ] ;then read -p "当前设备的QOS服务与本模式冲突,是否禁用相关功能?(1/0) > " res - [ "$res" = '1' ] && $CRASHDIR/misnap_init.sh tproxyfix && redir_mod=Tproxy混合 + [ "$res" = '1' ] && ${CRASHDIR}/misnap_init.sh tproxyfix && redir_mod=Tproxy混合 else redir_mod=Tproxy混合 fi @@ -1148,7 +1157,7 @@ clashcfg(){ elif [ "$num" = 5 ]; then if [ -f /etc/init.d/qca-nss-ecm -a "$systype" = "mi_snapshot" ] ;then read -p "当前设备的QOS服务与本模式冲突,是否禁用相关功能?(1/0) > " res - [ "$res" = '1' ] && $CRASHDIR/misnap_init.sh tproxyfix && redir_mod=Tproxy模式 + [ "$res" = '1' ] && ${CRASHDIR}/misnap_init.sh tproxyfix && redir_mod=Tproxy模式 else redir_mod=Tproxy模式 fi @@ -1196,6 +1205,8 @@ clashcfg(){ echo -e " 不支持绕过CN-IP功能" echo -e " 2 redir_host模式:\033[32m兼容性更好\033[0m" echo -e " 需搭配加密DNS使用" + echo -e " 3 mix混合模式: \033[32m内部realip外部fakeip\033[0m" + echo -e " 限singbox内核+geosite.db!" echo " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" ]; then @@ -1203,25 +1214,26 @@ clashcfg(){ elif [ "$num" = 0 ]; then i= elif [ "$num" = 1 ]; then - set_fake_ip(){ - dns_mod=fake-ip - setconfig dns_mod $dns_mod - echo ----------------------------------------------- - echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m" - } - if [ "$redir_mod" = "Redir模式" ];then - echo ----------------------------------------------- - read -p "fake-ip与Redir模式兼容性较差,是否依然强制使用?(1/0) > " res - [ "$res" = 1 ] && set_fake_ip - else - set_fake_ip - fi + dns_mod=fake-ip + setconfig dns_mod $dns_mod + echo ----------------------------------------------- + echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m" elif [ "$num" = 2 ]; then dns_mod=redir_host setconfig dns_mod $dns_mod echo ----------------------------------------------- echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m" + elif [ "$num" = 3 ]; then + if [ "$crashcore" = singbox ];then + dns_mod=mix + setconfig dns_mod $dns_mod + echo ----------------------------------------------- + echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m" + else + echo -e "\033[31m仅限singbox内核使用!!!\033[0m" + sleep 1 + fi else errornum fi @@ -1233,9 +1245,9 @@ clashcfg(){ echo -e "示例:*.b.com" echo -e "示例:*.*.b.com\033[0m" echo ----------------------------------------------- - if [ -s $CRASHDIR/configs/fake_ip_filter ];then + if [ -s ${CRASHDIR}/configs/fake_ip_filter ];then echo -e "\033[33m已添加Fake-ip过滤地址:\033[0m" - cat $CRASHDIR/configs/fake_ip_filter | awk '{print NR" "$1}' + cat ${CRASHDIR}/configs/fake_ip_filter | awk '{print NR" "$1}' else echo -e "\033[33m你还未添加Fake-ip过滤地址\033[0m" fi @@ -1246,14 +1258,14 @@ clashcfg(){ 0) ;; '') ;; [0-99]) - sed -i "${input}d" $CRASHDIR/configs/fake_ip_filter 2>/dev/null + sed -i "${input}d" ${CRASHDIR}/configs/fake_ip_filter 2>/dev/null echo -e "\033[32m移除成功!\033[0m" fake_ip_filter ;; *) echo -e "你输入的地址是:\033[32m$input\033[0m" read -p "确认添加?(1/0) > " res - [ "$res" = 1 ] && echo $input >> $CRASHDIR/configs/fake_ip_filter + [ "$res" = 1 ] && echo $input >> ${CRASHDIR}/configs/fake_ip_filter fake_ip_filter ;; esac @@ -1266,7 +1278,7 @@ clashcfg(){ [ -z "$cn_ip_route" ] && cn_ip_route=未开启 [ -z "$local_proxy" ] && local_proxy=未开启 [ -z "$quic_rj" ] && quic_rj=未开启 - [ -z "$(cat $CRASHDIR/configs/mac)" ] && mac_return=未开启 || mac_return=已启用 + [ -z "$(cat ${CRASHDIR}/configs/mac)" ] && mac_return=未开启 || mac_return=已启用 # echo ----------------------------------------------- echo -e "\033[30;47m欢迎使用功能设置菜单:\033[0m" @@ -1281,7 +1293,7 @@ clashcfg(){ echo -e " 6 设置本机代理服务: \033[36m$local_proxy\033[0m ————使本机流量经过ShellCrash内核" echo -e " 7 屏蔽QUIC流量: \033[36m$quic_rj\033[0m ————优化视频性能" [ "$disoverride" != "1" ] && { - [ "$dns_mod" = "fake-ip" ] && \ + [ "$dns_mod" = "fake-ip" -a "$crashcore" != "singbox" ] && \ echo -e " 8 管理Fake-ip过滤列表" || \ echo -e " 8 CN_IP绕过内核: \033[36m$cn_ip_route\033[0m ————优化性能,不兼容Fake-ip" } @@ -1301,11 +1313,11 @@ clashcfg(){ else set_redir_mod fi - clashcfg + normal_set elif [ "$num" = 2 ]; then set_dns_mod - clashcfg + normal_set elif [ "$num" = 3 ]; then echo ----------------------------------------------- @@ -1317,7 +1329,7 @@ clashcfg(){ skip_cert=未开启 fi setconfig skip_cert $skip_cert - clashcfg + normal_set elif [ "$num" = 4 ]; then set_common_ports(){ @@ -1335,20 +1347,20 @@ clashcfg(){ echo ----------------------------------------------- if [ -n "$(pidof CrashCore)" ];then read -p "切换时将停止服务,是否继续?(1/0) > " res - [ "$res" = 1 ] && $CRASHDIR/start.sh stop && set_common_ports + [ "$res" = 1 ] && ${CRASHDIR}/start.sh stop && set_common_ports else set_common_ports fi - clashcfg + normal_set elif [ "$num" = 5 ]; then - checkcfg_mac=$(cat $CRASHDIR/configs/mac) + checkcfg_mac=$(cat ${CRASHDIR}/configs/mac) macfilter if [ -n "$PID" ];then - checkcfg_mac_new=$(cat $CRASHDIR/configs/mac) + checkcfg_mac_new=$(cat ${CRASHDIR}/configs/mac) [ "$checkcfg_mac" != "$checkcfg_mac_new" ] && checkrestart fi - clashcfg + normal_set elif [ "$num" = 6 ]; then if [ "$local_proxy" = "未开启" ]; then @@ -1361,7 +1373,7 @@ clashcfg(){ echo -e "\033[33m已经停用本机代理规则,请尽快重启服务!!\033[0m" fi sleep 1 - clashcfg + normal_set elif [ "$num" = 7 ]; then echo ----------------------------------------------- @@ -1378,11 +1390,11 @@ clashcfg(){ echo -e "\033[33m当前模式默认不会代理UDP流量,无需设置!!\033[0m" fi sleep 1 - clashcfg + normal_set elif [ "$num" = 8 ]; then echo ----------------------------------------------- - if [ "$dns_mod" = "fake-ip" ];then + if [ "$dns_mod" = "fake-ip" -a "$crashcore" != "singbox" ];then fake_ip_filter else if [ -n "$(ipset -v 2>/dev/null)" -o -n "$(echo $redir_mod | grep Nft)" ];then @@ -1401,15 +1413,15 @@ clashcfg(){ sleep 1 fi fi - clashcfg + normal_set elif [ "$num" = 9 ]; then - clashstart + start_core else errornum fi } -clashadv(){ +advanced_set(){ #获取设置默认显示 [ -z "$proxies_bypass" ] && proxies_bypass=未启用 [ -z "$start_old" ] && start_old=未开启 @@ -1417,7 +1429,7 @@ clashadv(){ [ -z "$public_support" ] && public_support=未开启 [ -z "$sniffer" ] && sniffer=未启用 [ "$crashcore" = "clashpre" ] && [ "$dns_mod" = "redir_host" ] && sniffer=已启用 - [ "$bindir" = "/tmp/clash_$USER" ] && mini_clash=已开启 || mini_clash=未开启 + [ "$BINDIR" = "/tmp/ShellCrash" ] && mini_clash=已开启 || mini_clash=未开启 # echo ----------------------------------------------- echo -e "\033[30;47m欢迎使用进阶模式菜单:\033[0m" @@ -1428,7 +1440,7 @@ clashadv(){ echo -e " 3 配置公网及局域网防火墙" [ "$disoverride" != "1" ] && { echo -e " 4 启用域名嗅探: \033[36m$sniffer\033[0m ————用于流媒体及防DNS污染" - echo -e " 5 启用节点绕过: \033[36m$proxies_bypass\033[0m ————用于防止多设备多重流量" + [ "$crashcore" = singbox ] || echo -e " 5 启用节点绕过: \033[36m$proxies_bypass\033[0m ————用于防止多设备多重流量" echo -e " 6 配置内置DNS服务 \033[36m$dns_no\033[0m" } echo ----------------------------------------------- @@ -1439,21 +1451,21 @@ clashadv(){ case "$num" in 1) setipv6 - clashadv + advanced_set ;; 2) setmeta - clashadv + advanced_set ;; 3) setfirewall - clashadv + advanced_set ;; 4) echo ----------------------------------------------- if [ "$sniffer" = "未启用" ];then if [ "$crashcore" = "clash" ];then - rm -rf $bindir/clash + rm -rf ${BINDIR}/clash crashcore=meta setconfig crashcore $crashcore echo "已将ShellCrash内核切换为Meta内核!域名嗅探依赖Meta或者高版本clashpre内核!" @@ -1467,7 +1479,7 @@ clashadv(){ setconfig sniffer $sniffer echo -e "\033[32m设置成功!\033[0m" sleep 1 - clashadv + advanced_set ;; 5) echo ----------------------------------------------- @@ -1481,11 +1493,11 @@ clashadv(){ setconfig proxies_bypass $proxies_bypass echo -e "\033[32m设置成功!\033[0m" sleep 1 - clashadv + advanced_set ;; 6) setdns - clashadv + advanced_set ;; 9) echo -e " 1 备份脚本设置" @@ -1512,6 +1524,7 @@ clashadv(){ fi elif [ "$num" = 3 ]; then mv -f $CFG_PATH $CFG_PATH.bak + source ${CRASHDIR}/init.sh >/dev/null echo -e "\033[32m脚本设置已重置!(旧文件已备份!)\033[0m" fi echo -e "\033[33m请重新启动脚本!\033[0m" @@ -1527,8 +1540,8 @@ autoSSH(){ echo -e "\033[33m如有问题请加群反馈:\033[36;4mhttps://t.me/ShellClash\033[0m" read -p "请输入需要还原的SSH密码(不影响当前密码,回车可跳过) > " mi_autoSSH_pwd mi_autoSSH=已配置 - cp -f /etc/dropbear/dropbear_rsa_host_key $CRASHDIR/configs/dropbear_rsa_host_key 2>/dev/null - cp -f /etc/dropbear/authorized_keys $CRASHDIR/configs/authorized_keys 2>/dev/null + cp -f /etc/dropbear/dropbear_rsa_host_key ${CRASHDIR}/configs/dropbear_rsa_host_key 2>/dev/null + cp -f /etc/dropbear/authorized_keys ${CRASHDIR}/configs/authorized_keys 2>/dev/null ckcmd nvram && { nvram set ssh_en=1 nvram set telnet_en=1 @@ -1609,13 +1622,13 @@ tools(){ #获取设置默认显示 [ -n "$(cat /etc/crontabs/root 2>&1| grep otapredownload)" ] && mi_update=禁用 || mi_update=启用 [ "$mi_autoSSH" = "已配置" ] && mi_autoSSH_type=32m已配置 || mi_autoSSH_type=31m未配置 - [ -f $CRASHDIR/tools/tun.ko ] && mi_tunfix=32m已启用 || mi_tunfix=31m未启用 + [ -f ${CRASHDIR}/tools/tun.ko ] && mi_tunfix=32m已启用 || mi_tunfix=31m未启用 # echo ----------------------------------------------- echo -e "\033[30;47m欢迎使用其他工具菜单:\033[0m" echo -e "\033[33m本页工具可能无法兼容全部Linux设备,请酌情使用!\033[0m" echo -e "磁盘占用/所在目录:" - du -sh $CRASHDIR + du -sh ${CRASHDIR} echo ----------------------------------------------- echo -e " 1 ShellCrash\033[33m测试菜单\033[0m" echo -e " 2 ShellCrash\033[32m新手引导\033[0m" @@ -1635,10 +1648,10 @@ tools(){ i= elif [ "$num" = 1 ]; then - source $CRASHDIR/getdate.sh && testcommand + source ${CRASHDIR}/getdate.sh && testcommand elif [ "$num" = 2 ]; then - source $CRASHDIR/getdate.sh && userguide + source ${CRASHDIR}/getdate.sh && userguide elif [ "$num" = 3 ]; then log_pusher @@ -1651,17 +1664,17 @@ tools(){ elif [ "$num" = 7 ]; then echo ----------------------------------------------- - if [ ! -f $CRASHDIR/tools/ShellDDNS.sh ];then + if [ ! -f ${CRASHDIR}/tools/ShellDDNS.sh ];then echo -e "正在获取在线脚本……" - $CRASHDIR/start.sh webget $TMPDIR/ShellDDNS.sh $update_url/tools/ShellDDNS.sh + ${CRASHDIR}/start.sh webget ${TMPDIR}/ShellDDNS.sh $update_url/tools/ShellDDNS.sh if [ "$?" = "0" ];then - mv -f $TMPDIR/ShellDDNS.sh $CRASHDIR/tools/ShellDDNS.sh - source $CRASHDIR/tools/ShellDDNS.sh + mv -f ${TMPDIR}/ShellDDNS.sh ${CRASHDIR}/tools/ShellDDNS.sh + source ${CRASHDIR}/tools/ShellDDNS.sh else echo -e "\033[31m文件下载失败!\033[0m" fi else - source $CRASHDIR/tools/ShellDDNS.sh + source ${CRASHDIR}/tools/ShellDDNS.sh fi sleep 1 tools @@ -1681,10 +1694,10 @@ tools(){ fi tools elif [ "$num" = 8 ]; then - if [ -f $CRASHDIR/tools/tun.ko ];then + if [ -f ${CRASHDIR}/tools/tun.ko ];then read -p "是否禁用此功能并移除相关补丁?(1/0) > " res [ "$res" = 1 ] && { - rm -rf $CRASHDIR/tools/tun.ko + rm -rf ${CRASHDIR}/tools/tun.ko echo -e "\033[33m补丁文件已移除,请立即重启设备以防止出错!\033[0m" } elif [ -z "$(modinfo tun)" ];then @@ -1696,10 +1709,10 @@ tools(){ tunfixlink="${update_url}/bin/fix/tun.ko" echo ----------------------------------------------- echo 正在连接服务器获取Tun模块补丁文件………… - $CRASHDIR/start.sh webget $TMPDIR/tun.ko $tunfixlink + ${CRASHDIR}/start.sh webget ${TMPDIR}/tun.ko $tunfixlink if [ "$?" = "0" ];then - mv -f $TMPDIR/tun.ko $CRASHDIR/tools/tun.ko && \ - $CRASHDIR/misnap_init.sh tunfix && \ + mv -f ${TMPDIR}/tun.ko ${CRASHDIR}/tools/tun.ko && \ + ${CRASHDIR}/misnap_init.sh tunfix && \ echo -e "\033[32m设置成功!请重启服务!\033[0m" else echo -e "\033[31m文件下载失败,请重试!\033[0m" @@ -1715,7 +1728,7 @@ tools(){ fi } #主菜单 -clashsh(){ +main_menu(){ ############################# ckstatus ############################# @@ -1739,57 +1752,58 @@ clashsh(){ exit; elif [ "$num" = 1 ]; then - clashstart + start_core exit; elif [ "$num" = 2 ]; then checkcfg=$(cat $CFG_PATH) - clashcfg + normal_set if [ -n "$PID" ];then checkcfg_new=$(cat $CFG_PATH) [ "$checkcfg" != "$checkcfg_new" ] && checkrestart fi - clashsh + main_menu elif [ "$num" = 3 ]; then - $CRASHDIR/start.sh stop + ${CRASHDIR}/start.sh stop + sleep 1 echo ----------------------------------------------- echo -e "\033[31mClash服务已停止!\033[0m" - clashsh + main_menu elif [ "$num" = 4 ]; then setboot - clashsh + main_menu elif [ "$num" = 5 ]; then - source $CRASHDIR/task/task.sh && task_menu - clashsh + source ${CRASHDIR}/task/task.sh && task_menu + main_menu elif [ "$num" = 6 ]; then - source $CRASHDIR/getdate.sh && clashlink - clashsh + source ${CRASHDIR}/getdate.sh && set_core_config + main_menu elif [ "$num" = 7 ]; then checkcfg=$(cat $CFG_PATH) - clashadv + advanced_set if [ -n "$PID" ];then checkcfg_new=$(cat $CFG_PATH) [ "$checkcfg" != "$checkcfg_new" ] && checkrestart fi - clashsh + main_menu elif [ "$num" = 8 ]; then tools - clashsh + main_menu elif [ "$num" = 9 ]; then checkcfg=$(cat $CFG_PATH) - source $CRASHDIR/getdate.sh && update + source ${CRASHDIR}/getdate.sh && update if [ -n "$PID" ];then checkcfg_new=$(cat $CFG_PATH) [ "$checkcfg" != "$checkcfg_new" ] && checkrestart fi - clashsh + main_menu else errornum @@ -1800,13 +1814,13 @@ clashsh(){ [ -z "$CRASHDIR" ] && { echo 环境变量配置有误!正在初始化~~~ CRASHDIR=$(cd `dirname $0`; pwd) - source $CRASHDIR/init.sh + source ${CRASHDIR}/init.sh sleep 1 echo 请重启SSH窗口以完成初始化! exit } -[ -z "$1" ] && clashsh +[ -z "$1" ] && main_menu case "$1" in -h) @@ -1829,34 +1843,34 @@ case "$1" in ;; -t) shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash - $shtype -x $CRASHDIR/menu.sh + $shtype -x ${CRASHDIR}/menu.sh ;; -s) - $CRASHDIR/start.sh $2 $3 $4 $5 $6 + ${CRASHDIR}/start.sh $2 $3 $4 $5 $6 ;; -i) - source $CRASHDIR/init.sh + source ${CRASHDIR}/init.sh ;; -st) shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash - $shtype -x $CRASHDIR/start.sh $2 $3 $4 $5 $6 + $shtype -x ${CRASHDIR}/start.sh $2 $3 $4 $5 $6 ;; -u) read -p "确认卸载ShellCrash?(警告:该操作不可逆!)[1/0] > " res if [ "$res" = '1' ]; then - $CRASHDIR/start.sh stop - $CRASHDIR/start.sh cronset "clash服务" 2>/dev/null - $CRASHDIR/start.sh cronset "订阅链接" 2>/dev/null - $CRASHDIR/start.sh cronset "ShellCrash初始化" 2>/dev/null + ${CRASHDIR}/start.sh stop + ${CRASHDIR}/start.sh cronset "clash服务" 2>/dev/null + ${CRASHDIR}/start.sh cronset "订阅链接" 2>/dev/null + ${CRASHDIR}/start.sh cronset "ShellCrash初始化" 2>/dev/null read -p "是否保留脚本配置及订阅文件?[1/0] > " res if [ "$res" = '1' ]; then - mv -f $CRASHDIR/configs /tmp/clash_$USER - mv -f $CRASHDIR/yamls /tmp/clash_$USER - rm -rf $CRASHDIR/* - mv -f /tmp/clash_$USER/configs $CRASHDIR - mv -f /tmp/clash_$USER/yamls $CRASHDIR + mv -f ${CRASHDIR}/configs /tmp/ShellCrash + mv -f ${CRASHDIR}/yamls /tmp/ShellCrash + rm -rf ${CRASHDIR}/* + mv -f /tmp/ShellCrash/configs ${CRASHDIR} + mv -f /tmp/ShellCrash/yamls ${CRASHDIR} else - rm -rf $CRASHDIR + rm -rf ${CRASHDIR} fi [ -w ~/.bashrc ] && profile=~/.bashrc [ -w /etc/profile ] && profile=/etc/profile @@ -1869,12 +1883,12 @@ case "$1" in sed -i "/启用外网访问SSH服务/d" /etc/firewall.user sed -i '/ShellCrash初始化/'d /etc/storage/started_script.sh 2>/dev/null sed -i '/ShellCrash初始化/'d /jffs/.asusrouter 2>/dev/null - rm -rf $bindir - rm -rf /etc/init.d/clash + rm -rf ${BINDIR} + rm -rf /etc/init.d/shellcrash rm -rf /etc/systemd/system/shellcrash.service rm -rf /usr/lib/systemd/system/shellcrash.service rm -rf /www/clash - rm -rf /tmp/clash_$USER + rm -rf /tmp/ShellCrash sed -Ei s/0:7890/7890:7890/g /etc/passwd userdel -r shellcrash 2>/dev/null nvram set script_usbmount="" 2>/dev/null diff --git a/scripts/misnap_init.sh b/scripts/misnap_init.sh index a50be7e..f215f34 100644 --- a/scripts/misnap_init.sh +++ b/scripts/misnap_init.sh @@ -52,12 +52,12 @@ init(){ #初始化环境变量 sed -i "/alias crash/d" $profile sed -i "/export CRASHDIR/d" $profile - echo "alias crash=\"$CRASHDIR/menu.sh\"" >>$profile + echo "alias crash=\"sh $CRASHDIR/menu.sh\"" >>$profile echo "export CRASHDIR=\"$CRASHDIR\"" >>$profile #软固化功能 autoSSH #设置init.d服务 - cp -f $CRASHDIR/shellcrash.rc /etc/init.d/shellcrash + cp -f $CRASHDIR/shellcrash.procd /etc/init.d/shellcrash chmod 755 /etc/init.d/shellcrash #启动服务 if [ ! -f $CRASHDIR/.dis_startup ]; then diff --git a/scripts/shellcrash.rc b/scripts/shellcrash.procd similarity index 74% rename from scripts/shellcrash.rc rename to scripts/shellcrash.procd index 554c97f..d11be25 100644 --- a/scripts/shellcrash.rc +++ b/scripts/shellcrash.procd @@ -8,9 +8,7 @@ USE_PROCD=1 #获取目录 CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}') [ -z "$CRASHDIR" ] && CRASHDIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}') -BINDIR=$(cat $DIR/configs/ShellCrash.cfg | grep bindir | awk -F "=" '{print $2}') -[ -z "$BINDIR" ] && BINDIR=$DIR -source $DIR/configs/service.env +source ${CRASHDIR}/configs/command.env #加载启动命令和启动目录 start_service() { #检测必须文件 @@ -19,12 +17,16 @@ start_service() { #使用procd创建clash后台进程 procd_open_instance procd_set_param respawn + procd_set_param command $COMMAND procd_set_param stderr 0 procd_set_param stdout 0 - procd_set_param command $COMMAND procd_close_instance - #其他设置 + #启动结束执行 $CRASHDIR/start.sh afstart fi } - +stop_service(){ + procd_close_instance + $CRASHDIR/start.sh stop_firewall + $CRASHDIR/start.sh unset_proxy +} diff --git a/scripts/shellcrash.service b/scripts/shellcrash.service index ce06522..0eb4445 100644 --- a/scripts/shellcrash.service +++ b/scripts/shellcrash.service @@ -7,10 +7,10 @@ Type=simple User=root CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH -EnvironmentFile=/etc/ShellCrash/configs/systemd.env -ExecStartPre=$CRASHDIR/start.sh bfstart -ExecStart=$ExecStart -ExecStartPost=$CRASHDIR/start.sh afstart +ExecStartPre=/etc/ShellCrash/start.sh bfstart +ExecStart=/etc/ShellCrash/CrashCore run -D /etc/ShellCrash -c /tmp/ShellCrash/config.json +ExecStartPost=/etc/ShellCrash/start.sh afstart +ExecStopPost=/etc/ShellCrash/start.sh stop_firewall ; /etc/ShellCrash/start.sh unset_proxy Restart=on-failure RestartSec=5s LimitNOFILE=infinity diff --git a/scripts/start.sh b/scripts/start.sh index 5159812..b3746f6 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -2,18 +2,17 @@ # Copyright (C) Juewuy #初始化目录 -[ -d "/etc/storage/clash" ] && CRASHDIR=/etc/storage/clash -[ -d "/jffs/clash" ] && CRASHDIR=/jffs/clash -[ -z "$CRASHDIR" ] && CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}') -[ -z "$CRASHDIR" ] && CRASHDIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}') -CFG_PATH=$CRASHDIR/configs/ShellCrash.cfg -TMPDIR=/tmp/ShellCrash && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR +CRASHDIR=$(cd $(dirname $0);pwd) +#加载执行目录,失败则初始化 +source ${CRASHDIR}/configs/command.env &>/dev/null +[ -z "$BINDIR" -o -z "$TMPDIR" -o -z "$COMMAND" ] && source ${CRASHDIR}/init.sh &>/dev/null +[ ! -f ${TMPDIR} ] && mkdir -p ${TMPDIR} + #脚本内部工具 -getconfig(){ +getconfig(){ #获取脚本配置 #加载配置文件 - source $CFG_PATH &> /dev/null + source ${CRASHDIR}/configs/ShellCrash.cfg >/dev/null #默认设置 - [ -z "$bindir" ] && bindir=$CRASHDIR [ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod=Redir模式 [ -z "$redir_mod" ] && redir_mod=纯净模式 [ -z "$skip_cert" ] && skip_cert=已开启 @@ -34,21 +33,21 @@ getconfig(){ [ -z "$multiport" ] && multiport='22,53,80,123,143,194,443,465,587,853,993,995,5222,8080,8443' [ "$common_ports" = "已开启" ] && ports="-m multiport --dports $multiport" #内核配置文件 - [ -z "$core_config" ] && if [ "$crashcore" = singbox ];then - core_config=$CRASHDIR/jsons/config.json + if [ "$crashcore" = singbox ];then + core_config=${CRASHDIR}/jsons/config.json else - core_config=$CRASHDIR/yamls/config.yaml + core_config=${CRASHDIR}/yamls/config.yaml fi } -setconfig(){ +setconfig(){ #脚本配置工具 #参数1代表变量名,参数2代表变量值,参数3即文件路径 - [ -z "$3" ] && configpath=$CFG_PATH || configpath=$3 - [ -n "$(grep ${1} $configpath)" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath + [ -z "$3" ] && configpath=${CRASHDIR}/configs/ShellCrash.cfg || configpath="${3}" + [ -n "$(grep "${1}=" "$configpath")" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath } -ckcmd(){ +ckcmd(){ #检查命令是否存在 command -v sh &>/dev/null && command -v $1 &>/dev/null || type $1 &>/dev/null } -compare(){ +compare(){ #对比文件 if [ ! -f $1 -o ! -f $2 ];then return 1 elif ckcmd cmp;then @@ -57,12 +56,12 @@ compare(){ [ "$(cat $1)" = "$(cat $2)" ] && return 0 || return 1 fi } -logger(){ +logger(){ #日志工具 #$1日志内容$2显示颜色$3是否推送 [ -n "$2" -a "$2" != 0 ] && echo -e "\033[$2m$1\033[0m" log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1" - echo $log_text >> $TMPDIR/ShellCrash.log - [ "$(wc -l $TMPDIR/ShellCrash.log | awk '{print $1}')" -gt 99 ] && sed -i '1,50d' $TMPDIR/ShellCrash.log + echo $log_text >> ${TMPDIR}/ShellCrash.log + [ "$(wc -l ${TMPDIR}/ShellCrash.log | awk '{print $1}')" -gt 99 ] && sed -i '1,50d' ${TMPDIR}/ShellCrash.log [ -z "$3" ] && { getconfig [ -n "$device_name" ] && log_text="$log_text($device_name)" @@ -102,7 +101,7 @@ logger(){ } } & } -croncmd(){ +croncmd(){ #定时任务工具 if [ -n "$(crontab -h 2>&1 | grep '\-l')" ];then crontab $1 else @@ -115,9 +114,9 @@ croncmd(){ [ -f "$1" ] && cat $1 > $crondir/$USER fi } -cronset(){ +cronset(){ #定时任务设置 # 参数1代表要移除的关键字,参数2代表要添加的任务语句 - tmpcron=$TMPDIR/cron_$USER + tmpcron=${TMPDIR}/cron_$USER croncmd -l > $tmpcron sed -i "/$1/d" $tmpcron sed -i '/^$/d' $tmpcron @@ -125,29 +124,29 @@ cronset(){ croncmd $tmpcron rm -f $tmpcron } -get_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" fi } -put_save(){ +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 elif wget --version > /dev/null 2>&1;then wget -q --method=PUT --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" --body-data="$2" "$1" >/dev/null fi } -mark_time(){ - echo `date +%s` > $TMPDIR/crash_start_time +mark_time(){ #时间戳 + echo `date +%s` > ${TMPDIR}/crash_start_time } -getlanip(){ +getlanip(){ #获取局域网host地址 i=1 while [ "$i" -le "10" ];do host_ipv4=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'br' | grep -Ev 'iot' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/br.*$//g' | sed 's/metric.*$//g' ) #ipv4局域网网段 [ "$ipv6_redir" = "已开启" ] && host_ipv6=$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g' ) #ipv6公网地址段 - [ -f $TMPDIR/ShellCrash.log ] && break + [ -f ${TMPDIR}/ShellCrash.log ] && break [ -n "$host_ipv4" -a -n "$host_ipv6" ] && break sleep 2 && i=$((i+1)) done @@ -164,7 +163,7 @@ getlanip(){ reserve_ipv6="::/128 ::1/128 ::ffff:0:0/96 64:ff9b::/96 100::/64 2001::/32 2001:20::/28 2001:db8::/32 2002::/16 fc00::/7 fe80::/10 ff00::/8" } #配置文件相关 -check_clash_config(){ +check_clash_config(){ #检查clash配置文件 #检测节点或providers if [ -z "$(cat $core_config_new | grep -E 'server|proxy-providers' | grep -v 'nameserver' | head -n 1)" ];then echo ----------------------------------------------- @@ -193,45 +192,47 @@ check_clash_config(){ fi #检测并去除无效节点组 [ -n "$url_type" ] && ckcmd xargs && { - cat $core_config_new | sed '/^rules:/,$d' | grep -A 15 "\- name:" | xargs | sed 's/- name: /\n/g' | sed 's/ type: .*proxies: /#/g' | sed 's/- //g' | grep -E '#DIRECT $|#DIRECT$' | awk -F '#' '{print $1}' > $TMPDIR/clash_proxies_$USER + cat $core_config_new | sed '/^rules:/,$d' | grep -A 15 "\- name:" | xargs | sed 's/- name: /\n/g' | sed 's/ type: .*proxies: /#/g' | sed 's/- //g' | grep -E '#DIRECT $|#DIRECT$' | awk -F '#' '{print $1}' > ${TMPDIR}/clash_proxies_$USER while read line ;do sed -i "/- $line/d" $core_config_new sed -i "/- name: $line/,/- DIRECT/d" $core_config_new - done < $TMPDIR/clash_proxies_$USER - rm -rf $TMPDIR/clash_proxies_$USER + done < ${TMPDIR}/clash_proxies_$USER + rm -rf ${TMPDIR}/clash_proxies_$USER } #使用核心内置test功能检测 - if [ -x $bindir/clash ];then - $bindir/clash -t -d $bindir -f $core_config_new >/dev/null + if [ -x ${BINDIR}/CrashCore ];then + ${BINDIR}/CrashCore -t -d ${BINDIR} -f $core_config_new >/dev/null if [ "$?" != "0" ];then logger "配置文件加载失败!请查看报错信息!" 31 - $bindir/clash -t -d $bindir -f $core_config_new - echo "$($bindir/clash -t -d $bindir -f $core_config_new)" >> $TMPDIR/ShellCrash.log + ${BINDIR}/CrashCore -t -d ${BINDIR} -f $core_config_new + echo "$($BINDIR/CrashCore -t -d $BINDIR -f $core_config_new)" >> ${TMPDIR}/ShellCrash.log exit 1 fi fi } -check_singbox_config(){ +check_singbox_config(){ #检查singbox配置文件 #使用核心内置format功能检测并格式化 - if [ -x $bindir/singbox ];then - $bindir/singbox format -c $core_config_new > $TMPDIR/format.json + if [ -x ${BINDIR}/CrashCore ];then + echo -e "\033[36m已获取配置文件,正在调用内核检查文件可用性!\033[0m" + ${BINDIR}/CrashCore format -c $core_config_new > ${TMPDIR}/format.json if [ "$?" != "0" ];then logger "配置文件加载失败!请查看报错信息!" 31 - $bindir/singbox check -c $core_config_new - echo "$($bindir/singbox check -c $core_config_new)" >> $TMPDIR/ShellCrash.log + ${BINDIR}/CrashCore check -c $core_config_new + echo "$($BINDIR/CrashCore check -c $core_config_new)" >> ${TMPDIR}/ShellCrash.log exit 1 else - mv -f $TMPDIR/format.json $core_config_new + mv -f ${TMPDIR}/format.json $core_config_new fi fi } -get_core_config(){ +get_core_config(){ #下载内核配置文件 + getconfig [ -z "$rule_link" ] && rule_link=1 [ -z "$server_link" ] && server_link=1 - Server=$(grep -aE '^3|^4' $CRASHDIR/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}') - [ -n "$(echo $Url | grep -oE 'vless:|hysteria:')" ] && Server=$(grep -aE '^4' $CRASHDIR/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}') - [ "$retry" = 4 ] && Server=$(grep -aE '^497' $CRASHDIR/configs/servers.list | awk '{print $3}') - Config=$(grep -aE '^5' $CRASHDIR/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $3}') + Server=$(grep -aE '^3|^4' ${CRASHDIR}/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}') + [ -n "$(echo $Url | grep -oE 'vless:|hysteria:')" ] && Server=$(grep -aE '^4' ${CRASHDIR}/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}') + [ "$retry" = 4 ] && Server=$(grep -aE '^497' ${CRASHDIR}/configs/servers.list | awk '{print $3}') + Config=$(grep -aE '^5' ${CRASHDIR}/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $3}') #如果传来的是Url链接则合成Https链接,否则直接使用Https链接 if [ -z "$Https" ];then if [ "$crashcore" = singbox ];then @@ -241,18 +242,20 @@ get_core_config(){ target=clash format=yaml fi - Https="$Server/sub?target=$target&insert=true&new_name=true&scv=true&udp=true&exclude=$exclude&include=$include&url=$Url&config=$Config" + #Urlencord转码处理保留字符 + Url=$(echo $Url | sed 's/;/\%3B/g; s|/|\%2F|g; s/?/\%3F/g; s/:/\%3A/g; s/@/\%4O/g; s/=/\%3D/g; s/&/\%26/g') + Https="${Server}/sub?target=${target}&insert=true&new_name=true&scv=true&udp=true&exclude=${exclude}&include=${include}&url=${Url}&config=${Config}" url_type=true fi #输出 echo ----------------------------------------------- - logger 正在连接服务器获取$target配置文件………… + logger 正在连接服务器获取【${target}】配置文件………… echo -e "链接地址为:\033[4;32m$Https\033[0m" echo 可以手动复制该链接到浏览器打开并查看数据是否正常! #获取在线config文件 - core_config_new=$TMPDIR/$target_config.$format - rm -rf $core_config_new - $0 webget $core_config_new $Https + core_config_new=${TMPDIR}/${target}_config.${format} + rm -rf ${core_config_new} + $0 webget "$core_config_new" "$Https" if [ "$?" = "1" ];then if [ -z "$url_type" ];then echo ----------------------------------------------- @@ -263,7 +266,7 @@ get_core_config(){ else if [ "$retry" = 4 ];then logger "无法获取配置文件,请检查链接格式以及网络连接状态!" 31 - echo -e "\033[32m也可用浏览器下载以上链接后,使用WinSCP手动上传到/tmp目录后执行clash命令!\033[0m" + echo -e "\033[32m也可用浏览器下载以上链接后,使用WinSCP手动上传到/tmp目录后执行crash命令!\033[0m" exit 1 elif [ "$retry" = 3 ];then retry=4 @@ -299,7 +302,7 @@ get_core_config(){ echo -e "\033[32m已成功获取配置文件!\033[0m" fi } -modify_yaml(){ +modify_yaml(){ #修饰clash配置文件 ##########需要变更的配置########### [ -z "$dns_nameserver" ] && dns_nameserver='114.114.114.114, 223.5.5.5' [ -z "$dns_fallback" ] && dns_fallback='1.0.0.1, 8.8.4.4' @@ -319,9 +322,9 @@ modify_yaml(){ [ "$redir_mod" != "纯净模式" ] && find_process='find-process-mode: "off"' } #dns配置 - [ -z "$(cat $CRASHDIR/yamls/user.yaml 2>/dev/null | grep '^dns:')" ] && { + [ -z "$(cat ${CRASHDIR}/yamls/user.yaml 2>/dev/null | grep '^dns:')" ] && { [ "$crashcore" = 'meta' ] && dns_default_meta='- https://223.5.5.5/dns-query' - cat > $TMPDIR/dns.yaml < ${TMPDIR}/dns.yaml </dev/null | grep '\.' | sed "s/^/ - '/" | sed "s/$/'/" >> $TMPDIR/dns.yaml + cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep '\.' | sed "s/^/ - '/" | sed "s/$/'/" >> ${TMPDIR}/dns.yaml else - echo " - '+.*'" >> $TMPDIR/dns.yaml + echo " - '+.*'" >> ${TMPDIR}/dns.yaml #使用fake-ip模拟redir_host fi - cat >> $TMPDIR/dns.yaml <> ${TMPDIR}/dns.yaml <> $TMPDIR/dns.yaml - cat $CRASHDIR/configs/fallback_filter.list | grep '\.' | sed "s/^/ - '/" | sed "s/$/'/" >> $TMPDIR/dns.yaml + [ -s ${CRASHDIR}/configs/fallback_filter.list ] && { + echo " domain:" >> ${TMPDIR}/dns.yaml + cat ${CRASHDIR}/configs/fallback_filter.list | grep '\.' | sed "s/^/ - '/" | sed "s/$/'/" >> ${TMPDIR}/dns.yaml } } #域名嗅探配置 [ "$sniffer" = "已启用" ] && [ "$crashcore" = "meta" ] && sniffer_set="sniffer: {enable: true, skip-domain: [Mijia Cloud], sniff: {tls: {ports: [443, 8443]}, http: {ports: [80, 8080-8880]}}}" [ "$crashcore" = "clashpre" ] && [ "$dns_mod" = "redir_host" ] && exper="experimental: {ignore-resolve-fail: true, interface-name: en0, sniff-tls-sni: true}" #生成set.yaml - cat > $TMPDIR/set.yaml < ${TMPDIR}/set.yaml </dev/null)" ];then + if [ "$hosts_opt" != "未启用" ] && [ -z "$(grep -aE '^hosts:' ${CRASHDIR}/yamls/user.yaml 2>/dev/null)" ];then #NTP劫持 - cat >> $TMPDIR/hosts.yaml <> ${TMPDIR}/hosts.yaml <> $TMPDIR/hosts.yaml + [ -z "$(cat ${TMPDIR}/hosts.yaml | grep -oE "$hosts_domain")" ] && \ + echo " '$hosts_domain': $hosts_ip" >> ${TMPDIR}/hosts.yaml done < $sys_hosts fi #分割配置文件 yaml_char='proxies proxy-groups proxy-providers rules rule-providers' - for char in $core_config_char;do - sed -n "/^$char:/,/^[a-z]/ { /^[a-z]/d; p; }" $core_config > $TMPDIR/${char}.yaml + for char in $yaml_char;do + sed -n "/^$char:/,/^[a-z]/ { /^[a-z]/d; p; }" $core_config > ${TMPDIR}/${char}.yaml done #跳过本地tls证书验证 - [ "$skip_cert" = "已开启" ] && sed -i 's/skip-cert-verify: false/skip-cert-verify: true/' $TMPDIR/proxies.yaml || \ - sed -i 's/skip-cert-verify: true/skip-cert-verify: false/' $TMPDIR/proxies.yaml + [ "$skip_cert" = "已开启" ] && sed -i 's/skip-cert-verify: false/skip-cert-verify: true/' ${TMPDIR}/proxies.yaml || \ + sed -i 's/skip-cert-verify: true/skip-cert-verify: false/' ${TMPDIR}/proxies.yaml #插入自定义策略组 - sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $TMPDIR/proxy-groups.yaml - sed -i "/#自定义策略组/d" $TMPDIR/proxy-groups.yaml - [ -n "$(grep -Ev '^#' $CRASHDIR/yamls/proxy-groups.yaml 2>/dev/null)" ] && { + sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" ${TMPDIR}/proxy-groups.yaml + sed -i "/#自定义策略组/d" ${TMPDIR}/proxy-groups.yaml + [ -n "$(grep -Ev '^#' ${CRASHDIR}/yamls/proxy-groups.yaml 2>/dev/null)" ] && { #获取空格数 - space_name=$(grep -aE '^ *- name: ' $TMPDIR/proxy-groups.yaml | head -n 1 | grep -oE '^ *') - space_proxy=$(grep -A 1 'proxies:$' $TMPDIR/proxy-groups.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *') + space_name=$(grep -aE '^ *- name: ' ${TMPDIR}/proxy-groups.yaml | head -n 1 | grep -oE '^ *') + space_proxy=$(grep -A 1 'proxies:$' ${TMPDIR}/proxy-groups.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *') #合并自定义策略组到proxy-groups.yaml - cat $CRASHDIR/yamls/proxy-groups.yaml | sed "/^#/d" | sed "s/#.*//g" | sed '1i\ #自定义策略组开始' | sed '$a\ #自定义策略组结束' | sed "s/^ */${space_name} /g" | sed "s/^ *- /${space_proxy}- /g" | sed "s/^ *- name: /${space_name}- name: /g" > $TMPDIR/proxy-groups_add.yaml - cat $TMPDIR/proxy-groups.yaml >> $TMPDIR/proxy-groups_add.yaml - mv -f $TMPDIR/proxy-groups_add.yaml $TMPDIR/proxy-groups.yaml + cat ${CRASHDIR}/yamls/proxy-groups.yaml | sed "/^#/d" | sed "s/#.*//g" | sed '1i\ #自定义策略组开始' | sed '$a\ #自定义策略组结束' | sed "s/^ */${space_name} /g" | sed "s/^ *- /${space_proxy}- /g" | sed "s/^ *- name: /${space_name}- name: /g" > ${TMPDIR}/proxy-groups_add.yaml + cat ${TMPDIR}/proxy-groups.yaml >> ${TMPDIR}/proxy-groups_add.yaml + mv -f ${TMPDIR}/proxy-groups_add.yaml ${TMPDIR}/proxy-groups.yaml oldIFS="$IFS" - grep "\- name: " $CRASHDIR/yamls/proxy-groups.yaml | sed "/^#/d" | while read line;do #将自定义策略组插入现有的proxy-group + grep "\- name: " ${CRASHDIR}/yamls/proxy-groups.yaml | sed "/^#/d" | while read line;do #将自定义策略组插入现有的proxy-group new_group=$(echo $line | grep -Eo '^ *- name:.*#' | cut -d'#' -f1 | sed 's/.*name: //g') proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" ) IFS="#" for name in $proxy_groups; do - line_a=$(grep -n "\- name: $name" $TMPDIR/proxy-groups.yaml | awk -F: '{print $1}') #获取group行号 + line_a=$(grep -n "\- name: $name" ${TMPDIR}/proxy-groups.yaml | awk -F: '{print $1}') #获取group行号 [ -n "$line_a" ] && { - line_b=$(grep -A 8 "\- name: $name" $TMPDIR/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号 + line_b=$(grep -A 8 "\- name: $name" ${TMPDIR}/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号 line_c=$((line_a + line_b - 1)) #计算需要插入的行号 - space=$(sed -n "$((line_c + 1))p" $TMPDIR/proxy-groups.yaml | grep -oE '^ *') #获取空格数 - [ "$line_c" -gt 2 ] && sed -i "${line_c}a\\${space}- ${new_group} #自定义策略组" $TMPDIR/proxy-groups.yaml + space=$(sed -n "$((line_c + 1))p" ${TMPDIR}/proxy-groups.yaml | grep -oE '^ *') #获取空格数 + [ "$line_c" -gt 2 ] && sed -i "${line_c}a\\${space}- ${new_group} #自定义策略组" ${TMPDIR}/proxy-groups.yaml } done IFS="$oldIFS" done } #插入自定义代理 - sed -i "/#自定义代理/d" $TMPDIR/proxies.yaml - sed -i "/#自定义代理/d" $TMPDIR/proxy-groups.yaml - [ -n "$(grep -Ev '^#' $CRASHDIR/yamls/proxies.yaml 2>/dev/null)" ] && { - space_proxy=$(cat $TMPDIR/proxies.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *') #获取空格数 - cat $CRASHDIR/yamls/proxies.yaml | sed "s/^ *- /${space_proxy}- /g" | sed "/^#/d" | sed "/^ *$/d" | sed 's/#.*/ #自定义代理/g' >> $TMPDIR/proxies.yaml #插入节点 + sed -i "/#自定义代理/d" ${TMPDIR}/proxies.yaml + sed -i "/#自定义代理/d" ${TMPDIR}/proxy-groups.yaml + [ -n "$(grep -Ev '^#' ${CRASHDIR}/yamls/proxies.yaml 2>/dev/null)" ] && { + space_proxy=$(cat ${TMPDIR}/proxies.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *') #获取空格数 + cat ${CRASHDIR}/yamls/proxies.yaml | sed "s/^ *- /${space_proxy}- /g" | sed "/^#/d" | sed "/^ *$/d" | sed 's/#.*/ #自定义代理/g' >> ${TMPDIR}/proxies.yaml #插入节点 oldIFS="$IFS" - cat $CRASHDIR/yamls/proxies.yaml | sed "/^#/d" | while read line;do #将节点插入proxy-group + cat ${CRASHDIR}/yamls/proxies.yaml | sed "/^#/d" | while read line;do #将节点插入proxy-group proxy_name=$(echo $line | grep -Eo 'name: .+, ' | cut -d',' -f1 | sed 's/name: //g') proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" ) IFS="#" for name in $proxy_groups; do - line_a=$(grep -n "\- name: $name" $TMPDIR/proxy-groups.yaml | awk -F: '{print $1}') #获取group行号 + line_a=$(grep -n "\- name: $name" ${TMPDIR}/proxy-groups.yaml | awk -F: '{print $1}') #获取group行号 [ -n "$line_a" ] && { - line_b=$(grep -A 8 "\- name: $name" $TMPDIR/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号 + line_b=$(grep -A 8 "\- name: $name" ${TMPDIR}/proxy-groups.yaml | grep -n "proxies:$" | head -n 1 | awk -F: '{print $1}') #获取proxies行号 line_c=$((line_a + line_b - 1)) #计算需要插入的行号 - space=$(sed -n "$((line_c + 1))p" $TMPDIR/proxy-groups.yaml | grep -oE '^ *') #获取空格数 - [ "$line_c" -gt 2 ] && sed -i "${line_c}a\\${space}- ${proxy_name} #自定义代理" $TMPDIR/proxy-groups.yaml + space=$(sed -n "$((line_c + 1))p" ${TMPDIR}/proxy-groups.yaml | grep -oE '^ *') #获取空格数 + [ "$line_c" -gt 2 ] && sed -i "${line_c}a\\${space}- ${proxy_name} #自定义代理" ${TMPDIR}/proxy-groups.yaml } done IFS="$oldIFS" done } #节点绕过功能支持 - sed -i "/#节点绕过/d" $TMPDIR/rules.yaml + sed -i "/#节点绕过/d" ${TMPDIR}/rules.yaml [ "$proxies_bypass" = "已启用" ] && { - cat $TMPDIR/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '!a[$0]++' | sed 's/^/\ -\ IP-CIDR,/g' | sed 's|$|/32,DIRECT,no-resolve #节点绕过|g' >> $TMPDIR/proxies_bypass - cat $TMPDIR/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -vE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?'| awk '!a[$0]++' | sed 's/^/\ -\ DOMAIN,/g' | sed 's/$/,DIRECT #节点绕过/g' >> $TMPDIR/proxies_bypass - cat $TMPDIR/rules.yaml >> $TMPDIR/proxies_bypass - mv -f $TMPDIR/proxies_bypass $TMPDIR/rules.yaml + cat ${TMPDIR}/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '!a[$0]++' | sed 's/^/\ -\ IP-CIDR,/g' | sed 's|$|/32,DIRECT,no-resolve #节点绕过|g' >> ${TMPDIR}/proxies_bypass + cat ${TMPDIR}/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -vE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?'| awk '!a[$0]++' | sed 's/^/\ -\ DOMAIN,/g' | sed 's/$/,DIRECT #节点绕过/g' >> ${TMPDIR}/proxies_bypass + cat ${TMPDIR}/rules.yaml >> ${TMPDIR}/proxies_bypass + mv -f ${TMPDIR}/proxies_bypass ${TMPDIR}/rules.yaml } #插入自定义规则 - sed -i "/#自定义规则/d" $TMPDIR/rules.yaml - [ -f $CRASHDIR/yamls/rules.yaml ] && { - cat $CRASHDIR/yamls/rules.yaml | sed "/^#/d" | sed '$a\' | sed 's/$/ #自定义规则/g' > $TMPDIR/rules.add - cat $TMPDIR/rules.yaml >> $TMPDIR/rules.add - mv -f $TMPDIR/rules.add $TMPDIR/rules.yaml + sed -i "/#自定义规则/d" ${TMPDIR}/rules.yaml + [ -f ${CRASHDIR}/yamls/rules.yaml ] && { + cat ${CRASHDIR}/yamls/rules.yaml | sed "/^#/d" | sed '$a\' | sed 's/$/ #自定义规则/g' > ${TMPDIR}/rules.add + cat ${TMPDIR}/rules.yaml >> ${TMPDIR}/rules.add + mv -f ${TMPDIR}/rules.add ${TMPDIR}/rules.yaml } #对齐rules中的空格 - sed -i 's/^ *-/ -/g' $TMPDIR/rules.yaml + sed -i 's/^ *-/ -/g' ${TMPDIR}/rules.yaml #合并文件 - [ -s $CRASHDIR/yamls/user.yaml ] && { - yaml_user=$CRASHDIR/yamls/user.yaml + [ -s ${CRASHDIR}/yamls/user.yaml ] && { + yaml_user=${CRASHDIR}/yamls/user.yaml #set和user去重,且优先使用user.yaml - cp -f $TMPDIR/set.yaml $TMPDIR/set_bak.yaml + cp -f ${TMPDIR}/set.yaml ${TMPDIR}/set_bak.yaml for char in mode allow-lan log-level tun experimental interface-name dns store-selected;do - [ -n "$(grep -E "^$char" $core_config_user)" ] && sed -i "/^$char/d" $TMPDIR/set.yaml + [ -n "$(grep -E "^$char" $yaml_user)" ] && sed -i "/^$char/d" ${TMPDIR}/set.yaml done } - [ -s $TMPDIR/dns.yaml ] && yaml_dns=$TMPDIR/dns.yaml - [ -s $TMPDIR/hosts.yaml ] && yaml_hosts=$TMPDIR/hosts.yaml - [ -s $CRASHDIR/yamls/others.yaml ] && yaml_others=$CRASHDIR/yamls/others.yaml + [ -s ${TMPDIR}/dns.yaml ] && yaml_dns=${TMPDIR}/dns.yaml + [ -s ${TMPDIR}/hosts.yaml ] && yaml_hosts=${TMPDIR}/hosts.yaml + [ -s ${CRASHDIR}/yamls/others.yaml ] && yaml_others=${CRASHDIR}/yamls/others.yaml yaml_add= - for char in $core_config_char;do #将额外配置文件合并 - [ -s $TMPDIR/${char}.yaml ] && { - sed -i "1i\\${char}:" $TMPDIR/${char}.yaml - yaml_add="$core_config_add $TMPDIR/${char}.yaml" + for char in $yaml_char;do #将额外配置文件合并 + [ -s ${TMPDIR}/${char}.yaml ] && { + sed -i "1i\\${char}:" ${TMPDIR}/${char}.yaml + yaml_add="$yaml_add ${TMPDIR}/${char}.yaml" } done #合并完整配置文件 - cut -c 1- $TMPDIR/set.yaml $core_config_dns $core_config_hosts $core_config_user $core_config_others $core_config_add > $TMPDIR/config.yaml + cut -c 1- ${TMPDIR}/set.yaml $yaml_dns $yaml_hosts $yaml_user $yaml_others $yaml_add > ${TMPDIR}/config.yaml #测试自定义配置文件 - $bindir/clash -t -d $bindir -f $TMPDIR/config.yaml >/dev/null + ${BINDIR}/CrashCore -t -d ${BINDIR} -f ${TMPDIR}/config.yaml >/dev/null if [ "$?" != 0 ];then - logger "$($bindir/clash -t -d $bindir -f $TMPDIR/config.yaml | grep -Eo 'error.*=.*')" 31 + logger "$(${BINDIR}/CrashCore -t -d ${BINDIR} -f ${TMPDIR}/config.yaml | grep -Eo 'error.*=.*')" 31 logger "自定义配置文件校验失败!将使用基础配置文件启动!" 33 - logger "错误详情请参考 $TMPDIR/error.yaml 文件!" 33 - mv -f $TMPDIR/config.yaml $TMPDIR/error.yaml &>/dev/null - sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $TMPDIR/proxy-groups.yaml - mv -f $TMPDIR/set_bak.yaml $TMPDIR/set.yaml &>/dev/null + logger "错误详情请参考 ${TMPDIR}/error.yaml 文件!" 33 + mv -f ${TMPDIR}/config.yaml ${TMPDIR}/error.yaml &>/dev/null + sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" ${TMPDIR}/proxy-groups.yaml + mv -f ${TMPDIR}/set_bak.yaml ${TMPDIR}/set.yaml &>/dev/null #合并基础配置文件 - cut -c 1- $TMPDIR/set.yaml $core_config_dns $core_config_add > $TMPDIR/config.yaml - sed -i "/#自定义/d" $TMPDIR/config.yaml + cut -c 1- ${TMPDIR}/set.yaml $yaml_dns $yaml_add > ${TMPDIR}/config.yaml + sed -i "/#自定义/d" ${TMPDIR}/config.yaml fi #建立软连接 - [ "$TMPDIR" = "$bindir" ] || ln -sf $TMPDIR/config.yaml $bindir/config.yaml + [ "${TMPDIR}" = "${BINDIR}" ] || ln -sf ${TMPDIR}/config.yaml ${BINDIR}/config.yaml #清理缓存 - for char in $core_config_char set set_bak dns hosts;do - rm -f $TMPDIR/${char}.yaml + for char in $yaml_char set set_bak dns hosts;do + rm -f ${TMPDIR}/${char}.yaml done } -modify_json(){ +modify_json(){ #修饰singbox配置文件 #生成log.json - cat > $TMPDIR/log.json < ${TMPDIR}/log.json </dev/null | grep '^dns:')" ] && { - cat > $TMPDIR/dns.json </dev/null | grep '^dns:')" ] && { + [ -z "$dns_nameserver" ] && dns_nameserver='223.5.5.5' || dns_nameserver=$(echo $dns_nameserver | awk -F ',' '{print $1}') + [ -z "$dns_fallback" ] && dns_fallback='1.0.0.1' || dns_fallback=$(echo $dns_fallback | awk -F ',' '{print $1}') + [ "$ipv6_dns" = "已开启" ] && strategy='prefer_ipv4' || strategy='ipv4_only' + [ "$dns_mod" = "redir_host" ] && proxy_dns=dns_proxy && direct_dns=dns_direct + [ "$dns_mod" = "fake-ip" ] && proxy_dns=dns_fakeip && direct_dns=dns_fakeip + [ "$dns_mod" = "mix" ] && proxy_dns=dns_fakeip && direct_dns=dns_direct + cat > ${TMPDIR}/dns.json < $TMPDIR/ntp.json < ${TMPDIR}/ntp.json < $TMPDIR/inbounds.json < ${TMPDIR}/inbounds.json <> ${TMPDIR}/inbounds.json <> ${TMPDIR}/inbounds.json < $TMPDIR/experimental.json < ${TMPDIR}/experimental.json < $TMPDIR/outbounds.json - cat $core_config | sed -n '/"route":/,/"experimental":/{/"experimental":/d; p}' > $TMPDIR/route.json + cat $core_config | sed -n '/"outbounds":/,/"route":/{/"route":/d; p}' > ${TMPDIR}/outbounds.json + cat $core_config | sed -n '/"route":/,/"experimental":/{/"experimental":/d; p}' > ${TMPDIR}/route.json + #清理route.json中的process_name规则 + sed -i '/"process_name": \[/,/],$/d' ${TMPDIR}/route.json + sed -i '/"process_name": "[^"]*",/d' ${TMPDIR}/route.json #跳过本地tls证书验证 if [ -z "$skip_cert" -o "$skip_cert" = "已开启" ];then - sed -i 's/"insecure": false/"insecure": true/' $TMPDIR/outbounds.json + sed -i 's/"insecure": false/"insecure": true/' ${TMPDIR}/outbounds.json else - sed -i 's/"insecure": true/"insecure": false/' $TMPDIR/outbounds.json + sed -i 's/"insecure": true/"insecure": false/' ${TMPDIR}/outbounds.json fi #合并文件 json_all= for char in log dns ntp inbounds outbounds route experimental;do - [ -s $TMPDIR/$char.json ] && json_add=$TMPDIR/$char.json - [ -s $CRASHDIR/jsons/$char.json ] && json_add=$CRASHDIR/jsons/$char.json #如果有自定义配置文件则使用 + [ -s ${TMPDIR}/$char.json ] && json_add=${TMPDIR}/$char.json + [ -s ${CRASHDIR}/jsons/$char.json ] && json_add=${CRASHDIR}/jsons/$char.json #如果有自定义配置文件则使用 json_all="$json_all $json_add" done - cut -c 1- $json_all > $TMPDIR/all.json + cut -c 1- $json_all > ${TMPDIR}/config.json #测试自定义配置文件 - $bindir/singbox check -D $bindir -c $TMPDIR/config.json >/dev/null + ${BINDIR}/CrashCore check -D ${BINDIR} -c ${TMPDIR}/config.json >/dev/null if [ "$?" != 0 ];then - logger "$($bindir/singbox check -D $bindir -c $TMPDIR/config.json | grep -Eo 'error.*=.*')" 31 + logger "$(${BINDIR}/CrashCore check -D ${BINDIR} -c ${TMPDIR}/config.json | grep -Eo 'error.*=.*')" 31 logger "自定义配置文件校验失败!将使用基础配置文件启动!" 33 - logger "错误详情请参考 $TMPDIR/error.json 文件!" 33 - mv -f $TMPDIR/config.json $TMPDIR/error.json &>/dev/null + logger "错误详情请参考 ${TMPDIR}/error.json 文件!" 33 + mv -f ${TMPDIR}/config.json ${TMPDIR}/error.json &>/dev/null #合并基础配置文件 + json_all='' for char in log dns ntp inbounds outbounds route experimental;do - [ -s $TMPDIR/$char.json ] && json_add=$TMPDIR/$char.json + [ -s ${TMPDIR}/$char.json ] && json_add=${TMPDIR}/$char.json json_all="$json_all $json_add" done - cut -c 1- $json_all > $TMPDIR/config.json + cut -c 1- $json_all > ${TMPDIR}/config.json fi #清理缓存 for char in all log dns ntp inbounds outbounds route experimental;do - rm -f $TMPDIR/${char}.json + rm -f ${TMPDIR}/${char}.json done } #设置路由规则 -cn_ip_route(){ - [ ! -f $bindir/cn_ip.txt ] && { - if [ -f $CRASHDIR/cn_ip.txt ];then - mv $CRASHDIR/cn_ip.txt $bindir/cn_ip.txt +cn_ip_route(){ #CN-IP绕过 + [ ! -f ${BINDIR}/cn_ip.txt ] && { + if [ -f ${CRASHDIR}/cn_ip.txt ];then + mv ${CRASHDIR}/cn_ip.txt ${BINDIR}/cn_ip.txt else logger "未找到cn_ip列表,正在下载!" 33 - $0 webget $bindir/cn_ip.txt "$update_url/bin/geodata/china_ip_list.txt" - [ "$?" = "1" ] && rm -rf $bindir/cn_ip.txt && logger "列表下载失败!" 31 + $0 webget ${BINDIR}/cn_ip.txt "$update_url/bin/geodata/china_ip_list.txt" + [ "$?" = "1" ] && rm -rf ${BINDIR}/cn_ip.txt && logger "列表下载失败!" 31 fi } - [ -f $bindir/cn_ip.txt -a -z "$(echo $redir_mod|grep 'Nft')" ] && { + [ -f ${BINDIR}/cn_ip.txt -a -z "$(echo $redir_mod|grep 'Nft')" ] && { # see https://raw.githubusercontent.com/Hackl0us/GeoIP2-CN/release/CN-ip-cidr.txt - echo "create cn_ip hash:net family inet hashsize 10240 maxelem 10240" > $TMPDIR/cn_$USER.ipset - awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' $bindir/cn_ip.txt >> $TMPDIR/cn_$USER.ipset + echo "create cn_ip hash:net family inet hashsize 10240 maxelem 10240" > ${TMPDIR}/cn_$USER.ipset + awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' ${BINDIR}/cn_ip.txt >> ${TMPDIR}/cn_$USER.ipset ipset -! flush cn_ip 2>/dev/null - ipset -! restore < $TMPDIR/cn_$USER.ipset + ipset -! restore < ${TMPDIR}/cn_$USER.ipset rm -rf cn_$USER.ipset } } -cn_ipv6_route(){ - [ ! -f $bindir/cn_ipv6.txt ] && { - if [ -f $CRASHDIR/cn_ipv6.txt ];then - mv $CRASHDIR/cn_ipv6.txt $bindir/cn_ipv6.txt +cn_ipv6_route(){ #CN-IPV6绕过 + [ ! -f ${BINDIR}/cn_ipv6.txt ] && { + if [ -f ${CRASHDIR}/cn_ipv6.txt ];then + mv ${CRASHDIR}/cn_ipv6.txt ${BINDIR}/cn_ipv6.txt else logger "未找到cn_ipv6列表,正在下载!" 33 - $0 webget $bindir/cn_ipv6.txt "$update_url/bin/geodata/china_ipv6_list.txt" - [ "$?" = "1" ] && rm -rf $bindir/cn_ipv6.txt && logger "列表下载失败!" 31 + $0 webget ${BINDIR}/cn_ipv6.txt "$update_url/bin/geodata/china_ipv6_list.txt" + [ "$?" = "1" ] && rm -rf ${BINDIR}/cn_ipv6.txt && logger "列表下载失败!" 31 fi } - [ -f $bindir/cn_ipv6.txt -a -z "$(echo $redir_mod|grep 'Nft')" ] && { + [ -f ${BINDIR}/cn_ipv6.txt -a -z "$(echo $redir_mod|grep 'Nft')" ] && { #ipv6 #see https://ispip.clang.cn/all_cn_ipv6.txt - echo "create cn_ip6 hash:net family inet6 hashsize 2048 maxelem 2048" > $TMPDIR/cn6_$USER.ipset - awk '!/^$/&&!/^#/{printf("add cn_ip6 %s'" "'\n",$0)}' $bindir/cn_ipv6.txt >> $TMPDIR/cn6_$USER.ipset + echo "create cn_ip6 hash:net family inet6 hashsize 2048 maxelem 2048" > ${TMPDIR}/cn6_$USER.ipset + awk '!/^$/&&!/^#/{printf("add cn_ip6 %s'" "'\n",$0)}' ${BINDIR}/cn_ipv6.txt >> ${TMPDIR}/cn6_$USER.ipset ipset -! flush cn_ip6 2>/dev/null - ipset -! restore < $TMPDIR/cn6_$USER.ipset + ipset -! restore < ${TMPDIR}/cn6_$USER.ipset rm -rf cn6_$USER.ipset } } -start_redir(){ +start_redir(){ #iptables-redir #获取局域网host地址 getlanip #流量过滤 - iptables -t nat -N clash + iptables -t nat -N shellcrash for ip in $host_ipv4 $reserve_ipv4;do #跳过目标保留地址及目标本机网段 - iptables -t nat -A clash -d $ip -j RETURN + iptables -t nat -A shellcrash -d $ip -j RETURN done #绕过CN_IP [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && \ - iptables -t nat -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null + iptables -t nat -A shellcrash -m set --match-set cn_ip dst -j RETURN 2>/dev/null #局域网设备过滤 - if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then - for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单 - iptables -t nat -A clash -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port + if [ "$macfilter_type" = "白名单" -a -n "$(cat ${CRASHDIR}/configs/mac)" ];then + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac白名单 + iptables -t nat -A shellcrash -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port done else - for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单 - iptables -t nat -A clash -m mac --mac-source $mac -j RETURN + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac黑名单 + iptables -t nat -A shellcrash -m mac --mac-source $mac -j RETURN done #仅代理本机局域网网段流量 for ip in $host_ipv4;do - iptables -t nat -A clash -p tcp -s $ip -j REDIRECT --to-ports $redir_port + iptables -t nat -A shellcrash -p tcp -s $ip -j REDIRECT --to-ports $redir_port done fi - #将PREROUTING链指向clash链 - iptables -t nat -A PREROUTING -p tcp $ports -j clash - [ "$dns_mod" = "fake-ip" -a "$common_ports" = "已开启" ] && iptables -t nat -A PREROUTING -p tcp -d 198.18.0.0/16 -j clash + #将PREROUTING链指向shellcrash链 + iptables -t nat -A PREROUTING -p tcp $ports -j shellcrash + [ "$dns_mod" = "fake-ip" -a "$common_ports" = "已开启" ] && iptables -t nat -A PREROUTING -p tcp -d 198.18.0.0/16 -j shellcrash #设置ipv6转发 if [ "$ipv6_redir" = "已开启" -a -n "$(lsmod | grep 'ip6table_nat')" ];then - ip6tables -t nat -N clashv6 + ip6tables -t nat -N shellcrashv6 for ip in $reserve_ipv6 $host_ipv6;do #跳过目标保留地址及目标本机网段 - ip6tables -t nat -A clashv6 -d $ip -j RETURN + ip6tables -t nat -A shellcrashv6 -d $ip -j RETURN done #绕过CN_IPV6 [ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && \ - ip6tables -t nat -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null + ip6tables -t nat -A shellcrashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null #局域网设备过滤 - if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then - for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单 - ip6tables -t nat -A clashv6 -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port + if [ "$macfilter_type" = "白名单" -a -n "$(cat ${CRASHDIR}/configs/mac)" ];then + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac白名单 + ip6tables -t nat -A shellcrashv6 -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port done else - for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单 - ip6tables -t nat -A clashv6 -m mac --mac-source $mac -j RETURN + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac黑名单 + ip6tables -t nat -A shellcrashv6 -m mac --mac-source $mac -j RETURN done #仅代理本机局域网网段流量 for ip in $host_ipv6;do - ip6tables -t nat -A clashv6 -p tcp -s $ip -j REDIRECT --to-ports $redir_port + ip6tables -t nat -A shellcrashv6 -p tcp -s $ip -j REDIRECT --to-ports $redir_port done fi - ip6tables -t nat -A PREROUTING -p tcp $ports -j clashv6 + ip6tables -t nat -A PREROUTING -p tcp $ports -j shellcrashv6 fi return 0 } -start_ipt_dns(){ +start_ipt_dns(){ #iptables-dns #屏蔽OpenWrt内置53端口转发 [ "$(uci get dhcp.@dnsmasq[0].dns_redirect 2>/dev/null)" = 1 ] && { uci del dhcp.@dnsmasq[0].dns_redirect uci commit dhcp.@dnsmasq[0] } #设置dns转发 - iptables -t nat -N clash_dns - if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then - for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单 - iptables -t nat -A clash_dns -p udp -m mac --mac-source $mac -j REDIRECT --to $dns_port + iptables -t nat -N shellcrash_dns + if [ "$macfilter_type" = "白名单" -a -n "$(cat ${CRASHDIR}/configs/mac)" ];then + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac白名单 + iptables -t nat -A shellcrash_dns -p udp -m mac --mac-source $mac -j REDIRECT --to $dns_port done else - for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单 - iptables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac黑名单 + iptables -t nat -A shellcrash_dns -m mac --mac-source $mac -j RETURN done - iptables -t nat -A clash_dns -p tcp -j REDIRECT --to $dns_port - iptables -t nat -A clash_dns -p udp -j REDIRECT --to $dns_port + iptables -t nat -A shellcrash_dns -p tcp -j REDIRECT --to $dns_port + iptables -t nat -A shellcrash_dns -p udp -j REDIRECT --to $dns_port fi - iptables -t nat -I PREROUTING -p tcp --dport 53 -j clash_dns - iptables -t nat -I PREROUTING -p udp --dport 53 -j clash_dns + iptables -t nat -I PREROUTING -p tcp --dport 53 -j shellcrash_dns + iptables -t nat -I PREROUTING -p udp --dport 53 -j shellcrash_dns #ipv6DNS if [ -n "$(lsmod | grep 'ip6table_nat')" -a -n "$(lsmod | grep 'xt_nat')" ];then - ip6tables -t nat -N clashv6_dns > /dev/null 2>&1 - if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then - for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单 - ip6tables -t nat -A clashv6_dns -p udp -m mac --mac-source $mac -j REDIRECT --to $dns_port + ip6tables -t nat -N shellcrashv6_dns > /dev/null 2>&1 + if [ "$macfilter_type" = "白名单" -a -n "$(cat ${CRASHDIR}/configs/mac)" ];then + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac白名单 + ip6tables -t nat -A shellcrashv6_dns -p udp -m mac --mac-source $mac -j REDIRECT --to $dns_port done else - for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单 - ip6tables -t nat -A clashv6_dns -m mac --mac-source $mac -j RETURN + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac黑名单 + ip6tables -t nat -A shellcrashv6_dns -m mac --mac-source $mac -j RETURN done - ip6tables -t nat -A clashv6_dns -p tcp -j REDIRECT --to $dns_port - ip6tables -t nat -A clashv6_dns -p udp -j REDIRECT --to $dns_port + ip6tables -t nat -A shellcrashv6_dns -p tcp -j REDIRECT --to $dns_port + ip6tables -t nat -A shellcrashv6_dns -p udp -j REDIRECT --to $dns_port fi - ip6tables -t nat -I PREROUTING -p tcp --dport 53 -j clashv6_dns - ip6tables -t nat -I PREROUTING -p udp --dport 53 -j clashv6_dns + ip6tables -t nat -I PREROUTING -p tcp --dport 53 -j shellcrashv6_dns + ip6tables -t nat -I PREROUTING -p udp --dport 53 -j shellcrashv6_dns else ip6tables -I INPUT -p udp --dport 53 -m comment --comment "ShellCrash-IPV6_DNS-REJECT" -j REJECT 2>/dev/null fi return 0 } -start_tproxy(){ +start_tproxy(){ #iptables-tproxy #获取局域网host地址 getlanip modprobe xt_TPROXY &>/dev/null ip rule add fwmark $fwmark table 100 ip route add local default dev lo table 100 - iptables -t mangle -N clash - iptables -t mangle -A clash -p udp --dport 53 -j RETURN + iptables -t mangle -N shellcrash + iptables -t mangle -A shellcrash -p udp --dport 53 -j RETURN for ip in $host_ipv4 $reserve_ipv4;do #跳过目标保留地址及目标本机网段 - iptables -t mangle -A clash -d $ip -j RETURN + iptables -t mangle -A shellcrash -d $ip -j RETURN done #绕过CN_IP [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && \ - iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null + iptables -t mangle -A shellcrash -m set --match-set cn_ip dst -j RETURN 2>/dev/null #tcp&udp分别进代理链 tproxy_set(){ - if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then - for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单 - iptables -t mangle -A clash -p $1 -m mac --mac-source $mac -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark + if [ "$macfilter_type" = "白名单" -a -n "$(cat ${CRASHDIR}/configs/mac)" ];then + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac白名单 + iptables -t mangle -A shellcrash -p $1 -m mac --mac-source $mac -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark done else - for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单 - iptables -t mangle -A clash -m mac --mac-source $mac -j RETURN + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac黑名单 + iptables -t mangle -A shellcrash -m mac --mac-source $mac -j RETURN done #仅代理本机局域网网段流量 for ip in $host_ipv4;do - iptables -t mangle -A clash -p $1 -s $ip -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark + iptables -t mangle -A shellcrash -p $1 -s $ip -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark done fi - iptables -t mangle -A PREROUTING -p $1 $ports -j clash - [ "$dns_mod" = "fake-ip" -a "$common_ports" = "已开启" ] && iptables -t mangle -A PREROUTING -p $1 -d 198.18.0.0/16 -j clash + iptables -t mangle -A PREROUTING -p $1 $ports -j shellcrash + [ "$dns_mod" = "fake-ip" -a "$common_ports" = "已开启" ] && iptables -t mangle -A PREROUTING -p $1 -d 198.18.0.0/16 -j shellcrash } [ "$1" = "all" ] && tproxy_set tcp tproxy_set udp @@ -862,32 +893,32 @@ start_tproxy(){ [ "$ipv6_redir" = "已开启" ] && { ip -6 rule add fwmark $fwmark table 101 ip -6 route add local ::/0 dev lo table 101 - ip6tables -t mangle -N clashv6 - ip6tables -t mangle -A clashv6 -p udp --dport 53 -j RETURN + ip6tables -t mangle -N shellcrashv6 + ip6tables -t mangle -A shellcrashv6 -p udp --dport 53 -j RETURN for ip in $host_ipv6 $reserve_ipv6;do #跳过目标保留地址及目标本机网段 - ip6tables -t mangle -A clashv6 -d $ip -j RETURN + ip6tables -t mangle -A shellcrashv6 -d $ip -j RETURN done #绕过CN_IPV6 [ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && \ - ip6tables -t mangle -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null + ip6tables -t mangle -A shellcrashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null #tcp&udp分别进代理链 tproxy_set6(){ - if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then + if [ "$macfilter_type" = "白名单" -a -n "$(cat ${CRASHDIR}/configs/mac)" ];then #mac白名单 - for mac in $(cat $CRASHDIR/configs/mac); do - ip6tables -t mangle -A clashv6 -p $1 -m mac --mac-source $mac -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark + for mac in $(cat ${CRASHDIR}/configs/mac); do + ip6tables -t mangle -A shellcrashv6 -p $1 -m mac --mac-source $mac -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark done else #mac黑名单 - for mac in $(cat $CRASHDIR/configs/mac); do - ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j RETURN + for mac in $(cat ${CRASHDIR}/configs/mac); do + ip6tables -t mangle -A shellcrashv6 -m mac --mac-source $mac -j RETURN done #仅代理本机局域网网段流量 for ip in $host_ipv6;do - ip6tables -t mangle -A clashv6 -p $1 -s $ip -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark + ip6tables -t mangle -A shellcrashv6 -p $1 -s $ip -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark done fi - ip6tables -t mangle -A PREROUTING -p $1 $ports -j clashv6 + ip6tables -t mangle -A PREROUTING -p $1 $ports -j shellcrashv6 } [ "$1" = "all" ] && tproxy_set6 tcp tproxy_set6 udp @@ -899,43 +930,43 @@ start_tproxy(){ } } } -start_output(){ +start_output(){ #iptables本机代理 #获取局域网host地址 getlanip #流量过滤 - iptables -t nat -N clash_out - iptables -t nat -A clash_out -m owner --gid-owner 7890 -j RETURN + iptables -t nat -N shellcrash_out + iptables -t nat -A shellcrash_out -m owner --gid-owner 7890 -j RETURN for ip in $local_ipv4 $reserve_ipv4;do #跳过目标保留地址及目标本机网段 - iptables -t nat -A clash_out -d $ip -j RETURN + iptables -t nat -A shellcrash_out -d $ip -j RETURN done #绕过CN_IP [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && \ - iptables -t nat -A clash_out -m set --match-set cn_ip dst -j RETURN >/dev/null 2>&1 + iptables -t nat -A shellcrash_out -m set --match-set cn_ip dst -j RETURN >/dev/null 2>&1 #仅允许本机流量 for ip in 127.0.0.0/8 $local_ipv4;do - iptables -t nat -A clash_out -p tcp -s $ip -j REDIRECT --to-ports $redir_port + iptables -t nat -A shellcrash_out -p tcp -s $ip -j REDIRECT --to-ports $redir_port done - iptables -t nat -A OUTPUT -p tcp $ports -j clash_out + iptables -t nat -A OUTPUT -p tcp $ports -j shellcrash_out #设置dns转发 [ "$dns_no" != "已禁用" ] && { - iptables -t nat -N clash_dns_out - iptables -t nat -A clash_dns_out -m owner --gid-owner 453 -j RETURN #绕过本机dnsmasq - iptables -t nat -A clash_dns_out -m owner --gid-owner 7890 -j RETURN - iptables -t nat -A clash_dns_out -p udp -s 127.0.0.0/8 -j REDIRECT --to $dns_port - iptables -t nat -A OUTPUT -p udp --dport 53 -j clash_dns_out + iptables -t nat -N shellcrash_dns_out + iptables -t nat -A shellcrash_dns_out -m owner --gid-owner 453 -j RETURN #绕过本机dnsmasq + iptables -t nat -A shellcrash_dns_out -m owner --gid-owner 7890 -j RETURN + iptables -t nat -A shellcrash_dns_out -p udp -s 127.0.0.0/8 -j REDIRECT --to $dns_port + iptables -t nat -A OUTPUT -p udp --dport 53 -j shellcrash_dns_out } #Docker转发 ckcmd docker && { - iptables -t nat -N clash_docker + iptables -t nat -N shellcrash_docker for ip in $host_ipv4 $reserve_ipv4;do #跳过目标保留地址及目标本机网段 - iptables -t nat -A clash_docker -d $ip -j RETURN + iptables -t nat -A shellcrash_docker -d $ip -j RETURN done - iptables -t nat -A clash_docker -p tcp -j REDIRECT --to-ports $redir_port - iptables -t nat -A PREROUTING -p tcp -s 172.16.0.0/12 -j clash_docker + iptables -t nat -A shellcrash_docker -p tcp -j REDIRECT --to-ports $redir_port + iptables -t nat -A PREROUTING -p tcp -s 172.16.0.0/12 -j shellcrash_docker [ "$dns_no" != "已禁用" ] && iptables -t nat -A PREROUTING -p udp --dport 53 -s 172.16.0.0/12 -j REDIRECT --to $dns_port } } -start_tun(){ +start_tun(){ #iptables-tun modprobe tun &>/dev/null #允许流量 iptables -I FORWARD -o utun -j ACCEPT @@ -960,65 +991,65 @@ start_tun(){ ip rule add fwmark $fwmark table 100 #获取局域网host地址 getlanip - iptables -t mangle -N clash - iptables -t mangle -A clash -p udp --dport 53 -j RETURN + iptables -t mangle -N shellcrash + iptables -t mangle -A shellcrash -p udp --dport 53 -j RETURN for ip in $host_ipv4 $reserve_ipv4;do #跳过目标保留地址及目标本机网段 - iptables -t mangle -A clash -d $ip -j RETURN + iptables -t mangle -A shellcrash -d $ip -j RETURN done #防止回环 - iptables -t mangle -A clash -s 198.18.0.0/16 -j RETURN + iptables -t mangle -A shellcrash -s 198.18.0.0/16 -j RETURN #绕过CN_IP [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && \ - iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null + iptables -t mangle -A shellcrash -m set --match-set cn_ip dst -j RETURN 2>/dev/null #局域网设备过滤 - if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then - for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单 - iptables -t mangle -A clash -m mac --mac-source $mac -j MARK --set-mark $fwmark + if [ "$macfilter_type" = "白名单" -a -n "$(cat ${CRASHDIR}/configs/mac)" ];then + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac白名单 + iptables -t mangle -A shellcrash -m mac --mac-source $mac -j MARK --set-mark $fwmark done else - for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单 - iptables -t mangle -A clash -m mac --mac-source $mac -j RETURN + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac黑名单 + iptables -t mangle -A shellcrash -m mac --mac-source $mac -j RETURN done #仅代理本机局域网网段流量 for ip in $host_ipv4;do - iptables -t mangle -A clash -s $ip -j MARK --set-mark $fwmark + iptables -t mangle -A shellcrash -s $ip -j MARK --set-mark $fwmark done fi - iptables -t mangle -A PREROUTING -p udp $ports -j clash - [ "$1" = "all" ] && iptables -t mangle -A PREROUTING -p tcp $ports -j clash + iptables -t mangle -A PREROUTING -p udp $ports -j shellcrash + [ "$1" = "all" ] && iptables -t mangle -A PREROUTING -p tcp $ports -j shellcrash #设置ipv6转发 [ "$ipv6_redir" = "已开启" -a "$crashcore" = "meta" ] && { ip -6 route add default dev utun table 101 ip -6 rule add fwmark $fwmark table 101 - ip6tables -t mangle -N clashv6 - ip6tables -t mangle -A clashv6 -p udp --dport 53 -j RETURN + ip6tables -t mangle -N shellcrashv6 + ip6tables -t mangle -A shellcrashv6 -p udp --dport 53 -j RETURN for ip in $host_ipv6 $reserve_ipv6;do #跳过目标保留地址及目标本机网段 - ip6tables -t mangle -A clashv6 -d $ip -j RETURN + ip6tables -t mangle -A shellcrashv6 -d $ip -j RETURN done #绕过CN_IPV6 [ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && \ - ip6tables -t mangle -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null + ip6tables -t mangle -A shellcrashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null #局域网设备过滤 - if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then - for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单 - ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j MARK --set-mark $fwmark + if [ "$macfilter_type" = "白名单" -a -n "$(cat ${CRASHDIR}/configs/mac)" ];then + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac白名单 + ip6tables -t mangle -A shellcrashv6 -m mac --mac-source $mac -j MARK --set-mark $fwmark done else - for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单 - ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j RETURN + for mac in $(cat ${CRASHDIR}/configs/mac); do #mac黑名单 + ip6tables -t mangle -A shellcrashv6 -m mac --mac-source $mac -j RETURN done #仅代理本机局域网网段流量 for ip in $host_ipv6;do - ip6tables -t mangle -A clashv6 -s $ip -j MARK --set-mark $fwmark + ip6tables -t mangle -A shellcrashv6 -s $ip -j MARK --set-mark $fwmark done fi - ip6tables -t mangle -A PREROUTING -p udp $ports -j clashv6 - [ "$1" = "all" ] && ip6tables -t mangle -A PREROUTING -p tcp $ports -j clashv6 + ip6tables -t mangle -A PREROUTING -p udp $ports -j shellcrashv6 + [ "$1" = "all" ] && ip6tables -t mangle -A PREROUTING -p tcp $ports -j shellcrashv6 } } & } -start_nft(){ +start_nft(){ #nftables-allinone #获取局域网host地址 getlanip [ "$common_ports" = "已开启" ] && PORTS=$(echo $multiport | sed 's/,/, /g') @@ -1035,8 +1066,8 @@ start_nft(){ } [ -n "$(echo $redir_mod|grep Nft)" ] && { #过滤局域网设备 - [ -n "$(cat $CRASHDIR/configs/mac)" ] && { - MAC=$(awk '{printf "%s, ",$1}' $CRASHDIR/configs/mac) + [ -n "$(cat ${CRASHDIR}/configs/mac)" ] && { + MAC=$(awk '{printf "%s, ",$1}' ${CRASHDIR}/configs/mac) [ "$macfilter_type" = "黑名单" ] && \ nft add rule inet shellcrash prerouting ether saddr {$MAC} return || \ nft add rule inet shellcrash prerouting ether saddr != {$MAC} return @@ -1046,8 +1077,8 @@ start_nft(){ #仅代理本机局域网网段流量 nft add rule inet shellcrash prerouting ip saddr != {$HOST_IP} return #绕过CN-IP - [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" -a -f $bindir/cn_ip.txt ] && { - CN_IP=$(awk '{printf "%s, ",$1}' $bindir/cn_ip.txt) + [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" -a -f ${BINDIR}/cn_ip.txt ] && { + CN_IP=$(awk '{printf "%s, ",$1}' ${BINDIR}/cn_ip.txt) [ -n "$CN_IP" ] && nft add rule inet shellcrash prerouting ip daddr {$CN_IP} return } #过滤常用端口 @@ -1063,8 +1094,8 @@ start_nft(){ #仅代理本机局域网网段流量 nft add rule inet shellcrash prerouting ip6 saddr != {$HOST_IP6} return #绕过CN_IPV6 - [ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" -a -f $bindir/cn_ipv6.txt ] && { - CN_IP6=$(awk '{printf "%s, ",$1}' $bindir/cn_ipv6.txt) + [ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" -a -f ${BINDIR}/cn_ipv6.txt ] && { + CN_IP6=$(awk '{printf "%s, ",$1}' ${BINDIR}/cn_ipv6.txt) [ -n "$CN_IP6" ] && nft add rule inet shellcrash prerouting ip6 daddr {$CN_IP6} return } else @@ -1104,11 +1135,11 @@ start_nft(){ } } } -start_nft_dns(){ +start_nft_dns(){ #nftables-dns nft add chain inet shellcrash dns { type nat hook prerouting priority -100 \; } #过滤局域网设备 - [ -n "$(cat $CRASHDIR/configs/mac)" ] && { - MAC=$(awk '{printf "%s, ",$1}' $CRASHDIR/configs/mac) + [ -n "$(cat ${CRASHDIR}/configs/mac)" ] && { + MAC=$(awk '{printf "%s, ",$1}' ${CRASHDIR}/configs/mac) [ "$macfilter_type" = "黑名单" ] && \ nft add rule inet shellcrash dns ether saddr {$MAC} return || \ nft add rule inet shellcrash dns ether saddr != {$MAC} return @@ -1116,7 +1147,7 @@ start_nft_dns(){ nft add rule inet shellcrash dns udp dport 53 redirect to ${dns_port} nft add rule inet shellcrash dns tcp dport 53 redirect to ${dns_port} } -start_wan(){ +start_wan(){ #iptables公网访问防火墙 #获取局域网host地址 getlanip if [ "$public_support" = "已开启" ];then @@ -1143,21 +1174,22 @@ start_wan(){ fi iptables -I INPUT -p tcp -d 127.0.0.1 -j ACCEPT #本机请求全放行 } -stop_firewall(){ +stop_firewall(){ #还原防火墙配置 + getconfig #获取局域网host地址 getlanip #重置iptables相关规则 ckcmd iptables && { #redir - iptables -t nat -D PREROUTING -p tcp $ports -j clash 2> /dev/null - iptables -t nat -D PREROUTING -p tcp -d 198.18.0.0/16 -j clash 2> /dev/null - iptables -t nat -F clash 2> /dev/null - iptables -t nat -X clash 2> /dev/null + iptables -t nat -D PREROUTING -p tcp $ports -j shellcrash 2> /dev/null + iptables -t nat -D PREROUTING -p tcp -d 198.18.0.0/16 -j shellcrash 2> /dev/null + iptables -t nat -F shellcrash 2> /dev/null + iptables -t nat -X shellcrash 2> /dev/null #dns - iptables -t nat -D PREROUTING -p tcp --dport 53 -j clash_dns 2> /dev/null - iptables -t nat -D PREROUTING -p udp --dport 53 -j clash_dns 2> /dev/null - iptables -t nat -F clash_dns 2> /dev/null - iptables -t nat -X clash_dns 2> /dev/null + iptables -t nat -D PREROUTING -p tcp --dport 53 -j shellcrash_dns 2> /dev/null + iptables -t nat -D PREROUTING -p udp --dport 53 -j shellcrash_dns 2> /dev/null + iptables -t nat -F shellcrash_dns 2> /dev/null + iptables -t nat -X shellcrash_dns 2> /dev/null #tun iptables -D FORWARD -o utun -j ACCEPT 2> /dev/null iptables -D FORWARD -s 198.18.0.0/16 -o utun -j RETURN 2> /dev/null @@ -1166,24 +1198,24 @@ stop_firewall(){ iptables -D INPUT -p udp --dport 443 -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip -j REJECT 2> /dev/null iptables -D FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip -j REJECT 2> /dev/null #本机代理 - iptables -t nat -D OUTPUT -p tcp $ports -j clash_out 2> /dev/null - iptables -t nat -F clash_out 2> /dev/null - iptables -t nat -X clash_out 2> /dev/null - iptables -t nat -D OUTPUT -p udp --dport 53 -j clash_dns_out 2> /dev/null - iptables -t nat -F clash_dns_out 2> /dev/null - iptables -t nat -X clash_dns_out 2> /dev/null + iptables -t nat -D OUTPUT -p tcp $ports -j shellcrash_out 2> /dev/null + iptables -t nat -F shellcrash_out 2> /dev/null + iptables -t nat -X shellcrash_out 2> /dev/null + iptables -t nat -D OUTPUT -p udp --dport 53 -j shellcrash_dns_out 2> /dev/null + iptables -t nat -F shellcrash_dns_out 2> /dev/null + iptables -t nat -X shellcrash_dns_out 2> /dev/null #docker - iptables -t nat -F clash_docker 2> /dev/null - iptables -t nat -X clash_docker 2> /dev/null - iptables -t nat -D PREROUTING -p tcp -s 172.16.0.0/12 -j clash_docker 2> /dev/null + iptables -t nat -F shellcrash_docker 2> /dev/null + iptables -t nat -X shellcrash_docker 2> /dev/null + iptables -t nat -D PREROUTING -p tcp -s 172.16.0.0/12 -j shellcrash_docker 2> /dev/null iptables -t nat -D PREROUTING -p udp --dport 53 -s 172.16.0.0/12 -j REDIRECT --to $dns_port 2> /dev/null #TPROXY&tun - iptables -t mangle -D PREROUTING -p tcp $ports -j clash 2> /dev/null - iptables -t mangle -D PREROUTING -p udp $ports -j clash 2> /dev/null - iptables -t mangle -D PREROUTING -p tcp -d 198.18.0.0/16 -j clash 2> /dev/null - iptables -t mangle -D PREROUTING -p udp -d 198.18.0.0/16 -j clash 2> /dev/null - iptables -t mangle -F clash 2> /dev/null - iptables -t mangle -X clash 2> /dev/null + iptables -t mangle -D PREROUTING -p tcp $ports -j shellcrash 2> /dev/null + iptables -t mangle -D PREROUTING -p udp $ports -j shellcrash 2> /dev/null + iptables -t mangle -D PREROUTING -p tcp -d 198.18.0.0/16 -j shellcrash 2> /dev/null + iptables -t mangle -D PREROUTING -p udp -d 198.18.0.0/16 -j shellcrash 2> /dev/null + iptables -t mangle -F shellcrash 2> /dev/null + iptables -t mangle -X shellcrash 2> /dev/null #公网访问 for ip in $host_ipv4 $local_ipv4 $reserve_ipv4;do iptables -D INPUT -p tcp -s $ip --dport $mix_port -j ACCEPT 2> /dev/null @@ -1198,15 +1230,15 @@ stop_firewall(){ #重置ipv6规则 ckcmd ip6tables && { #redir - ip6tables -t nat -D PREROUTING -p tcp $ports -j clashv6 2> /dev/null + ip6tables -t nat -D PREROUTING -p tcp $ports -j shellcrashv6 2> /dev/null ip6tables -D INPUT -p udp --dport 53 -m comment --comment "ShellCrash-IPV6_DNS-REJECT" -j REJECT 2> /dev/null - ip6tables -t nat -F clashv6 2> /dev/null - ip6tables -t nat -X clashv6 2> /dev/null + ip6tables -t nat -F shellcrashv6 2> /dev/null + ip6tables -t nat -X shellcrashv6 2> /dev/null #dns - ip6tables -t nat -D PREROUTING -p tcp --dport 53 -j clashv6_dns 2>/dev/null - ip6tables -t nat -D PREROUTING -p udp --dport 53 -j clashv6_dns 2>/dev/null - ip6tables -t nat -F clashv6_dns 2> /dev/null - ip6tables -t nat -X clashv6_dns 2> /dev/null + ip6tables -t nat -D PREROUTING -p tcp --dport 53 -j shellcrashv6_dns 2>/dev/null + ip6tables -t nat -D PREROUTING -p udp --dport 53 -j shellcrashv6_dns 2>/dev/null + ip6tables -t nat -F shellcrashv6_dns 2> /dev/null + ip6tables -t nat -X shellcrashv6_dns 2> /dev/null #tun ip6tables -D FORWARD -o utun -j ACCEPT 2> /dev/null ip6tables -D FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellCrash-QUIC-REJECT" -j REJECT >/dev/null 2>&1 @@ -1220,10 +1252,10 @@ stop_firewall(){ ip6tables -D INPUT -p tcp --dport $db_port -j REJECT 2> /dev/null ip6tables -D INPUT -p tcp --dport $db_port -j ACCEPT 2> /dev/null #tproxy&tun - ip6tables -t mangle -D PREROUTING -p tcp $ports -j clashv6 2> /dev/null - ip6tables -t mangle -D PREROUTING -p udp $ports -j clashv6 2> /dev/null - ip6tables -t mangle -F clashv6 2> /dev/null - ip6tables -t mangle -X clashv6 2> /dev/null + ip6tables -t mangle -D PREROUTING -p tcp $ports -j shellcrashv6 2> /dev/null + ip6tables -t mangle -D PREROUTING -p udp $ports -j shellcrashv6 2> /dev/null + ip6tables -t mangle -F shellcrashv6 2> /dev/null + ip6tables -t mangle -X shellcrashv6 2> /dev/null ip6tables -D INPUT -p udp --dport 443 -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip -j REJECT 2> /dev/null } #清理ipset规则 @@ -1249,26 +1281,27 @@ stop_firewall(){ #还原防火墙文件 [ -s /etc/init.d/firewall.bak ] && mv -f /etc/init.d/firewall.bak /etc/init.d/firewall } -#面板配置保存相关 -web_save(){ +#启动相关 +web_save(){ #最小化保存面板节点选择 + getconfig #使用get_save获取面板节点设置 - get_save http://127.0.0.1:${db_port}/proxies | awk -F ':\\{"' '{for(i=1;i<=NF;i++) print $i}' | grep -aE '(^all|^alive)".*"Selector"' > $TMPDIR/clash_web_check_$USER + get_save http://127.0.0.1:${db_port}/proxies | awk -F ':\\{"' '{for(i=1;i<=NF;i++) print $i}' | grep -aE '(^all|^alive)".*"Selector"' > ${TMPDIR}/shellcrash_web_check_$USER while read line ;do def=$(echo $line | awk -F "[[,]" '{print $2}') now=$(echo $line | grep -oE '"now".*",' | sed 's/"now"://g' | sed 's/"type":.*//g' | sed 's/,//g') - [ "$def" != "$now" ] && echo $line | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g' | sed 's/"type":.*//g' | sed 's/"//g' >> $TMPDIR/clash_web_save_$USER - done < $TMPDIR/clash_web_check_$USER - rm -rf $TMPDIR/clash_web_check_$USER + [ "$def" != "$now" ] && echo $line | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g' | sed 's/"type":.*//g' | sed 's/"//g' >> ${TMPDIR}/shellcrash_web_save_$USER + done < ${TMPDIR}/shellcrash_web_check_$USER + rm -rf ${TMPDIR}/shellcrash_web_check_$USER #对比文件,如果有变动且不为空则写入磁盘,否则清除缓存 - if [ -s $TMPDIR/clash_web_save_$USER ];then - compare $TMPDIR/clash_web_save_$USER $CRASHDIR/configs/web_save - [ "$?" = 0 ] && rm -rf $TMPDIR/clash_web_save_$USER || mv -f $TMPDIR/clash_web_save_$USER $CRASHDIR/configs/web_save + if [ -s ${TMPDIR}/shellcrash_web_save_$USER ];then + compare ${TMPDIR}/shellcrash_web_save_$USER ${CRASHDIR}/configs/web_save + [ "$?" = 0 ] && rm -rf ${TMPDIR}/shellcrash_web_save_$USER || mv -f ${TMPDIR}/shellcrash_web_save_$USER ${CRASHDIR}/configs/web_save else - echo > $CRASHDIR/configs/web_save + echo > ${CRASHDIR}/configs/web_save fi } -web_restore(){ - +web_restore(){ #还原面板节点 + getconfig #设置循环检测clash面板端口 i=1 while [ -z "$test" -a "$i" -lt 20 ];do @@ -1281,18 +1314,17 @@ web_restore(){ i=$((i+1)) done #发送数据 - num=$(cat $CRASHDIR/configs/web_save | wc -l) + num=$(cat ${CRASHDIR}/configs/web_save | wc -l) i=1 while [ "$i" -le "$num" ];do - group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' $CRASHDIR/configs/web_save | sed 's/ /%20/g') - now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' $CRASHDIR/configs/web_save) + group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' ${CRASHDIR}/configs/web_save | sed 's/ /%20/g') + now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' ${CRASHDIR}/configs/web_save) put_save http://127.0.0.1:${db_port}/proxies/${group_name} "{\"name\":\"${now_name}\"}" i=$((i+1)) done } -#启动相关 -makehtml(){ - cat > $bindir/ui/index.html < ${BINDIR}/ui/index.html < @@ -1314,12 +1346,12 @@ makehtml(){ &1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) [ -z "$host_pac" ] && host_pac=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) - cat > $TMPDIR/clash_pac < ${TMPDIR}/shellcrash_pac </dev/null + if [ "$crashcore" = singbox ];then + core_v=$(${TMPDIR}/core.new version 2>/dev/null | grep version | awk '{print $3}') + else + core_v=$(${TMPDIR}/core.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //') + fi + if [ -z "$core_v" ];then + rm -rf ${TMPDIR}/core.new + logger "核心下载失败,请重新运行或更换安装源!" 31 + exit 1 + else + mv -f ${TMPDIR}/core.new ${BINDIR}/CrashCore + setconfig crashcore $crashcore + setconfig core_v $core_v + fi + fi + fi +} +clash_check(){ #clash启动前检查 #检测vless/hysteria协议 if [ "$crashcore" != "meta" ] && [ -n "$(cat $core_config | grep -oE 'type: vless|type: hysteria')" ];then echo ----------------------------------------------- logger "检测到vless/hysteria协议!将改为使用meta核心启动!" 33 - rm -rf $bindir/clash + rm -rf ${BINDIR}/CrashCore crashcore=meta echo ----------------------------------------------- fi @@ -1355,65 +1418,67 @@ clash_check(){ [ "$redir_mod" = "Tun模式" ] && { echo ----------------------------------------------- logger "检测到高级功能!将改为使用ClashPre核心启动!" 33 - rm -rf $bindir/clash + rm -rf ${BINDIR}/CrashCore crashcore=clashpre echo ----------------------------------------------- } fi + core_check #预下载GeoIP数据库 - if [ ! -f $bindir/Country.mmdb ];then - if [ -f $CRASHDIR/Country.mmdb ];then - mv $CRASHDIR/Country.mmdb $bindir/Country.mmdb + if [ ! -f ${BINDIR}/Country.mmdb ];then + if [ -f ${CRASHDIR}/Country.mmdb ];then + mv ${CRASHDIR}/Country.mmdb ${BINDIR}/Country.mmdb else logger "未找到GeoIP数据库,正在下载!" 33 - $0 webget $bindir/Country.mmdb $update_url/bin/geodata/cn_mini.mmdb - [ "$?" = "1" ] && rm -rf $bindir/Country.mmdb && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1 + $0 webget ${BINDIR}/Country.mmdb $update_url/bin/geodata/cn_mini.mmdb + [ "$?" = "1" ] && rm -rf ${BINDIR}/Country.mmdb && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1 Geo_v=$(date +"%Y%m%d") setconfig Geo_v $Geo_v fi fi #预下载GeoSite数据库 - if [ -n "$(cat $core_config|grep -Ei 'geosite')" ] && [ ! -f $bindir/GeoSite.dat ];then - if [ -f $CRASHDIR/GeoSite.dat ];then - mv -f $CRASHDIR/GeoSite.dat $bindir/GeoSite.dat + if [ -n "$(cat $core_config|grep -Ei 'geosite')" ] && [ ! -f ${BINDIR}/GeoSite.dat ];then + if [ -f ${CRASHDIR}/GeoSite.dat ];then + mv -f ${CRASHDIR}/GeoSite.dat ${BINDIR}/GeoSite.dat else logger "未找到GeoSite数据库,正在下载!" 33 - $0 webget $bindir/GeoSite.dat $update_url/bin/geodata/geosite.dat - [ "$?" = "1" ] && rm -rf $bindir/GeoSite.dat && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1 + $0 webget ${BINDIR}/GeoSite.dat $update_url/bin/geodata/geosite.dat + [ "$?" = "1" ] && rm -rf ${BINDIR}/GeoSite.dat && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1 fi fi } -singbox_check(){ +singbox_check(){ #singbox启动前检查 + core_check #预下载GeoIP数据库 - if [ ! -f $bindir/geoip.db ];then - if [ -f $CRASHDIR/geoip.db ];then - mv $CRASHDIR/geoip.db $bindir/geoip.db + if [ ! -f ${BINDIR}/geoip.db ];then + if [ -f ${CRASHDIR}/geoip.db ];then + mv ${CRASHDIR}/geoip.db ${BINDIR}/geoip.db else logger "未找到GeoIP数据库,正在下载!" 33 - $0 webget $bindir/geoip.db $update_url/bin/geodata/geoip_cn.db - [ "$?" = "1" ] && rm -rf $bindir/geoip.db && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1 + $0 webget ${BINDIR}/geoip.db $update_url/bin/geodata/geoip_cn.db + [ "$?" = "1" ] && rm -rf ${BINDIR}/geoip.db && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1 Geo_v=$(date +"%Y%m%d") setconfig Geo_v $Geo_v fi fi #预下载GeoSite数据库 - if [ -n "$(cat $core_config|grep -Ei '"geosite":')" ] && [ ! -f $bindir/geosite.db ];then - if [ -f $CRASHDIR/geosite.db ];then - mv -f $CRASHDIR/geosite.db$bindir/geosite.db + if [ -n "$(cat $core_config|grep -Ei '"geosite":')" ] && [ ! -f ${BINDIR}/geosite.db ];then + if [ -f ${CRASHDIR}/geosite.db ];then + mv -f ${CRASHDIR}/geosite.db ${BINDIR}/geosite.db else logger "未找到GeoSite数据库,正在下载!" 33 - $0 webget $bindir/geosite.db $update_url/bin/geodata/geosite_cn.db - [ "$?" = "1" ] && rm -rf $bindir/geosite.db && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1 + $0 webget ${BINDIR}/geosite.db $update_url/bin/geodata/geosite_cn.db + [ "$?" = "1" ] && rm -rf ${BINDIR}/geosite.db && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1 Geo_v=$(date +"%Y%m%d") setconfig Geo_v $Geo_v fi fi } -bfstart(){ +bfstart(){ #启动前 #读取ShellCrash配置 getconfig [ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master - [ ! -d $bindir/ui ] && mkdir -p $bindir/ui + [ ! -d ${BINDIR}/ui ] && mkdir -p ${BINDIR}/ui [ -z "$crashcore" ] && crashcore=clash #检查内核配置文件 if [ ! -f $core_config ];then @@ -1426,51 +1491,21 @@ bfstart(){ exit 1 fi fi - #检查dashboard文件 - if [ -f $CRASHDIR/ui/index.html -a ! -f $bindir/ui/index.html ];then - cp -rf $CRASHDIR/ui $bindir + if [ -f ${CRASHDIR}/ui/index.html -a ! -f ${BINDIR}/ui/index.html ];then + cp -rf ${CRASHDIR}/ui ${BINDIR} fi - [ ! -s $bindir/ui/index.html ] && makehtml #如没有面板则创建跳转界面 - #生成pac文件 - catpac + [ ! -s ${BINDIR}/ui/index.html ] && makehtml #如没有面板则创建跳转界面 + catpac #生成pac文件 #内核及内核配置文件检查 + [ ! -x ${BINDIR}/CrashCore ] && chmod +x ${BINDIR}/CrashCore #检测可执行权限 if [ "$crashcore" = singbox ];then singbox_check - [ "$disoverride" != "1" ] && modify_json || ln -sf $core_config $bindir/config.json + [ "$disoverride" != "1" ] && modify_json || ln -sf $core_config ${TMPDIR}/config.json else clash_check - [ "$disoverride" != "1" ] && modify_yaml || ln -sf $core_config $bindir/config.yaml + [ "$disoverride" != "1" ] && modify_yaml || ln -sf $core_config ${TMPDIR}/config.yaml fi - #检查及下载内核文件 - if [ ! -f $bindir/CrashCore ];then - if [ -f $CRASHDIR/CrashCore ];then - mv $CRASHDIR/CrashCore $bindir/CrashCore - elif [ -f $CRASHDIR/clash ];then - mv $CRASHDIR/clash $bindir/CrashCore - else - logger "未找到【$crashcore】核心,正在下载!" 33 - [ -z "$cpucore" ] && source $CRASHDIR/getdate.sh && getcpucore - [ -z "$cpucore" ] && logger 找不到设备的CPU信息,请手动指定处理器架构类型! 31 && exit 1 - $0 webget $bindir/core.new "$update_url/bin/$crashcore/clash-linux-$cpucore" - #校验内核 - chmod +x $bindir/core.new 2>/dev/null - if [ "$crashcore" = singbox ];then - core_v=$($TMPDIR/core.new version 2>/dev/null | grep version | awk '{print $3}') - else - core_v=$($TMPDIR/core.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //') - fi - if [ -z "$core_v" ];then - rm -rf $bindir/clash - logger "核心下载失败,请重新运行或更换安装源!" 31 - exit 1 - else - setconfig crashcore $crashcore - setconfig core_v $core_v - fi - fi - fi - [ ! -x $bindir/clash ] && chmod +x $bindir/clash #检测可执行权限 #本机代理准备 if [ "$local_proxy" = "已开启" -a -n "$(echo $local_type | grep '增强模式')" ];then #添加shellcrash用户 @@ -1488,9 +1523,9 @@ bfstart(){ if [ "$start_old" != "已开启" ];then [ -w /etc/systemd/system/shellcrash.service ] && servdir=/etc/systemd/system/shellcrash.service [ -w /usr/lib/systemd/system/shellcrash.service ] && servdir=/usr/lib/systemd/system/shellcrash.service - if [ -w /etc/init.d/clash ]; then - [ -z "$(grep 'procd_set_param user shellcrash' /etc/init.d/clash)" ] && \ - sed -i '/procd_close_instance/i\\t\tprocd_set_param user shellcrash' /etc/init.d/clash + if [ -w /etc/init.d/shellcrash ]; then + [ -z "$(grep 'procd_set_param user shellcrash' /etc/init.d/shellcrash)" ] && \ + sed -i '/procd_close_instance/i\\t\tprocd_set_param user shellcrash' /etc/init.d/shellcrash elif [ -w "$servdir" ]; then setconfig User shellcrash $servdir systemctl daemon-reload >/dev/null @@ -1498,15 +1533,16 @@ bfstart(){ fi fi #执行条件任务 - [ -s $CRASHDIR/task/bfstart ] && source $CRASHDIR/task/bfstart + [ -s ${CRASHDIR}/task/bfstart ] && source ${CRASHDIR}/task/bfstart + return 0 } -afstart(){ +afstart(){ #启动后 #读取配置文件 getconfig #延迟启动 - [ ! -f $TMPDIR/crash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && { - logger "clash将延迟$start_delay秒启动" 31 pushoff + [ ! -f ${TMPDIR}/crash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && { + logger "ShellCrash将延迟$start_delay秒启动" 31 pushoff sleep $start_delay } #设置DNS转发 @@ -1548,65 +1584,97 @@ afstart(){ } ckcmd iptables && start_wan #本地防火墙 mark_time #标记启动时间 - [ -s $CRASHDIR/task/cron ] && croncmd $CRASHDIR/task/cron #加载定时任务 - [ -s $CRASHDIR/configs/web_save ] && web_restore & #后台还原面板配置 + [ -s ${CRASHDIR}/configs/web_save ] && web_restore &>/dev/null & #后台还原面板配置 { sleep 5;logger Clash服务已启动!;} & #推送日志 - #执行条件任务 - [ -s $CRASHDIR/task/afstart ] && { source $CRASHDIR/task/afstart ;} & - [ -s $CRASHDIR/task/running ] && { + #加载定身任务 + [ -s ${CRASHDIR}/task/cron ] && croncmd ${CRASHDIR}/task/cron + [ -s ${CRASHDIR}/task/running ] && { cronset '运行时每' while read line ;do cronset '2fjdi124dd12s' "$line" - done < $CRASHDIR/task/running + done < ${CRASHDIR}/task/running } - [ -s $CRASHDIR/task/affirewall -a -s /etc/init.d/firewall -a ! -f /etc/init.d/firewall.bak ] && { + #加载条件任务 + [ -s ${CRASHDIR}/task/afstart ] && { source ${CRASHDIR}/task/afstart ;} & + [ -s ${CRASHDIR}/task/affirewall -a -s /etc/init.d/firewall -a ! -f /etc/init.d/firewall.bak ] && { #注入防火墙 line=$(grep -En "fw3 restart" /etc/init.d/firewall | cut -d ":" -f 1) - sed -i.bak "${line}a\\source $CRASHDIR/task/affirewall" /etc/init.d/firewall + sed -i.bak "${line}a\\source ${CRASHDIR}/task/affirewall" /etc/init.d/firewall line=$(grep -En "fw3 .* start" /etc/init.d/firewall | cut -d ":" -f 1) - sed -i "${line}a\\source $CRASHDIR/task/affirewall" /etc/init.d/firewall - } + sed -i "${line}a\\source ${CRASHDIR}/task/affirewall" /etc/init.d/firewall + } & + return 0 } -start_old(){ - source $CRASHDIR/configs/service.env - bfstart +start_error(){ #启动报错 + ckcmd journalctl && journalctl -xeu shellcrash > $TMPDIR/core_test.log + error=$(cat $TMPDIR/core_test.log | grep -Eo 'error.*=.*|.*ERROR.*|.*FATAL.*') + logger "服务启动失败!请查看报错信息!详细信息请查看$TMPDIR/core_test.log" 33 + logger "$error" 31 + exit 1 +} +start_old(){ #保守模式 #使用传统后台执行二进制文件的方式执行 if [ "$local_proxy" = "已开启" -a -n "$(echo $local_type | grep '增强模式')" ];then if ckcmd su;then - su shellcrash -c "$COMMAND" 2>&1 & + su shellcrash -c "$COMMAND" >/dev/null & else logger "当前设备缺少su命令,保守模式下无法兼容本机代理增强模式,已停止启动!" 31 exit 1 fi else ckcmd nohup && nohup=nohup #华硕调用nohup启动 - $nohup "$COMMAND" 2>&1 & + $nohup $COMMAND &>/dev/null & fi + afstart - $0 daemon + cronset '保守模式守护进程' "*/1 * * * * test -z \"\$(pidof CrashCore)\" && ${CRASHDIR}/start.sh restart #ShellCrash保守模式守护进程" +} +#杂项 +update_config(){ #更新订阅并重启 + getconfig + get_core_config && \ + $0 restart +} +hotupdate(){ #热更新订阅 + getconfig + get_core_config + modify_$format && \ + put_save http://127.0.0.1:${db_port}/configs "{\"path\":\"${CRASHDIR}/config.$format\"}" +} +set_proxy(){ #设置环境变量 + getconfig + if [ "$local_type" = "环境变量" ];then + [ -w ~/.bashrc ] && profile=~/.bashrc + [ -w /etc/profile ] && profile=/etc/profile + echo 'export all_proxy=http://127.0.0.1:'"$mix_port" >> $profile + echo 'export ALL_PROXY=$all_proxy' >> $profile + fi +} +unset_proxy(){ #卸载环境变量 + [ -w ~/.bashrc ] && profile=~/.bashrc + [ -w /etc/profile ] && profile=/etc/profile + sed -i '/all_proxy/'d $profile + sed -i '/ALL_PROXY/'d $profile } case "$1" in -bfstart) - bfstart - ;; -afstart) - afstart - ;; start) [ -n "$(pidof CrashCore)" ] && $0 stop #禁止多实例 getconfig stop_firewall #清理路由策略 #使用不同方式启动服务 if [ "$start_old" = "已开启" ];then - start_old - elif [ -f /etc/rc.common -a -n "$(pidof procd)" ];then - service shellcrash start - elif [ "$USER" = "root" -a -n "$(pidof systemd)" ];then - systemctl start shellcrash.service + bfstart && start_old + elif [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ];then + /etc/init.d/shellcrash start + elif [ "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ];then + FragmentPath=$(systemctl show -p FragmentPath shellcrash | sed 's/FragmentPath=//') + setconfig ExecStart "$COMMAND >/dev/null" "$FragmentPath" + systemctl daemon-reload + systemctl start shellcrash.service || start_error else - start_old + bfstart && start_old fi ;; stop) @@ -1618,24 +1686,24 @@ stop) cronset '运行时每' cronset '流媒体预解析' #多种方式结束进程 - if [ -f /etc/rc.common ];then - service shellcrash stop >/dev/null 2>&1 - elif [ "$USER" = "root" ];then - systemctl stop shellcrash.service >/dev/null 2>&1 + + if [ "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ];then + systemctl stop shellcrash.service &>/dev/null + elif [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ];then + /etc/init.d/shellcrash stop &>/dev/null + else + stop_firewall #清理路由策略 + unset_proxy #禁用本机代理 fi - PID=$(pidof CrashCore) && [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1 - stop_firewall #清理路由策略 - $0 unset_proxy #禁用本机代理 + PID=$(pidof CrashCore) && [ -n "$PID" ] && kill -9 $PID &>/dev/null ;; restart) $0 stop $0 start ;; init) - CRASHDIR=$(cd $(dirname $0);pwd) profile=/etc/profile - if [ -d "/etc/storage/clash" ];then - CRASHDIR=/etc/storage/clash + if [ -d "/etc/storage/clash" -o -d "/etc/storage/ShellCrash" ];then i=1 while [ ! -w /etc/profile -a "$i" -lt 10 ];do sleep 5 && i=$((i+1)) @@ -1654,26 +1722,8 @@ init) sed -i "/export CRASHDIR/d" $profile echo "alias crash=\"$CRASHDIR/menu.sh\"" >> $profile echo "export CRASHDIR=\"$CRASHDIR\"" >> $profile - [ -f $CRASHDIR/.dis_startup ] && cronset "保守模式守护进程" || $0 start + [ -f ${CRASHDIR}/.dis_startup ] && cronset "保守模式守护进程" || $0 start ;; -getyaml) - getconfig - get_core_config && \ - logger "任务:【更新订阅并重启服务】配置文件已更新!" - ;; -updateyaml) - getconfig - get_core_config - modify_$format && \ - put_save http://127.0.0.1:${db_port}/configs "{\"path\":\"${CRASHDIR}/config.$format\"}" && \ - logger "任务:【热更新订阅】配置文件已更新!" - ;; -ntp) - { ckcmd ntpd && ntpd -n -q -p 203.107.6.88 &>/dev/null;exit 0 ;} & - ;; -logger) - logger $2 $3 $4 - ;; webget) #设置临时代理 if [ -n "$(pidof CrashCore)" ];then @@ -1691,18 +1741,18 @@ webget) [ "$4" = "echooff" ] && progress='-s' || progress='-#' [ "$5" = "rediroff" ] && redirect='' || redirect='-L' [ "$6" = "skipceroff" ] && certificate='' || certificate='-k' - result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$2" "$url") - [ "$result" != "200" ] && export all_proxy="" && result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$2" "$3") + result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$2" "$url" 2>/dev/null) + [ "$result" != "200" ] && export all_proxy="" && result=$(curl $agent -w %{http_code} --connect-timeout 5 $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' + timeout='--timeout=5 -t 2' fi [ "$4" = "echoon" ] && progress='' [ "$4" = "echooff" ] && progress='-q' - wget -Y on $agent $progress $redirect $certificate $timeout -O "$2" "$url" + wget -Y on $agent $progress $redirect $certificate $timeout -O "$2" "$url" 2>/dev/null if [ "$?" != "0" ];then wget -Y off $agent $progress $redirect $certificate $timeout -O "$2" "$3" [ "$?" = "0" ] && result="200" @@ -1712,43 +1762,8 @@ webget) fi [ "$result" = "200" ] && exit 0 || exit 1 ;; -get_save) - get_save $2 - ;; -web_save) - getconfig - web_save - ;; -web_restore) - getconfig - web_restore - ;; -daemon) - getconfig - cronset '保守模式守护进程' "*/1 * * * * test -z \"\$(pidof CrashCore)\" && $CRASHDIR/start.sh restart #ShellCrash保守模式守护进程" - ;; -cronset) - cronset $2 $3 - ;; -set_proxy) - getconfig - if [ "$local_type" = "环境变量" ];then - [ -w ~/.bashrc ] && profile=~/.bashrc - [ -w /etc/profile ] && profile=/etc/profile - echo 'export all_proxy=http://127.0.0.1:'"$mix_port" >> $profile - echo 'export ALL_PROXY=$all_proxy' >> $profile - fi - ;; -unset_proxy) - [ -w ~/.bashrc ] && profile=~/.bashrc - [ -w /etc/profile ] && profile=/etc/profile - sed -i '/all_proxy/'d $profile - sed -i '/ALL_PROXY/'d $profile - ;; *) $1 $2 $3 $4 $5 $6 $7 ;; esac - -exit 0 diff --git a/scripts/task.sh b/scripts/task.sh index b1144a9..a694014 100644 --- a/scripts/task.sh +++ b/scripts/task.sh @@ -2,14 +2,12 @@ # Copyright (C) Juewuy #加载全局变量 -[ -d "/etc/storage/clash" ] && CRASHDIR=/etc/storage/clash -[ -d "/jffs/clash" ] && CRASHDIR=/jffs/clash -[ -z "$CRASHDIR" ] && CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}') -[ -z "$CRASHDIR" ] && CRASHDIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}') -[ -z "$bindir" ] && bindir=$CRASHDIR -CFG_PATH=$CRASHDIR/configs/ShellCrash.cfg -TMPDIR=/tmp/ShellCrash && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR +CRASHDIR=$(cd $(dirname $0);pwd) +[ -z "$BINDIR" ] && BINDIR=${CRASHDIR} +CFG_PATH=${CRASHDIR}/configs/ShellCrash.cfg +TMPDIR=/tmp/ShellCrash && [ ! -f ${TMPDIR} ] && mkdir -p ${TMPDIR} source $CFG_PATH &> /dev/null + setconfig(){ #参数1代表变量名,参数2代表变量值,参数3即文件路径 [ -z "$3" ] && configpath=$CFG_PATH || configpath=$3 @@ -18,9 +16,9 @@ setconfig(){ #任务命令 check_update(){ #检查更新工具 - $CRASHDIR/start.sh webget $TMPDIR/crashversion "$update_url/bin/version" echooff - [ "$?" = "0" ] && source $TMPDIR/crashversion 2>/dev/null - rm -rf $TMPDIR/crashversion + ${CRASHDIR}/start.sh webget ${TMPDIR}/crashversion "$update_url/bin/version" echooff + [ "$?" = "0" ] && source ${TMPDIR}/crashversion 2>/dev/null + rm -rf ${TMPDIR}/crashversion } update_core(){ #自动更新内核 #检查版本 @@ -32,29 +30,29 @@ update_core(){ #自动更新内核 else #更新内核 [ "$crashcore" = singbox ] && core_new=singbox || core_new=clash - $CRASHDIR/start.sh webget $TMPDIR/core.new "${update_url}/bin/${crashcore}/${core_new}-linux-${cpucore}" + ${CRASHDIR}/start.sh webget ${TMPDIR}/core.new "${update_url}/bin/${crashcore}/${core_new}-linux-${cpucore}" if [ "$?" != "0" ];then logger "任务【自动更新内核】出错-下载失败!" - rm -rf $TMPDIR/core.new + rm -rf ${TMPDIR}/core.new return 1 else - chmod +x $TMPDIR/core.new - $CRASHDIR/start.sh stop + chmod +x ${TMPDIR}/core.new + ${CRASHDIR}/start.sh stop if [ "$crashcore" = singbox ];then - core_v=$($TMPDIR/core.new version 2>/dev/null | grep version | awk '{print $3}') + core_v=$(${TMPDIR}/core.new version 2>/dev/null | grep version | awk '{print $3}') else - core_v=$($TMPDIR/core.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //') + core_v=$(${TMPDIR}/core.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //') fi if [ -z "$core_v" ];then logger "任务【自动更新内核】出错-内核校验失败!" - rm -rf $TMPDIR/core.new - $CRASHDIR/start.sh start + rm -rf ${TMPDIR}/core.new + ${CRASHDIR}/start.sh start return 1 else - mv -f $TMPDIR/core.new $bindir/CrashCore + mv -f ${TMPDIR}/core.new ${BINDIR}/CrashCore logger "任务【自动更新内核】下载完成,正在重启服务!" setconfig core_v $core_v - $CRASHDIR/start.sh start + ${CRASHDIR}/start.sh start return 0 fi fi @@ -67,20 +65,20 @@ update_shellcrash(){ #自动更新脚本 logger "任务【自动更新脚本】中止-未检测到版本更新" exit 1 else - $CRASHDIR/start.sh webget $TMPDIR/clashfm.tar.gz "$update_url/bin/clashfm.tar.gz" + ${CRASHDIR}/start.sh webget ${TMPDIR}/update.tar.gz "$update_url/bin/update.tar.gz" if [ "$?" != "0" ];then - rm -rf $TMPDIR/clashfm.tar.gz + rm -rf ${TMPDIR}/update.tar.gz logger "任务【自动更新内核】出错-下载失败!" return 1 else #解压 - tar -zxvf "$TMPDIR/clashfm.tar.gz" -C $CRASHDIR/ || tar -zxvf "$TMPDIR/clashfm.tar.gz" --no-same-owner -C $CRASHDIR/ + tar -zxvf "${TMPDIR}/update.tar.gz" -C ${CRASHDIR}/ || tar -zxvf "${TMPDIR}/update.tar.gz" --no-same-owner -C ${CRASHDIR}/ if [ $? -ne 0 ];then - rm -rf $TMPDIR/clashfm.tar.gz + rm -rf ${TMPDIR}/update.tar.gz logger "任务【自动更新内核】出错-解压失败!" return 1 else - source $CRASHDIR/init.sh >/dev/null + source ${CRASHDIR}/init.sh >/dev/null return 0 fi fi @@ -97,13 +95,13 @@ update_mmdb(){ #自动更新数据库 logger "任务【自动更新数据库文件】跳过-未检测到$2版本更新" else #更新文件 - $CRASHDIR/start.sh webget $TMPDIR/$1 "$update_url/bin/geodata/$2" + ${CRASHDIR}/start.sh webget ${TMPDIR}/$1 "$update_url/bin/geodata/$2" if [ "$?" != "0" ];then logger "任务【自动更新数据库文件】更新【$2】下载失败!" - rm -rf $TMPDIR/$1 + rm -rf ${TMPDIR}/$1 return 1 else - mv -f $TMPDIR/$1 $bindir/$1 + mv -f ${TMPDIR}/$1 ${BINDIR}/$1 setconfig $geo_v $GeoIP_v logger "任务【自动更新数据库文件】更新【$2】成功!" return 0 @@ -119,8 +117,11 @@ update_mmdb(){ #自动更新数据库 [ -n "${geosite_cn_v}" ] && getgeo geosite.db geosite_cn.db } reset_firewall(){ #重设透明路由防火墙 - $CRASHDIR/start.sh stop_firewall - $CRASHDIR/start.sh afstart + ${CRASHDIR}/start.sh stop_firewall + ${CRASHDIR}/start.sh afstart +} +ntp(){ + ckcmd ntpd && ntpd -n -q -p 203.107.6.88 &>/dev/null || exit 0 & } #任务工具 @@ -128,7 +129,7 @@ logger(){ [ "$task_push" = 1 ] && push= || push=off [ -n "$2" -a "$2" != 0 ] && echo -e "\033[$2m$1\033[0m" [ "$3" = 'off' ] && push=off - $CRASHDIR/start.sh logger $1 0 $push + ${CRASHDIR}/start.sh logger $1 0 $push } croncmd(){ if [ -n "$(crontab -h 2>&1 | grep '\-l')" ];then @@ -145,14 +146,14 @@ croncmd(){ } cronset(){ # 参数1代表要移除的关键字,参数2代表要添加的任务语句 - tmpcron=$TMPDIR/cron_$USER + tmpcron=${TMPDIR}/cron_$USER croncmd -l > $tmpcron sed -i "/$1/d" $tmpcron sed -i '/^$/d' $tmpcron echo "$2" >> $tmpcron croncmd $tmpcron #华硕/Padavan固件存档在本地,其他则删除 - [ "$CRASHDIR" = "/jffs/clash" -o "$CRASHDIR" = "/etc/storage/clash" ] && mv -f $tmpcron $CRASHDIR/task/cron || rm -f $tmpcron + [ -d /jffs -o -d /etc/storage/clash -o -d /etc/storage/ShellCrash ] && mv -f $tmpcron ${CRASHDIR}/task/cron || rm -f $tmpcron } set_cron(){ [ -z $week ] && week=* @@ -164,14 +165,14 @@ set_cron(){ if [ "$res" = '1' ]; then task_txt="$min $hour * * $week $CRASHDIR/task/task.sh $task_id $cron_time$task_name" cronset "$cron_time$task_name" "$task_txt" + echo -e "任务【$cron_time$task_name】\033[32m已添加!\033[0m" fi unset week hour min - echo -e "任务【$cron_time$task_name】\033[32m添加成功!\033[0m" sleep 1 } set_service(){ # 参数1代表要任务类型,参数2代表任务ID,参数3代表任务描述,参数4代表running任务cron时间 - task_file=$CRASHDIR/task/$1 + task_file=${CRASHDIR}/task/$1 [ -s $task_file ] && sed -i "/$3/d" $task_file #运行时每分钟执行的任务特殊处理 if [ "$1" = "running" ];then @@ -188,18 +189,18 @@ set_service(){ task_user_add(){ #自定义命令添加 echo ----------------------------------------------- echo -e "\033[33m命令可包含空格,请确保命令可执行!\033[0m" - echo -e "也可以手动编辑\033[32m$CRASHDIR/task/task.user\033[0m添加" + echo -e "也可以手动编辑\033[32m${CRASHDIR}/task/task.user\033[0m添加" read -p "请输入命令语句 > " script if [ -n "$script" ];then task_command=$script echo -e "请检查输入:\033[32m$task_command\033[0m" #获取本任务ID - task_max_id=$(awk -F'#' '{print $1}' $CRASHDIR/task/task.user | sort -n | tail -n 1) + task_max_id=$(awk -F'#' '{print $1}' ${CRASHDIR}/task/task.user | sort -n | tail -n 1) [ -z "$task_max_id" ] && task_max_id=200 task_id=$((task_max_id + 1)) read -p "请输入任务备注 > " txt [ -n "$txt" ] && task_name=$txt || task_name=自定义任务$task_id - echo "$task_id#$task_command#$task_name" >> $CRASHDIR/task/task.user + echo "$task_id#$task_command#$task_name" >> ${CRASHDIR}/task/task.user echo -e "\033[32m自定义任务已添加!\033[0m" sleep 1 else @@ -210,15 +211,15 @@ task_user_add(){ #自定义命令添加 task_user_del(){ #自定义命令删除 echo ----------------------------------------------- echo -e "请输入对应ID移除对应自定义任务(不会影响内置任务)" - echo -e "也可以手动编辑\033[32m$CRASHDIR/task/task.user\033[0m" + echo -e "也可以手动编辑\033[32m${CRASHDIR}/task/task.user\033[0m" echo ----------------------------------------------- - cat $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^#' | awk -F '#' '{print $1" "$3}' + cat ${CRASHDIR}/task/task.user 2>/dev/null | grep -Ev '^#' | awk -F '#' '{print $1" "$3}' echo ----------------------------------------------- echo 0 返回上级菜单 echo ----------------------------------------------- read -p "请输入对应数字 > " num if [ -n "$num" ];then - sed -i "/^$num#/d" $CRASHDIR/task/task.user 2>/dev/null + sed -i "/^$num#/d" ${CRASHDIR}/task/task.user 2>/dev/null [ "$num" != 0 ] && task_user_del else echo -e "\033[31m输入错误,请重新输入!\033[0m" @@ -230,9 +231,9 @@ task_add(){ #任务添加 echo -e "\033[36m请选择需要添加的任务\033[0m" echo ----------------------------------------------- #检测并创建自定义任务文件 - [ -f $CRASHDIR/task/task.user ] || echo '#任务ID(必须>200并顺序排列)#任务命令#任务说明(#号隔开,任务命令和说明中都不允许包含#号)' > $CRASHDIR/task/task.user + [ -f ${CRASHDIR}/task/task.user ] || echo '#任务ID(必须>200并顺序排列)#任务命令#任务说明(#号隔开,任务命令和说明中都不允许包含#号)' > ${CRASHDIR}/task/task.user #输出任务列表 - cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | awk -F '#' '{print " "NR" "$3}' + cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | awk -F '#' '{print " "NR" "$3}' echo ----------------------------------------------- echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num @@ -240,9 +241,9 @@ task_add(){ #任务添加 0) ;; [1-9]|[1-9][0-9]) - if [ "$num" -le "$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | wc -l)" ];then - task_id=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | sed -n "$num p" | awk -F '#' '{print $1}') - task_name=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | sed -n "$num p" | awk -F '#' '{print $3}') + if [ "$num" -le "$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | wc -l)" ];then + task_id=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | sed -n "$num p" | awk -F '#' '{print $1}') + task_name=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | sed -n "$num p" | awk -F '#' '{print $3}') task_type else errornum @@ -255,14 +256,14 @@ task_add(){ #任务添加 } task_del(){ #任务删除 #删除定时任务 - croncmd -l > $TMPDIR/cron && sed -i "/$1/d" $TMPDIR/cron && croncmd $TMPDIR/cron - rm -f $TMPDIR/cron + croncmd -l > ${TMPDIR}/cron && sed -i "/$1/d" ${TMPDIR}/cron && croncmd ${TMPDIR}/cron + rm -f ${TMPDIR}/cron #删除条件任务 - sed -i "/$1/d" $CRASHDIR/task/cron 2>/dev/null - sed -i "/$1/d" $CRASHDIR/task/bfstart 2>/dev/null - sed -i "/$1/d" $CRASHDIR/task/afstart 2>/dev/null - sed -i "/$1/d" $CRASHDIR/task/running 2>/dev/null - sed -i "/$1/d" $CRASHDIR/task/affirewall 2>/dev/null + sed -i "/$1/d" ${CRASHDIR}/task/cron 2>/dev/null + sed -i "/$1/d" ${CRASHDIR}/task/bfstart 2>/dev/null + sed -i "/$1/d" ${CRASHDIR}/task/afstart 2>/dev/null + sed -i "/$1/d" ${CRASHDIR}/task/running 2>/dev/null + sed -i "/$1/d" ${CRASHDIR}/task/affirewall 2>/dev/null } task_type(){ #任务条件选择菜单 echo ----------------------------------------------- @@ -355,25 +356,32 @@ task_type(){ #任务条件选择菜单 task_manager(){ #任务管理列表 echo ----------------------------------------------- #抽取并生成临时列表 - croncmd -l > $TMPDIR/task_cronlist - cat $TMPDIR/task_cronlist $CRASHDIR/task/running 2>/dev/null | sort -u | grep -oE "task/task.sh .*" | awk -F ' ' '{print $2" "$3}' > $TMPDIR/task_list - cat $CRASHDIR/task/bfstart $CRASHDIR/task/afstart $CRASHDIR/task/affirewall 2>/dev/null | awk -F ' ' '{print $2" "$3}' >> $TMPDIR/task_list - rm -rf $TMPDIR/task_cronlist + croncmd -l > ${TMPDIR}/task_cronlist + cat ${TMPDIR}/task_cronlist ${CRASHDIR}/task/running 2>/dev/null | sort -u | grep -oE "task/task.sh .*" | awk -F ' ' '{print $2" "$3}' > ${TMPDIR}/task_list + cat ${CRASHDIR}/task/bfstart ${CRASHDIR}/task/afstart ${CRASHDIR}/task/affirewall 2>/dev/null | awk -F ' ' '{print $2" "$3}' >> ${TMPDIR}/task_list + cat ${TMPDIR}/task_cronlist 2>/dev/null | sort -u | grep -oE " #.*" | grep -v "守护" | awk -F '#' '{print "0 旧版任务-"$2}' >> ${TMPDIR}/task_list + rm -rf ${TMPDIR}/task_cronlist #判断为空则返回 - if [ ! -s $TMPDIR/task_list ];then + if [ ! -s ${TMPDIR}/task_list ];then echo -e "\033[31m当前没有可供管理的任务!\033[36m" sleep 1 else echo -e "\033[33m已添加的任务:\033[0m" echo ----------------------------------------------- - cat $TMPDIR/task_list | awk '{print " " NR " " $2}' + cat ${TMPDIR}/task_list | awk '{print " " NR " " $2}' echo ----------------------------------------------- - echo -e " d 清空任务列表" + echo -e " a 清空旧版任务" + echo -e " d 清空任务列表" echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num case "$num" in 0) ;; + a) + task_del "#" + echo -e "\033[31m旧版任务已清空!\033[36m" + sleep 1 + ;; d) task_del "task.sh" echo -e "\033[31m全部任务已清空!\033[36m" @@ -381,48 +389,57 @@ task_manager(){ #任务管理列表 ;; [1-9]|[1-9][0-9]) - task_txt=$(sed -n "$num p" $TMPDIR/task_list) + task_txt=$(sed -n "$num p" ${TMPDIR}/task_list) task_id=$(echo $task_txt | awk '{print $1}') - task_des=$(echo $task_txt | awk '{print $2}') - task_name=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$task_id" | awk -F '#' '{print $3}') - echo ----------------------------------------------- - echo -e "当前任务为:\033[36m $task_des\033[0m" - echo -e " 1 \033[33m修改\033[0m当前任务" - echo -e " 2 \033[31m删除\033[0m当前任务" - echo -e " 3 \033[32m立即执行\033[0m一次" - echo -e " 4 查看\033[33m执行记录\033[0m" - echo ----------------------------------------------- - echo -e " 0 返回上级菜单" - read -p "请选择需要执行的操作 > " num - case "$num" in - 0) - ;; - 1) - task_type && task_del $task_des - ;; - 2) - task_del $task_des - ;; - 3) - task_command=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$task_id" | awk -F '#' '{print $2}') - eval $task_command && task_res='执行成功!' || task_res='执行失败!' - logger "任务【$task_des】$task_res" 33 off - sleep 1 - ;; - 4) + if [ "$task_id" = 0 ];then + read -p "旧版任务不支持管理,是否移除?(1/0) > " res + [ "$res" = 1 ] && { + cronname=$(echo $task_txt | awk -F '-' '{print $2}') + croncmd -l > $TMPDIR/conf && sed -i "/$cronname/d" $TMPDIR/conf && croncmd $TMPDIR/conf + sed -i "/$cronname/d" $clashdir/tools/cron 2>/dev/null + rm -f $TMPDIR/conf + } + else + task_des=$(echo $task_txt | awk '{print $2}') + task_name=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep "$task_id" | awk -F '#' '{print $3}') echo ----------------------------------------------- - if [ -n "$(cat $TMPDIR/ShellCrash.log | grep "$task_name")" ];then - cat $TMPDIR/ShellCrash.log | grep "$task_name" - else - echo -e "\033[31m未找到相关执行记录!\033[0m" - fi - sleep 1 - ;; - *) - errornum - ;; - esac - + echo -e "当前任务为:\033[36m $task_des\033[0m" + echo -e " 1 \033[33m修改\033[0m当前任务" + echo -e " 2 \033[31m删除\033[0m当前任务" + echo -e " 3 \033[32m立即执行\033[0m一次" + echo -e " 4 查看\033[33m执行记录\033[0m" + echo ----------------------------------------------- + echo -e " 0 返回上级菜单" + read -p "请选择需要执行的操作 > " num + case "$num" in + 0) + ;; + 1) + task_type && task_del $task_des + ;; + 2) + task_del $task_des + ;; + 3) + task_command=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep "$task_id" | awk -F '#' '{print $2}') + eval $task_command && task_res='执行成功!' || task_res='执行失败!' + logger "任务【$task_des】$task_res" 33 off + sleep 1 + ;; + 4) + echo ----------------------------------------------- + if [ -n "$(cat ${TMPDIR}/ShellCrash.log | grep "$task_name")" ];then + cat ${TMPDIR}/ShellCrash.log | grep "$task_name" + else + echo -e "\033[31m未找到相关执行记录!\033[0m" + fi + sleep 1 + ;; + *) + errornum + ;; + esac + fi task_manager ;; *) @@ -443,7 +460,7 @@ task_recom(){ #任务推荐 [ "$res" = 1 ] && { set_service running "106" "运行时每10分钟自动保存面板配置" "*/10 * * * *" set_service afstart "107" "服务启动后自动同步ntp时间" - cronset "在每周3的3点整更新订阅并重启服务" "0 3 * * 3 $CRASHDIR/task/task.sh 104 在每周3的3点整更新订阅并重启服务" && \ + cronset "在每周3的3点整更新订阅并重启服务" "0 3 * * 3 ${CRASHDIR}/task/task.sh 104 在每周3的3点整更新订阅并重启服务" && \ echo -e "任务【在每周3的3点整更新订阅并重启服务】\033[32m添加成功!\033[0m" } } @@ -470,13 +487,13 @@ task_menu(){ #任务菜单 ;; 2) task_manager - rm -rf $TMPDIR/task_list + rm -rf ${TMPDIR}/task_list task_menu ;; 3) - if [ -n "$(cat $TMPDIR/ShellCrash.log | grep '任务【')" ];then + if [ -n "$(cat ${TMPDIR}/ShellCrash.log | grep '任务【')" ];then echo ----------------------------------------------- - cat $TMPDIR/ShellCrash.log | grep '任务【' + cat ${TMPDIR}/ShellCrash.log | grep '任务【' else echo -e "\033[31m未找到任务相关执行日志!\033[0m" fi @@ -514,8 +531,8 @@ case "$1" in task_menu ;; [1-9][0-9][0-9]) - task_command=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $2}') - task_name=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $3}') + task_command=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $2}') + task_name=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $3}') #logger "任务$task_name 开始执行" eval $task_command && task_res=成功 || task_res=失败 logger "任务【$2】执行$task_res"