v1.8.4(未测试)
~全面适配singbox内核 ~保守模式启动优化 ~修复推荐任务每10分钟保存节点配置未生效的bug
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
[Unit]
|
||||
Description=clash
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
ExecStartPre=/etc/clash/start.sh bfstart
|
||||
ExecStart=/etc/clash/clash -d /etc/clash >/dev/null
|
||||
ExecStartPost=/etc/clash/start.sh afstart
|
||||
Restart=on-failure
|
||||
RestartSec=3s
|
||||
LimitNOFILE=999999
|
||||
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,45 +0,0 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
|
||||
SERVICE_DAEMONIZE=1
|
||||
SERVICE_WRITE_PID=1
|
||||
USE_PROCD=1
|
||||
#获取目录
|
||||
DIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}')
|
||||
[ -z "$DIR" ] && DIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}')
|
||||
BINDIR=$(cat $DIR/configs/ShellCrash.cfg | grep bindir | awk -F "=" '{print $2}')
|
||||
[ -z "$BINDIR" ] && BINDIR=$DIR
|
||||
|
||||
start_service() {
|
||||
#检测必须文件
|
||||
$DIR/start.sh bfstart
|
||||
if [ "$?" = "0" ];then
|
||||
#使用procd创建clash后台进程
|
||||
procd_open_instance
|
||||
procd_set_param respawn
|
||||
procd_set_param stderr 0
|
||||
procd_set_param stdout 0
|
||||
procd_set_param command $BINDIR/clash -d $BINDIR
|
||||
procd_close_instance
|
||||
#其他设置
|
||||
$DIR/start.sh afstart
|
||||
fi
|
||||
}
|
||||
|
||||
start() {
|
||||
if [ -z "$(pidof procd)" ];then
|
||||
#检测必须文件
|
||||
$DIR/start.sh bfstart
|
||||
if [ "$?" = "0" ];then
|
||||
#创建后台进程
|
||||
service_start $BINDIR/clash -d $BINDIR
|
||||
#其他设置
|
||||
$DIR/start.sh afstart
|
||||
#设置守护进程
|
||||
$DIR/start.sh daemon
|
||||
fi
|
||||
else
|
||||
start_service
|
||||
fi
|
||||
}
|
||||
@@ -548,7 +548,7 @@ override(){
|
||||
case "$num" in
|
||||
1)
|
||||
source $CFG_PATH
|
||||
if [ -n "$(pidof clash)" ];then
|
||||
if [ -n "$(pidof CrashCore)" ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[33m检测到服务正在运行,需要先停止服务!\033[0m"
|
||||
read -p "是否停止服务?(1/0) > " res
|
||||
@@ -807,11 +807,61 @@ setcpucore(){
|
||||
setconfig cpucore $cpucore
|
||||
fi
|
||||
}
|
||||
setcoretype(){
|
||||
[ "$crashcore" = singbox ] && core_old=singbox || core_old=clash
|
||||
echo -e "\033[33m请确认该自定义内核的类型:\033[0m"
|
||||
echo -e " 1 Clash基础内核"
|
||||
echo -e " 2 Clash-Premium内核"
|
||||
echo -e " 3 Clash-Meta内核"
|
||||
echo -e " 4 Sing-Box内核"
|
||||
read -p "请输入对应数字 > " num
|
||||
case "$num" in
|
||||
2) crashcore=clashpre ;;
|
||||
3) crashcore=meta ;;
|
||||
4) crashcore=singbox ;;
|
||||
*) crashcore=clash ;;
|
||||
esac
|
||||
[ "$crashcore" = singbox ] && core_new=singbox || core_new=clash
|
||||
}
|
||||
switch_core(){
|
||||
#singbox和clash内核切换时提示是否保留文件
|
||||
[ "$core_new" != "$core_old" ] && {
|
||||
echo -e "\033[33m已从$core_old内核切换至$core_new内核\033[0m"
|
||||
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
|
||||
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
|
||||
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
|
||||
}
|
||||
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"
|
||||
else
|
||||
COMMAND="$bindir/CrashCore -d $bindir -f $TMPDIR/config.yaml >/dev/null"
|
||||
COMMAND_T="$bindir/CrashCore -t -d $bindir -f $TMPDIR/config.yaml"
|
||||
fi
|
||||
setconfig COMMAND $COMMAND $CRASHDIR/configs/service.env
|
||||
setconfig COMMAND_T $COMMAND_T $CRASHDIR/configs/service.env
|
||||
}
|
||||
getcore(){
|
||||
[ -z "$crashcore" ] && crashcore=clashpre
|
||||
[ -z "$cpucore" ] && getcpucore
|
||||
[ "$crashcore" = singbox ] && core_new=singbox || core_new=clash
|
||||
#生成链接
|
||||
[ -z "$custcorelink" ] && corelink="$update_url/bin/$crashcore/clash-linux-$cpucore" || corelink="$custcorelink"
|
||||
[ -z "$custcorelink" ] && corelink="${update_url}/bin/${crashcore}/${core_new}-linux-${cpucore}" || corelink="$custcorelink"
|
||||
#获取在线内核文件
|
||||
echo -----------------------------------------------
|
||||
echo 正在在线获取$crashcore核心文件……
|
||||
@@ -820,9 +870,10 @@ getcore(){
|
||||
echo -e "\033[31m核心文件下载失败!\033[0m"
|
||||
rm -rf $TMPDIR/core.new
|
||||
[ -z "$custcorelink" ] && error_down
|
||||
else=
|
||||
else
|
||||
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}')
|
||||
else
|
||||
@@ -837,6 +888,8 @@ getcore(){
|
||||
mv -f $TMPDIR/core.new $bindir/CrashCore
|
||||
chmod +x $bindir/CrashCore
|
||||
setconfig crashcore $crashcore
|
||||
setconfig core_v $core_v
|
||||
switch_core
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -876,7 +929,7 @@ setcustcore(){
|
||||
4)
|
||||
read -p "请输入自定义内核的链接地址(必须是二进制文件) > " link
|
||||
[ -n "$link" ] && custcorelink="$link"
|
||||
crashcore=meta
|
||||
crashcore=unknow
|
||||
getcore
|
||||
;;
|
||||
*)
|
||||
@@ -887,11 +940,13 @@ setcustcore(){
|
||||
}
|
||||
setcore(){
|
||||
#获取核心及版本信息
|
||||
[ -z "$crashcore" ] && crashcore="unknow"
|
||||
[ ! -f $CRASHDIR/CrashCore ] && crashcore="未安装核心"
|
||||
[ "$crashcore" = singbox ] && core_old=singbox || core_old=clash
|
||||
###
|
||||
echo -----------------------------------------------
|
||||
[ -z "$cpucore" ] && getcpucore
|
||||
echo -e "当前clash核心:\033[42;30m $crashcore \033[47;30m$clashv\033[0m"
|
||||
echo -e "当前内核:\033[42;30m $crashcore \033[47;30m$core_v\033[0m"
|
||||
echo -e "当前系统处理器架构:\033[32m $cpucore \033[0m"
|
||||
echo -e "\033[33m请选择需要使用的核心版本!\033[0m"
|
||||
echo -----------------------------------------------
|
||||
@@ -943,9 +998,11 @@ setcore(){
|
||||
}
|
||||
|
||||
getgeo(){
|
||||
#生成链接
|
||||
[ -z "$custcorelink" ] && geolink="$update_url/bin/geodata/$geotype" || geolink="$custcorelink"
|
||||
echo -----------------------------------------------
|
||||
echo 正在从服务器获取数据库文件…………
|
||||
$CRASHDIR/start.sh webget $TMPDIR/$geoname $update_url/bin/geodata/$geotype
|
||||
$CRASHDIR/start.sh webget $TMPDIR/$geoname $geolink
|
||||
if [ "$?" = "1" ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m文件下载失败!\033[0m"
|
||||
@@ -964,19 +1021,110 @@ getgeo(){
|
||||
fi
|
||||
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
|
||||
echo -----------------------------------------------
|
||||
cat $TMPDIR/github_api | awk '{print " "NR" "$3,$2,$4}'
|
||||
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
|
||||
else
|
||||
errornum
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
errornum
|
||||
;;
|
||||
esac
|
||||
rm -rf $TMPDIR/github_api
|
||||
else
|
||||
echo -e "\033[31m查找失败,请检查网络连接!\033[0m"
|
||||
sleep 1
|
||||
fi
|
||||
}
|
||||
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 -----------------------------------------------
|
||||
echo -e "9 \033[33m 自定义数据库链接 \033[0m"
|
||||
echo -e "0 返回上级菜单"
|
||||
read -p "请输入对应数字 > " num
|
||||
case "$num" in
|
||||
0)
|
||||
;;
|
||||
1)
|
||||
project=MetaCubeX/meta-rules-dat
|
||||
checkcustgeo
|
||||
;;
|
||||
2)
|
||||
project=DustinWin/clash-geosite
|
||||
checkcustgeo
|
||||
;;
|
||||
3)
|
||||
project=lyc8503/sing-box-rules
|
||||
checkcustgeo
|
||||
;;
|
||||
4)
|
||||
project=Loyalsoldier/geoip
|
||||
checkcustgeo
|
||||
;;
|
||||
9)
|
||||
read -p "请输入自定义数据库的链接地址 > " link
|
||||
[ -n "$link" ] && custgeolink="$link"
|
||||
getgeo
|
||||
;;
|
||||
*)
|
||||
errornum
|
||||
;;
|
||||
esac
|
||||
}
|
||||
}
|
||||
setgeo(){
|
||||
source $CFG_PATH > /dev/null
|
||||
[ -n "$cn_mini.mmdb_v" ] && geo_type_des=精简版 || geo_type_des=全球版
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[36m请选择需要更新的GeoIP/CN_IP数据库:\033[0m"
|
||||
echo -e "\033[36m请选择需要更新的Geo/CN数据库文件:\033[0m"
|
||||
echo -e "\033[36m全球版GeoIP和精简版CN-IP数据库不共存\033[0m"
|
||||
echo -e "\033[36mClash内核和SingBox内核的数据库文件不通用\033[0m"
|
||||
echo -e "在线数据库最新版本:\033[32m$GeoIP_v\033[0m"
|
||||
echo -----------------------------------------------
|
||||
echo -e " 1 全球版GeoIP数据库(约6mb) \033[33m$Country_v\033[0m"
|
||||
echo -e " 2 精简版CN-IP数据库(约0.2mb) \033[33m$cn_mini_v\033[0m"
|
||||
echo -e " 3 CN-IP绕过文件(约0.2mb) \033[33m$china_ip_list_v\033[0m"
|
||||
echo -e " 4 CN-IPV6绕过文件(约50kb) \033[33m$china_ipv6_list_v\033[0m"
|
||||
echo -e " 5 GeoSite数据库(约4.5mb) \033[33m$geosite_v\033[0m"
|
||||
echo -e " 1 CN-IP绕过文件(约0.1mb) \033[33m$china_ip_list_v\033[0m"
|
||||
echo -e " 2 CN-IPV6绕过文件(约30kb) \033[33m$china_ipv6_list_v\033[0m"
|
||||
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 " 9 \033[32m自定义数据库\033[0m: \033[33m仅限专业用户使用\033[0m"
|
||||
echo " 0 返回上级菜单"
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入对应数字 > " num
|
||||
@@ -984,18 +1132,6 @@ setgeo(){
|
||||
0)
|
||||
;;
|
||||
1)
|
||||
geotype=Country.mmdb
|
||||
geoname=Country.mmdb
|
||||
getgeo
|
||||
setgeo
|
||||
;;
|
||||
2)
|
||||
geotype=cn_mini.mmdb
|
||||
geoname=Country.mmdb
|
||||
getgeo
|
||||
setgeo
|
||||
;;
|
||||
3)
|
||||
if [ "$cn_ip_route" = "已开启" ]; then
|
||||
geotype=china_ip_list.txt
|
||||
geoname=cn_ip.txt
|
||||
@@ -1007,7 +1143,7 @@ setgeo(){
|
||||
fi
|
||||
setgeo
|
||||
;;
|
||||
4)
|
||||
2)
|
||||
if [ "$cn_ipv6_route" = "已开启" -a "$ipv6_redir" = "已开启" ]; then
|
||||
geotype=china_ipv6_list.txt
|
||||
geoname=cn_ipv6.txt
|
||||
@@ -1019,6 +1155,30 @@ setgeo(){
|
||||
fi
|
||||
setgeo
|
||||
;;
|
||||
3)
|
||||
if [ "$crashcore" != "singbox" ]; then
|
||||
geotype=Country.mmdb
|
||||
geoname=Country.mmdb
|
||||
getgeo
|
||||
else
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m当前未使用clash内核,无需使用此数据库!!\033[0m"
|
||||
sleep 1
|
||||
fi
|
||||
setgeo
|
||||
;;
|
||||
4)
|
||||
if [ "$crashcore" != "singbox" ]; then
|
||||
geotype=cn_mini.mmdb
|
||||
geoname=Country.mmdb
|
||||
getgeo
|
||||
else
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m当前未使用clash内核,无需使用此数据库!!\033[0m"
|
||||
sleep 1
|
||||
fi
|
||||
setgeo
|
||||
;;
|
||||
5)
|
||||
if [ "$crashcore" = "meta" ]; then
|
||||
geotype=geosite.dat
|
||||
@@ -1026,11 +1186,38 @@ setgeo(){
|
||||
getgeo
|
||||
else
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m当前未使用meta内核,无需更新GeoSite数据库!!\033[0m"
|
||||
echo -e "\033[31m当前未使用meta内核,无需使用此数据库!!\033[0m"
|
||||
sleep 1
|
||||
fi
|
||||
setgeo
|
||||
;;
|
||||
6)
|
||||
if [ "$crashcore" = "singbox" ]; then
|
||||
geotype=geoip_cn.db
|
||||
geoname=geoip.db
|
||||
getgeo
|
||||
else
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m当前未使用singbox内核,无需使用此数据库!!\033[0m"
|
||||
sleep 1
|
||||
fi
|
||||
setgeo
|
||||
;;
|
||||
7)
|
||||
if [ "$crashcore" = "singbox" ]; then
|
||||
geotype=geosite_cn.db
|
||||
geoname=geosite.db
|
||||
getgeo
|
||||
else
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m当前未使用singbox内核,无需使用此数据库!!\033[0m"
|
||||
sleep 1
|
||||
fi
|
||||
setgeo
|
||||
;;
|
||||
9)
|
||||
setcustgeo
|
||||
;;
|
||||
*)
|
||||
errornum
|
||||
;;
|
||||
@@ -1313,8 +1500,7 @@ update(){
|
||||
echo -----------------------------------------------
|
||||
echo -ne "\033[32m正在检查更新!\033[0m\r"
|
||||
checkupdate
|
||||
core_v=$($bindir/clash -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //')
|
||||
[ -z "$core_v" ] && core_v=$clashv
|
||||
[ -z "$core_v" ] && core_v=unknow
|
||||
core_v_new=$(eval echo \$${crashcore}_v)
|
||||
echo -e "\033[30;47m欢迎使用更新功能:\033[0m"
|
||||
echo -----------------------------------------------
|
||||
@@ -1431,7 +1617,7 @@ userguide(){
|
||||
}
|
||||
#设置开机启动
|
||||
[ -f /etc/rc.common ] && /etc/init.d/clash enable
|
||||
ckcmd systemctl && systemctl enable clash.service > /dev/null 2>&1
|
||||
ckcmd systemctl && systemctl enable shellcrash.service > /dev/null 2>&1
|
||||
rm -rf $CRASHDIR/.dis_startup
|
||||
autostart=enable
|
||||
#检测IP转发
|
||||
@@ -1598,7 +1784,7 @@ testcommand(){
|
||||
elif [ "$num" = 4 ]; then
|
||||
|
||||
if [ -n "$(echo $redir_mod | grep 'Nft')" -o "$local_type" = "nftables增强模式" ];then
|
||||
nft list table inet shellclash
|
||||
nft list table inet shellcrash
|
||||
else
|
||||
echo -------------------Redir---------------------
|
||||
iptables -t nat -L PREROUTING --line-numbers
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) Juewuy
|
||||
|
||||
version=1.8.3d
|
||||
version=1.8.3e
|
||||
|
||||
setdir(){
|
||||
dir_avail(){
|
||||
@@ -157,17 +157,17 @@ mkdir -p $CRASHDIR/configs
|
||||
#本地安装跳过新手引导
|
||||
#[ -z "$url" ] && setconfig userguide 1
|
||||
#判断系统类型写入不同的启动文件
|
||||
if [ -f /etc/rc.common ];then
|
||||
if [ -f /etc/rc.common ] && [ -n "$(pidof procd)" ];then
|
||||
#设为init.d方式启动
|
||||
cp -f $CRASHDIR/clashservice /etc/init.d/clash
|
||||
chmod 755 /etc/init.d/clash
|
||||
cp -f $CRASHDIR/crash.rc /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
|
||||
#设为systemd方式启动
|
||||
mv -f $CRASHDIR/clash.service $sysdir/clash.service 2>/dev/null
|
||||
sed -i "s%/etc/clash%$CRASHDIR%g" $sysdir/clash.service
|
||||
mv -f $CRASHDIR/shellcrash.service $sysdir/shellcrash.service 2>/dev/null
|
||||
sed -i "s%/etc/ShellCrash%$CRASHDIR%g" $sysdir/shellcrash.service
|
||||
systemctl daemon-reload
|
||||
else
|
||||
#设为保守模式启动
|
||||
@@ -188,13 +188,13 @@ setconfig versionsh_l $version
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
if [ -n "$profile" ];then
|
||||
sed -i '/alias crash=*/'d $profile
|
||||
echo "alias crash=\"$shtype $CRASHDIR/clash.sh\"" >> $profile #设置快捷命令环境变量
|
||||
echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >> $profile #设置快捷命令环境变量
|
||||
sed -i '/export CRASHDIR=*/'d $profile
|
||||
echo "export CRASHDIR=\"$CRASHDIR\"" >> $profile #设置clash路径环境变量
|
||||
echo "export CRASHDIR=\"$CRASHDIR\"" >> $profile #设置路径环境变量
|
||||
source $profile &>/dev/null || echo 运行错误!请使用bash而不是dash运行安装命令!!!
|
||||
#适配zsh环境变量
|
||||
[ -n "$(ls -l /bin/sh|grep -oE 'zsh')" ] && [ -z "$(cat ~/.zshrc 2>/dev/null|grep CRASHDIR)" ] && {
|
||||
echo "alias crash=\"$shtype $CRASHDIR/clash.sh\"" >> ~/.zshrc
|
||||
echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >> ~/.zshrc
|
||||
echo "export CRASHDIR=\"$CRASHDIR\"" >> ~/.zshrc
|
||||
source ~/.zshrc &>/dev/null
|
||||
}
|
||||
@@ -231,7 +231,7 @@ fi
|
||||
nvram commit
|
||||
}
|
||||
#删除临时文件
|
||||
rm -rf /tmp/*lash*gz
|
||||
rm -rf /tmp/*rash*gz
|
||||
rm -rf /tmp/SC_tmp
|
||||
#转换&清理旧版本文件
|
||||
mkdir -p $CRASHDIR/yamls
|
||||
@@ -256,10 +256,14 @@ for file in cron task.sh task.list;do
|
||||
mv -f $CRASHDIR/$file $CRASHDIR/task/$file 2>/dev/null
|
||||
done
|
||||
chmod 755 $CRASHDIR/task/task.sh
|
||||
for file in log clash.service mark? mark.bak;do
|
||||
#旧版文件清理
|
||||
rm -rf $sysdir/shellcrash.service
|
||||
for file in log shellcrash.service mark? mark.bak;do
|
||||
rm -rf $CRASHDIR/$file
|
||||
done
|
||||
|
||||
#旧版变量改名
|
||||
sed -i "s/clashcore/crashcore/g" $configpath
|
||||
sed -i "s/ShellClash/ShellCrash/g" $configpath
|
||||
#旧版任务清理
|
||||
$CRASHDIR/start.sh cronset "clash服务" 2>/dev/null
|
||||
$CRASHDIR/start.sh cronset "订阅链接" 2>/dev/null
|
||||
|
||||
@@ -55,7 +55,7 @@ ckstatus(){
|
||||
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 clash.service 2>&1 | grep enable)" ] && autostart=enable || autostart=disable
|
||||
[ -n "$(systemctl is-enabled shellcrash.service 2>&1 | grep enable)" ] && autostart=enable || autostart=disable
|
||||
else
|
||||
[ -f $CRASHDIR/.dis_startup ] && autostart=disable || autostart=enable
|
||||
fi
|
||||
@@ -68,7 +68,7 @@ ckstatus(){
|
||||
auto1="\033[36m允许\033[0mShellCrash开机启动"
|
||||
fi
|
||||
#获取运行状态
|
||||
PID=$(pidof clash | awk '{print $NF}')
|
||||
PID=$(pidof CrashCore | awk '{print $NF}')
|
||||
if [ -n "$PID" ];then
|
||||
run="\033[32m正在运行($redir_mod)\033[0m"
|
||||
VmRSS=`cat /proc/$PID/status|grep -w VmRSS|awk '{print $2,$3}'`
|
||||
@@ -111,17 +111,12 @@ ckstatus(){
|
||||
echo -e "发现可用的内核文件: \033[36m$file\033[0m "
|
||||
read -p "是否加载?(1/0) > " res
|
||||
[ "$res" = 1 ] && {
|
||||
echo -e " 1 Clash内核"
|
||||
echo -e " 2 Clashpre内核"
|
||||
echo -e " 3 Clash.Meta内核"
|
||||
read -p "请手动确定该内核类型 > " num
|
||||
case "$num" in
|
||||
2) crashcore=clashpre ;;
|
||||
3) crashcore=meta ;;
|
||||
*) crashcore=clash ;;
|
||||
esac
|
||||
mv -f $file $bindir/clash && echo -e "\033[32m内核加载完成!\033[0m " && sleep 1
|
||||
setconfig crashcore $crashcore
|
||||
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"
|
||||
@@ -180,7 +175,7 @@ clashstart(){
|
||||
if [ -s $CRASHDIR/yamls/config.yaml -o -n "$Url" -o -n "$Https" ];then
|
||||
$CRASHDIR/start.sh start
|
||||
sleep 1
|
||||
[ -n "$(pidof clash)" ] && startover
|
||||
[ -n "$(pidof CrashCore)" ] && startover
|
||||
else
|
||||
echo -e "\033[31m没有找到配置文件,请先导入配置文件!\033[0m"
|
||||
source $CRASHDIR/getdate.sh && clashlink
|
||||
@@ -903,7 +898,7 @@ macfilter(){
|
||||
fi
|
||||
}
|
||||
localproxy(){
|
||||
[ -w /etc/systemd/system/clash.service -o -w /usr/lib/systemd/system/clash.service -o -x /bin/su ] && local_enh=1
|
||||
[ -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 -----------------------------------------------
|
||||
[ -n "$local_enh" ] && {
|
||||
@@ -964,13 +959,13 @@ setboot(){
|
||||
1)
|
||||
if [ "$autostart" = "enable" ]; then
|
||||
[ -d /etc/rc.d ] && cd /etc/rc.d && rm -rf *clash > /dev/null 2>&1 && cd - >/dev/null
|
||||
ckcmd systemctl && systemctl disable clash.service > /dev/null 2>&1
|
||||
ckcmd systemctl && systemctl disable shellcrash.service > /dev/null 2>&1
|
||||
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
|
||||
ckcmd systemctl && systemctl enable clash.service > /dev/null 2>&1
|
||||
ckcmd systemctl && systemctl enable shellcrash.service > /dev/null 2>&1
|
||||
rm -rf $CRASHDIR/.dis_startup
|
||||
autostart=enable
|
||||
echo -e "\033[32m已设置Clash开机启动!\033[0m"
|
||||
@@ -984,7 +979,7 @@ setboot(){
|
||||
setconfig start_old $start_old
|
||||
$CRASHDIR/start.sh stop
|
||||
else
|
||||
if [ -f /etc/init.d/clash -o -w /etc/systemd/system -o -w /usr/lib/systemd/system ];then
|
||||
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初始化"
|
||||
start_old=未开启
|
||||
@@ -1338,7 +1333,7 @@ clashcfg(){
|
||||
setconfig common_ports $common_ports
|
||||
}
|
||||
echo -----------------------------------------------
|
||||
if [ -n "$(pidof clash)" ];then
|
||||
if [ -n "$(pidof CrashCore)" ];then
|
||||
read -p "切换时将停止服务,是否继续?(1/0) > " res
|
||||
[ "$res" = 1 ] && $CRASHDIR/start.sh stop && set_common_ports
|
||||
else
|
||||
@@ -1362,7 +1357,7 @@ clashcfg(){
|
||||
local_proxy=未开启
|
||||
setconfig local_proxy $local_proxy
|
||||
setconfig local_type
|
||||
sed -i '/user shellclash/d' /etc/init.d/clash 2>/dev/null
|
||||
sed -i '/user shellcrash/d' /etc/init.d/clash 2>/dev/null
|
||||
echo -e "\033[33m已经停用本机代理规则,请尽快重启服务!!\033[0m"
|
||||
fi
|
||||
sleep 1
|
||||
@@ -1834,7 +1829,7 @@ case "$1" in
|
||||
;;
|
||||
-t)
|
||||
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
|
||||
$shtype -x $CRASHDIR/clash.sh
|
||||
$shtype -x $CRASHDIR/menu.sh
|
||||
;;
|
||||
-s)
|
||||
$CRASHDIR/start.sh $2 $3 $4 $5 $6
|
||||
@@ -1876,12 +1871,12 @@ case "$1" in
|
||||
sed -i '/ShellCrash初始化/'d /jffs/.asusrouter 2>/dev/null
|
||||
rm -rf $bindir
|
||||
rm -rf /etc/init.d/clash
|
||||
rm -rf /etc/systemd/system/clash.service
|
||||
rm -rf /usr/lib/systemd/system/clash.service
|
||||
rm -rf /etc/systemd/system/shellcrash.service
|
||||
rm -rf /usr/lib/systemd/system/shellcrash.service
|
||||
rm -rf /www/clash
|
||||
rm -rf /tmp/clash_$USER
|
||||
sed -Ei s/0:7890/7890:7890/g /etc/passwd
|
||||
userdel -r shellclash 2>/dev/null
|
||||
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
|
||||
@@ -52,13 +52,13 @@ init(){
|
||||
#初始化环境变量
|
||||
sed -i "/alias crash/d" $profile
|
||||
sed -i "/export CRASHDIR/d" $profile
|
||||
echo "alias crash=\"$CRASHDIR/clash.sh\"" >>$profile
|
||||
echo "alias crash=\"$CRASHDIR/menu.sh\"" >>$profile
|
||||
echo "export CRASHDIR=\"$CRASHDIR\"" >>$profile
|
||||
#软固化功能
|
||||
autoSSH
|
||||
#设置init.d服务
|
||||
cp -f $CRASHDIR/clashservice /etc/init.d/clash
|
||||
chmod 755 /etc/init.d/clash
|
||||
cp -f $CRASHDIR/shellcrash.rc /etc/init.d/shellcrash
|
||||
chmod 755 /etc/init.d/shellcrash
|
||||
#启动服务
|
||||
if [ ! -f $CRASHDIR/.dis_startup ]; then
|
||||
#AX6S/AX6000修复tun功能
|
||||
@@ -66,8 +66,8 @@ init(){
|
||||
#小米7000/小米万兆修复tproxy
|
||||
[ -f /etc/init.d/qca-nss-ecm ] && [ -n "$(grep 'redir_mod=Tproxy' $CRASHDIR/configs/ShellCrash.cfg )" ] && tproxyfix
|
||||
#启动服务
|
||||
/etc/init.d/clash start
|
||||
/etc/init.d/clash enable
|
||||
/etc/init.d/shellcrash start
|
||||
/etc/init.d/shellcrash enable
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ case "$1" in
|
||||
tproxyfix) tproxyfix ;;
|
||||
init) init ;;
|
||||
*)
|
||||
if [ -z $(pidof clash) ];then
|
||||
if [ -z $(pidof CrashCore) ];then
|
||||
init &
|
||||
fi
|
||||
;;
|
||||
|
||||
30
scripts/shellcrash.rc
Normal file
30
scripts/shellcrash.rc
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
|
||||
SERVICE_DAEMONIZE=1
|
||||
SERVICE_WRITE_PID=1
|
||||
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
|
||||
|
||||
start_service() {
|
||||
#检测必须文件
|
||||
$CRASHDIR/start.sh bfstart
|
||||
if [ "$?" = "0" ];then
|
||||
#使用procd创建clash后台进程
|
||||
procd_open_instance
|
||||
procd_set_param respawn
|
||||
procd_set_param stderr 0
|
||||
procd_set_param stdout 0
|
||||
procd_set_param command $COMMAND
|
||||
procd_close_instance
|
||||
#其他设置
|
||||
$CRASHDIR/start.sh afstart
|
||||
fi
|
||||
}
|
||||
|
||||
20
scripts/shellcrash.service
Normal file
20
scripts/shellcrash.service
Normal file
@@ -0,0 +1,20 @@
|
||||
[Unit]
|
||||
Description=ShellCrash Core
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
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
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
LimitNOFILE=infinity
|
||||
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
800
scripts/start.sh
800
scripts/start.sh
File diff suppressed because it is too large
Load Diff
@@ -18,44 +18,49 @@ setconfig(){
|
||||
|
||||
#任务命令
|
||||
check_update(){ #检查更新工具
|
||||
$CRASHDIR/start.sh webget $TMPDIR/clashversion "$update_url/bin/version" echooff
|
||||
[ "$?" = "0" ] && source $TMPDIR/clashversion 2>/dev/null
|
||||
rm -rf $TMPDIR/clashversion
|
||||
$CRASHDIR/start.sh webget $TMPDIR/crashversion "$update_url/bin/version" echooff
|
||||
[ "$?" = "0" ] && source $TMPDIR/crashversion 2>/dev/null
|
||||
rm -rf $TMPDIR/crashversion
|
||||
}
|
||||
update_core(){ #自动更新内核
|
||||
#检查版本
|
||||
check_update
|
||||
clash_v_new=$(eval echo \$${crashcore}_v)
|
||||
clash_v_now=$($bindir/clash -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //')
|
||||
if [ -z "$clash_v_new" -o "$clash_v_new" = "clash_v_now" ];then
|
||||
crash_v_new=$(eval echo \$${crashcore}_v)
|
||||
if [ -z "$crash_v_new" -o "$crash_v_new" = "core_v" ];then
|
||||
logger "任务【自动更新内核】中止-未检测到版本更新"
|
||||
exit 1
|
||||
else
|
||||
#更新内核
|
||||
$CRASHDIR/start.sh webget $TMPDIR/clash.new "$update_url/bin/$crashcore/clash-linux-$cpucore"
|
||||
[ "$crashcore" = singbox ] && core_new=singbox || core_new=clash
|
||||
$CRASHDIR/start.sh webget $TMPDIR/core.new "${update_url}/bin/${crashcore}/${core_new}-linux-${cpucore}"
|
||||
if [ "$?" != "0" ];then
|
||||
logger "任务【自动更新内核】出错-下载失败!"
|
||||
rm -rf $TMPDIR/clash.new
|
||||
rm -rf $TMPDIR/core.new
|
||||
return 1
|
||||
else
|
||||
chmod +x $TMPDIR/clash.new
|
||||
chmod +x $TMPDIR/core.new
|
||||
$CRASHDIR/start.sh stop
|
||||
clashv=$($TMPDIR/clash.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //')
|
||||
if [ -z "$clashv" ];then
|
||||
logger "任务【自动更新内核】出错-下载失败!"
|
||||
rm -rf $TMPDIR/clash.new
|
||||
[ $crashcore = meta ] && $CRASHDIR/start.sh start
|
||||
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
|
||||
logger "任务【自动更新内核】出错-内核校验失败!"
|
||||
rm -rf $TMPDIR/core.new
|
||||
$CRASHDIR/start.sh start
|
||||
return 1
|
||||
else
|
||||
mv -f $TMPDIR/clash.new $bindir/clash
|
||||
mv -f $TMPDIR/core.new $bindir/CrashCore
|
||||
logger "任务【自动更新内核】下载完成,正在重启服务!"
|
||||
setconfig core_v $core_v
|
||||
$CRASHDIR/start.sh start
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
update_shellclash(){ #自动更新脚本
|
||||
update_shellcrash(){ #自动更新脚本
|
||||
#检查版本
|
||||
check_update
|
||||
if [ -z "$versionsh" -o "$versionsh" = "versionsh_l" ];then
|
||||
@@ -110,6 +115,8 @@ update_mmdb(){ #自动更新数据库
|
||||
[ -n "${china_ip_list_v}" ] && getgeo cn_ip.txt china_ip_list.txt
|
||||
[ -n "${china_ipv6_list_v}" ] && getgeo cn_ipv6.txt china_ipv6_list.txt
|
||||
[ -n "${geosite_v}" ] && getgeo GeoSite.dat geosite.dat
|
||||
[ -n "${geoip_cn_v}" ] && getgeo geoip.db geoip_cn.db
|
||||
[ -n "${geosite_cn_v}" ] && getgeo geosite.db geosite_cn.db
|
||||
}
|
||||
reset_firewall(){ #重设透明路由防火墙
|
||||
$CRASHDIR/start.sh stop_firewall
|
||||
@@ -170,7 +177,7 @@ set_service(){
|
||||
if [ "$1" = "running" ];then
|
||||
task_txt="$4 $CRASHDIR/task/task.sh $2 $3"
|
||||
echo "$task_txt" >> $task_file
|
||||
[ -n "$(pidof clash)" ] && cronset "$3" "$task_txt"
|
||||
[ -n "$(pidof CrashCore)" ] && cronset "$3" "$task_txt"
|
||||
else
|
||||
echo "$CRASHDIR/task/task.sh $2 $3" >> $task_file
|
||||
fi
|
||||
@@ -294,7 +301,7 @@ task_type(){ #任务条件选择菜单
|
||||
echo -e " 输入 6-18 代表\033[36m早6点至晚18点间每小时\033[0m运行"
|
||||
read -p "想在每日的具体哪个小时执行?(0-23) > " hour
|
||||
echo -----------------------------------------------
|
||||
read -p "想在具体哪分钟执行?(1-59的整数) > " min
|
||||
read -p "想在具体哪分钟执行?(0-59的整数) > " min
|
||||
cron_time="在每日的$hour点$min分"
|
||||
set_cron
|
||||
;;
|
||||
@@ -434,7 +441,7 @@ task_recom(){ #任务推荐
|
||||
echo -----------------------------------------------
|
||||
read -p "是否启用?(1/0) > " res
|
||||
[ "$res" = 1 ] && {
|
||||
set_service running "106" "运行时每10分钟自动保存面板配置" "*/10"
|
||||
set_service running "106" "运行时每10分钟自动保存面板配置" "*/10 * * * *"
|
||||
set_service afstart "107" "服务启动后自动同步ntp时间"
|
||||
cronset "在每周3的3点整更新订阅并重启服务" "0 3 * * 3 $CRASHDIR/task/task.sh 104 在每周3的3点整更新订阅并重启服务" && \
|
||||
echo -e "任务【在每周3的3点整更新订阅并重启服务】\033[32m添加成功!\033[0m"
|
||||
|
||||
Reference in New Issue
Block a user