diff --git a/.github/workflows/bin_update.yml b/.github/workflows/bin_update.yml index 6e93b1a..9a1a32c 100644 --- a/.github/workflows/bin_update.yml +++ b/.github/workflows/bin_update.yml @@ -20,9 +20,11 @@ jobs: steps: - - name: Checkout - uses: actions/checkout@master - + - name: Checkout ShellCrash + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + repository: juewuy/ShellCrash + ref: dev - name: Apt Update env: DEBIAN_FRONTEND: noninteractive diff --git a/.github/workflows/update_premium.latest_core.yaml b/.github/workflows/update_premium.latest_core.yaml index 591ff6b..08bf2cb 100644 --- a/.github/workflows/update_premium.latest_core.yaml +++ b/.github/workflows/update_premium.latest_core.yaml @@ -1,7 +1,7 @@ name: Update Premium latest Core on: - schedule: - - cron: 0 20 * * 6 + #schedule: + #- cron: 0 20 * * 6 workflow_dispatch: env: diff --git a/README_CN.md b/README_CN.md index 25be4fd..6f11848 100644 --- a/README_CN.md +++ b/README_CN.md @@ -101,9 +101,26 @@ export url='https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master' && wget -q export url='http://t.jwsc.eu.org' && wget -q -O /tmp/install.sh $url/install.sh && sh /tmp/install.sh && source /etc/profile &> /dev/null ``` -~**DOCKER环境下安装:**
+~**虚拟机/Docker环境安装:**
+ +虚拟机或Docker环境推荐使用Alpine镜像安装
+ +这里以Docker为例(其他虚拟机请自行查找安装Alpine镜像安装教程)
+ +```shell +#注意,以下命令请分步执行! +#Docker一键启动Alpine镜像 +docker run -d --name ShellCrash alpine sleep infinity +#进入容器内sh环境 +docker exec -it ShellCrash sh +#安装必要依赖 +apk add curl +apk add nftables +#执行安装命令 +export url='https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master' && sh -c "$(curl -kfsSl $url/install.sh)" && source /etc/profile &> /dev/null +``` + -请参考 [ShellCrash_docker 一键脚本和镜像](https://github.com/echvoyager/shellCrash_docker) ### **本地安装:**
diff --git a/bin/ShellCrash.tar.gz b/bin/ShellCrash.tar.gz index 7e703b2..b59f410 100644 Binary files a/bin/ShellCrash.tar.gz and b/bin/ShellCrash.tar.gz differ diff --git a/bin/clashfm.tar.gz b/bin/clashfm.tar.gz index 2173a62..ca1f1ba 100644 Binary files a/bin/clashfm.tar.gz and b/bin/clashfm.tar.gz differ diff --git a/bin/public.tar.gz b/bin/public.tar.gz index f2a4895..8d883c3 100644 Binary files a/bin/public.tar.gz and b/bin/public.tar.gz differ diff --git a/bin/singbox/singbox-linux-amd64 b/bin/singbox/singbox-linux-amd64 new file mode 100755 index 0000000..1a27286 Binary files /dev/null and b/bin/singbox/singbox-linux-amd64 differ diff --git a/bin/singbox/singbox-linux-armv5 b/bin/singbox/singbox-linux-armv5 new file mode 100755 index 0000000..56c446e Binary files /dev/null and b/bin/singbox/singbox-linux-armv5 differ diff --git a/bin/singbox/singbox-linux-armv7 b/bin/singbox/singbox-linux-armv7 new file mode 100755 index 0000000..693a546 Binary files /dev/null and b/bin/singbox/singbox-linux-armv7 differ diff --git a/bin/singbox/singbox-linux-armv8 b/bin/singbox/singbox-linux-armv8 new file mode 100755 index 0000000..e1a1bcd Binary files /dev/null and b/bin/singbox/singbox-linux-armv8 differ diff --git a/bin/singbox/singbox-linux-mips-softfloat b/bin/singbox/singbox-linux-mips-softfloat new file mode 100755 index 0000000..b302caf Binary files /dev/null and b/bin/singbox/singbox-linux-mips-softfloat differ diff --git a/bin/singbox/singbox-linux-mipsle-hardfloat b/bin/singbox/singbox-linux-mipsle-hardfloat new file mode 100755 index 0000000..c76ac73 Binary files /dev/null and b/bin/singbox/singbox-linux-mipsle-hardfloat differ diff --git a/bin/singbox/singbox-linux-mipsle-softfloat b/bin/singbox/singbox-linux-mipsle-softfloat new file mode 100755 index 0000000..1fa9239 Binary files /dev/null and b/bin/singbox/singbox-linux-mipsle-softfloat differ diff --git a/bin/version b/bin/version index 59141e8..e3dc917 100644 --- a/bin/version +++ b/bin/version @@ -2,5 +2,7 @@ clashnet_v=v1.7.6 clashpre_v=2022.11.25 clash_v=v1.7.1 meta_v=v1.18.0 + singbox_v=1.7.8 versionsh=1.8.5d +GeoIP_v=20240113 \ No newline at end of file diff --git a/public/servers.list b/public/servers.list index 01d0298..2170e5a 100644 --- a/public/servers.list +++ b/public/servers.list @@ -1,22 +1,20 @@ -# ID&类型 说明 地址 其他说明 (类型:100-稳定源;200-测试源;300-基础sub;400-meta_sub;500-规则地址) +# ID&类型 说明 地址 其他说明 (类型:100-三版全通源;200-单一源;300-基础sub;400-meta_sub;500-规则地址) -101 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellCrash 稳定版 -102 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellCrash 稳定版 +101 Jsdelivr_CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellCrash +102 Github直连源(请注意网络环境) https://raw.githubusercontent.com/juewuy/ShellCrash +103 ShellClash自建源(请勿滥用!) https://gh.jwsc.eu.org +104 Cloudflare_CDN源 https://gh.shellclash.workers.dev/https://raw.githubusercontent.com/juewuy/ShellCrash -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/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 公测版 +201 wwng2333自建CN源(请勿滥用!) https://mirrors.csgo.ovh/ShellClash 公测版 +202 http私人内测源(危险!非必要请勿使用) http://t.jwsc.eu.org 开发版 301 墙洞提供,不支持vless|hy https://api.dler.io 302 SUB作者提供,不支持vless|hy https://sub.xeton.dev 303 品云提供,不支持vless|hy https://sub.id9.cc -401 肥羊提供(有广告),支持vless|hy2 https://sub.d1.mk -402 肥羊提供(有广告),支持vless|hy2 https://api.v1.mk -403 作者提供,支持vless|hy2 https://sub.jwsc.eu.org +401 肥羊提供(有广告),支持vless|hy2 https://sub.d1.mk +402 作者提供,支持vless|hy2 https://sub.jwsc.eu.org +403 肥羊提供(有广告),支持vless|hy2 https://api.v1.mk 497 作者提供,未加密仅备用 http://sub2.jwsc.eu.org 498 本地服务器 http://127.0.0.1:25500 diff --git a/rules/ShellClash_Mini.ini b/rules/ShellClash_Mini.ini index 8478a88..8dc1c44 100644 --- a/rules/ShellClash_Mini.ini +++ b/rules/ShellClash_Mini.ini @@ -6,6 +6,7 @@ ruleset=🛑 广告拦截,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/mast ruleset=🎥 奈飞解锁,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Ruleset/Netflix.list ruleset=🎥 奈飞解锁,https://raw.githubusercontent.com/LM-Firefly/Rules/master/Global-Services/Netflix.list ruleset=🎥 奈飞解锁,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Ruleset/DisneyPlus.list +ruleset=🤖 人工智能,https://raw.githubusercontent.com/juewuy/ShellClash/master/rules/ai.list ruleset=🚀 节点选择,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/ProxyLite.list ruleset=🚀 节点选择,https://raw.githubusercontent.com/juewuy/ShellClash/master/rules/ai.list ruleset=🎯 全球直连,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/ChinaDomain.list @@ -18,6 +19,7 @@ custom_proxy_group=♻️ 自动选择`url-test`.*`http://www.gstatic.com/genera custom_proxy_group=🔯 故障转移首选`select`.* custom_proxy_group=🔯 故障转移`fallback`[]🔯 故障转移首选`[]👍 高级节点`[]♻️ 自动选择`http://www.gstatic.com/generate_204`180 custom_proxy_group=🛑 广告拦截`select`[]DIRECT`[]REJECT +custom_proxy_group=🤖 人工智能`select`[]🇺🇲 美国节点`[]🇸🇬 新加坡节点`[]🇯🇵 日韩节点`[]🚀 手动切换 custom_proxy_group=🎥 奈飞解锁`select`[]🎥 流媒体解锁`[]👍 高级节点`[]🔯 故障转移`[]🚀 节点选择 custom_proxy_group=🎯 全球直连`select`[]DIRECT`[]🚀 节点选择`[]♻️ 自动选择 custom_proxy_group=🐟 漏网之鱼`select`[]🔯 故障转移`[]🚀 节点选择`[]📺 省流节点`[]♻️ 自动选择`[]DIRECT diff --git a/scripts/getdate.sh b/scripts/getdate.sh index 8a3b166..03961da 100644 --- a/scripts/getdate.sh +++ b/scripts/getdate.sh @@ -9,6 +9,7 @@ dir_avail(){ 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}' } + #导入订阅、配置文件相关 setrules(){ #自定义clash规则 set_rule_type(){ @@ -761,7 +762,7 @@ set_core_config(){ #配置文件功能 } #下载更新相关 gettar(){ - ${CRASHDIR}/start.sh webget ${TMPDIR}/clashfm.tar.gz $tarurl + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/update.tar.gz bin/clashfm.tar.gz if [ "$?" != "0" ];then echo -e "\033[33m文件下载失败!\033[0m" error_down @@ -771,7 +772,7 @@ gettar(){ 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}/ + tar -zxvf "${TMPDIR}/update.tar.gz" -C ${CRASHDIR}/ 2>/dev/null || tar -zxvf "${TMPDIR}/update.tar.gz" --no-same-owner -C ${CRASHDIR}/ if [ $? -ne 0 ];then echo -e "\033[33m文件解压失败!\033[0m" error_down @@ -780,18 +781,17 @@ gettar(){ echo -e "\033[32m脚本更新成功!\033[0m" fi fi - rm -rf ${TMPDIR}/clashfm.tar.gz + rm -rf ${TMPDIR}/update.tar.gz exit } getsh(){ echo ----------------------------------------------- echo -e "当前脚本版本为:\033[33m $versionsh_l \033[0m" - echo -e "最新脚本版本为:\033[32m $release_new \033[0m" + echo -e "最新脚本版本为:\033[32m $version_new \033[0m" echo -e "注意更新时会停止服务!" echo ----------------------------------------------- read -p "是否更新脚本?[1/0] > " res if [ "$res" = '1' ]; then - tarurl=$update_url/bin/clashfm.tar.gz #下载更新 gettar #提示 @@ -884,12 +884,14 @@ getcore(){ [ -z "$crashcore" ] && crashcore=clashpre [ -z "$cpucore" ] && getcpucore [ "$crashcore" = singbox ] && core_new=singbox || core_new=clash - #生成链接 - [ -z "$custcorelink" ] && corelink="${update_url}/bin/${crashcore}/${core_new}-linux-${cpucore}" || corelink="$custcorelink" #获取在线内核文件 echo ----------------------------------------------- echo 正在在线获取$crashcore核心文件…… - ${CRASHDIR}/start.sh webget ${TMPDIR}/core.new $corelink + if [ -z "$custcorelink" ];then + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/core.new bin/${crashcore}/${core_new}-linux-${cpucore} + else + ${CRASHDIR}/start.sh webget ${TMPDIR}/core.new "$custcorelink" + fi if [ "$?" = "1" ];then echo -e "\033[31m核心文件下载失败!\033[0m" rm -rf ${TMPDIR}/core.new @@ -931,7 +933,7 @@ setcustcore(){ echo -e "\033[33m请选择需要使用的核心!\033[0m" echo -e "1 \033[32m 测试版ClashPre内核 \033[0m" echo -e "2 \033[32m 最新Meta.Alpha内核 \033[0m" - echo -e "3 \033[32m Sing-Box官方内核 \033[0m" + #echo -e "3 \033[32m Sing-Box官方内核 \033[0m" echo -e "4 \033[33m 自定义内核链接 \033[0m" read -p "请输入对应数字 > " num case "$num" in @@ -984,11 +986,15 @@ setcore(){ echo echo -e "3 \033[43;30mClash.Meta\033[0m: \033[32m多功能,支持最全面\033[0m" echo -e " (Meta稳定内核) \033[33m内存占用较高\033[0m" - echo -e " 说明文档: \033[36;4mhttps://docs.metacubex.one\033[0m" + echo -e " 说明文档: \033[36;4mhttps://wiki.metacubex.one\033[0m" echo - echo -e "4 \033[32m自定义内核\033[0m: \033[33m仅限专业用户使用\033[0m" + echo -e "4 \033[43;30mSing-Box\033[0m: \033[32m支持全面占用低\033[0m" + echo -e " (sing-box内核) \033[33m另一个选择\033[0m" + echo -e " 说明文档: \033[36;4mhttps://sing-box.sagernet.org\033[0m" echo - echo "5 手动指定处理器架构" + echo -e "5 \033[32m自定义内核\033[0m: \033[33m仅限专业用户使用\033[0m" + echo + echo "6 手动指定处理器架构" echo ----------------------------------------------- echo 0 返回上级菜单 read -p "请输入对应数字 > " num @@ -1009,9 +1015,14 @@ setcore(){ getcore ;; 4) - setcustcore + crashcore=singbox + custcorelink='' + getcore ;; 5) + setcustcore + ;; + 6) setcpucore setcore ;; @@ -1023,10 +1034,9 @@ setcore(){ getgeo(){ #生成链接 - [ -z "$custgeolink" ] && geolink="$update_url/bin/geodata/$geotype" || geolink="$custgeolink" echo ----------------------------------------------- echo 正在从服务器获取数据库文件………… - ${CRASHDIR}/start.sh webget ${TMPDIR}/$geoname $geolink + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/$geoname bin/geodata/$geotype if [ "$?" = "1" ];then echo ----------------------------------------------- echo -e "\033[31m文件下载失败!\033[0m" @@ -1118,7 +1128,7 @@ setcustgeo(){ echo -e "\033[0m请选择需要更新的数据库项目来源:\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 " 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 ----------------------------------------------- @@ -1277,10 +1287,10 @@ esac } getdb(){ - dblink="${update_url}/bin/dashboard/${db_type}.tar.gz" + dblink="${update_url}/" echo ----------------------------------------------- echo 正在连接服务器获取安装文件………… - ${CRASHDIR}/start.sh webget ${TMPDIR}/clashdb.tar.gz $dblink + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/clashdb.tar.gz bin/dashboard/${db_type}.tar.gz if [ "$?" = "1" ];then echo ----------------------------------------------- echo -e "\033[31m文件下载失败!\033[0m" @@ -1402,10 +1412,9 @@ setdb(){ } getcrt(){ - crtlink="${update_url}/bin/fix/ca-certificates.crt" echo ----------------------------------------------- echo 正在连接服务器获取安装文件………… - ${CRASHDIR}/start.sh webget ${TMPDIR}/ca-certificates.crt $crtlink + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/ca-certificates.crt bin/fix/ca-certificates.crt if [ "$?" = "1" ];then echo ----------------------------------------------- echo -e "\033[31m文件下载失败!\033[0m" @@ -1414,12 +1423,11 @@ getcrt(){ echo ----------------------------------------------- mkdir -p $openssldir mv -f ${TMPDIR}/ca-certificates.crt $crtdir - ${CRASHDIR}/start.sh webget ${TMPDIR}/ssl_test https://baidu.com echooff rediron skipceroff + ${CRASHDIR}/start.sh webget /dev/null 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 echo -e "\033[32m证书安装成功!\033[0m" sleep 1 fi @@ -1454,68 +1462,123 @@ setcrt(){ } #安装源 setserver(){ + [ -z "$release_type" ] && release_name=未指定 + [ -n "$release_type" ] && release_name=${release_type}'(回退)' + [ "$release_type" = stable ] && release_name=稳定版 + [ "$release_type" = master ] && release_name=公测版 + [ "$release_type" = dev ] && release_name=开发版 + [ -n "$url_id" ] && url_name=$(grep "$url_id" ${CRASHDIR}/configs/servers.list 2>/dev/null | awk '{print $2}') || url_name=$update_url saveserver(){ #写入配置文件 setconfig update_url \'$update_url\' - setconfig release_url \'$release_url\' + setconfig url_id $url_id + setconfig release_type $release_type echo ----------------------------------------------- echo -e "\033[32m源地址更新成功!\033[0m" - release_new="" } echo ----------------------------------------------- echo -e "\033[30;47m切换ShellCrash版本及更新源地址\033[0m" - echo -e "当前源地址:\033[4;32m$update_url\033[0m" + echo -e "当前版本:\033[4;33m$release_name\033[0m 当前源:\033[4;32m$url_name\033[0m" echo ----------------------------------------------- - grep -aE '^1|^2' ${CRASHDIR}/configs/servers.list | awk '{print " "NR" "$4" "$2}' + grep -E "^1|$release_name" ${CRASHDIR}/configs/servers.list | awk '{print " "NR" "$2}' echo ----------------------------------------------- - echo -e " a 自定义源地址(用于本地源或自建源)" - echo -e " b \033[31m版本回退\033[0m" + echo -e " a 切换至\033[32m稳定版\033[0m" + echo -e " b 切换至\033[36m公测版\033[0m" + echo -e " c 切换至\033[33m开发版\033[0m" + echo ----------------------------------------------- + echo -e " d 自定义源地址(用于本地源或自建源)" + echo -e " e \033[31m版本回退\033[0m" echo -e " 0 返回上级菜单" - read -p "请输入对应数字 > " num + echo ----------------------------------------------- + read -p "请输入对应字母或数字 > " num case $num in 0) ;; [1-99]) - 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}') + url_id_new=$(grep -E "^1|$release_name" ${CRASHDIR}/configs/servers.list | sed -n ""$num"p" | awk '{print $1}') + if [ -z "$url_id_new" ];then + errornum + sleep 1 + setserver + elif [ "$url_id_new" -ge 200 ];then + update_url=$(grep -E "^1|$release_name" ${CRASHDIR}/configs/servers.list | sed -n ""$num"p" | awk '{print $3}') + url_id='' + saveserver else - update_url=$(grep -aE '^1|^2' ${CRASHDIR}/configs/servers.list | sed -n ""$num"p" | awk '{print $3}') - unset release_url + url_id=$url_id_new + update_url='' + saveserver fi - saveserver + unset url_id_new ;; a) + release_type=stable + setconfig release_type $release_type + setserver + ;; + b) + release_type=master + setconfig release_type $release_type + setserver + ;; + c) + echo ----------------------------------------------- + echo -e "\033[33m开发版未经过妥善测试,可能依然存在大量bug!!!\033[0m" + echo -e "\033[36m如果你没有足够的耐心或者测试经验,切勿使用此版本!\033[0m" + echo -e "请务必加入我们的讨论组:\033[32;4mhttps://t.me/ShellClash\033[0m" + read -p "是否依然切换到开发版?(1/0) > " res + if [ "$res" = 1 ];then + release_type=dev + setconfig release_type $release_type + fi + setserver + ;; + d) echo ----------------------------------------------- read -p "请输入个人源路径 > " update_url if [ -z "$update_url" ];then echo ----------------------------------------------- echo -e "\033[31m取消输入,返回上级菜单\033[0m" else + url_id='' + release_type='' saveserver - unset release_url fi ;; - b) + e) echo ----------------------------------------------- - echo -e "\033[33m如无法连接,请务必先启用服务!!!\033[0m" - ${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}/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}/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 + if [ -n "$url_id" ] && [ "$url_id" -lt 200 ];then + echo -ne "\033[32m正在获取版本信息!\033[0m\r" + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/release_version bin/release_version + if [ "$?" = "0" ];then + echo -e "\033[31m请选择想要回退至的稳定版版本:\033[0m" + cat ${TMPDIR}/release_version | awk '{print " "NR" "$1}' + echo -e " 0 返回上级菜单" + read -p "请输入对应数字 > " num + if [ -z "$num" -o "$num" = 0 ]; then + setserver + elif [ $num -le $(cat ${TMPDIR}/release_version 2>/dev/null | awk 'END{print NR}') ]; then + release_type=$(cat ${TMPDIR}/release_version | awk '{print $1}' | sed -n "$num"p) + update_url='' + saveserver + else + echo ----------------------------------------------- + errornum + sleep 1 + setserver + fi + else + echo ----------------------------------------------- + echo -e "\033[31m版本回退信息获取失败,请尝试更换其他安装源!\033[0m" + sleep 1 + setserver + fi + rm -rf ${TMPDIR}/release_version else - echo ----------------------------------------------- - echo -e "\033[31m输入有误,请重新输入!\033[0m" + echo -e "\033[31m当前源不支持版本回退,请尝试更换其他安装源!\033[0m" + sleep 1 + setserver fi - rm -rf ${TMPDIR}/release_new ;; *) errornum @@ -1524,29 +1587,16 @@ setserver(){ } #检查更新 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}/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}/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 + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/version_new bin/version echooff + [ "$?" = "0" ] && version_new=$(cat ${TMPDIR}/version_new | grep -oE 'versionsh=.*' | awk -F'=' '{ print $2 }') + if [ -n "$version_new" ];then source ${TMPDIR}/version_new 2>/dev/null else - echo -e "\033[31m检查更新失败!请切换其他安装源!\033[0m" - echo -e "\033[36m如全部安装源都无法使用,请先运行服务后再使用更新功能!\033[0m" - sleep 1 + echo -e "\033[31m检查更新失败!请尝试切换其他安装源!\033[0m" setserver + checkupdate fi rm -rf ${TMPDIR}/version_new -fi } update(){ echo ----------------------------------------------- @@ -1557,13 +1607,13 @@ update(){ 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 ] && { + [ "$(dir_avail ${CRASHDIR})" -le 5120 ] && [ "$CRASHDIR" = "$BINDIR" ] && { echo -e "\033[33m当前目录剩余空间较低,建议开启小闪存模式!\033[0m" sleep 1 } echo ----------------------------------------------- - echo -e " 1 更新\033[36m管理脚本 \033[33m$versionsh_l\033[0m > \033[32m$versionsh$release_type\033[0m" - echo -e " 2 切换\033[33m内核文件 \033[33m$core_v\033[0m > \033[32m$core_v_new\033[0m" + echo -e " 1 更新\033[36m管理脚本 \033[33m$versionsh_l\033[0m > \033[32m$version_new\033[0m" + echo -e " 2 切换\033[33m内核文件 \033[33m$core_v\033[0m > \033[32m$core_v_new\033[0m" echo -e " 3 更新\033[32m数据库文件\033[0m" echo -e " 4 安装本地\033[35mDashboard\033[0m面板" echo -e " 5 安装/更新本地\033[33m根证书文件\033[0m" @@ -1615,7 +1665,7 @@ update(){ update elif [ "$num" = 9 ]; then - $0 -u + uninstall exit elif [ "$num" = 99 ]; then @@ -1706,14 +1756,11 @@ userguide(){ echo -e "\033[0m每次开机后首次运行服务时都会自动的重新下载相关文件\033[0m" echo ----------------------------------------------- read -p "是否开启?(1/0) > " res - [ "$res" = 1 ] && setconfig BINDIR /tmp/ShellCrash ${CRASHDIR}/configs/command.env + [ "$res" = 1 ] && { + BINDIR=/tmp/ShellCrash + setconfig BINDIR /tmp/ShellCrash ${CRASHDIR}/configs/command.env + } fi - #下载本地面板 - # echo ----------------------------------------------- - # echo -e "\033[33m安装本地Dashboard面板,可以更快捷的管理clash内置规则!\033[0m" - # echo ----------------------------------------------- - # read -p "需要安装本地Dashboard面板吗?(1/0) > " res - # [ "$res" = 1 ] && checkupdate && setdb #检测及下载根证书 if [ -d /etc/ssl/certs -a ! -f '/etc/ssl/certs/ca-certificates.crt' ];then echo ----------------------------------------------- @@ -1723,14 +1770,13 @@ userguide(){ [ "$res" = 1 ] && checkupdate && getcrt fi #设置加密DNS - ${CRASHDIR}/start.sh webget ${TMPDIR}/ssl_test https://doh.pub echooff rediron + ${CRASHDIR}/start.sh webget /dev/null https://baidu.com 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 #开启公网访问 sethost(){ read -p "请输入你的公网IP地址 > " host @@ -1774,12 +1820,14 @@ userguide(){ [ "$res" = 1 ] && autoSSH fi #提示导入订阅或者配置文件 - echo ----------------------------------------------- - echo -e "\033[32m是否导入配置文件?\033[0m(这是运行前的最后一步)" - echo -e "\033[0m你必须拥有一份yaml格式的配置文件才能运行服务!\033[0m" - echo ----------------------------------------------- - read -p "现在开始导入?(1/0) > " res - [ "$res" = 1 ] && inuserguide=1 && set_core_config && inuserguide="" + [ ! -s $CRASHDIR/yamls/config.yaml -a ! -s $CRASHDIR/jsons/config.json ] && { + echo ----------------------------------------------- + echo -e "\033[32m是否导入配置文件?\033[0m(这是运行前的最后一步)" + echo -e "\033[0m你必须拥有一份yaml格式的配置文件才能运行服务!\033[0m" + echo ----------------------------------------------- + read -p "现在开始导入?(1/0) > " res + [ "$res" = 1 ] && inuserguide=1 && set_core_config && inuserguide="" + } #回到主界面 echo ----------------------------------------------- echo -e "\033[36m很好!现在只需要执行启动就可以愉快的使用了!\033[0m" @@ -1789,13 +1837,66 @@ userguide(){ main_menu } #测试菜单 +debug(){ + [ "$crashcore" = singbox ] && config_tmp=$TMPDIR/config.json || config_tmp=$TMPDIR/config.yaml + echo ----------------------------------------------- + echo -e "\033[36m注意:Debug运行均会停止原本的内核服务\033[0m" + echo -e "后台运行日志地址:\033[32m$TMPDIR/debug.log\033[0m" + echo -e "如长时间运行后台监测,日志等级推荐error!防止文件过大!" + echo -e "你也可以通过:\033[33mcrash -s debug 'warning'\033[0m 命令使用其他日志等级" + echo ----------------------------------------------- + echo -e " 1 仅测试\033[32m$config_tmp\033[0m配置文件可用性" + echo -e " 2 前台运行\033[32m$config_tmp\033[0m配置文件,不配置防火墙劫持(\033[33m使用Ctrl+C手动停止\033[0m)" + echo -e " 3 后台运行完整启动流程,并配置防火墙劫持,日志等级:\033[31merror\033[0m" + echo -e " 4 后台运行完整启动流程,并配置防火墙劫持,日志等级:\033[32minfo\033[0m" + echo -e " 5 后台运行完整启动流程,并配置防火墙劫持,日志等级:\033[33mdebug\033[0m" + echo ----------------------------------------------- + echo " 0 返回上级目录!" + read -p "请输入对应数字 > " num + case "$num" in + 0) ;; + 1) + $CRASHDIR/start.sh stop + if [ "$crashcore" = singbox ] ;then + $BINDIR/CrashCore run -D $BINDIR -c $TMPDIR/config.json & + { sleep 4 ; kill $! &>/dev/null & } + wait + else + $BINDIR/CrashCore -t -d $BINDIR -f $TMPDIR/config.yaml + fi + echo ----------------------------------------------- + exit + ;; + 2) + $CRASHDIR/start.sh stop + $COMMAND + echo ----------------------------------------------- + exit + ;; + 3) + $CRASHDIR/start.sh debug error + main_menu + ;; + 4) + $CRASHDIR/start.sh debug info + main_menu + ;; + 5) + $CRASHDIR/start.sh debug debug + main_menu + ;; + *) + errornum + ;; + esac +} 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 查看内核运行时的报错信息" + echo " 1 Debug模式运行内核" echo " 2 查看系统DNS端口(:53)占用 " echo " 3 测试ssl加密(aes-128-gcm)跑分" echo " 4 查看ShellCrash相关路由规则" @@ -1810,16 +1911,8 @@ testcommand(){ elif [ "$num" = 0 ]; then main_menu elif [ "$num" = 1 ]; then - echo ----------------------------------------------- - 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未找到因内核运行错误所产生的日志文件!\033[0m" - sleep 1 - fi + debug + testcommand elif [ "$num" = 2 ]; then echo ----------------------------------------------- netstat -ntulp |grep 53 diff --git a/scripts/init.sh b/scripts/init.sh index 8f6ab31..1c5e545 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,7 +1,7 @@ #!/bin/sh # Copyright (C) Juewuy -version=1.8.5d +version=1.8.7d setdir(){ dir_avail(){ @@ -127,8 +127,6 @@ setconfig(){ [ -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 #防止进程冲突 #特殊固件识别及标记 [ -f "/etc/storage/started_script.sh" ] && { systype=Padavan #老毛子固件 @@ -152,8 +150,6 @@ mv -f /tmp/SC_tmp/* ${CRASHDIR} 2>/dev/null #初始化 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 -a "$(cat /proc/1/comm)" = "procd" ];then #设为init.d方式启动 @@ -174,7 +170,7 @@ else fi fi #修饰文件及版本号 -type bash &>/dev/null && shtype=bash || shtype=sh +command -v bash &>/dev/null && shtype=bash || shtype=sh for file in start.sh task.sh ;do sed -i "s|/bin/sh|/bin/$shtype|" ${CRASHDIR}/${file} chmod 755 ${CRASHDIR}/${file} @@ -186,7 +182,7 @@ 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 +if [ -x ${CRASHDIR}/CrashCore ] && [ -n "$(grep 'crashcore=singbox' ${CRASHDIR}/configs/ShellCrash.cfg)" ];then COMMAND='"$BINDIR/CrashCore run -D $BINDIR -c $TMPDIR/config.json"' else COMMAND='"$BINDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"' @@ -202,6 +198,8 @@ setconfig COMMAND "$COMMAND" ${CRASHDIR}/configs/command.env if [ -n "$profile" ];then sed -i '/alias crash=*/'d $profile echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >> $profile #设置快捷命令环境变量 + sed -i '/alias clash=*/'d $profile + echo "alias clash=\"$shtype $CRASHDIR/menu.sh\"" >> $profile #设置快捷命令环境变量 sed -i '/export CRASHDIR=*/'d $profile echo "export CRASHDIR=\"$CRASHDIR\"" >> $profile #设置路径环境变量 source $profile &>/dev/null || echo 运行错误!请使用bash而不是dash运行安装命令!!! @@ -271,8 +269,9 @@ for file in cron task.sh task.list;do done chmod 755 ${CRASHDIR}/task/task.sh #旧版文件清理 - rm -rf /etc/init.d/clash +rm -rf $CRASHDIR/clashservice +rm -rf $CRASHDIR/shellcrash.rc rm -rf $CRASHDIR/clash.sh for file in log shellcrash.service mark? mark.bak;do rm -rf ${CRASHDIR}/$file @@ -282,9 +281,5 @@ sed -i "s/clashcore/crashcore/g" $configpath sed -i "s/clash_v/core_v/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 echo -e "\033[32m脚本初始化完成,请输入\033[30;47m crash \033[0;33m命令开始使用!\033[0m" diff --git a/scripts/menu.sh b/scripts/menu.sh index 3458b91..46619bb 100644 --- a/scripts/menu.sh +++ b/scripts/menu.sh @@ -18,7 +18,9 @@ setconfig(){ ckcmd(){ command -v sh &>/dev/null && command -v $1 &>/dev/null || type $1 &>/dev/null } -ckstatus(){ + +#脚本启动前检查 +ckstatus(){ #检查/读取脚本配置文件 if [ -f $CFG_PATH ];then [ -n "$(awk 'a[$0]++' $CFG_PATH)" ] && awk '!a[$0]++' $CFG_PATH > $CFG_PATH #检查重复行并去除 @@ -29,8 +31,6 @@ ckstatus(){ versionsh=$(cat ${CRASHDIR}/init.sh | grep -E ^version= | head -n 1 | sed 's/version=//') [ -n "$versionsh" ] && versionsh_l=$versionsh #服务器缺省地址 - [ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellCrash - #设置默认端口及变量 [ -z "$mix_port" ] && mix_port=7890 [ -z "$redir_port" ] && redir_port=7892 [ -z "$db_port" ] && db_port=9999 @@ -84,6 +84,7 @@ ckstatus(){ checkport fi [ "$crashcore" = singbox ] && corename=Sing-Box || corename=Clash + [ -f ${TMPDIR}/debug.log -a -n "$PID" ] && auto="\033[33m并处于debug状态!\033[0m" #输出状态 echo ----------------------------------------------- echo -e "\033[30;46m欢迎使用ShellCrash!\033[0m 版本:$versionsh_l" @@ -101,15 +102,15 @@ ckstatus(){ #检查执行权限 [ ! -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.*|^sing.*box|^clash.meta.*'` ; do + for file in `ls -F /tmp | grep -v [/\$] | grep -v '\ ' | grep -Ev ".*[(gz)(zip)(7z)(tar)]$" | grep -iE '^clash$|^clash-linux.*|^mihomo.*|^sing.*box|^clash.meta.*'` ; do file=/tmp/$file chmod +x $file echo -e "发现可用的内核文件: \033[36m$file\033[0m " read -p "是否加载(会停止当前服务)?(1/0) > " res [ "$res" = 1 ] && { ${CRASHDIR}/start.sh stop - core_v=$($file -v &>/dev/null) - [ -z "$core_v" ] && $($file version &>/dev/null) + core_v=$($file -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //') + [ -z "$core_v" ] && core_v=$($file version 2>/dev/null | grep -Eo 'version .*' | sed 's/version //') if [ -n "$core_v" ];then source ${CRASHDIR}/getdate.sh && setcoretype && \ mv -f $file ${CRASHDIR}/CrashCore && \ @@ -152,7 +153,6 @@ ckstatus(){ } } -#启动相关 errornum(){ echo ----------------------------------------------- echo -e "\033[31m请输入正确的字母或数字!\033[0m" @@ -394,7 +394,7 @@ log_pusher(){ #日志菜单 *) errornum ;; esac } -setport(){ +setport(){ #端口设置 source $CFG_PATH > /dev/null [ -z "$secret" ] && secret=未设置 [ -z "$authentication" ] && auth=未设置 || auth=****** @@ -514,7 +514,7 @@ setport(){ setport fi } -setdns(){ +setdns(){ #DNS设置 [ -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' [ -z "$hosts_opt" ] && hosts_opt=已开启 @@ -627,7 +627,7 @@ setdns(){ setdns fi } -setipv6(){ +setipv6(){ #ipv6设置 [ -z "$ipv6_support" ] && ipv6_support=已开启 [ -z "$ipv6_redir" ] && ipv6_redir=未开启 @@ -687,7 +687,7 @@ setipv6(){ ;; esac } -setfirewall(){ +setfirewall(){ #防火墙设置 set_cust_host_ipv4(){ echo ----------------------------------------------- echo -e "当前已自动设置透明路由的网段为: \033[32m$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'br' | grep -v 'iot' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/br.*$//g' | sed 's/metric.*$//g' | tr '\n' ' ' && echo ) \033[0m" @@ -763,7 +763,7 @@ setfirewall(){ ;; esac } -checkport(){ +checkport(){ #自动检查端口冲突 for portx in $dns_port $mix_port $redir_port $db_port ;do if [ -n "$(netstat -ntul 2>&1 |grep '\:$portx ')" ];then echo ----------------------------------------------- @@ -777,7 +777,7 @@ checkport(){ fi done } -macfilter(){ +macfilter(){ #局域网设备过滤 add_mac(){ echo ----------------------------------------------- echo 已添加的mac地址: @@ -908,7 +908,7 @@ macfilter(){ macfilter fi } -localproxy(){ +localproxy(){ #本机代理 [ -w /etc/systemd/system/shellcrash.service -o -w /usr/lib/systemd/system/shellcrash.service -o -x /bin/su ] && local_enh=1 [ -f /etc/rc.common -a -w /etc/passwd ] && local_enh=1 echo ----------------------------------------------- @@ -949,7 +949,7 @@ localproxy(){ setconfig local_proxy $local_proxy setconfig local_type $local_type } -setboot(){ +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允许" @@ -1096,7 +1096,7 @@ metacfg(){ echo ----------------------------------------------- } -normal_set(){ +normal_set(){ #基础设置 set_redir_mod(){ set_redir_config(){ setconfig redir_mod $redir_mod @@ -1110,7 +1110,7 @@ normal_set(){ echo -e "\033[36m已设为 $redir_mod !!\033[0m" } [ -n "$(iptables -j TPROXY 2>&1 | grep 'on-port')" ] && sup_tp=1 - [ -n "$(lsmod | grep '^tun')" ] || ip tuntap &>/dev/null && sup_tun=1 + [ -n "$(ls /dev/net/tun)" ] || ip tuntap &>/dev/null && sup_tun=1 ckcmd nft && sup_nft=1 echo ----------------------------------------------- echo -e "当前代理模式为:\033[47;30m $redir_mod \033[0m;Clash核心为:\033[47;30m $crashcore \033[0m" @@ -1423,7 +1423,7 @@ normal_set(){ errornum fi } -advanced_set(){ +advanced_set(){ #进阶设置 #获取设置默认显示 [ -z "$proxies_bypass" ] && proxies_bypass=未启用 [ -z "$start_old" ] && start_old=未开启 @@ -1556,6 +1556,56 @@ autoSSH(){ setconfig mi_autoSSH_pwd $mi_autoSSH_pwd sleep 1 } +uninstall(){ + read -p "确认卸载ShellCrash?(警告:该操作不可逆!)[1/0] > " res + if [ "$res" = '1' ]; then + ${CRASHDIR}/start.sh stop 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 + read -p "是否保留脚本配置及订阅文件?[1/0] > " res + if [ "$res" = '1' ]; then + mv -f ${CRASHDIR}/configs /tmp/ShellCrash + mv -f ${CRASHDIR}/yamls /tmp/ShellCrash + mv -f ${CRASHDIR}/jsons /tmp/ShellCrash + rm -rf ${CRASHDIR}/* + mv -f /tmp/ShellCrash/configs ${CRASHDIR} + mv -f /tmp/ShellCrash/yamls ${CRASHDIR} + mv -f /tmp/ShellCrash/jsons ${CRASHDIR} + else + rm -rf ${CRASHDIR} + fi + [ -w ~/.bashrc ] && profile=~/.bashrc + [ -w /etc/profile ] && profile=/etc/profile + sed -i '/alias clash=*/'d $profile + sed -i '/alias crash=*/'d $profile + sed -i '/export CRASHDIR=*/'d $profile + sed -i '/export crashdir=*/'d $profile + sed -i '/all_proxy/'d $profile + sed -i '/ALL_PROXY/'d $profile + sed -i "/启用外网访问SSH服务/d" /etc/firewall.user 2>/dev/null + sed -i '/ShellCrash初始化/'d /etc/storage/started_script.sh 2>/dev/null + sed -i '/ShellCrash初始化/'d /jffs/.asusrouter 2>/dev/null + [ "$BINDIR" != "$CRASHDIR" ] && 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/ShellCrash + sed -Ei s/0:7890/7890:7890/g /etc/passwd + userdel -r shellcrash 2>/dev/null + nvram set script_usbmount="" 2>/dev/null + nvram commit 2>/dev/null + uci delete firewall.ShellCrash 2>/dev/null + uci commit firewall 2>/dev/null + echo ----------------------------------------------- + echo -e "\033[36m已卸载ShellCrash相关文件!有缘再会!\033[0m" + echo -e "\033[33m请手动关闭当前窗口以重置环境变量!\033[0m" + echo ----------------------------------------------- + exit + fi + echo -e "\033[31m操作已取消!\033[0m" +} tools(){ ssh_tools(){ stop_iptables(){ @@ -1668,7 +1718,7 @@ tools(){ echo ----------------------------------------------- if [ ! -f ${CRASHDIR}/tools/ShellDDNS.sh ];then echo -e "正在获取在线脚本……" - ${CRASHDIR}/start.sh webget ${TMPDIR}/ShellDDNS.sh $update_url/tools/ShellDDNS.sh + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/ShellDDNS.sh tools/ShellDDNS.sh if [ "$?" = "0" ];then mv -f ${TMPDIR}/ShellDDNS.sh ${CRASHDIR}/tools/ShellDDNS.sh source ${CRASHDIR}/tools/ShellDDNS.sh @@ -1691,7 +1741,6 @@ tools(){ sed -i "/^\s*#.*otapredownload/ s/^\s*#//" /etc/crontabs/root || \ echo "15 3,4,5 * * * /usr/sbin/otapredownload >/dev/null 2>&1" >> /etc/crontabs/root fi - echo ----------------------------------------------- echo -e "已\033[33m$mi_update\033[0m小米路由器的自动更新,如未生效,请在官方APP中同步设置!" sleep 1 @@ -1717,10 +1766,9 @@ tools(){ sleep 1 read -p "我已知晓,出现问题会自行承担!(1/0) > " res if [ "$res" = 1 ];then - tunfixlink="${update_url}/bin/fix/tun.ko" echo ----------------------------------------------- echo 正在连接服务器获取Tun模块补丁文件………… - ${CRASHDIR}/start.sh webget ${TMPDIR}/tun.ko $tunfixlink + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/tun.ko bin/fix/tun.ko if [ "$?" = "0" ];then mv -f ${TMPDIR}/tun.ko ${CRASHDIR}/tools/tun.ko && \ ${CRASHDIR}/misnap_init.sh tunfix && \ @@ -1844,7 +1892,7 @@ case "$1" in echo " -i 初始化脚本" echo ----------------------------------------- echo " crash -s start 启动服务" - echo " crash -s stop 停止服务" + echo " crash -s stop 停止服务" echo " 安装目录/start.sh init 开机初始化" echo ----------------------------------------- echo "在线求助:t.me/ShellClash" @@ -1867,53 +1915,7 @@ case "$1" in $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 - read -p "是否保留脚本配置及订阅文件?[1/0] > " res - if [ "$res" = '1' ]; then - 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} - fi - [ -w ~/.bashrc ] && profile=~/.bashrc - [ -w /etc/profile ] && profile=/etc/profile - sed -i '/alias clash=*/'d $profile - sed -i '/alias crash=*/'d $profile - sed -i '/export CRASHDIR=*/'d $profile - sed -i '/export crashdir=*/'d $profile - sed -i '/all_proxy/'d $profile - sed -i '/ALL_PROXY/'d $profile - 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/shellcrash - rm -rf /etc/systemd/system/shellcrash.service - rm -rf /usr/lib/systemd/system/shellcrash.service - rm -rf /www/clash - 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 - nvram commit 2>/dev/null - uci delete firewall.ShellClash 2>/dev/null - uci delete firewall.ShellCrash 2>/dev/null - uci commit firewall 2>/dev/null - echo ----------------------------------------------- - echo -e "\033[36m已卸载ShellCrash相关文件!有缘再会!\033[0m" - echo -e "\033[33m请手动关闭当前窗口以重置环境变量!\033[0m" - echo ----------------------------------------------- - exit - fi - echo -e "\033[31m操作已取消!\033[0m" + uninstall ;; *) $0 -h diff --git a/scripts/misnap_init.sh b/scripts/misnap_init.sh index f215f34..359334b 100644 --- a/scripts/misnap_init.sh +++ b/scripts/misnap_init.sh @@ -51,8 +51,10 @@ init(){ done #初始化环境变量 sed -i "/alias crash/d" $profile + sed -i "/alias clash/d" $profile sed -i "/export CRASHDIR/d" $profile echo "alias crash=\"sh $CRASHDIR/menu.sh\"" >>$profile + echo "alias clash=\"sh $CRASHDIR/menu.sh\"" >>$profile echo "export CRASHDIR=\"$CRASHDIR\"" >>$profile #软固化功能 autoSSH diff --git a/scripts/start.sh b/scripts/start.sh index b3746f6..b2b7c55 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -138,6 +138,20 @@ put_save(){ #推送面板选择 wget -q --method=PUT --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" --body-data="$2" "$1" >/dev/null fi } +get_bin(){ #专用于项目内部文件的下载 + source ${CRASHDIR}/configs/ShellCrash.cfg >/dev/null + [ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master + if [ -n "$url_id" ];then + if [ "$url_id" = 101 ];then + url="$(grep "$url_id" ${CRASHDIR}/configs/servers.list | awk '{print $3}')@$release_type/$2" #jsdelivr特殊处理 + else + url="$(grep "$url_id" ${CRASHDIR}/configs/servers.list | awk '{print $3}')/$release_type/$2" + fi + else + url="$update_url/$2" + fi + $0 webget "$1" "$url" "$3" "$4" "$5" "$6" +} mark_time(){ #时间戳 echo `date +%s` > ${TMPDIR}/crash_start_time } @@ -199,16 +213,6 @@ check_clash_config(){ #检查clash配置文件 done < ${TMPDIR}/clash_proxies_$USER rm -rf ${TMPDIR}/clash_proxies_$USER } - #使用核心内置test功能检测 - if [ -x ${BINDIR}/CrashCore ];then - ${BINDIR}/CrashCore -t -d ${BINDIR} -f $core_config_new >/dev/null - if [ "$?" != "0" ];then - logger "配置文件加载失败!请查看报错信息!" 31 - ${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(){ #检查singbox配置文件 #使用核心内置format功能检测并格式化 @@ -542,7 +546,7 @@ EOF [ -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" = "fake-ip" ] && proxy_dns=dns_fakeip && direct_dns=dns_direct [ "$dns_mod" = "mix" ] && proxy_dns=dns_fakeip && direct_dns=dns_direct cat > ${TMPDIR}/dns.json < ${TMPDIR}/ntp.json < ${TMPDIR}/format.json + mv -f ${TMPDIR}/format.json $core_config + } 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规则 + #清理route.json中的process_name规则以及"auto_detect_interface" sed -i '/"process_name": \[/,/],$/d' ${TMPDIR}/route.json sed -i '/"process_name": "[^"]*",/d' ${TMPDIR}/route.json + sed -i 's/"auto_detect_interface": true/"auto_detect_interface": false/g' ${TMPDIR}/route.json + #修饰route.json结尾 + sed -i '/^ }$/s/ }/ },/' ${TMPDIR}/route.json + sed -i '/^}$/d' ${TMPDIR}/route.json #跳过本地tls证书验证 if [ -z "$skip_cert" -o "$skip_cert" = "已开启" ];then sed -i 's/"insecure": false/"insecure": true/' ${TMPDIR}/outbounds.json @@ -688,6 +697,7 @@ EOF [ -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" + json_add='' done cut -c 1- $json_all > ${TMPDIR}/config.json #测试自定义配置文件 @@ -718,7 +728,7 @@ cn_ip_route(){ #CN-IP绕过 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" + get_bin ${BINDIR}/cn_ip.txt "bin/geodata/china_ip_list.txt" [ "$?" = "1" ] && rm -rf ${BINDIR}/cn_ip.txt && logger "列表下载失败!" 31 fi } @@ -737,7 +747,7 @@ cn_ipv6_route(){ #CN-IPV6绕过 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" + get_bin ${BINDIR}/cn_ipv6.txt "bin/geodata/china_ipv6_list.txt" [ "$?" = "1" ] && rm -rf ${BINDIR}/cn_ipv6.txt && logger "列表下载失败!" 31 fi } @@ -1285,11 +1295,14 @@ stop_firewall(){ #还原防火墙配置 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}/shellcrash_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 '"Selector"' | grep -aoE '"name":.*"now":".*",' > ${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}/shellcrash_web_save_$USER + def=$(echo $line | grep -oE '"all".*",' | awk -F "[:\"]" '{print $5}' ) + now=$(echo $line | grep -oE '"now".*",' | awk -F "[:\"]" '{print $5}' ) + [ "$def" != "$now" ] && { + name=$(echo $line | grep -oE '"name".*",' | awk -F "[:\"]" '{print $5}' ) + echo "${name},${now}" >> ${TMPDIR}/shellcrash_web_save_$USER + } done < ${TMPDIR}/shellcrash_web_check_$USER rm -rf ${TMPDIR}/shellcrash_web_check_$USER #对比文件,如果有变动且不为空则写入磁盘,否则清除缓存 @@ -1382,14 +1395,17 @@ core_check(){ 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" + get_bin ${BINDIR}/core.new "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}') + COMMAND='"$BINDIR/CrashCore run -D $BINDIR -c $TMPDIR/config.json"' else core_v=$(${TMPDIR}/core.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //') + COMMAND='"$BINDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"' fi + setconfig COMMAND "$COMMAND" ${CRASHDIR}/configs/command.env if [ -z "$core_v" ];then rm -rf ${TMPDIR}/core.new logger "核心下载失败,请重新运行或更换安装源!" 31 @@ -1430,7 +1446,7 @@ clash_check(){ #clash启动前检查 mv ${CRASHDIR}/Country.mmdb ${BINDIR}/Country.mmdb else logger "未找到GeoIP数据库,正在下载!" 33 - $0 webget ${BINDIR}/Country.mmdb $update_url/bin/geodata/cn_mini.mmdb + get_bin ${BINDIR}/Country.mmdb 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 @@ -1442,7 +1458,7 @@ clash_check(){ #clash启动前检查 mv -f ${CRASHDIR}/GeoSite.dat ${BINDIR}/GeoSite.dat else logger "未找到GeoSite数据库,正在下载!" 33 - $0 webget ${BINDIR}/GeoSite.dat $update_url/bin/geodata/geosite.dat + get_bin ${BINDIR}/GeoSite.dat bin/geodata/geosite.dat [ "$?" = "1" ] && rm -rf ${BINDIR}/GeoSite.dat && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1 fi fi @@ -1455,7 +1471,7 @@ singbox_check(){ #singbox启动前检查 mv ${CRASHDIR}/geoip.db ${BINDIR}/geoip.db else logger "未找到GeoIP数据库,正在下载!" 33 - $0 webget ${BINDIR}/geoip.db $update_url/bin/geodata/geoip_cn.db + get_bin ${BINDIR}/geoip.db 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 @@ -1467,7 +1483,7 @@ singbox_check(){ #singbox启动前检查 mv -f ${CRASHDIR}/geosite.db ${BINDIR}/geosite.db else logger "未找到GeoSite数据库,正在下载!" 33 - $0 webget ${BINDIR}/geosite.db $update_url/bin/geodata/geosite_cn.db + get_bin ${BINDIR}/geosite.db 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 @@ -1498,7 +1514,7 @@ bfstart(){ #启动前 [ ! -s ${BINDIR}/ui/index.html ] && makehtml #如没有面板则创建跳转界面 catpac #生成pac文件 #内核及内核配置文件检查 - [ ! -x ${BINDIR}/CrashCore ] && chmod +x ${BINDIR}/CrashCore #检测可执行权限 + [ ! -x ${BINDIR}/CrashCore ] && chmod +x ${BINDIR}/CrashCore 2>/dev/null #检测可执行权限 if [ "$crashcore" = singbox ];then singbox_check [ "$disoverride" != "1" ] && modify_json || ln -sf $core_config ${TMPDIR}/config.json @@ -1532,6 +1548,8 @@ bfstart(){ #启动前 fi fi fi + #清理debug日志 + rm -rf ${TMPDIR}/debug.log #执行条件任务 [ -s ${CRASHDIR}/task/bfstart ] && source ${CRASHDIR}/task/bfstart return 0 @@ -1616,7 +1634,7 @@ start_old(){ #保守模式 #使用传统后台执行二进制文件的方式执行 if [ "$local_proxy" = "已开启" -a -n "$(echo $local_type | grep '增强模式')" ];then if ckcmd su;then - su shellcrash -c "$COMMAND" >/dev/null & + su shellcrash -c "$COMMAND &>/dev/null" & else logger "当前设备缺少su命令,保守模式下无法兼容本机代理增强模式,已停止启动!" 31 exit 1 @@ -1701,6 +1719,22 @@ restart) $0 stop $0 start ;; +debug) + [ -n "$(pidof CrashCore)" ] && $0 stop >/dev/null #禁止多实例 + getconfig + stop_firewall >/dev/null #清理路由策略 + bfstart + [ -n "$2" ] && { + if [ "$crashcore" = singbox ];then + sed -i "s/\"level\": \"info\"/\"level\": \"$2\"/" ${TMPDIR}/config.json + else + sed -i "s/log-level: info/log-level: $2/" ${TMPDIR}/config.yaml + fi + } + $COMMAND &>${TMPDIR}/debug.log & + afstart + logger "已运行debug模式!如需停止,请正常重启一次服务!" 33 + ;; init) profile=/etc/profile if [ -d "/etc/storage/clash" -o -d "/etc/storage/ShellCrash" ];then @@ -1719,8 +1753,10 @@ init) fi fi sed -i "/alias crash/d" $profile + sed -i "/alias clash/d" $profile sed -i "/export CRASHDIR/d" $profile echo "alias crash=\"$CRASHDIR/menu.sh\"" >> $profile + echo "alias clash=\"$CRASHDIR/menu.sh\"" >> $profile echo "export CRASHDIR=\"$CRASHDIR\"" >> $profile [ -f ${CRASHDIR}/.dis_startup ] && cronset "保守模式守护进程" || $0 start ;; @@ -1741,7 +1777,7 @@ 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" 2>/dev/null) + 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 5 $progress $redirect $certificate -o "$2" "$3") else if wget --version > /dev/null 2>&1;then @@ -1752,7 +1788,7 @@ webget) fi [ "$4" = "echoon" ] && progress='' [ "$4" = "echooff" ] && progress='-q' - wget -Y on $agent $progress $redirect $certificate $timeout -O "$2" "$url" 2>/dev/null + wget -Y on $agent $progress $redirect $certificate $timeout -O "$2" "$url" if [ "$?" != "0" ];then wget -Y off $agent $progress $redirect $certificate $timeout -O "$2" "$3" [ "$?" = "0" ] && result="200" diff --git a/scripts/task.sh b/scripts/task.sh index 06e2227..af741db 100644 --- a/scripts/task.sh +++ b/scripts/task.sh @@ -19,7 +19,7 @@ ckcmd(){ #检查命令是否存在 #任务命令 check_update(){ #检查更新工具 - ${CRASHDIR}/start.sh webget ${TMPDIR}/crashversion "$update_url/bin/version" echooff + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/crashversion "bin/version" echooff [ "$?" = "0" ] && source ${TMPDIR}/crashversion 2>/dev/null rm -rf ${TMPDIR}/crashversion } @@ -33,7 +33,7 @@ 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 get_bin ${TMPDIR}/core.new "bin/${crashcore}/${core_new}-linux-${cpucore}" if [ "$?" != "0" ];then logger "任务【自动更新内核】出错-下载失败!" rm -rf ${TMPDIR}/core.new @@ -68,7 +68,7 @@ update_shellcrash(){ #自动更新脚本 logger "任务【自动更新脚本】中止-未检测到版本更新" exit 1 else - ${CRASHDIR}/start.sh webget ${TMPDIR}/update.tar.gz "$update_url/bin/update.tar.gz" + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/update.tar.gz "bin/update.tar.gz" if [ "$?" != "0" ];then rm -rf ${TMPDIR}/update.tar.gz logger "任务【自动更新内核】出错-下载失败!" @@ -98,7 +98,7 @@ update_mmdb(){ #自动更新数据库 logger "任务【自动更新数据库文件】跳过-未检测到$2版本更新" else #更新文件 - ${CRASHDIR}/start.sh webget ${TMPDIR}/$1 "$update_url/bin/geodata/$2" + ${CRASHDIR}/start.sh get_bin ${TMPDIR}/$1 "bin/geodata/$2" if [ "$?" != "0" ];then logger "任务【自动更新数据库文件】更新【$2】下载失败!" rm -rf ${TMPDIR}/$1 @@ -124,7 +124,7 @@ reset_firewall(){ #重设透明路由防火墙 ${CRASHDIR}/start.sh afstart } ntp(){ - ckcmd ntpd && ntpd -n -q -p 203.107.6.88 &>/dev/null || exit 0 & + [ "$crashcore" != singbox ] && ckcmd ntpd && ntpd -n -q -p 203.107.6.88 &>/dev/null || exit 0 & } #任务工具