~增加debug模式菜单(8-1-1)
~优化tun模式识别机制
~继续修复覆盖安装或升级时卡死的bug
~修复卸载脚本时的若干报错
This commit is contained in:
juewuy
2024-01-14 12:53:23 +08:00
parent 0e402881a1
commit 82a8c1cf6a
8 changed files with 144 additions and 84 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -4,4 +4,4 @@ clash_v=v1.7.1
meta_v=v1.18.0
singbox_v=1.8.0
GeoIP_v=20240107
versionsh=1.8.6c
versionsh=1.8.7

View File

@@ -787,7 +787,7 @@ gettar(){
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
@@ -1665,7 +1665,7 @@ update(){
update
elif [ "$num" = 9 ]; then
crash -u
uninstall
exit
elif [ "$num" = 99 ]; then
@@ -1758,12 +1758,6 @@ userguide(){
read -p "是否开启?(1/0) > " res
[ "$res" = 1 ] && 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 -----------------------------------------------
@@ -1823,12 +1817,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"
@@ -1838,13 +1834,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相关路由规则"
@@ -1859,17 +1908,8 @@ testcommand(){
elif [ "$num" = 0 ]; then
main_menu
elif [ "$num" = 1 ]; then
echo -----------------------------------------------
$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;
debug
testcommand
elif [ "$num" = 2 ]; then
echo -----------------------------------------------
netstat -ntulp |grep 53

View File

@@ -1,7 +1,7 @@
#!/bin/sh
# Copyright (C) Juewuy
version=1.8.6c
version=1.8.7
setdir(){
dir_avail(){
@@ -150,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方式启动
@@ -172,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}
@@ -184,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"'
@@ -271,7 +269,6 @@ 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

View File

@@ -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"
@@ -1109,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[0mClash核心为\033[47;30m $crashcore \033[0m"
@@ -1555,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(){
@@ -1833,7 +1884,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"
@@ -1856,53 +1907,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

View File

@@ -1555,6 +1555,8 @@ bfstart(){ #启动前
fi
fi
fi
#清理debug日志
rm -rf ${TMPDIR}/debug.log
#执行条件任务
[ -s ${CRASHDIR}/task/bfstart ] && source ${CRASHDIR}/task/bfstart
return 0
@@ -1724,6 +1726,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
@@ -1764,7 +1782,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
@@ -1775,7 +1793,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"