———————————
d:
~改名!ShellClash成为过去时!
~执行命令改为crash(覆盖安装则兼容clash命令)
~优化数据库下载逻辑,独立显示版本号
~定时任务增加更多功能
~增加推荐任务(任务菜单及新手引导)
~每10分钟保存面板配置及自动同步ntp时间功能移至推荐任务
~增加自动下载数据库功能
~自动更新相关任务支持版本校验
~增加更细化的任务执行日志
~修复meta内核因内存不足导致无法更新的bug
~修复部分定时任务会每分钟执行一次的bug
b:
~修复定时任务相关bug
a:
~同步最新版本Meta1.17.0内核
~重写定时任务功能
  ·增加更多任务
  ·增加自动任务执行条件
  ·增加更多定时时间条件
  ·增加任务日志及日志推送
  ·优化管理脚本
  ·优化自定义命令功能
~iptables增加对tcp53端口的dns劫持
~部分提示及描述优化
~修复nft模式本机代理语句报错的bug
~修复服务启动前会执行两次启动检查的bug
~修复自定义规则无法删除旧规则的bug
~修复节点绕过功能未添加no-resolve参数的bug
This commit is contained in:
juewuy 2024-01-02 17:09:11 +08:00
parent 1381172d9f
commit 74bfde8eb1
27 changed files with 984 additions and 593 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

View File

View File

View File

Binary file not shown.

View File

@ -2,5 +2,5 @@ clashnet_v=v1.7.6
clashpre_v=2022.11.25 clashpre_v=2022.11.25
clash_v=v1.7.1 clash_v=v1.7.1
meta_v=v1.17.0 meta_v=v1.17.0
versionsh=1.8.1
GeoIP_v=20231230 GeoIP_v=20231230
versionsh=1.8.2d

16
public/task.list Normal file
View File

@ -0,0 +1,16 @@
#任务ID#任务命令#任务说明(#号隔开,任务命令和说明中都不允许包含#号)
101#$clashdir/start.sh start#启动clash服务
102#$clashdir/start.sh stop#停止clash服务
103#$clashdir/start.sh restart#重启clash服务
104#$clashdir/start.sh getyaml && $clashdir/start.sh restart#更新订阅并重启服务
105#$clashdir/start.sh updateyaml#热更新订阅
106#$clashdir/start.sh web_save#自动保存面板配置
107#$clashdir/start.sh ntp#自动同步ntp时间
111#$clashdir/task/task.sh update_core#自动更新内核
112#$clashdir/task/task.sh update_shellclash#自动更新脚本
113#$clashdir/task/task.sh update_mmdb#自动更新数据库文件
121#$clashdir/task/task.sh reset_firewall#重设透明路由防火墙

View File

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh
# Copyright (C) Juewuy # Copyright (C) Juewuy
CFG_PATH=$clashdir/configs/ShellClash.cfg CFG_PATH=$CRASHDIR/configs/ShellCrash.cfg
YAMLSDIR=$clashdir/yamls YAMLSDIR=$CRASHDIR/yamls
TMPDIR=/tmp/ShellClash && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR TMPDIR=/tmp/ShellCrash && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR
#读取配置相关 #读取配置相关
setconfig(){ setconfig(){
#参数1代表变量名参数2代表变量值,参数3即文件路径 #参数1代表变量名参数2代表变量值,参数3即文件路径
@ -16,7 +16,7 @@ ckcmd(){
ckstatus(){ ckstatus(){
#服务器缺省地址 #服务器缺省地址
[ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellClash [ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellCrash
#检查/读取脚本配置文件 #检查/读取脚本配置文件
if [ -f $CFG_PATH ];then if [ -f $CFG_PATH ];then
#检查重复行并去除 #检查重复行并去除
@ -26,13 +26,13 @@ ckstatus(){
#使用source加载配置文件 #使用source加载配置文件
source $CFG_PATH > /dev/null source $CFG_PATH > /dev/null
else else
mkdir -p $clashdir/configs mkdir -p $CRASHDIR/configs
echo '#标识clash运行状态的文件不明勿动' > $CFG_PATH echo '#标识clash运行状态的文件不明勿动' > $CFG_PATH
fi fi
versionsh=$(cat $clashdir/init.sh | grep -E ^version= | head -n 1 | sed 's/version=//') versionsh=$(cat $CRASHDIR/init.sh | grep -E ^version= | head -n 1 | sed 's/version=//')
[ -n "$versionsh" ] && versionsh_l=$versionsh [ -n "$versionsh" ] && versionsh_l=$versionsh
#设置默认核心资源目录 #设置默认核心资源目录
[ -z "$bindir" ] && bindir=$clashdir [ -z "$bindir" ] && bindir=$CRASHDIR
#设置默认端口及变量 #设置默认端口及变量
[ -z "$mix_port" ] && mix_port=7890 [ -z "$mix_port" ] && mix_port=7890
[ -z "$redir_port" ] && redir_port=7892 [ -z "$redir_port" ] && redir_port=7892
@ -42,14 +42,14 @@ ckstatus(){
[ -z "$local_proxy" ] && local_proxy=未开启 [ -z "$local_proxy" ] && local_proxy=未开启
[ -z "$redir_mod" ] && redir_mod=纯净模式 [ -z "$redir_mod" ] && redir_mod=纯净模式
#检查mac地址记录 #检查mac地址记录
[ ! -f $clashdir/configs/mac ] && touch $clashdir/configs/mac [ ! -f $CRASHDIR/configs/mac ] && touch $CRASHDIR/configs/mac
#获取本机host地址 #获取本机host地址
[ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) [ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
[ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'lan' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'lan' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
[ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
[ -z "$host" ] && host='设备IP地址' [ -z "$host" ] && host='设备IP地址'
#dashboard目录位置 #dashboard目录位置
[ -f $clashdir/ui/index.html ] && dbdir=$clashdir/ui && hostdir=":$db_port/ui" [ -f $CRASHDIR/ui/index.html ] && dbdir=$CRASHDIR/ui && hostdir=":$db_port/ui"
[ -f /www/clash/index.html ] && dbdir=/www/clash && hostdir=/clash [ -f /www/clash/index.html ] && dbdir=/www/clash && hostdir=/clash
#开机自启检测 #开机自启检测
if [ -f /etc/rc.common ];then if [ -f /etc/rc.common ];then
@ -57,7 +57,7 @@ ckstatus(){
elif [ -w /etc/systemd/system -o -w /usr/lib/systemd/system ];then 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 clash.service 2>&1 | grep enable)" ] && autostart=enable || autostart=disable
else else
[ -f $clashdir/.dis_startup ] && autostart=disable || autostart=enable [ -f $CRASHDIR/.dis_startup ] && autostart=disable || autostart=enable
fi fi
#开机自启描述 #开机自启描述
if [ "$autostart" = "enable" ]; then if [ "$autostart" = "enable" ]; then
@ -88,7 +88,7 @@ ckstatus(){
fi fi
#输出状态 #输出状态
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[30;46m欢迎使用ShellClash\033[0m 版本:$versionsh_l" echo -e "\033[30;46m欢迎使用ShellCrash\033[0m 版本:$versionsh_l"
echo -e "Clash服务"$run""$auto"" echo -e "Clash服务"$run""$auto""
if [ -n "$PID" ];then if [ -n "$PID" ];then
echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m已运行\033[46;30m"$day"\033[44;37m"$time"\033[0m" echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m已运行\033[46;30m"$day"\033[44;37m"$time"\033[0m"
@ -98,12 +98,12 @@ ckstatus(){
#检查新手引导 #检查新手引导
if [ -z "$userguide" ];then if [ -z "$userguide" ];then
setconfig userguide 1 setconfig userguide 1
source $clashdir/getdate.sh && userguide source $CRASHDIR/getdate.sh && userguide
fi fi
#检查执行权限 #检查执行权限
[ ! -x $clashdir/start.sh ] && chmod +x $clashdir/start.sh [ ! -x $CRASHDIR/start.sh ] && chmod +x $CRASHDIR/start.sh
#检查/tmp内核文件 #检查/tmp内核文件
for file in `ls -F /tmp | grep -v [/\$] | grep -v '\ ' | grep -Ev ".*[(gz)(zip)(7z)(tar)(xz)]$" | grep -iE '^clash$|^clash-linux*|^clash.meta*'` ; do for file in `ls -F /tmp | grep -v [/\$] | grep -v '\ ' | grep -Ev ".*[(gz)(zip)(7z)(tar)(xz)]$" | grep -iE '^clash$|^clash-linux*|^mihomo*|^clash.meta*'` ; do
file=/tmp/$file file=/tmp/$file
chmod +x $file chmod +x $file
tmp_version=$($file -v 2>/dev/null) tmp_version=$($file -v 2>/dev/null)
@ -117,7 +117,7 @@ ckstatus(){
read -p "请手动确定该内核类型 > " num read -p "请手动确定该内核类型 > " num
case "$num" in case "$num" in
2) clashcore=clashpre ;; 2) clashcore=clashpre ;;
3) clashcore=clash.meta ;; 3) clashcore=meta ;;
*) clashcore=clash ;; *) clashcore=clash ;;
esac esac
mv -f $file $bindir/clash && echo -e "\033[32m内核加载完成\033[0m " && sleep 1 mv -f $file $bindir/clash && echo -e "\033[32m内核加载完成\033[0m " && sleep 1
@ -139,7 +139,7 @@ ckstatus(){
echo -e "发现可用的YAML配置文件 \033[36m$file\033[0m " echo -e "发现可用的YAML配置文件 \033[36m$file\033[0m "
read -p "加载为yaml配置文件/或者移除该文件?(1/0) > " res read -p "加载为yaml配置文件/或者移除该文件?(1/0) > " res
[ "$res" = 1 ] && { [ "$res" = 1 ] && {
mv -f $file $clashdir/yamls/config.yaml mv -f $file $CRASHDIR/yamls/config.yaml
echo -e "\033[32m配置文件加载完成\033[0m " echo -e "\033[32m配置文件加载完成\033[0m "
sleep 1 sleep 1
} }
@ -163,10 +163,10 @@ ckstatus(){
#启动相关 #启动相关
errornum(){ errornum(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字!\033[0m" echo -e "\033[31m请输入正确的字母或数字!\033[0m"
} }
startover(){ startover(){
echo -e "\033[32mclash服务已启动!\033[0m" echo -e "\033[32m服务已启动!\033[0m"
if [ -n "$hostdir" ];then if [ -n "$hostdir" ];then
echo -e "请使用 \033[4;32mhttp://$host$hostdir\033[0m 管理内置规则" echo -e "请使用 \033[4;32mhttp://$host$hostdir\033[0m 管理内置规则"
else else
@ -183,20 +183,20 @@ startover(){
clashstart(){ clashstart(){
#检查yaml配置文件 #检查yaml配置文件
echo ----------------------------------------------- echo -----------------------------------------------
if [ -s $clashdir/yamls/config.yaml -o -n "$Url" -o -n "$Https" ];then if [ -s $CRASHDIR/yamls/config.yaml -o -n "$Url" -o -n "$Https" ];then
$clashdir/start.sh start $CRASHDIR/start.sh start
sleep 1 sleep 1
[ -n "$(pidof clash)" ] && startover [ -n "$(pidof clash)" ] && startover
else else
echo -e "\033[31m没有找到配置文件请先导入配置文件\033[0m" echo -e "\033[31m没有找到配置文件请先导入配置文件\033[0m"
source $clashdir/getdate.sh && clashlink source $CRASHDIR/getdate.sh && clashlink
fi fi
} }
checkrestart(){ checkrestart(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m检测到已变更的内容请重启clash服务!\033[0m" echo -e "\033[32m检测到已变更的内容请重启服务!\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "是否现在重启clash服务?(1/0) > " res read -p "是否现在重启服务?(1/0) > " res
[ "$res" = 1 ] && clashstart [ "$res" = 1 ] && clashstart
} }
#功能相关 #功能相关
@ -205,6 +205,7 @@ log_pusher(){
[ -n "$push_Deer" ] && stat_Deer=32m已启用 || stat_Deer=33m未启用 [ -n "$push_Deer" ] && stat_Deer=32m已启用 || stat_Deer=33m未启用
[ -n "$push_bark" ] && stat_bark=32m已启用 || stat_bark=33m未启用 [ -n "$push_bark" ] && stat_bark=32m已启用 || stat_bark=33m未启用
[ -n "$push_Po" ] && stat_Po=32m已启用 || stat_Po=33m未启用 [ -n "$push_Po" ] && stat_Po=32m已启用 || stat_Po=33m未启用
[ -n "$task_push" ] && task_push=32m已启用 || task_push=33m未启用
[ -n "$device_name" ] && device_s=32m$device_name || device_s=33m未设置 [ -n "$device_name" ] && device_s=32m$device_name || device_s=33m未设置
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 查看\033[36m运行日志\033[0m" echo -e " 1 查看\033[36m运行日志\033[0m"
@ -212,13 +213,14 @@ log_pusher(){
echo -e " 3 PushDeer推送 ——\033[$stat_Deer\033[0m" echo -e " 3 PushDeer推送 ——\033[$stat_Deer\033[0m"
echo -e " 4 Bark推送-IOS ——\033[$stat_bark\033[0m" echo -e " 4 Bark推送-IOS ——\033[$stat_bark\033[0m"
echo -e " 5 Passover推送 ——\033[$stat_Po\033[0m" echo -e " 5 Passover推送 ——\033[$stat_Po\033[0m"
echo -e " 6 推送任务日志 ——\033[$task_push\033[0m"
echo -e " 9 设置设备名称 ——\033[$device_s\033[0m" echo -e " 9 设置设备名称 ——\033[$device_s\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
case $num in case $num in
1) 1)
echo ----------------------------------------------- echo -----------------------------------------------
cat $TMPDIR/ShellClash_log cat $TMPDIR/ShellCrash.log
exit exit
;; ;;
2) 2)
@ -254,7 +256,7 @@ log_pusher(){
push_TG=$TOKEN push_TG=$TOKEN
setconfig push_TG $TOKEN setconfig push_TG $TOKEN
setconfig chat_ID $chat_ID setconfig chat_ID $chat_ID
$clashdir/start.sh logger "已完成Telegram日志推送设置" 32 $CRASHDIR/start.sh logger "已完成Telegram日志推送设置" 32
else else
echo -e "\033[31m无法获取对话ID请重新配置\033[0m" echo -e "\033[31m无法获取对话ID请重新配置\033[0m"
fi fi
@ -282,7 +284,7 @@ log_pusher(){
if [ -n "$url" ];then if [ -n "$url" ];then
push_Deer=$url push_Deer=$url
setconfig push_Deer $url setconfig push_Deer $url
$clashdir/start.sh logger "已完成PushDeer日志推送设置" 32 $CRASHDIR/start.sh logger "已完成PushDeer日志推送设置" 32
else else
echo -e "\033[31m输入错误请重新输入\033[0m" echo -e "\033[31m输入错误请重新输入\033[0m"
fi fi
@ -310,14 +312,14 @@ log_pusher(){
push_bark=$url push_bark=$url
setconfig push_bark $url setconfig push_bark $url
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m例: ?group=ShellClash\033[0m" echo -e "\033[32m例: ?group=ShellCrash\033[0m"
read -p "请输入你的Bark请求参数(默认回车为空) > " param read -p "请输入你的Bark请求参数(默认回车为空) > " param
param=$(echo $param | sed 's/\&/\\\&/g') param=$(echo $param | sed 's/\&/\\\&/g')
if [ -n "$param" ];then if [ -n "$param" ];then
bark_param=$param bark_param=$param
setconfig bark_param \'$param\' setconfig bark_param \'$param\'
fi fi
$clashdir/start.sh logger "已完成Bark日志推送设置" 32 $CRASHDIR/start.sh logger "已完成Bark日志推送设置" 32
else else
echo -e "\033[31m输入错误请重新输入\033[0m" echo -e "\033[31m输入错误请重新输入\033[0m"
fi fi
@ -353,7 +355,7 @@ log_pusher(){
push_Po_key=$key push_Po_key=$key
setconfig push_Po $Token setconfig push_Po $Token
setconfig push_Po_key $key setconfig push_Po_key $key
$clashdir/start.sh logger "已完成Passover日志推送设置" 32 $CRASHDIR/start.sh logger "已完成Passover日志推送设置" 32
else else
echo -e "\033[31m输入错误请重新输入\033[0m" echo -e "\033[31m输入错误请重新输入\033[0m"
fi fi
@ -366,6 +368,12 @@ log_pusher(){
sleep 1 sleep 1
log_pusher log_pusher
;; ;;
6)
[ "$task_push" = 1 ] && task_push= || task_push=1
setconfig task_push $task_push
sleep 1
log_pusher
;;
9) 9)
read -p "请输入本设备自定义推送名称 > " device_name read -p "请输入本设备自定义推送名称 > " device_name
setconfig device_name $device_name setconfig device_name $device_name
@ -761,7 +769,7 @@ macfilter(){
add_mac(){ add_mac(){
echo ----------------------------------------------- echo -----------------------------------------------
echo 已添加的mac地址 echo 已添加的mac地址
cat $clashdir/configs/mac cat $CRASHDIR/configs/mac
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[32m" echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[32m"
cat $dhcpdir | awk '{print " "NR" "$3,$2,$4}' cat $dhcpdir | awk '{print " "NR" "$3,$2,$4}'
@ -773,8 +781,8 @@ macfilter(){
if [ -z "$num" -o "$num" = 0 ]; then if [ -z "$num" -o "$num" = 0 ]; then
i= i=
elif [ -n "$(echo $num | grep -aE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')" ];then elif [ -n "$(echo $num | grep -aE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')" ];then
if [ -z "$(cat $clashdir/configs/mac | grep -E "$num")" ];then if [ -z "$(cat $CRASHDIR/configs/mac | grep -E "$num")" ];then
echo $num | grep -oE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$' >> $clashdir/configs/mac echo $num | grep -oE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$' >> $CRASHDIR/configs/mac
else else
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m已添加的设备请勿重复添加\033[0m" echo -e "\033[31m已添加的设备请勿重复添加\033[0m"
@ -782,8 +790,8 @@ macfilter(){
add_mac add_mac
elif [ $num -le $(cat $dhcpdir 2>/dev/null | awk 'END{print NR}') ]; then elif [ $num -le $(cat $dhcpdir 2>/dev/null | awk 'END{print NR}') ]; then
macadd=$(cat $dhcpdir | awk '{print $2}' | sed -n "$num"p) macadd=$(cat $dhcpdir | awk '{print $2}' | sed -n "$num"p)
if [ -z "$(cat $clashdir/configs/mac | grep -E "$macadd")" ];then if [ -z "$(cat $CRASHDIR/configs/mac | grep -E "$macadd")" ];then
echo $macadd >> $clashdir/configs/mac echo $macadd >> $CRASHDIR/configs/mac
else else
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m已添加的设备请勿重复添加\033[0m" echo -e "\033[31m已添加的设备请勿重复添加\033[0m"
@ -797,12 +805,12 @@ macfilter(){
} }
del_mac(){ del_mac(){
echo ----------------------------------------------- echo -----------------------------------------------
if [ -z "$(cat $clashdir/configs/mac)" ];then if [ -z "$(cat $CRASHDIR/configs/mac)" ];then
echo -e "\033[31m列表中没有需要移除的设备\033[0m" echo -e "\033[31m列表中没有需要移除的设备\033[0m"
else else
echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[0m" echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[0m"
i=1 i=1
for mac in $(cat $clashdir/configs/mac); do for mac in $(cat $CRASHDIR/configs/mac); do
dev_ip=$(cat $dhcpdir | grep $mac | awk '{print $3}') && [ -z "$dev_ip" ] && dev_ip='000.000.00.00' dev_ip=$(cat $dhcpdir | grep $mac | awk '{print $3}') && [ -z "$dev_ip" ] && dev_ip='000.000.00.00'
dev_mac=$(cat $dhcpdir | grep $mac | awk '{print $2}') && [ -z "$dev_mac" ] && dev_mac=$mac dev_mac=$(cat $dhcpdir | grep $mac | awk '{print $2}') && [ -z "$dev_mac" ] && dev_mac=$mac
dev_name=$(cat $dhcpdir | grep $mac | awk '{print $4}') && [ -z "$dev_name" ] && dev_name='未知设备' dev_name=$(cat $dhcpdir | grep $mac | awk '{print $4}') && [ -z "$dev_name" ] && dev_name='未知设备'
@ -814,8 +822,8 @@ macfilter(){
read -p "请输入需要移除的设备的对应序号 > " num read -p "请输入需要移除的设备的对应序号 > " num
if [ -z "$num" ]||[ "$num" -le 0 ]; then if [ -z "$num" ]||[ "$num" -le 0 ]; then
n= n=
elif [ $num -le $(cat $clashdir/configs/mac | wc -l) ];then elif [ $num -le $(cat $CRASHDIR/configs/mac | wc -l) ];then
sed -i "${num}d" $clashdir/configs/mac sed -i "${num}d" $CRASHDIR/configs/mac
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m对应设备已移除\033[0m" echo -e "\033[32m对应设备已移除\033[0m"
del_mac del_mac
@ -844,11 +852,11 @@ macfilter(){
echo -e "\033[30;47m请在此添加或移除设备\033[0m" echo -e "\033[30;47m请在此添加或移除设备\033[0m"
echo -e "当前过滤方式为:\033[33m$macfilter_type模式\033[0m" echo -e "当前过滤方式为:\033[33m$macfilter_type模式\033[0m"
echo -e "仅列表内设备\033[36m$macfilter_scrip经过\033[0mClash内核" echo -e "仅列表内设备\033[36m$macfilter_scrip经过\033[0mClash内核"
if [ -n "$(cat $clashdir/configs/mac)" ]; then if [ -n "$(cat $CRASHDIR/configs/mac)" ]; then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "当前已过滤设备为:\033[36m" echo -e "当前已过滤设备为:\033[36m"
echo -e "\033[33m 设备IP 设备mac地址 设备名称\033[0m" echo -e "\033[33m 设备IP 设备mac地址 设备名称\033[0m"
for mac in $(cat $clashdir/configs/mac); do for mac in $(cat $CRASHDIR/configs/mac); do
dev_ip=$(cat $dhcpdir | grep $mac | awk '{print $3}') && [ -z "$dev_ip" ] && dev_ip='000.000.00.00' dev_ip=$(cat $dhcpdir | grep $mac | awk '{print $3}') && [ -z "$dev_ip" ] && dev_ip='000.000.00.00'
dev_mac=$(cat $dhcpdir | grep $mac | awk '{print $2}') && [ -z "$dev_mac" ] && dev_mac=$mac dev_mac=$(cat $dhcpdir | grep $mac | awk '{print $2}') && [ -z "$dev_mac" ] && dev_mac=$mac
dev_name=$(cat $dhcpdir | grep $mac | awk '{print $4}') && [ -z "$dev_name" ] && dev_name='未知设备' dev_name=$(cat $dhcpdir | grep $mac | awk '{print $4}') && [ -z "$dev_name" ] && dev_name='未知设备'
@ -879,7 +887,7 @@ macfilter(){
del_mac del_mac
macfilter macfilter
elif [ "$num" = 4 ]; then elif [ "$num" = 4 ]; then
:>$clashdir/configs/mac :>$CRASHDIR/configs/mac
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m设备列表已清空\033[0m" echo -e "\033[31m设备列表已清空\033[0m"
macfilter macfilter
@ -933,7 +941,7 @@ setboot(){
[ -z "$start_old" ] && start_old=未开启 [ -z "$start_old" ] && start_old=未开启
[ -z "$start_delay" -o "$start_delay" = 0 ] && delay=未设置 || delay=${start_delay} [ -z "$start_delay" -o "$start_delay" = 0 ] && delay=未设置 || delay=${start_delay}
[ "$autostart" = "enable" ] && auto_set="\033[33m禁止" || auto_set="\033[32m允许" [ "$autostart" = "enable" ] && auto_set="\033[33m禁止" || auto_set="\033[32m允许"
[ "$bindir" = "$clashdir" ] && mini_clash=未开启 || mini_clash=已开启 [ "$bindir" = "$CRASHDIR" ] && mini_clash=未开启 || mini_clash=已开启
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[30;47m欢迎使用启动设置菜单\033[0m" echo -e "\033[30;47m欢迎使用启动设置菜单\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
@ -941,7 +949,7 @@ setboot(){
echo -e " 2 使用保守模式: \033[36m$start_old\033[0m ————基于定时任务(每分钟检测)" echo -e " 2 使用保守模式: \033[36m$start_old\033[0m ————基于定时任务(每分钟检测)"
echo -e " 3 设置自启延时: \033[36m$delay\033[0m ————用于解决自启后服务受限" echo -e " 3 设置自启延时: \033[36m$delay\033[0m ————用于解决自启后服务受限"
echo -e " 4 启用小闪存模式: \033[36m$mini_clash\033[0m ————用于闪存空间不足的设备" echo -e " 4 启用小闪存模式: \033[36m$mini_clash\033[0m ————用于闪存空间不足的设备"
[ "$bindir" != "$clashdir" ] && echo -e " 5 设置小闪存目录: \033[36m$bindir\033[0m" [ "$bindir" != "$CRASHDIR" ] && echo -e " 5 设置小闪存目录: \033[36m$bindir\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 0 \033[0m返回上级菜单\033[0m" echo -e " 0 \033[0m返回上级菜单\033[0m"
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
@ -951,13 +959,13 @@ setboot(){
if [ "$autostart" = "enable" ]; then if [ "$autostart" = "enable" ]; then
[ -d /etc/rc.d ] && cd /etc/rc.d && rm -rf *clash > /dev/null 2>&1 && cd - >/dev/null [ -d /etc/rc.d ] && cd /etc/rc.d && rm -rf *clash > /dev/null 2>&1 && cd - >/dev/null
ckcmd systemctl && systemctl disable clash.service > /dev/null 2>&1 ckcmd systemctl && systemctl disable clash.service > /dev/null 2>&1
touch $clashdir/.dis_startup touch $CRASHDIR/.dis_startup
autostart=disable autostart=disable
echo -e "\033[33m已禁止Clash开机启动\033[0m" echo -e "\033[33m已禁止Clash开机启动\033[0m"
elif [ "$autostart" = "disable" ]; then elif [ "$autostart" = "disable" ]; then
[ -f /etc/rc.common ] && /etc/init.d/clash enable [ -f /etc/rc.common ] && /etc/init.d/clash enable
ckcmd systemctl && systemctl enable clash.service > /dev/null 2>&1 ckcmd systemctl && systemctl enable clash.service > /dev/null 2>&1
rm -rf $clashdir/.dis_startup rm -rf $CRASHDIR/.dis_startup
autostart=enable autostart=enable
echo -e "\033[32m已设置Clash开机启动\033[0m" echo -e "\033[32m已设置Clash开机启动\033[0m"
fi fi
@ -965,17 +973,17 @@ setboot(){
;; ;;
2) 2)
if [ "$start_old" = "未开启" ] > /dev/null 2>&1; then if [ "$start_old" = "未开启" ] > /dev/null 2>&1; then
echo -e "\033[33m改为使用保守模式启动clash服务!!\033[0m" echo -e "\033[33m改为使用保守模式启动服务!!\033[0m"
start_old=已开启 start_old=已开启
setconfig start_old $start_old setconfig start_old $start_old
$clashdir/start.sh stop $CRASHDIR/start.sh stop
else else
if [ -f /etc/init.d/clash -o -w /etc/systemd/system -o -w /usr/lib/systemd/system ];then if [ -f /etc/init.d/clash -o -w /etc/systemd/system -o -w /usr/lib/systemd/system ];then
echo -e "\033[32m改为使用系统守护进程启动clash服务!!\033[0m" echo -e "\033[32m改为使用系统守护进程启动服务!!\033[0m"
$clashdir/start.sh cronset "ShellClash初始化" $CRASHDIR/start.sh cronset "ShellCrash初始化"
start_old=未开启 start_old=未开启
setconfig start_old $start_old setconfig start_old $start_old
$clashdir/start.sh stop $CRASHDIR/start.sh stop
else else
echo -e "\033[31m当前设备不支持以其他模式启动\033[0m" echo -e "\033[31m当前设备不支持以其他模式启动\033[0m"
@ -1002,12 +1010,12 @@ setboot(){
setboot setboot
;; ;;
4) 4)
dir_size=$(df $clashdir |awk '{ for(i=1;i<=NF;i++){ if(NR==1){ arr[i]=$i; }else{ arr[i]=arr[i]" "$i; } } } END{ for(i=1;i<=NF;i++){ print arr[i]; } }' |grep Ava |awk '{print $2}') dir_size=$(df $CRASHDIR |awk '{ for(i=1;i<=NF;i++){ if(NR==1){ arr[i]=$i; }else{ arr[i]=arr[i]" "$i; } } } END{ for(i=1;i<=NF;i++){ print arr[i]; } }' |grep Ava |awk '{print $2}')
if [ "$mini_clash" = "未开启" ]; then if [ "$mini_clash" = "未开启" ]; then
if [ "$dir_size" -gt 20480 ];then if [ "$dir_size" -gt 20480 ];then
echo -e "\033[33m您的设备空间充足(>20M),无需开启!\033[0m" echo -e "\033[33m您的设备空间充足(>20M),无需开启!\033[0m"
else else
[ "$bindir" = "$clashdir" ] && bindir="/tmp/clash_$USER" [ "$bindir" = "$CRASHDIR" ] && bindir="/tmp/clash_$USER"
echo -e "\033[32m已经启用小闪存功能\033[0m" echo -e "\033[32m已经启用小闪存功能\033[0m"
echo -e "如需更换目录,请使用【设置小闪存目录】功能\033[0m" echo -e "如需更换目录,请使用【设置小闪存目录】功能\033[0m"
fi fi
@ -1015,10 +1023,10 @@ setboot(){
if [ "$dir_size" -lt 8192 ];then if [ "$dir_size" -lt 8192 ];then
echo -e "\033[31m您的设备剩余空间不足8M停用后可能无法正常运行\033[0m" echo -e "\033[31m您的设备剩余空间不足8M停用后可能无法正常运行\033[0m"
read -p "确认停用此功能?(1/0) > " res read -p "确认停用此功能?(1/0) > " res
[ "$res" = 1 ] && bindir="$clashdir" && echo -e "\033[33m已经停用小闪存功能\033[0m" [ "$res" = 1 ] && bindir="$CRASHDIR" && echo -e "\033[33m已经停用小闪存功能\033[0m"
else else
rm -rf /tmp/clash_$USER rm -rf /tmp/clash_$USER
bindir="$clashdir" bindir="$CRASHDIR"
echo -e "\033[33m已经停用小闪存功能\033[0m" echo -e "\033[33m已经停用小闪存功能\033[0m"
fi fi
fi fi
@ -1083,8 +1091,8 @@ clashcfg(){
setconfig dns_mod $dns_mod setconfig dns_mod $dns_mod
if [ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ] && [ "$clashcore" = "clash" ];then if [ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ] && [ "$clashcore" = "clash" ];then
rm -rf $bindir/clash rm -rf $bindir/clash
rm -rf $clashdir/clash rm -rf $CRASHDIR/clash
setconfig clashcore clash.meta setconfig clashcore meta
fi fi
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[36m已设为 $redir_mod \033[0m" echo -e "\033[36m已设为 $redir_mod \033[0m"
@ -1094,7 +1102,7 @@ clashcfg(){
ckcmd nft && sup_nft=1 ckcmd nft && sup_nft=1
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "当前代理模式为:\033[47;30m $redir_mod \033[0mClash核心为\033[47;30m $clashcore \033[0m" echo -e "当前代理模式为:\033[47;30m $redir_mod \033[0mClash核心为\033[47;30m $clashcore \033[0m"
echo -e "\033[33m切换模式后需要手动重启clash服务以生效!\033[0m" echo -e "\033[33m切换模式后需要手动重启服务以生效!\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 \033[32mRedir模式\033[0m Redir转发TCP不转发UDP" echo -e " 1 \033[32mRedir模式\033[0m Redir转发TCP不转发UDP"
echo -e " 2 \033[36m混合模式\033[0m Redir转发TCPTun转发UDP" echo -e " 2 \033[36m混合模式\033[0m Redir转发TCPTun转发UDP"
@ -1126,7 +1134,7 @@ clashcfg(){
elif [ "$num" = 3 ]; then elif [ "$num" = 3 ]; then
if [ -f /etc/init.d/qca-nss-ecm -a "$systype" = "mi_snapshot" ] ;then if [ -f /etc/init.d/qca-nss-ecm -a "$systype" = "mi_snapshot" ] ;then
read -p "当前设备的QOS服务与本模式冲突是否禁用相关功能(1/0) > " res read -p "当前设备的QOS服务与本模式冲突是否禁用相关功能(1/0) > " res
[ "$res" = '1' ] && $clashdir/misnap_init.sh tproxyfix && redir_mod=Tproxy混合 [ "$res" = '1' ] && $CRASHDIR/misnap_init.sh tproxyfix && redir_mod=Tproxy混合
else else
redir_mod=Tproxy混合 redir_mod=Tproxy混合
fi fi
@ -1139,7 +1147,7 @@ clashcfg(){
elif [ "$num" = 5 ]; then elif [ "$num" = 5 ]; then
if [ -f /etc/init.d/qca-nss-ecm -a "$systype" = "mi_snapshot" ] ;then if [ -f /etc/init.d/qca-nss-ecm -a "$systype" = "mi_snapshot" ] ;then
read -p "当前设备的QOS服务与本模式冲突是否禁用相关功能(1/0) > " res read -p "当前设备的QOS服务与本模式冲突是否禁用相关功能(1/0) > " res
[ "$res" = '1' ] && $clashdir/misnap_init.sh tproxyfix && redir_mod=Tproxy模式 [ "$res" = '1' ] && $CRASHDIR/misnap_init.sh tproxyfix && redir_mod=Tproxy模式
else else
redir_mod=Tproxy模式 redir_mod=Tproxy模式
fi fi
@ -1181,7 +1189,7 @@ clashcfg(){
set_dns_mod(){ set_dns_mod(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "当前DNS运行模式为\033[47;30m $dns_mod \033[0m" echo -e "当前DNS运行模式为\033[47;30m $dns_mod \033[0m"
echo -e "\033[33m切换模式后需要手动重启clash服务以生效!\033[0m" echo -e "\033[33m切换模式后需要手动重启服务以生效!\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 fake-ip模式 \033[32m响应速度更快\033[0m" echo -e " 1 fake-ip模式 \033[32m响应速度更快\033[0m"
echo -e " 不支持绕过CN-IP功能" echo -e " 不支持绕过CN-IP功能"
@ -1224,9 +1232,9 @@ clashcfg(){
echo -e "示例:*.b.com" echo -e "示例:*.b.com"
echo -e "示例:*.*.b.com\033[0m" echo -e "示例:*.*.b.com\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
if [ -s $clashdir/configs/fake_ip_filter ];then if [ -s $CRASHDIR/configs/fake_ip_filter ];then
echo -e "\033[33m已添加Fake-ip过滤地址\033[0m" echo -e "\033[33m已添加Fake-ip过滤地址\033[0m"
cat $clashdir/configs/fake_ip_filter | awk '{print NR" "$1}' cat $CRASHDIR/configs/fake_ip_filter | awk '{print NR" "$1}'
else else
echo -e "\033[33m你还未添加Fake-ip过滤地址\033[0m" echo -e "\033[33m你还未添加Fake-ip过滤地址\033[0m"
fi fi
@ -1237,14 +1245,14 @@ clashcfg(){
0) ;; 0) ;;
'') ;; '') ;;
[0-99]) [0-99])
sed -i "${input}d" $clashdir/configs/fake_ip_filter 2>/dev/null sed -i "${input}d" $CRASHDIR/configs/fake_ip_filter 2>/dev/null
echo -e "\033[32m移除成功\033[0m" echo -e "\033[32m移除成功\033[0m"
fake_ip_filter fake_ip_filter
;; ;;
*) *)
echo -e "你输入的地址是:\033[32m$input\033[0m" echo -e "你输入的地址是:\033[32m$input\033[0m"
read -p "确认添加?(1/0) > " res read -p "确认添加?(1/0) > " res
[ "$res" = 1 ] && echo $input >> $clashdir/configs/fake_ip_filter [ "$res" = 1 ] && echo $input >> $CRASHDIR/configs/fake_ip_filter
fake_ip_filter fake_ip_filter
;; ;;
esac esac
@ -1257,7 +1265,7 @@ clashcfg(){
[ -z "$cn_ip_route" ] && cn_ip_route=未开启 [ -z "$cn_ip_route" ] && cn_ip_route=未开启
[ -z "$local_proxy" ] && local_proxy=未开启 [ -z "$local_proxy" ] && local_proxy=未开启
[ -z "$quic_rj" ] && quic_rj=未开启 [ -z "$quic_rj" ] && quic_rj=未开启
[ -z "$(cat $clashdir/configs/mac)" ] && mac_return=未开启 || mac_return=已启用 [ -z "$(cat $CRASHDIR/configs/mac)" ] && mac_return=未开启 || mac_return=已启用
# #
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[30;47m欢迎使用功能设置菜单\033[0m" echo -e "\033[30;47m欢迎使用功能设置菜单\033[0m"
@ -1325,18 +1333,18 @@ clashcfg(){
} }
echo ----------------------------------------------- echo -----------------------------------------------
if [ -n "$(pidof clash)" ];then if [ -n "$(pidof clash)" ];then
read -p "切换时将停止clash服务,是否继续?(1/0) > " res read -p "切换时将停止服务,是否继续?(1/0) > " res
[ "$res" = 1 ] && $clashdir/start.sh stop && set_common_ports [ "$res" = 1 ] && $CRASHDIR/start.sh stop && set_common_ports
else else
set_common_ports set_common_ports
fi fi
clashcfg clashcfg
elif [ "$num" = 5 ]; then elif [ "$num" = 5 ]; then
checkcfg_mac=$(cat $clashdir/configs/mac) checkcfg_mac=$(cat $CRASHDIR/configs/mac)
macfilter macfilter
if [ -n "$PID" ];then if [ -n "$PID" ];then
checkcfg_mac_new=$(cat $clashdir/configs/mac) checkcfg_mac_new=$(cat $CRASHDIR/configs/mac)
[ "$checkcfg_mac" != "$checkcfg_mac_new" ] && checkrestart [ "$checkcfg_mac" != "$checkcfg_mac_new" ] && checkrestart
fi fi
clashcfg clashcfg
@ -1349,7 +1357,7 @@ clashcfg(){
setconfig local_proxy $local_proxy setconfig local_proxy $local_proxy
setconfig local_type setconfig local_type
sed -i '/user shellclash/d' /etc/init.d/clash 2>/dev/null sed -i '/user shellclash/d' /etc/init.d/clash 2>/dev/null
echo -e "\033[33m已经停用本机代理规则,请尽快重启clash服务!!\033[0m" echo -e "\033[33m已经停用本机代理规则,请尽快重启服务!!\033[0m"
fi fi
sleep 1 sleep 1
clashcfg clashcfg
@ -1445,7 +1453,7 @@ clashadv(){
if [ "$sniffer" = "未启用" ];then if [ "$sniffer" = "未启用" ];then
if [ "$clashcore" = "clash" ];then if [ "$clashcore" = "clash" ];then
rm -rf $bindir/clash rm -rf $bindir/clash
clashcore=clash.meta clashcore=meta
setconfig clashcore $clashcore setconfig clashcore $clashcore
echo "已将clash内核切换为Meta内核域名嗅探依赖Meta或者高版本clashpre内核" echo "已将clash内核切换为Meta内核域名嗅探依赖Meta或者高版本clashpre内核"
fi fi
@ -1464,7 +1472,7 @@ clashadv(){
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$proxies_bypass" = "未启用" ];then if [ "$proxies_bypass" = "未启用" ];then
proxies_bypass=已启用 proxies_bypass=已启用
echo -e "\033[33m仅当ShellClash与子网络同类应用使用相同节点配置时方可生效\033[0m" echo -e "\033[33m仅当ShellCrash与子网络同类应用使用相同节点配置时方可生效\033[0m"
sleep 1 sleep 1
else else
proxies_bypass=未启用 proxies_bypass=未启用
@ -1518,8 +1526,8 @@ autoSSH(){
echo -e "\033[33m如有问题请加群反馈\033[36;4mhttps://t.me/ShellClash\033[0m" echo -e "\033[33m如有问题请加群反馈\033[36;4mhttps://t.me/ShellClash\033[0m"
read -p "请输入需要还原的SSH密码(不影响当前密码,回车可跳过) > " mi_autoSSH_pwd read -p "请输入需要还原的SSH密码(不影响当前密码,回车可跳过) > " mi_autoSSH_pwd
mi_autoSSH=已配置 mi_autoSSH=已配置
cp -f /etc/dropbear/dropbear_rsa_host_key $clashdir/configs/dropbear_rsa_host_key 2>/dev/null cp -f /etc/dropbear/dropbear_rsa_host_key $CRASHDIR/configs/dropbear_rsa_host_key 2>/dev/null
cp -f /etc/dropbear/authorized_keys $clashdir/configs/authorized_keys 2>/dev/null cp -f /etc/dropbear/authorized_keys $CRASHDIR/configs/authorized_keys 2>/dev/null
ckcmd nvram && { ckcmd nvram && {
nvram set ssh_en=1 nvram set ssh_en=1
nvram set telnet_en=1 nvram set telnet_en=1
@ -1541,7 +1549,7 @@ tools(){
[ -n "$(cat /etc/firewall.user 2>&1 | grep '启用外网访问SSH服务')" ] && ssh_ol=禁止 || ssh_ol=开启 [ -n "$(cat /etc/firewall.user 2>&1 | grep '启用外网访问SSH服务')" ] && ssh_ol=禁止 || ssh_ol=开启
[ -z "$ssh_port" ] && ssh_port=10022 [ -z "$ssh_port" ] && ssh_port=10022
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[33m此功能仅针对使用Openwrt系统的设备生效且不依赖clash服务\033[0m" echo -e "\033[33m此功能仅针对使用Openwrt系统的设备生效且不依赖服务\033[0m"
echo -e "\033[31m本功能不支持红米AX6S等镜像化系统设备请勿尝试\033[0m" echo -e "\033[31m本功能不支持红米AX6S等镜像化系统设备请勿尝试\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 \033[32m修改\033[0m外网访问端口\033[36m$ssh_port\033[0m" echo -e " 1 \033[32m修改\033[0m外网访问端口\033[36m$ssh_port\033[0m"
@ -1600,16 +1608,16 @@ tools(){
#获取设置默认显示 #获取设置默认显示
[ -n "$(cat /etc/crontabs/root 2>&1| grep otapredownload)" ] && mi_update=禁用 || mi_update=启用 [ -n "$(cat /etc/crontabs/root 2>&1| grep otapredownload)" ] && mi_update=禁用 || mi_update=启用
[ "$mi_autoSSH" = "已配置" ] && mi_autoSSH_type=32m已配置 || mi_autoSSH_type=31m未配置 [ "$mi_autoSSH" = "已配置" ] && mi_autoSSH_type=32m已配置 || mi_autoSSH_type=31m未配置
[ -f $clashdir/tools/tun.ko ] && mi_tunfix=32m已启用 || mi_tunfix=31m未启用 [ -f $CRASHDIR/tools/tun.ko ] && mi_tunfix=32m已启用 || mi_tunfix=31m未启用
# #
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[30;47m欢迎使用其他工具菜单\033[0m" echo -e "\033[30;47m欢迎使用其他工具菜单\033[0m"
echo -e "\033[33m本页工具可能无法兼容全部Linux设备请酌情使用\033[0m" echo -e "\033[33m本页工具可能无法兼容全部Linux设备请酌情使用\033[0m"
echo -e "磁盘占用/所在目录:" echo -e "磁盘占用/所在目录:"
du -sh $clashdir du -sh $CRASHDIR
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 ShellClash\033[33m测试菜单\033[0m" echo -e " 1 ShellCrash\033[33m测试菜单\033[0m"
echo -e " 2 ShellClash\033[32m新手引导\033[0m" echo -e " 2 ShellCrash\033[32m新手引导\033[0m"
echo -e " 3 \033[36m日志及推送工具\033[0m" echo -e " 3 \033[36m日志及推送工具\033[0m"
[ -f /etc/firewall.user ] && echo -e " 4 \033[32m配置\033[0m外网访问SSH" [ -f /etc/firewall.user ] && echo -e " 4 \033[32m配置\033[0m外网访问SSH"
[ -x /usr/sbin/otapredownload ] && echo -e " 5 \033[33m$mi_update\033[0m小米系统自动更新" [ -x /usr/sbin/otapredownload ] && echo -e " 5 \033[33m$mi_update\033[0m小米系统自动更新"
@ -1626,10 +1634,10 @@ tools(){
i= i=
elif [ "$num" = 1 ]; then elif [ "$num" = 1 ]; then
source $clashdir/getdate.sh && testcommand source $CRASHDIR/getdate.sh && testcommand
elif [ "$num" = 2 ]; then elif [ "$num" = 2 ]; then
source $clashdir/getdate.sh && userguide source $CRASHDIR/getdate.sh && userguide
elif [ "$num" = 3 ]; then elif [ "$num" = 3 ]; then
log_pusher log_pusher
@ -1642,17 +1650,17 @@ tools(){
elif [ "$num" = 7 ]; then elif [ "$num" = 7 ]; then
echo ----------------------------------------------- echo -----------------------------------------------
if [ ! -f $clashdir/tools/ShellDDNS.sh ];then if [ ! -f $CRASHDIR/tools/ShellDDNS.sh ];then
echo -e "正在获取在线脚本……" echo -e "正在获取在线脚本……"
$clashdir/start.sh webget $TMPDIR/ShellDDNS.sh $update_url/tools/ShellDDNS.sh $CRASHDIR/start.sh webget $TMPDIR/ShellDDNS.sh $update_url/tools/ShellDDNS.sh
if [ "$?" = "0" ];then if [ "$?" = "0" ];then
mv -f $TMPDIR/ShellDDNS.sh $clashdir/tools/ShellDDNS.sh mv -f $TMPDIR/ShellDDNS.sh $CRASHDIR/tools/ShellDDNS.sh
source $clashdir/tools/ShellDDNS.sh source $CRASHDIR/tools/ShellDDNS.sh
else else
echo -e "\033[31m文件下载失败\033[0m" echo -e "\033[31m文件下载失败\033[0m"
fi fi
else else
source $clashdir/tools/ShellDDNS.sh source $CRASHDIR/tools/ShellDDNS.sh
fi fi
sleep 1 sleep 1
tools tools
@ -1672,10 +1680,10 @@ tools(){
fi fi
tools tools
elif [ "$num" = 8 ]; then elif [ "$num" = 8 ]; then
if [ -f $clashdir/tools/tun.ko ];then if [ -f $CRASHDIR/tools/tun.ko ];then
read -p "是否禁用此功能并移除相关补丁?(1/0) > " res read -p "是否禁用此功能并移除相关补丁?(1/0) > " res
[ "$res" = 1 ] && { [ "$res" = 1 ] && {
rm -rf $clashdir/tools/tun.ko rm -rf $CRASHDIR/tools/tun.ko
echo -e "\033[33m补丁文件已移除请立即重启设备以防止出错\033[0m" echo -e "\033[33m补丁文件已移除请立即重启设备以防止出错\033[0m"
} }
elif [ -z "$(modinfo tun)" ];then elif [ -z "$(modinfo tun)" ];then
@ -1687,11 +1695,11 @@ tools(){
tunfixlink="${update_url}/bin/fix/tun.ko" tunfixlink="${update_url}/bin/fix/tun.ko"
echo ----------------------------------------------- echo -----------------------------------------------
echo 正在连接服务器获取Tun模块补丁文件………… echo 正在连接服务器获取Tun模块补丁文件…………
$clashdir/start.sh webget $TMPDIR/tun.ko $tunfixlink $CRASHDIR/start.sh webget $TMPDIR/tun.ko $tunfixlink
if [ "$?" = "0" ];then if [ "$?" = "0" ];then
mv -f $TMPDIR/tun.ko $clashdir/tools/tun.ko && \ mv -f $TMPDIR/tun.ko $CRASHDIR/tools/tun.ko && \
$clashdir/misnap_init.sh tunfix && \ $CRASHDIR/misnap_init.sh tunfix && \
echo -e "\033[32m设置成功请重启clash服务!\033[0m" echo -e "\033[32m设置成功请重启服务!\033[0m"
else else
echo -e "\033[31m文件下载失败请重试\033[0m" echo -e "\033[31m文件下载失败请重试\033[0m"
fi fi
@ -1705,186 +1713,18 @@ tools(){
errornum errornum
fi fi
} }
clashcron(){
croncmd(){
if [ -n "$(crontab -h 2>&1 | grep '\-l')" ];then
crontab $1
else
crondir="$(crond -h 2>&1 | grep -oE 'Default:.*' | awk -F ":" '{print $2}')"
[ ! -w "$crondir" ] && crondir="/etc/storage/cron/crontabs"
[ ! -w "$crondir" ] && crondir="/var/spool/cron/crontabs"
[ ! -w "$crondir" ] && crondir="/var/spool/cron"
[ ! -w "$crondir" ] && echo "你的设备不支持定时任务配置,脚本大量功能无法启用,请前往 https://t.me/ShellClash 申请适配!"
[ "$1" = "-l" ] && cat $crondir/$USER 2>/dev/null
[ -f "$1" ] && cat $1 > $crondir/$USER
fi
}
setcron(){
setcrontab(){
#设置具体时间
echo -----------------------------------------------
read -p "请输入小时0-23 > " num
if [ -z "$num" ]; then
errornum
setcron
elif [ $num -gt 23 ] || [ $num -lt 0 ]; then
errornum
setcron
else
hour=$num
echo -----------------------------------------------
read -p "请输入分钟0-59 > " num
if [ -z "$num" ]; then
errornum
setcron
elif [ $num -gt 59 ] || [ $num -lt 0 ]; then
errornum
setcron
else
min=$num
echo -----------------------------------------------
echo 将在$week1的$hour点$min分$cronname(旧的任务会被覆盖)
read -p "是否确认添加定时任务?(1/0) > " res
if [ "$res" = '1' ]; then
cronwords="$min $hour * * $week $cronset #$week1的$hour点$min分$cronname"
tmpcron=$TMPDIR/cron_$USER
croncmd -l > $tmpcron
sed -i "/$cronname/d" $tmpcron
sed -i '/^$/d' $tmpcron
echo "$cronwords" >> $tmpcron
croncmd $tmpcron
#华硕/Padavan固件存档在本地,其他则删除
[ "$clashdir" = "/jffs/clash" -o "$clashdir" = "/etc/storage/clash" ] && mv -f $tmpcron $clashdir/tools/cron || rm -f $tmpcron
echo -----------------------------------------------
echo -e "\033[31m定时任务已添加\033[0m"
fi
fi
fi
}
echo -----------------------------------------------
echo -e " 正在设置:\033[32m$cronname\033[0m定时任务"
echo -e " 输入 1~7 对应\033[33m每周的指定某天\033[0m运行"
echo -e " 输入 8 设为\033[33m每天\033[0m定时运行"
echo -e " 输入 1,3,6 代表\033[36m指定每周1,3,6\033[0m运行(小写逗号分隔)"
echo -e " 输入 a,b,c 代表\033[36m指定每周a,b,c\033[0m运行(1<=abc<=7)"
echo -----------------------------------------------
echo -e " 输入 9 \033[31m删除定时任务\033[0m"
echo -e " 输入 0 返回上级菜单"
echo -----------------------------------------------
read -p "请输入对应数字 > " num
if [ -z "$num" ]; then
errornum
elif [ "$num" = 0 ]; then
i=
elif [ "$num" = 9 ]; then
croncmd -l > $TMPDIR/conf && sed -i "/$cronname/d" $TMPDIR/conf && croncmd $TMPDIR/conf
sed -i "/$cronname/d" $clashdir/tools/cron 2>/dev/null
rm -f $TMPDIR/conf
echo -----------------------------------------------
echo -e "\033[31m定时任务$cronname已删除\033[0m"
elif [ "$num" = 8 ]; then
week='*'
week1=每天
echo 已设为每天定时运行!
setcrontab
else
week=$num
week1=每周$week
echo 已设为每周 $num 运行!
setcrontab
fi
}
#定时任务菜单
echo -----------------------------------------------
echo -e "\033[30;47m欢迎使用定时任务功能\033[0m"
echo -----------------------------------------------
echo -e "\033[33m已添加的定时任务\033[36m"
croncmd -l | grep -oE ' #.*'
echo -e "\033[0m"-----------------------------------------------
echo -e " 1 设置\033[33m定时重启\033[0mclash服务"
echo -e " 2 设置\033[31m定时停止\033[0mclash服务"
echo -e " 3 设置\033[32m定时开启\033[0mclash服务"
echo -e " 4 设置\033[33m定时更新\033[0m订阅并重启服务"
echo -e " 5 设置\033[33m定时热更新\033[0m订阅"
echo -e " 6 设置\033[36m自定义命令\033[0m"
echo -e " 7 删除\033[31m指定任务\033[0m"
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
if [ -z "$num" ]; then
errornum
elif [ "$num" = 0 ]; then
i=
elif [ "$num" = 1 ]; then
cronname=重启clash服务
cronset="$clashdir/start.sh restart"
setcron
clashcron
elif [ "$num" = 2 ]; then
cronname=停止clash服务
cronset="$clashdir/start.sh stop"
setcron
clashcron
elif [ "$num" = 3 ]; then
cronname=开启clash服务
cronset="$clashdir/start.sh start"
setcron
clashcron
elif [ "$num" = 4 ]; then
cronname=更新订阅链接
cronset="$clashdir/start.sh getyaml && $clashdir/start.sh restart"
setcron
clashcron
elif [ "$num" = 5 ]; then
cronname=更新订阅但不重启
cronset="$clashdir/start.sh updateyaml"
setcron
clashcron
elif [ "$num" = 6 ]; then
echo -----------------------------------------------
echo -e "\033[33m可包含空格请确保命令可执行\033[0m"
read -p "请输入命令语句 > " script
if [ -n "$script" ];then
cronset=$script
echo -e "请检查输入:\033[32m$cronset\033[0m"
read -p "请输入任务备注 > " txt
[ -n "$txt" ] && cronname=$txt || cronname=ShellClash自定义
setcron
else
echo -e "\033[31m输入错误请重新输入\033[0m"
sleep 1
fi
clashcron
elif [ "$num" = 7 ]; then
echo -----------------------------------------------
echo -e "\033[33m将按照关键词匹配并删除所有匹配\033[0m"
read -p "请输入备注的关键词 > " txt
[ -n "$txt" ] && {
cronname=$txt
croncmd -l > $TMPDIR/conf && sed -i "/$cronname/d" $TMPDIR/conf && croncmd $TMPDIR/conf
sed -i "/$cronname/d" $clashdir/tools/cron 2>/dev/null
rm -f $TMPDIR/conf
echo -----------------------------------------------
echo -e "所有关键词\033[32m$cronname\033[0m匹配的定时任务均已删除\033[0m"
sleep 1
}
clashcron
else
errornum
fi
}
#主菜单 #主菜单
clashsh(){ clashsh(){
############################# #############################
ckstatus ckstatus
############################# #############################
echo -e " 1 \033[32m启动/重启\033[0mclash服务" echo -e " 1 \033[32m启动/重启\033[0m服务"
echo -e " 2 clash\033[33m功能设置\033[0m" echo -e " 2 内核\033[33m功能设置\033[0m"
echo -e " 3 \033[31m停止\033[0mclash服务" echo -e " 3 \033[31m停止\033[0m内核服务"
echo -e " 4 clash\033[36m启动设置\033[0m" echo -e " 4 内核\033[36m启动设置\033[0m"
echo -e " 5 设置\033[33m定时任务\033[0m$cronoff" echo -e " 5 配置\033[33m自动任务\033[0m"
echo -e " 6 导入\033[32m配置文件\033[0m" echo -e " 6 导入\033[32m配置文件\033[0m"
echo -e " 7 clash\033[31m进阶设置\033[0m" echo -e " 7 内核\033[31m进阶设置\033[0m"
echo -e " 8 \033[35m其他工具\033[0m" echo -e " 8 \033[35m其他工具\033[0m"
echo -e " 9 \033[36m更新/卸载\033[0m" echo -e " 9 \033[36m更新/卸载\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
@ -1911,7 +1751,7 @@ clashsh(){
clashsh clashsh
elif [ "$num" = 3 ]; then elif [ "$num" = 3 ]; then
$clashdir/start.sh stop $CRASHDIR/start.sh stop
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31mClash服务已停止\033[0m" echo -e "\033[31mClash服务已停止\033[0m"
clashsh clashsh
@ -1921,11 +1761,11 @@ clashsh(){
clashsh clashsh
elif [ "$num" = 5 ]; then elif [ "$num" = 5 ]; then
clashcron source $CRASHDIR/task/task.sh && task_menu
clashsh clashsh
elif [ "$num" = 6 ]; then elif [ "$num" = 6 ]; then
source $clashdir/getdate.sh && clashlink source $CRASHDIR/getdate.sh && clashlink
clashsh clashsh
elif [ "$num" = 7 ]; then elif [ "$num" = 7 ]; then
@ -1943,7 +1783,7 @@ clashsh(){
elif [ "$num" = 9 ]; then elif [ "$num" = 9 ]; then
checkcfg=$(cat $CFG_PATH) checkcfg=$(cat $CFG_PATH)
source $clashdir/getdate.sh && update source $CRASHDIR/getdate.sh && update
if [ -n "$PID" ];then if [ -n "$PID" ];then
checkcfg_new=$(cat $CFG_PATH) checkcfg_new=$(cat $CFG_PATH)
[ "$checkcfg" != "$checkcfg_new" ] && checkrestart [ "$checkcfg" != "$checkcfg_new" ] && checkrestart
@ -1956,10 +1796,10 @@ clashsh(){
fi fi
} }
[ -z "$clashdir" ] && { [ -z "$CRASHDIR" ] && {
echo 环境变量配置有误!正在初始化~~~ echo 环境变量配置有误!正在初始化~~~
clashdir=$(cd `dirname $0`; pwd) CRASHDIR=$(cd `dirname $0`; pwd)
source $clashdir/init.sh source $CRASHDIR/init.sh
sleep 1 sleep 1
echo 请重启SSH窗口以完成初始化 echo 请重启SSH窗口以完成初始化
exit exit
@ -1970,7 +1810,7 @@ clashsh(){
case "$1" in case "$1" in
-h) -h)
echo ----------------------------------------- echo -----------------------------------------
echo "欢迎使用ShellClash" echo "欢迎使用ShellCrash"
echo ----------------------------------------- echo -----------------------------------------
echo " -t 测试模式" echo " -t 测试模式"
echo " -h 帮助列表" echo " -h 帮助列表"
@ -1982,46 +1822,48 @@ case "$1" in
echo ----------------------------------------- echo -----------------------------------------
echo "在线求助t.me/ShellClash" echo "在线求助t.me/ShellClash"
echo "官方博客juewuy.github.io" echo "官方博客juewuy.github.io"
echo "发布页面github.com/juewuy/ShellClash" echo "发布页面github.com/juewuy/ShellCrash"
echo ----------------------------------------- echo -----------------------------------------
;; ;;
-t) -t)
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
$shtype -x $clashdir/clash.sh $shtype -x $CRASHDIR/clash.sh
;; ;;
-s) -s)
$clashdir/start.sh $2 $3 $4 $5 $6 $CRASHDIR/start.sh $2 $3 $4 $5 $6
;; ;;
-st) -st)
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
$shtype -x $clashdir/start.sh $2 $3 $4 $5 $6 $shtype -x $CRASHDIR/start.sh $2 $3 $4 $5 $6
;; ;;
-u) -u)
read -p "确认卸载ShellClash(警告:该操作不可逆!)[1/0] > " res read -p "确认卸载ShellCrash(警告:该操作不可逆!)[1/0] > " res
if [ "$res" = '1' ]; then if [ "$res" = '1' ]; then
$clashdir/start.sh stop $CRASHDIR/start.sh stop
$clashdir/start.sh cronset "clash服务" $CRASHDIR/start.sh cronset "clash服务"
$clashdir/start.sh cronset "订阅链接" $CRASHDIR/start.sh cronset "订阅链接"
$clashdir/start.sh cronset "ShellClash初始化" $CRASHDIR/start.sh cronset "ShellCrash初始化"
read -p "是否保留脚本配置及订阅文件?[1/0] > " res read -p "是否保留脚本配置及订阅文件?[1/0] > " res
if [ "$res" = '1' ]; then if [ "$res" = '1' ]; then
mv -f $clashdir/configs /tmp/clash_$USER mv -f $CRASHDIR/configs /tmp/clash_$USER
mv -f $clashdir/yamls /tmp/clash_$USER mv -f $CRASHDIR/yamls /tmp/clash_$USER
rm -rf $clashdir/* rm -rf $CRASHDIR/*
mv -f /tmp/clash_$USER/configs $clashdir mv -f /tmp/clash_$USER/configs $CRASHDIR
mv -f /tmp/clash_$USER/yamls $clashdir mv -f /tmp/clash_$USER/yamls $CRASHDIR
else else
rm -rf $clashdir rm -rf $CRASHDIR
fi fi
[ -w ~/.bashrc ] && profile=~/.bashrc [ -w ~/.bashrc ] && profile=~/.bashrc
[ -w /etc/profile ] && profile=/etc/profile [ -w /etc/profile ] && profile=/etc/profile
sed -i '/alias clash=*/'d $profile sed -i '/alias clash=*/'d $profile
sed -i '/export clashdir=*/'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 '/ALL_PROXY/'d $profile sed -i '/ALL_PROXY/'d $profile
sed -i "/启用外网访问SSH服务/d" /etc/firewall.user sed -i "/启用外网访问SSH服务/d" /etc/firewall.user
sed -i '/ShellClash初始化/'d /etc/storage/started_script.sh 2>/dev/null sed -i '/ShellCrash初始化/'d /etc/storage/started_script.sh 2>/dev/null
sed -i '/ShellClash初始化/'d /jffs/.asusrouter 2>/dev/null sed -i '/ShellCrash初始化/'d /jffs/.asusrouter 2>/dev/null
rm -rf $bindir rm -rf $bindir
rm -rf /etc/init.d/clash rm -rf /etc/init.d/clash
rm -rf /etc/systemd/system/clash.service rm -rf /etc/systemd/system/clash.service
@ -2033,7 +1875,7 @@ case "$1" in
nvram set script_usbmount="" 2>/dev/null nvram set script_usbmount="" 2>/dev/null
nvram commit 2>/dev/null nvram commit 2>/dev/null
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[36m已卸载ShellClash相关文件有缘再会\033[0m" echo -e "\033[36m已卸载ShellCrash相关文件有缘再会\033[0m"
echo -e "\033[33m请手动关闭当前窗口以重置环境变量\033[0m" echo -e "\033[33m请手动关闭当前窗口以重置环境变量\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
exit exit

View File

@ -6,9 +6,9 @@ SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1 SERVICE_WRITE_PID=1
USE_PROCD=1 USE_PROCD=1
#获取目录 #获取目录
DIR=$(cat /etc/profile | grep clashdir | awk -F "\"" '{print $2}') DIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}')
[ -z "$DIR" ] && DIR=$(cat ~/.bashrc | grep clashdir | awk -F "\"" '{print $2}') [ -z "$DIR" ] && DIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}')
BINDIR=$(cat $DIR/configs/ShellClash.cfg | grep bindir | awk -F "=" '{print $2}') BINDIR=$(cat $DIR/configs/ShellCrash.cfg | grep bindir | awk -F "=" '{print $2}')
[ -z "$BINDIR" ] && BINDIR=$DIR [ -z "$BINDIR" ] && BINDIR=$DIR
start_service() { start_service() {

View File

@ -12,18 +12,18 @@ dir_avail(){
#导入订阅、配置文件相关 #导入订阅、配置文件相关
linkconfig(){ linkconfig(){
echo ----------------------------------------------- echo -----------------------------------------------
echo 当前使用规则为:$(grep -aE '^5' $clashdir/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $2}') echo 当前使用规则为:$(grep -aE '^5' $CRASHDIR/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $2}')
grep -aE '^5' $clashdir/configs/servers.list | awk '{print " "NR" "$2$4}' grep -aE '^5' $CRASHDIR/configs/servers.list | awk '{print " "NR" "$2$4}'
echo ----------------------------------------------- echo -----------------------------------------------
echo 0 返回上级菜单 echo 0 返回上级菜单
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
totalnum=$(grep -acE '^5' $clashdir/configs/servers.list ) totalnum=$(grep -acE '^5' $CRASHDIR/configs/servers.list )
if [ -z "$num" ] || [ "$num" -gt "$totalnum" ];then if [ -z "$num" ] || [ "$num" -gt "$totalnum" ];then
errornum errornum
elif [ "$num" = 0 ];then elif [ "$num" = 0 ];then
echo echo
elif [ "$num" -le "$totalnum" ];then elif [ "$num" -le "$totalnum" ];then
#将对应标记值写入mark #将对应标记值写入配置
rule_link=$num rule_link=$num
setconfig rule_link $rule_link setconfig rule_link $rule_link
echo ----------------------------------------------- echo -----------------------------------------------
@ -34,18 +34,18 @@ linkserver(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[36m以下为互联网采集的第三方服务器具体安全性请自行斟酌\033[0m" echo -e "\033[36m以下为互联网采集的第三方服务器具体安全性请自行斟酌\033[0m"
echo -e "\033[32m感谢以下作者的无私奉献\033[0m" echo -e "\033[32m感谢以下作者的无私奉献\033[0m"
echo 当前使用后端为:$(grep -aE '^3|^4' $clashdir/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}') echo 当前使用后端为:$(grep -aE '^3|^4' $CRASHDIR/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}')
grep -aE '^3|^4' $clashdir/configs/servers.list | awk '{print " "NR" "$3" "$2}' grep -aE '^3|^4' $CRASHDIR/configs/servers.list | awk '{print " "NR" "$3" "$2}'
echo ----------------------------------------------- echo -----------------------------------------------
echo 0 返回上级菜单 echo 0 返回上级菜单
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
totalnum=$(grep -acE '^3|^4' $clashdir/configs/servers.list ) totalnum=$(grep -acE '^3|^4' $CRASHDIR/configs/servers.list )
if [ -z "$num" ] || [ "$num" -gt "$totalnum" ];then if [ -z "$num" ] || [ "$num" -gt "$totalnum" ];then
errornum errornum
elif [ "$num" = 0 ];then elif [ "$num" = 0 ];then
echo echo
elif [ "$num" -le "$totalnum" ];then elif [ "$num" -le "$totalnum" ];then
#将对应标记值写入mark #将对应标记值写入配置
server_link=$num server_link=$num
setconfig server_link $server_link setconfig server_link $server_link
echo ----------------------------------------------- echo -----------------------------------------------
@ -93,10 +93,10 @@ linkfilter2(){
setconfig include \'$include\' setconfig include \'$include\'
} }
getyaml(){ getyaml(){
$clashdir/start.sh getyaml $CRASHDIR/start.sh getyaml
if [ "$?" = 0 ];then if [ "$?" = 0 ];then
if [ "$inuserguide" != 1 ];then if [ "$inuserguide" != 1 ];then
read -p "是否启动clash服务以使配置文件生效?(1/0) > " res read -p "是否启动服务以使配置文件生效?(1/0) > " res
[ "$res" = 1 ] && clashstart || clashsh [ "$res" = 1 ] && clashstart || clashsh
exit; exit;
fi fi
@ -142,7 +142,7 @@ getlink(){
elif [ "$link" = '1' ]; then elif [ "$link" = '1' ]; then
if [ -n "$Url_link" ];then if [ -n "$Url_link" ];then
i=100 i=100
#将用户链接写入mark #将用户链接写入配置
setconfig Https setconfig Https
setconfig Url \'$Url_link\' setconfig Url \'$Url_link\'
#获取在线yaml文件 #获取在线yaml文件
@ -197,7 +197,7 @@ getlink2(){
echo -e "\033[4;32m$link\033[0m" echo -e "\033[4;32m$link\033[0m"
read -p "确认导入配置文件原配置文件将被更名为config.yaml.bak![1/0] > " res read -p "确认导入配置文件原配置文件将被更名为config.yaml.bak![1/0] > " res
if [ "$res" = '1' ]; then if [ "$res" = '1' ]; then
#将用户链接写入mark #将用户链接写入配置
sed -i '/Url=*/'d $CFG_PATH sed -i '/Url=*/'d $CFG_PATH
setconfig Https \'$link\' setconfig Https \'$link\'
setconfig Url setconfig Url
@ -278,8 +278,10 @@ setrules(){
0) ;; 0) ;;
'') ;; '') ;;
*) *)
if [ $num -le $(cat $YAMLSDIR/rules.yaml | grep -Ev '^#' | grep -Ev '^ *$' | wc -l) ];then text=$(cat $YAMLSDIR/rules.yaml | grep -Ev '^#' | sed -n "$num p")
sed -i "$num{/^\s*[^#]/d}" $YAMLSDIR/rules.yaml if [ -n $text ];then
sed -i "/$text/d" $YAMLSDIR/rules.yaml
sleep 1
del_rule_type del_rule_type
else else
errornum errornum
@ -292,7 +294,7 @@ setrules(){
echo -e "\033[36m如需批量操作请手动编辑$YAMLSDIR/rules.yaml\033[0m" echo -e "\033[36m如需批量操作请手动编辑$YAMLSDIR/rules.yaml\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 新增自定义规则" echo -e " 1 新增自定义规则"
echo -e " 2 管理自定义规则" echo -e " 2 移除自定义规则"
echo -e " 3 清空规则列表" echo -e " 3 清空规则列表"
echo -e " 4 配置节点绕过: \033[36m$proxies_bypass\033[0m" echo -e " 4 配置节点绕过: \033[36m$proxies_bypass\033[0m"
echo -e " 0 返回上级菜单" echo -e " 0 返回上级菜单"
@ -323,7 +325,7 @@ setrules(){
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$proxies_bypass" = "未启用" ];then if [ "$proxies_bypass" = "未启用" ];then
echo -e "\033[33m本功能会自动将当前配置文件中的节点域名或IP设置为直连规则以防止出现双重流量\033[0m" echo -e "\033[33m本功能会自动将当前配置文件中的节点域名或IP设置为直连规则以防止出现双重流量\033[0m"
echo -e "\033[33m请确保下游设备使用的节点与ShellClash中使用的节点相同否则无法生效\033[0m" echo -e "\033[33m请确保下游设备使用的节点与ShellCrash中使用的节点相同否则无法生效\033[0m"
read -p "启用节点绕过?(1/0) > " res read -p "启用节点绕过?(1/0) > " res
[ "$res" = "1" ] && proxies_bypass=已启用 [ "$res" = "1" ] && proxies_bypass=已启用
else else
@ -513,7 +515,7 @@ setproxies(){
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$proxies_bypass" = "未启用" ];then if [ "$proxies_bypass" = "未启用" ];then
echo -e "\033[33m本功能会自动将当前配置文件中的节点域名或IP设置为直连规则以防止出现双重流量\033[0m" echo -e "\033[33m本功能会自动将当前配置文件中的节点域名或IP设置为直连规则以防止出现双重流量\033[0m"
echo -e "\033[33m请确保下游设备使用的节点与ShellClash中使用的节点相同否则无法生效\033[0m" echo -e "\033[33m请确保下游设备使用的节点与ShellCrash中使用的节点相同否则无法生效\033[0m"
read -p "启用节点绕过?(1/0) > " res read -p "启用节点绕过?(1/0) > " res
[ "$res" = "1" ] && proxies_bypass=已启用 [ "$res" = "1" ] && proxies_bypass=已启用
else else
@ -548,10 +550,10 @@ override(){
source $CFG_PATH source $CFG_PATH
if [ -n "$(pidof clash)" ];then if [ -n "$(pidof clash)" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[33m检测到clash服务正在运行,需要先停止clash服务!\033[0m" echo -e "\033[33m检测到服务正在运行,需要先停止服务!\033[0m"
read -p "是否停止clash服务?(1/0) > " res read -p "是否停止服务?(1/0) > " res
if [ "$res" = "1" ];then if [ "$res" = "1" ];then
$clashdir/start.sh stop $CRASHDIR/start.sh stop
setport setport
fi fi
else else
@ -686,7 +688,7 @@ clashlink(){
if [ "$res" = '1' ]; then if [ "$res" = '1' ]; then
mv $YAMLSDIR/config.yaml.bak $YAMLSDIR/config.yaml mv $YAMLSDIR/config.yaml.bak $YAMLSDIR/config.yaml
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m配置文件已还原请手动重启clash服务!\033[0m" echo -e "\033[32m配置文件已还原请手动重启服务!\033[0m"
sleep 1 sleep 1
else else
echo ----------------------------------------------- echo -----------------------------------------------
@ -715,7 +717,8 @@ clashlink(){
fi fi
;; ;;
5) 5)
clashcron source $CRASHDIR/task/task.sh && task_add
clashlink
;; ;;
6) 6)
checkcfg=$(cat $CFG_PATH) checkcfg=$(cat $CFG_PATH)
@ -731,23 +734,23 @@ clashlink(){
} }
#下载更新相关 #下载更新相关
gettar(){ gettar(){
$clashdir/start.sh webget $TMPDIR/clashfm.tar.gz $tarurl $CRASHDIR/start.sh webget $TMPDIR/clashfm.tar.gz $tarurl
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo -e "\033[33m文件下载失败\033[0m" echo -e "\033[33m文件下载失败\033[0m"
error_down error_down
else else
$clashdir/start.sh stop 2>/dev/null $CRASHDIR/start.sh stop 2>/dev/null
#解压 #解压
echo ----------------------------------------------- echo -----------------------------------------------
echo 开始解压文件! echo 开始解压文件!
mkdir -p $clashdir > /dev/null mkdir -p $CRASHDIR > /dev/null
tar -zxvf "$TMPDIR/clashfm.tar.gz" -C $clashdir/ tar -zxvf "$TMPDIR/clashfm.tar.gz" -C $CRASHDIR/
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
rm -rf $TMPDIR/clashfm.tar.gz rm -rf $TMPDIR/clashfm.tar.gz
echo -e "\033[33m文件解压失败\033[0m" echo -e "\033[33m文件解压失败\033[0m"
error_down error_down
else else
source $clashdir/init.sh >/dev/null source $CRASHDIR/init.sh >/dev/null
echo -e "\033[32m脚本更新成功\033[0m" echo -e "\033[32m脚本更新成功\033[0m"
fi fi
fi fi
@ -757,7 +760,7 @@ getsh(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "当前脚本版本为:\033[33m $versionsh_l \033[0m" echo -e "当前脚本版本为:\033[33m $versionsh_l \033[0m"
echo -e "最新脚本版本为:\033[32m $release_new \033[0m" echo -e "最新脚本版本为:\033[32m $release_new \033[0m"
echo -e "注意更新时会停止clash服务!" echo -e "注意更新时会停止服务!"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "是否更新脚本?[1/0] > " res read -p "是否更新脚本?[1/0] > " res
if [ "$res" = '1' ]; then if [ "$res" = '1' ]; then
@ -812,13 +815,14 @@ getcore(){
#获取在线clash核心文件 #获取在线clash核心文件
echo ----------------------------------------------- echo -----------------------------------------------
echo 正在在线获取clash核心文件…… echo 正在在线获取clash核心文件……
$clashdir/start.sh webget $TMPDIR/clash.new $corelink $CRASHDIR/start.sh webget $TMPDIR/clash.new $corelink
if [ "$?" = "1" ];then if [ "$?" = "1" ];then
echo -e "\033[31m核心文件下载失败\033[0m" echo -e "\033[31m核心文件下载失败\033[0m"
rm -rf $TMPDIR/clash.new rm -rf $TMPDIR/clash.new
[ -z "$custcorelink" ] && error_down [ -z "$custcorelink" ] && error_down
else else
chmod +x $TMPDIR/clash.new chmod +x $TMPDIR/clash.new
$CRASHDIR/start.sh stop
clashv=$($TMPDIR/clash.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //') clashv=$($TMPDIR/clash.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //')
if [ -z "$clashv" ];then if [ -z "$clashv" ];then
echo -e "\033[31m核心文件下载成功但校验失败请尝试手动指定CPU版本\033[0m" echo -e "\033[31m核心文件下载成功但校验失败请尝试手动指定CPU版本\033[0m"
@ -829,7 +833,6 @@ getcore(){
mv -f $TMPDIR/clash.new $bindir/clash mv -f $TMPDIR/clash.new $bindir/clash
chmod +x $bindir/clash chmod +x $bindir/clash
setconfig clashcore $clashcore setconfig clashcore $clashcore
setconfig clashv $version
fi fi
fi fi
} }
@ -838,7 +841,7 @@ setcustcore(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[36m自定义内核均未经过适配可能存在部分功能不兼容的问题\033[0m" echo -e "\033[36m自定义内核均未经过适配可能存在部分功能不兼容的问题\033[0m"
echo -e "\033[36m如你不熟悉clash的运行机制请使用脚本已经适配过的内核\033[0m" echo -e "\033[36m如你不熟悉clash的运行机制请使用脚本已经适配过的内核\033[0m"
echo -e "\033[36m自定义内核不兼容小闪存模式且下载可能依赖clash服务!\033[0m" echo -e "\033[36m自定义内核不兼容小闪存模式且下载可能依赖服务!\033[0m"
echo -e "\033[33m继续后如出现任何问题请务必自行解决一切提问恕不受理\033[0m" echo -e "\033[33m继续后如出现任何问题请务必自行解决一切提问恕不受理\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
sleep 1 sleep 1
@ -852,18 +855,18 @@ setcustcore(){
case "$num" in case "$num" in
1) 1)
clashcore=clashpre clashcore=clashpre
custcorelink=https://github.com/juewuy/ShellClash/releases/download/clash.premium.latest/clash-linux-$cpucore custcorelink=https://github.com/juewuy/ShellCrash/releases/download/clash.premium.latest/clash-linux-$cpucore
getcore getcore
;; ;;
2) 2)
clashcore=clash.meta clashcore=meta
custcorelink=https://github.com/juewuy/ShellClash/releases/download/clash.meta.alpha/clash-linux-$cpucore custcorelink=https://github.com/juewuy/ShellCrash/releases/download/clash.meta.alpha/clash-linux-$cpucore
getcore getcore
;; ;;
3) 3)
read -p "请输入自定义内核的链接地址(必须是二进制文件) > " link read -p "请输入自定义内核的链接地址(必须是二进制文件) > " link
[ -n "$link" ] && custcorelink="$link" [ -n "$link" ] && custcorelink="$link"
clashcore=clash.meta clashcore=meta
getcore getcore
;; ;;
*) *)
@ -874,7 +877,7 @@ setcustcore(){
} }
setcore(){ setcore(){
#获取核心及版本信息 #获取核心及版本信息
[ ! -f $clashdir/clash ] && clashcore="未安装核心" [ ! -f $CRASHDIR/clash ] && clashcore="未安装核心"
### ###
echo ----------------------------------------------- echo -----------------------------------------------
[ -z "$cpucore" ] && getcpucore [ -z "$cpucore" ] && getcpucore
@ -912,7 +915,7 @@ setcore(){
getcore getcore
;; ;;
3) 3)
clashcore=clash.meta clashcore=meta
custcorelink='' custcorelink=''
getcore getcore
;; ;;
@ -932,7 +935,7 @@ setcore(){
getgeo(){ getgeo(){
echo ----------------------------------------------- echo -----------------------------------------------
echo 正在从服务器获取数据库文件………… echo 正在从服务器获取数据库文件…………
$clashdir/start.sh webget $TMPDIR/$geoname $update_url/bin/geodata/$geotype $CRASHDIR/start.sh webget $TMPDIR/$geoname $update_url/bin/geodata/$geotype
if [ "$?" = "1" ];then if [ "$?" = "1" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m文件下载失败\033[0m" echo -e "\033[31m文件下载失败\033[0m"
@ -940,26 +943,29 @@ getgeo(){
else else
mv -f $TMPDIR/$geoname $bindir/$geoname mv -f $TMPDIR/$geoname $bindir/$geoname
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32mGeoIP/CN_IP数据库文件下载成功\033[0m" echo -e "\033[32m$geotype数据库文件下载成功\033[0m"
Geo_v=$GeoIP_v #全球版GeoIP和精简版CN-IP数据库不共存
setconfig Geo_v $GeoIP_v [ "$geoname" = "Country.mmdb" ] && {
if [ "$geoname" = "Country.mmdb" ];then setconfig Country_v
geotype=$geotype setconfig cn_mini_v
setconfig geotype $geotype }
fi geo_v="$(echo $geotype | awk -F "." '{print $1}')_v"
setconfig $geo_v $GeoIP_v
fi fi
sleep 1
} }
setgeo(){ setgeo(){
[ -n "$cn_mini.mmdb_v" ] && geo_type_des=精简版 || geo_type_des=全球版
echo ----------------------------------------------- echo -----------------------------------------------
[ "$geotype" = "cn_mini.mmdb" ] && echo -e "当前使用的是\033[47;30m精简版数据库\033[0m" || echo -e "当前使用的是\033[47;30m全球版数据库\033[0m" echo -e "\033[36m请选择需要更新的GeoIP/CN_IP数据库\033[0m"
echo -e "\033[36m请选择需要更新/切换的GeoIP/CN_IP数据库\033[0m" echo -e "\033[36m全球版GeoIP和精简版CN-IP数据库不共存\033[0m"
echo -e "在线数据库最新版本:\033[32m$GeoIP_v\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 由\033[32malecthw\033[0m提供的全球版GeoIP数据库(约6mb)" echo -e " 1 全球版GeoIP数据库(约6mb) \033[33m$Country_v\033[0m"
echo -e " 2 由\033[32mHackl0us\033[0m提供的精简版CN-IP数据库(约0.2mb)" echo -e " 2 精简版CN-IP数据库(约0.2mb) \033[33m$cn_mini_v\033[0m"
echo -e " 3 由\033[32m17mon\033[0m提供的CN-IP文件(需启用CN_IP绕过约0.2mb)" echo -e " 3 CN-IP绕过文件(约0.2mb) \033[33m$china_ip_list_v\033[0m"
echo -e " 4 由\033[32mChanthMiao\033[0m提供的CN-IPV6文件(需ipv6启用CN_IP绕过约50kb)" echo -e " 4 CN-IPV6绕过文件(约50kb) \033[33m$china_ipv6_list_v\033[0m"
[ "$clashcore" = "clash.meta" ] && \ echo -e " 5 GeoSite数据库(约4.5mb) \033[33m$geosite_v\033[0m"
echo -e " 5 由\033[32mLoyalsoldier\033[0m提供的GeoSite数据库(限Meta内核约4.5mb)"
echo " 0 返回上级菜单" echo " 0 返回上级菜单"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
@ -967,10 +973,12 @@ setgeo(){
geotype=Country.mmdb geotype=Country.mmdb
geoname=Country.mmdb geoname=Country.mmdb
getgeo getgeo
setgeo
elif [ "$num" = '2' ]; then elif [ "$num" = '2' ]; then
geotype=cn_mini.mmdb geotype=cn_mini.mmdb
geoname=Country.mmdb geoname=Country.mmdb
getgeo getgeo
setgeo
elif [ "$num" = '3' ]; then elif [ "$num" = '3' ]; then
if [ "$cn_ip_route" = "已开启" ]; then if [ "$cn_ip_route" = "已开启" ]; then
geotype=china_ip_list.txt geotype=china_ip_list.txt
@ -981,6 +989,7 @@ setgeo(){
echo -e "\033[31m未开启绕过内核功能无需更新CN-IP文件\033[0m" echo -e "\033[31m未开启绕过内核功能无需更新CN-IP文件\033[0m"
sleep 1 sleep 1
fi fi
setgeo
elif [ "$num" = '4' ]; then elif [ "$num" = '4' ]; then
if [ "$cn_ipv6_route" = "已开启" -a "$ipv6_redir" = "已开启" ]; then if [ "$cn_ipv6_route" = "已开启" -a "$ipv6_redir" = "已开启" ]; then
geotype=china_ipv6_list.txt geotype=china_ipv6_list.txt
@ -991,10 +1000,18 @@ setgeo(){
echo -e "\033[31m未开启ipv6下CN绕过功能无需更新CN-IPV6文件\033[0m" echo -e "\033[31m未开启ipv6下CN绕过功能无需更新CN-IPV6文件\033[0m"
sleep 1 sleep 1
fi fi
setgeo
elif [ "$num" = '5' ]; then elif [ "$num" = '5' ]; then
geotype=geosite.dat if [ "$clashcore" = "meta" ]; then
geoname=GeoSite.dat geotype=geosite.dat
getgeo geoname=GeoSite.dat
getgeo
else
echo -----------------------------------------------
echo -e "\033[31m当前未使用meta内核无需更新GeoSite数据库\033[0m"
sleep 1
fi
setgeo
else else
update update
fi fi
@ -1002,21 +1019,21 @@ setgeo(){
getdb(){ getdb(){
#下载及安装 #下载及安装
if [ -f /www/clash/index.html -o -f $clashdir/ui/index.html ];then if [ -f /www/clash/index.html -o -f $CRASHDIR/ui/index.html ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m检测到您已经安装过本地面板了\033[0m" echo -e "\033[31m检测到您已经安装过本地面板了\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "是否覆盖安装?[1/0] > " res read -p "是否覆盖安装?[1/0] > " res
if [ "$res" = 1 ]; then if [ "$res" = 1 ]; then
rm -rf /www/clash rm -rf /www/clash
rm -rf $clashdir/ui rm -rf $CRASHDIR/ui
rm -rf $bindir/ui rm -rf $bindir/ui
fi fi
fi fi
dblink="${update_url}/bin/dashboard/${db_type}.tar.gz" dblink="${update_url}/bin/dashboard/${db_type}.tar.gz"
echo ----------------------------------------------- echo -----------------------------------------------
echo 正在连接服务器获取安装文件………… echo 正在连接服务器获取安装文件…………
$clashdir/start.sh webget $TMPDIR/clashdb.tar.gz $dblink $CRASHDIR/start.sh webget $TMPDIR/clashdb.tar.gz $dblink
if [ "$?" = "1" ];then if [ "$?" = "1" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m文件下载失败\033[0m" echo -e "\033[31m文件下载失败\033[0m"
@ -1053,14 +1070,14 @@ setdb(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "请选择面板\033[33m安装目录\033[0m" echo -e "请选择面板\033[33m安装目录\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 在$clashdir/ui目录安装" echo -e " 1 在$CRASHDIR/ui目录安装"
echo -e " 2 在/www/clash目录安装" echo -e " 2 在/www/clash目录安装"
echo ----------------------------------------------- echo -----------------------------------------------
echo " 0 返回上级菜单" echo " 0 返回上级菜单"
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
if [ "$num" = '1' ]; then if [ "$num" = '1' ]; then
dbdir=$clashdir/ui dbdir=$CRASHDIR/ui
hostdir=":$db_port/ui" hostdir=":$db_port/ui"
elif [ "$num" = '2' ]; then elif [ "$num" = '2' ]; then
dbdir=/www/clash dbdir=/www/clash
@ -1069,7 +1086,7 @@ setdb(){
setdb setdb
fi fi
else else
dbdir=$clashdir/ui dbdir=$CRASHDIR/ui
hostdir=":$db_port/ui" hostdir=":$db_port/ui"
fi fi
} }
@ -1113,7 +1130,7 @@ setdb(){
read -p "确认卸载本地面板?(1/0) > " res read -p "确认卸载本地面板?(1/0) > " res
if [ "$res" = 1 ];then if [ "$res" = 1 ];then
rm -rf /www/clash rm -rf /www/clash
rm -rf $clashdir/ui rm -rf $CRASHDIR/ui
rm -rf $bindir/ui rm -rf $bindir/ui
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m面板已经卸载\033[0m" echo -e "\033[31m面板已经卸载\033[0m"
@ -1128,7 +1145,7 @@ getcrt(){
crtlink="${update_url}/bin/fix/ca-certificates.crt" crtlink="${update_url}/bin/fix/ca-certificates.crt"
echo ----------------------------------------------- echo -----------------------------------------------
echo 正在连接服务器获取安装文件………… echo 正在连接服务器获取安装文件…………
$clashdir/start.sh webget $TMPDIR/ca-certificates.crt $crtlink $CRASHDIR/start.sh webget $TMPDIR/ca-certificates.crt $crtlink
if [ "$?" = "1" ];then if [ "$?" = "1" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m文件下载失败\033[0m" echo -e "\033[31m文件下载失败\033[0m"
@ -1137,7 +1154,7 @@ getcrt(){
echo ----------------------------------------------- echo -----------------------------------------------
mkdir -p $openssldir mkdir -p $openssldir
mv -f $TMPDIR/ca-certificates.crt $crtdir mv -f $TMPDIR/ca-certificates.crt $crtdir
$clashdir/start.sh webget $TMPDIR/ssl_test https://baidu.com echooff rediron skipceroff $CRASHDIR/start.sh webget $TMPDIR/ssl_test https://baidu.com echooff rediron skipceroff
if [ "$?" = "1" ];then if [ "$?" = "1" ];then
export CURL_CA_BUNDLE=$crtdir export CURL_CA_BUNDLE=$crtdir
echo "export CURL_CA_BUNDLE=$crtdir" >> /etc/profile echo "export CURL_CA_BUNDLE=$crtdir" >> /etc/profile
@ -1178,7 +1195,7 @@ setcrt(){
#安装源 #安装源
setserver(){ setserver(){
saveserver(){ saveserver(){
#写入mark文件 #写入配置文件
setconfig update_url \'$update_url\' setconfig update_url \'$update_url\'
setconfig release_url \'$release_url\' setconfig release_url \'$release_url\'
echo ----------------------------------------------- echo -----------------------------------------------
@ -1186,10 +1203,10 @@ setserver(){
release_new="" release_new=""
} }
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[30;47m切换ShellClash版本及更新源地址\033[0m" echo -e "\033[30;47m切换ShellCrash版本及更新源地址\033[0m"
echo -e "当前源地址:\033[4;32m$update_url\033[0m" echo -e "当前源地址:\033[4;32m$update_url\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
grep -aE '^1|^2' $clashdir/configs/servers.list | awk '{print " "NR" "$4" "$2}' grep -aE '^1|^2' $CRASHDIR/configs/servers.list | awk '{print " "NR" "$4" "$2}'
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " a 自定义源地址(用于本地源或自建源)" echo -e " a 自定义源地址(用于本地源或自建源)"
echo -e " b \033[31m版本回退\033[0m" echo -e " b \033[31m版本回退\033[0m"
@ -1197,11 +1214,11 @@ setserver(){
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
case $num in case $num in
[0-99]) [0-99])
release_type=$(grep -aE '^1|^2' $clashdir/configs/servers.list | sed -n ""$num"p" | awk '{print $4}') release_type=$(grep -aE '^1|^2' $CRASHDIR/configs/servers.list | sed -n ""$num"p" | awk '{print $4}')
if [ "release_type" = "稳定版" ];then if [ "release_type" = "稳定版" ];then
release_url=$(grep -aE '^1' $clashdir/configs/servers.list | sed -n ""$num"p" | awk '{print $3}') release_url=$(grep -aE '^1' $CRASHDIR/configs/servers.list | sed -n ""$num"p" | awk '{print $3}')
else else
update_url=$(grep -aE '^1|^2' $clashdir/configs/servers.list | sed -n ""$num"p" | awk '{print $3}') update_url=$(grep -aE '^1|^2' $CRASHDIR/configs/servers.list | sed -n ""$num"p" | awk '{print $3}')
unset release_url unset release_url
fi fi
saveserver saveserver
@ -1219,8 +1236,8 @@ setserver(){
;; ;;
b) b)
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[33m如无法连接请务必先启用clash服务!!!\033[0m" echo -e "\033[33m如无法连接请务必先启用服务!!!\033[0m"
$clashdir/start.sh webget $TMPDIR/clashrelease https://raw.githubusercontent.com/juewuy/ShellClash/master/bin/release_version echooff rediroff 2>$TMPDIR/clashrelease $CRASHDIR/start.sh webget $TMPDIR/clashrelease https://raw.githubusercontent.com/juewuy/ShellCrash/master/bin/release_version echooff rediroff 2>$TMPDIR/clashrelease
echo -e "\033[31m请选择想要回退至的release版本\033[0m" echo -e "\033[31m请选择想要回退至的release版本\033[0m"
cat $TMPDIR/clashrelease | awk '{print " "NR" "$1}' cat $TMPDIR/clashrelease | awk '{print " "NR" "$1}'
echo -e " 0 返回上级菜单" echo -e " 0 返回上级菜单"
@ -1229,7 +1246,7 @@ setserver(){
setserver setserver
elif [ $num -le $(cat $TMPDIR/clashrelease 2>/dev/null | awk 'END{print NR}') ]; then elif [ $num -le $(cat $TMPDIR/clashrelease 2>/dev/null | awk 'END{print NR}') ]; then
release_version=$(cat $TMPDIR/clashrelease | awk '{print $1}' | sed -n "$num"p) release_version=$(cat $TMPDIR/clashrelease | awk '{print $1}' | sed -n "$num"p)
update_url="https://raw.githubusercontent.com/juewuy/ShellClash/$release_version" update_url="https://raw.githubusercontent.com/juewuy/ShellCrash/$release_version"
saveserver saveserver
unset release_url unset release_url
else else
@ -1248,7 +1265,7 @@ checkupdate(){
if [ -z "$release_new" ];then if [ -z "$release_new" ];then
if [ -n "$release_url" ];then if [ -n "$release_url" ];then
[ -n "$(echo $release_url|grep 'jsdelivr')" ] && check_url=$release_url@master || check_url=$release_url/master [ -n "$(echo $release_url|grep 'jsdelivr')" ] && check_url=$release_url@master || check_url=$release_url/master
$clashdir/start.sh webget $TMPDIR/clashversion $check_url/bin/release_version echoon rediroff 2>$TMPDIR/clashversion $CRASHDIR/start.sh webget $TMPDIR/clashversion $check_url/bin/release_version echoon rediroff 2>$TMPDIR/clashversion
release_new=$(cat $TMPDIR/clashversion | head -1) release_new=$(cat $TMPDIR/clashversion | head -1)
[ -n "$(echo $release_url|grep 'jsdelivr')" ] && update_url=$release_url@$release_new || update_url=$release_url/$release_new [ -n "$(echo $release_url|grep 'jsdelivr')" ] && update_url=$release_url@$release_new || update_url=$release_url/$release_new
setconfig update_url \'$update_url\' setconfig update_url \'$update_url\'
@ -1256,13 +1273,13 @@ if [ -z "$release_new" ];then
else else
release_type=测试版 release_type=测试版
fi fi
$clashdir/start.sh webget $TMPDIR/clashversion $update_url/bin/version echooff $CRASHDIR/start.sh webget $TMPDIR/clashversion $update_url/bin/version echooff
[ "$?" = "0" ] && release_new=$(cat $TMPDIR/clashversion | grep -oE 'versionsh=.*' | awk -F'=' '{ print $2 }') [ "$?" = "0" ] && release_new=$(cat $TMPDIR/clashversion | grep -oE 'versionsh=.*' | awk -F'=' '{ print $2 }')
if [ -n "$release_new" ];then if [ -n "$release_new" ];then
source $TMPDIR/clashversion 2>/dev/null source $TMPDIR/clashversion 2>/dev/null
else else
echo -e "\033[31m检查更新失败请切换其他安装源\033[0m" echo -e "\033[31m检查更新失败请切换其他安装源\033[0m"
echo -e "\033[36m如全部安装源都无法使用请先运行clash服务后再使用更新功能!\033[0m" echo -e "\033[36m如全部安装源都无法使用请先运行服务后再使用更新功能!\033[0m"
sleep 1 sleep 1
setserver setserver
fi fi
@ -1273,30 +1290,27 @@ update(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -ne "\033[32m正在检查更新\033[0m\r" echo -ne "\033[32m正在检查更新\033[0m\r"
checkupdate checkupdate
[ "$clashcore" = "clash" ] && clash_n=$clash_v || clash_n=$clashpre_v
[ "$clashcore" = "clashpre" ] && clash_n=$clashpre_v
[ "$clashcore" = "clash.net" ] && clash_n=$clashnet_v
[ "$clashcore" = "clash.meta" ] && clash_n=$meta_v
clash_v=$($bindir/clash -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //') clash_v=$($bindir/clash -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //')
[ -z "$clash_v" ] && clash_v=$clashv [ -z "$clash_v" ] && clash_v=$clashv
clash_v_new=$(eval echo \$${clashcore}_v)
echo -e "\033[30;47m欢迎使用更新功能\033[0m" echo -e "\033[30;47m欢迎使用更新功能\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "当前目录(\033[32m$clashdir\033[0m)剩余空间:\033[36m$(dir_avail $clashdir -h)\033[0m" echo -e "当前目录(\033[32m$CRASHDIR\033[0m)剩余空间:\033[36m$(dir_avail $CRASHDIR -h)\033[0m"
[ "$(dir_avail $clashdir)" -le 5120 ] && { [ "$(dir_avail $CRASHDIR)" -le 5120 ] && {
echo -e "\033[33m当前目录剩余空间较低建议开启小闪存模式\033[0m" echo -e "\033[33m当前目录剩余空间较低建议开启小闪存模式\033[0m"
sleep 1 sleep 1
} }
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 更新\033[36m管理脚本 \033[33m$versionsh_l\033[0m > \033[32m$versionsh$release_type\033[0m" echo -e " 1 更新\033[36m管理脚本 \033[33m$versionsh_l\033[0m > \033[32m$versionsh$release_type\033[0m"
echo -e " 2 切换\033[33mclash核心 \033[33m$clash_v\033[0m > \033[32m$clash_n\033[0m" echo -e " 2 切换\033[33mclash核心 \033[33m$clash_v\033[0m > \033[32m$clash_v_new\033[0m"
echo -e " 3 更新\033[32mGeoIP/CN-IP \033[33m$Geo_v\033[0m > \033[32m$GeoIP_v\033[0m" echo -e " 3 更新\033[32m数据库文件\033[0m"
echo -e " 4 安装本地\033[35mDashboard\033[0m面板" echo -e " 4 安装本地\033[35mDashboard\033[0m面板"
echo -e " 5 安装/更新本地\033[33m根证书文件\033[0m" echo -e " 5 安装/更新本地\033[33m根证书文件\033[0m"
echo -e " 6 查看\033[32mPAC\033[0m自动代理配置" echo -e " 6 查看\033[32mPAC\033[0m自动代理配置"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 7 切换\033[36m安装源\033[0m及\033[36m安装版本\033[0m" echo -e " 7 切换\033[36m安装源\033[0m及\033[36m安装版本\033[0m"
echo -e " 8 \033[32m重新初始化运行环境\033[0m" echo -e " 8 \033[32m配置自动更新\033[0m"
echo -e " 9 \033[31m卸载\033[34mShellClash\033[0m" echo -e " 9 \033[31m卸载ShellCrash\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "99 \033[36m鸣谢\033[0m" echo -e "99 \033[36m鸣谢\033[0m"
echo -e " 0 返回上级菜单" echo -e " 0 返回上级菜单"
@ -1336,7 +1350,7 @@ update(){
setserver setserver
update update
elif [ "$num" = 8 ]; then elif [ "$num" = 8 ]; then
source $clashdir/init.sh source $CRASHDIR/task/task.sh && task_add
update update
elif [ "$num" = 9 ]; then elif [ "$num" = 9 ]; then
@ -1367,7 +1381,7 @@ userguide(){
forwhat(){ forwhat(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[30;46m 欢迎使用ShellClash新手引导 \033[0m" echo -e "\033[30;46m 欢迎使用ShellCrash新手引导 \033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[33m请先选择你的使用环境 \033[0m" echo -e "\033[33m请先选择你的使用环境 \033[0m"
echo -e "\033[0m(你之后依然可以在设置中更改各种配置)\033[0m" echo -e "\033[0m(你之后依然可以在设置中更改各种配置)\033[0m"
@ -1395,7 +1409,7 @@ userguide(){
#设置开机启动 #设置开机启动
[ -f /etc/rc.common ] && /etc/init.d/clash enable [ -f /etc/rc.common ] && /etc/init.d/clash enable
ckcmd systemctl && systemctl enable clash.service > /dev/null 2>&1 ckcmd systemctl && systemctl enable clash.service > /dev/null 2>&1
rm -rf $clashdir/.dis_startup rm -rf $CRASHDIR/.dis_startup
autostart=enable autostart=enable
#检测IP转发 #检测IP转发
if [ "$(cat /proc/sys/net/ipv4/ip_forward)" = "0" ];then if [ "$(cat /proc/sys/net/ipv4/ip_forward)" = "0" ];then
@ -1423,7 +1437,7 @@ userguide(){
} }
forwhat forwhat
#检测小内存模式 #检测小内存模式
dir_size=$(df $clashdir | awk '{print $4}' | sed 1d) dir_size=$(df $CRASHDIR | awk '{print $4}' | sed 1d)
if [ "$dir_size" -lt 10240 ];then if [ "$dir_size" -lt 10240 ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[33m检测到你的安装目录空间不足10M是否开启小闪存模式\033[0m" echo -e "\033[33m检测到你的安装目录空间不足10M是否开启小闪存模式\033[0m"
@ -1448,7 +1462,7 @@ userguide(){
[ "$res" = 1 ] && checkupdate && getcrt [ "$res" = 1 ] && checkupdate && getcrt
fi fi
#设置加密DNS #设置加密DNS
$clashdir/start.sh webget $TMPDIR/ssl_test https://doh.pub echooff rediron $CRASHDIR/start.sh webget $TMPDIR/ssl_test https://doh.pub echooff rediron
if [ "$?" = "0" ];then if [ "$?" = "0" ];then
dns_nameserver='https://223.5.5.5/dns-query, https://doh.pub/dns-query, tls://dns.rubyfish.cn:853' 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' dns_fallback='https://1.0.0.1/dns-query, https://8.8.4.4/dns-query, https://doh.opendns.com/dns-query'
@ -1489,6 +1503,8 @@ userguide(){
setconfig authentication \'$authentication\' setconfig authentication \'$authentication\'
fi fi
fi fi
#启用推荐的自动任务配置
source $CRASHDIR/task/task.sh && task_recom
#小米设备软固化 #小米设备软固化
if [ "$systype" = "mi_snapshot" ];then if [ "$systype" = "mi_snapshot" ];then
echo ----------------------------------------------- echo -----------------------------------------------
@ -1499,7 +1515,7 @@ userguide(){
#提示导入订阅或者配置文件 #提示导入订阅或者配置文件
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m是否导入配置文件\033[0m(这是运行前的最后一步)" echo -e "\033[32m是否导入配置文件\033[0m(这是运行前的最后一步)"
echo -e "\033[0m你必须拥有一份yaml格式的配置文件才能运行clash服务!\033[0m" echo -e "\033[0m你必须拥有一份yaml格式的配置文件才能运行服务!\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "现在开始导入?(1/0) > " res read -p "现在开始导入?(1/0) > " res
[ "$res" = 1 ] && inuserguide=1 && clashlink && inuserguide="" [ "$res" = 1 ] && inuserguide=1 && clashlink && inuserguide=""
@ -1507,7 +1523,7 @@ userguide(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[36m很好现在只需要执行启动就可以愉快的使用了\033[0m" echo -e "\033[36m很好现在只需要执行启动就可以愉快的使用了\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "立即启动clash服务?(1/0) > " res read -p "立即启动服务?(1/0) > " res
[ "$res" = 1 ] && clashstart && sleep 2 [ "$res" = 1 ] && clashstart && sleep 2
clashsh clashsh
} }
@ -1517,7 +1533,7 @@ testcommand(){
echo -e "\033[30;47m这里是测试命令菜单\033[0m" echo -e "\033[30;47m这里是测试命令菜单\033[0m"
echo -e "\033[33m如遇问题尽量运行相应命令后截图提交issue或TG讨论组\033[0m" echo -e "\033[33m如遇问题尽量运行相应命令后截图提交issue或TG讨论组\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo " 1 查看Clash运行时的报错信息(会停止clash服务)" echo " 1 查看Clash运行时的报错信息(会停止服务)"
echo " 2 查看系统DNS端口(:53)占用 " echo " 2 查看系统DNS端口(:53)占用 "
echo " 3 测试ssl加密(aes-128-gcm)跑分" echo " 3 测试ssl加密(aes-128-gcm)跑分"
echo " 4 查看clash相关路由规则" echo " 4 查看clash相关路由规则"
@ -1532,11 +1548,11 @@ testcommand(){
elif [ "$num" = 0 ]; then elif [ "$num" = 0 ]; then
clashsh clashsh
elif [ "$num" = 1 ]; then elif [ "$num" = 1 ]; then
$clashdir/start.sh stop $CRASHDIR/start.sh stop
echo ----------------------------------------------- echo -----------------------------------------------
if $clashdir/clash -v &>/dev/null;then if $CRASHDIR/clash -v &>/dev/null;then
clash -s modify_yaml &>/dev/null clash -s modify_yaml &>/dev/null
$clashdir/clash -t -d $clashdir -f $TMPDIR/config.yaml $CRASHDIR/clash -t -d $CRASHDIR -f $TMPDIR/config.yaml
[ "$?" = 0 ] && testover=32m测试通过|| testover=31m出现错误请截图后到TG群询问 [ "$?" = 0 ] && testover=32m测试通过|| testover=31m出现错误请截图后到TG群询问
echo -e "\033[$testover\033[0m" echo -e "\033[$testover\033[0m"
else else
@ -1592,7 +1608,7 @@ testcommand(){
exit; exit;
elif [ "$num" = 5 ]; then elif [ "$num" = 5 ]; then
echo ----------------------------------------------- echo -----------------------------------------------
sed -n '1,40p' $clashdir/config.yaml sed -n '1,40p' $CRASHDIR/config.yaml
echo ----------------------------------------------- echo -----------------------------------------------
exit; exit;
elif [ "$num" = 6 ]; then elif [ "$num" = 6 ]; then
@ -1611,4 +1627,10 @@ testcommand(){
errornum errornum
clashsh clashsh
fi fi
} }
case "$1" in
*)
$1
;;
esac

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# Copyright (C) Juewuy # Copyright (C) Juewuy
version=1.8.1 version=1.8.2d
setdir(){ setdir(){
dir_avail(){ dir_avail(){
@ -76,7 +76,7 @@ if [ -n "$systype" ];then
} }
[ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt [ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt
else else
echo -e "\033[33m安装ShellClash至少需要预留约1MB的磁盘空间\033[0m" echo -e "\033[33m安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m"
echo -e " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)" echo -e " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)"
echo -e " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)" echo -e " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)"
echo -e " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)" echo -e " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)"
@ -119,16 +119,16 @@ if [ ! -w $dir ];then
else else
echo -e "目标目录\033[32m$dir\033[0m空间剩余$(dir_avail $dir -h)" echo -e "目标目录\033[32m$dir\033[0m空间剩余$(dir_avail $dir -h)"
read -p "确认安装?(1/0) > " res read -p "确认安装?(1/0) > " res
[ "$res" = "1" ] && clashdir=$dir/clash || setdir [ "$res" = "1" ] && CRASHDIR=$dir/clash || setdir
fi fi
} }
setconfig(){ setconfig(){
#参数1代表变量名参数2代表变量值,参数3即文件路径 #参数1代表变量名参数2代表变量值,参数3即文件路径
[ -z "$3" ] && configpath=$clashdir/configs/ShellClash.cfg || configpath=$3 [ -z "$3" ] && configpath=$CRASHDIR/configs/ShellCrash.cfg || configpath=$3
[ -n "$(grep -E "^${1}=" $configpath)" ] && sed -i "s#^${1}=\(.*\)#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath [ -n "$(grep -E "^${1}=" $configpath)" ] && sed -i "s#^${1}=\(.*\)#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath
} }
$clashdir/start.sh stop 2>/dev/null #防止进程冲突 $CRASHDIR/start.sh stop 2>/dev/null #防止进程冲突
#特殊固件识别及标记 #特殊固件识别及标记
[ -f "/etc/storage/started_script.sh" ] && { [ -f "/etc/storage/started_script.sh" ] && {
systype=Padavan #老毛子固件 systype=Padavan #老毛子固件
@ -143,30 +143,30 @@ $clashdir/start.sh stop 2>/dev/null #防止进程冲突
[ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot #NETGEAR设备 [ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot #NETGEAR设备
#检查环境变量 #检查环境变量
[ -z "$clashdir" -a -d /tmp/SC_tmp ] && { [ -z "$CRASHDIR" -a -d /tmp/SC_tmp ] && {
setdir setdir
} }
#移动文件 #移动文件
mkdir -p $clashdir mkdir -p $CRASHDIR
mv -f /tmp/SC_tmp/* $clashdir 2>/dev/null mv -f /tmp/SC_tmp/* $CRASHDIR 2>/dev/null
#初始化 #初始化
mkdir -p $clashdir/configs mkdir -p $CRASHDIR/configs
[ -f "$clashdir/configs/ShellClash.cfg" ] || echo '#ShellClash配置文件不明勿动' > $clashdir/configs/ShellClash.cfg [ -f "$CRASHDIR/configs/ShellCrash.cfg" ] || echo '#ShellCrash配置文件不明勿动' > $CRASHDIR/configs/ShellCrash.cfg
#本地安装跳过新手引导 #本地安装跳过新手引导
#[ -z "$url" ] && setconfig userguide 1 #[ -z "$url" ] && setconfig userguide 1
#判断系统类型写入不同的启动文件 #判断系统类型写入不同的启动文件
if [ -f /etc/rc.common ];then if [ -f /etc/rc.common ];then
#设为init.d方式启动 #设为init.d方式启动
cp -f $clashdir/clashservice /etc/init.d/clash cp -f $CRASHDIR/clashservice /etc/init.d/clash
chmod 755 /etc/init.d/clash chmod 755 /etc/init.d/clash
else else
[ -w /etc/systemd/system ] && sysdir=/etc/systemd/system [ -w /etc/systemd/system ] && sysdir=/etc/systemd/system
[ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system [ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system
if [ -n "$sysdir" -a -z "$WSL_DISTRO_NAME" ];then #wsl环境不使用systemd if [ -n "$sysdir" -a -z "$WSL_DISTRO_NAME" ];then #wsl环境不使用systemd
#设为systemd方式启动 #设为systemd方式启动
mv -f $clashdir/clash.service $sysdir/clash.service 2>/dev/null mv -f $CRASHDIR/clash.service $sysdir/clash.service 2>/dev/null
sed -i "s%/etc/clash%$clashdir%g" $sysdir/clash.service sed -i "s%/etc/clash%$CRASHDIR%g" $sysdir/clash.service
systemctl daemon-reload systemctl daemon-reload
else else
#设为保守模式启动 #设为保守模式启动
@ -175,8 +175,9 @@ else
fi fi
#修饰文件及版本号 #修饰文件及版本号
type bash &>/dev/null && shtype=bash || shtype=sh type bash &>/dev/null && shtype=bash || shtype=sh
sed -i "s|/bin/sh|/bin/$shtype|" $clashdir/start.sh sed -i "s|/bin/sh|/bin/$shtype|" $CRASHDIR/start.sh
chmod 755 $clashdir/start.sh chmod 755 $CRASHDIR/start.sh
chmod 755 $CRASHDIR/task.sh
setconfig versionsh_l $version setconfig versionsh_l $version
#设置更新地址 #设置更新地址
[ -n "$url" ] && setconfig update_url $url [ -n "$url" ] && setconfig update_url $url
@ -186,15 +187,15 @@ setconfig versionsh_l $version
[ -w ~/.bashrc ] && profile=~/.bashrc [ -w ~/.bashrc ] && profile=~/.bashrc
[ -w /etc/profile ] && profile=/etc/profile [ -w /etc/profile ] && profile=/etc/profile
if [ -n "$profile" ];then if [ -n "$profile" ];then
sed -i '/alias clash=*/'d $profile sed -i '/alias crash=*/'d $profile
echo "alias clash=\"$shtype $clashdir/clash.sh\"" >> $profile #设置快捷命令环境变量 echo "alias crash=\"$shtype $CRASHDIR/clash.sh\"" >> $profile #设置快捷命令环境变量
sed -i '/export clashdir=*/'d $profile sed -i '/export CRASHDIR=*/'d $profile
echo "export clashdir=\"$clashdir\"" >> $profile #设置clash路径环境变量 echo "export CRASHDIR=\"$CRASHDIR\"" >> $profile #设置clash路径环境变量
source $profile &>/dev/null || echo 运行错误请使用bash而不是dash运行安装命令 source $profile &>/dev/null || echo 运行错误请使用bash而不是dash运行安装命令
#适配zsh环境变量 #适配zsh环境变量
[ -n "$(ls -l /bin/sh|grep -oE 'zsh')" ] && [ -z "$(cat ~/.zshrc 2>/dev/null|grep clashdir)" ] && { [ -n "$(ls -l /bin/sh|grep -oE 'zsh')" ] && [ -z "$(cat ~/.zshrc 2>/dev/null|grep CRASHDIR)" ] && {
echo "alias clash=\"$shtype $clashdir/clash.sh\"" >> ~/.zshrc echo "alias clash=\"$shtype $CRASHDIR/clash.sh\"" >> ~/.zshrc
echo "export clashdir=\"$clashdir\"" >> ~/.zshrc echo "export CRASHDIR=\"$CRASHDIR\"" >> ~/.zshrc
source ~/.zshrc &>/dev/null source ~/.zshrc &>/dev/null
} }
else else
@ -203,49 +204,59 @@ else
fi fi
#梅林/Padavan额外设置 #梅林/Padavan额外设置
[ -n "$initdir" ] && { [ -n "$initdir" ] && {
sed -i '/ShellClash初始化/'d $initdir sed -i '/ShellCrash初始化/'d $initdir
touch $initdir touch $initdir
echo "$clashdir/start.sh init #ShellClash初始化脚本" >> $initdir echo "$CRASHDIR/start.sh init #ShellCrash初始化脚本" >> $initdir
chmod a+rx $initdir 2>/dev/null chmod a+rx $initdir 2>/dev/null
setconfig initdir $initdir setconfig initdir $initdir
} }
#镜像化OpenWrt(snapshot)额外设置 #镜像化OpenWrt(snapshot)额外设置
if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ];then if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ];then
chmod 755 $clashdir/misnap_init.sh chmod 755 $CRASHDIR/misnap_init.sh
uci set firewall.ShellClash=include uci set firewall.ShellCrash=include
uci set firewall.ShellClash.type='script' uci set firewall.ShellCrash.type='script'
uci set firewall.ShellClash.path="$clashdir/misnap_init.sh" uci set firewall.ShellCrash.path="$CRASHDIR/misnap_init.sh"
uci set firewall.ShellClash.enabled='1' uci set firewall.ShellCrash.enabled='1'
uci commit firewall uci commit firewall
setconfig systype $systype setconfig systype $systype
else else
rm -rf $clashdir/misnap_init.sh rm -rf $CRASHDIR/misnap_init.sh
fi fi
#华硕USB启动额外设置 #华硕USB启动额外设置
[ "$usb_status" = "1" ] && { [ "$usb_status" = "1" ] && {
echo "$clashdir/start.sh init #ShellClash初始化脚本" > $clashdir/asus_usb_mount.sh echo "$CRASHDIR/start.sh init #ShellCrash初始化脚本" > $CRASHDIR/asus_usb_mount.sh
nvram set script_usbmount="$clashdir/asus_usb_mount.sh" nvram set script_usbmount="$CRASHDIR/asus_usb_mount.sh"
nvram commit nvram commit
} }
#删除临时文件 #删除临时文件
rm -rf /tmp/*lash*gz rm -rf /tmp/*lash*gz
rm -rf /tmp/SC_tmp rm -rf /tmp/SC_tmp
#转换&清理旧版本文件 #转换&清理旧版本文件
mkdir -p $clashdir/yamls mkdir -p $CRASHDIR/yamls
mkdir -p $clashdir/tools mkdir -p $CRASHDIR/tools
mkdir -p $CRASHDIR/task
for file in config.yaml.bak user.yaml proxies.yaml proxy-groups.yaml rules.yaml others.yaml ;do for file in config.yaml.bak user.yaml proxies.yaml proxy-groups.yaml rules.yaml others.yaml ;do
mv -f $clashdir/$file $clashdir/yamls/$file 2>/dev/null mv -f $CRASHDIR/$file $CRASHDIR/yamls/$file 2>/dev/null
done done
[ ! -L $clashdir/config.yaml ] && mv -f $clashdir/config.yaml $clashdir/yamls/config.yaml 2>/dev/null [ ! -L $CRASHDIR/config.yaml ] && mv -f $CRASHDIR/config.yaml $CRASHDIR/yamls/config.yaml 2>/dev/null
for file in fake_ip_filter mac web_save servers.list fake_ip_filter.list fallback_filter.list;do for file in fake_ip_filter mac web_save servers.list fake_ip_filter.list fallback_filter.list;do
mv -f $clashdir/$file $clashdir/configs/$file 2>/dev/null mv -f $CRASHDIR/$file $CRASHDIR/configs/$file 2>/dev/null
done done
mv -f $clashdir/mark $clashdir/configs/ShellClash.cfg 2>/dev/null #配置文件改名
for file in cron dropbear_rsa_host_key authorized_keys tun.ko ShellDDNS.sh;do mv -f $CRASHDIR/mark $CRASHDIR/configs/ShellCrash.cfg 2>/dev/null
mv -f $clashdir/$file $clashdir/tools/$file 2>/dev/null mv -f $CRASHDIR/configs/ShellClash.cfg $CRASHDIR/configs/ShellCrash.cfg 2>/dev/null
for file in dropbear_rsa_host_key authorized_keys tun.ko ShellDDNS.sh;do
mv -f $CRASHDIR/$file $CRASHDIR/tools/$file 2>/dev/null
done
for file in cron task.sh task.list;do
mv -f $CRASHDIR/$file $CRASHDIR/task/$file 2>/dev/null
done done
for file in log clash.service mark? mark.bak;do for file in log clash.service mark? mark.bak;do
rm -rf $clashdir/$file rm -rf $CRASHDIR/$file
done done
#旧版任务清理
$CRASHDIR/start.sh cronset "clash服务"
$CRASHDIR/start.sh cronset "订阅链接"
$CRASHDIR/start.sh cronset "ShellCrash初始化"
sleep 1 sleep 1
echo -e "\033[32m脚本初始化完成,请输入\033[30;47m clash \033[0;33m命令开始使用\033[0m" echo -e "\033[32m脚本初始化完成,请输入\033[30;47m crash \033[0;33m命令开始使用\033[0m"

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# Copyright (C) Juewuy # Copyright (C) Juewuy
clashdir="$(uci get firewall.ShellClash.path | sed 's/\/misnap_init.sh//')" CRASHDIR="$(uci get firewall.ShellClash.path | sed 's/\/misnap_init.sh//')"
profile=/etc/profile profile=/etc/profile
autoSSH(){ autoSSH(){
@ -13,7 +13,7 @@ autoSSH(){
[ -z "$(pidof dropbear)" -o -z "$(netstat -ntul | grep :22)" ] && { [ -z "$(pidof dropbear)" -o -z "$(netstat -ntul | grep :22)" ] && {
sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear
/etc/init.d/dropbear restart /etc/init.d/dropbear restart
mi_autoSSH_pwd=$(grep 'mi_autoSSH_pwd=' $clashdir/mark | awk -F "=" '{print $2}') mi_autoSSH_pwd=$(grep 'mi_autoSSH_pwd=' $CRASHDIR/configs/ShellCrash.cfg | awk -F "=" '{print $2}')
[ -n "$mi_autoSSH_pwd" ] && echo -e "$mi_autoSSH_pwd\n$mi_autoSSH_pwd" | passwd root [ -n "$mi_autoSSH_pwd" ] && echo -e "$mi_autoSSH_pwd\n$mi_autoSSH_pwd" | passwd root
} }
#配置nvram #配置nvram
@ -21,8 +21,8 @@ autoSSH(){
[ "$(nvram get telnet_en)" = 0 ] && nvram set telnet_en=1 [ "$(nvram get telnet_en)" = 0 ] && nvram set telnet_en=1
nvram commit &> /dev/null nvram commit &> /dev/null
#备份还原SSH秘钥 #备份还原SSH秘钥
[ -f $clashdir/configs/dropbear_rsa_host_key ] && ln -sf $clashdir/configs/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key [ -f $CRASHDIR/configs/dropbear_rsa_host_key ] && ln -sf $CRASHDIR/configs/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key
[ -f $clashdir/configs/authorized_keys ] && ln -sf $clashdir/configs/authorized_keys /etc/dropbear/authorized_keys [ -f $CRASHDIR/configs/authorized_keys ] && ln -sf $CRASHDIR/configs/authorized_keys /etc/dropbear/authorized_keys
#自动清理升级备份文件夹 #自动清理升级备份文件夹
rm -rf /data/etc_bak rm -rf /data/etc_bak
} }
@ -34,7 +34,7 @@ tunfix(){
mkdir -p /tmp/overlay/work mkdir -p /tmp/overlay/work
mount -o noatime,lowerdir=${ko_dir},upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work -t overlay "overlay_mods_only" ${ko_dir} mount -o noatime,lowerdir=${ko_dir},upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work -t overlay "overlay_mods_only" ${ko_dir}
#将tun.ko链接到lib #将tun.ko链接到lib
ln -sf $clashdir/tools/tun.ko ${ko_dir}/tun.ko ln -sf $CRASHDIR/tools/tun.ko ${ko_dir}/tun.ko
} }
tproxyfix(){ tproxyfix(){
sed -i 's/sysctl -w net.bridge.bridge-nf-call-ip/#sysctl -w net.bridge.bridge-nf-call-ip/g' /etc/init.d/qca-nss-ecm sed -i 's/sysctl -w net.bridge.bridge-nf-call-ip/#sysctl -w net.bridge.bridge-nf-call-ip/g' /etc/init.d/qca-nss-ecm
@ -51,20 +51,20 @@ init(){
done done
#初始化环境变量 #初始化环境变量
sed -i "/alias clash/d" $profile sed -i "/alias clash/d" $profile
sed -i "/export clashdir/d" $profile sed -i "/export CRASHDIR/d" $profile
echo "alias clash=\"$clashdir/clash.sh\"" >>$profile echo "alias clash=\"$CRASHDIR/clash.sh\"" >>$profile
echo "export clashdir=\"$clashdir\"" >>$profile echo "export CRASHDIR=\"$CRASHDIR\"" >>$profile
#软固化功能 #软固化功能
autoSSH autoSSH
#设置init.d服务 #设置init.d服务
cp -f $clashdir/clashservice /etc/init.d/clash cp -f $CRASHDIR/clashservice /etc/init.d/clash
chmod 755 /etc/init.d/clash chmod 755 /etc/init.d/clash
#启动服务 #启动服务
if [ ! -f $clashdir/.dis_startup ]; then if [ ! -f $CRASHDIR/.dis_startup ]; then
#AX6S/AX6000修复tun功能 #AX6S/AX6000修复tun功能
[ -f $clashdir/configs/tun.ko ] && tunfix [ -f $CRASHDIR/configs/tun.ko ] && tunfix
#小米7000/小米万兆修复tproxy #小米7000/小米万兆修复tproxy
[ -f /etc/init.d/qca-nss-ecm ] && [ -n "$(grep 'redir_mod=Tproxy' $clashdir/configs/ShellClash.cfg )" ] && tproxyfix [ -f /etc/init.d/qca-nss-ecm ] && [ -n "$(grep 'redir_mod=Tproxy' $CRASHDIR/configs/ShellClash.cfg )" ] && tproxyfix
#启动服务 #启动服务
/etc/init.d/clash start /etc/init.d/clash start
/etc/init.d/clash enable /etc/init.d/clash enable

View File

@ -2,18 +2,18 @@
# Copyright (C) Juewuy # Copyright (C) Juewuy
#初始化目录 #初始化目录
[ -d "/etc/storage/clash" ] && clashdir=/etc/storage/clash [ -d "/etc/storage/clash" ] && CRASHDIR=/etc/storage/clash
[ -d "/jffs/clash" ] && clashdir=/jffs/clash [ -d "/jffs/clash" ] && CRASHDIR=/jffs/clash
[ -z "$clashdir" ] && clashdir=$(cat /etc/profile | grep clashdir | awk -F "\"" '{print $2}') [ -z "$CRASHDIR" ] && CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}')
[ -z "$clashdir" ] && clashdir=$(cat ~/.bashrc | grep clashdir | awk -F "\"" '{print $2}') [ -z "$CRASHDIR" ] && CRASHDIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}')
CFG_PATH=$clashdir/configs/ShellClash.cfg CFG_PATH=$CRASHDIR/configs/ShellCrash.cfg
TMPDIR=/tmp/ShellClash && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR TMPDIR=/tmp/ShellCrash && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR
#脚本内部工具 #脚本内部工具
getconfig(){ getconfig(){
#加载配置文件 #加载配置文件
source $CFG_PATH &> /dev/null source $CFG_PATH &> /dev/null
#默认设置 #默认设置
[ -z "$bindir" ] && bindir=$clashdir [ -z "$bindir" ] && bindir=$CRASHDIR
[ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod=Redir模式 [ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod=Redir模式
[ -z "$redir_mod" ] && redir_mod=纯净模式 [ -z "$redir_mod" ] && redir_mod=纯净模式
[ -z "$skip_cert" ] && skip_cert=已开启 [ -z "$skip_cert" ] && skip_cert=已开启
@ -34,7 +34,7 @@ getconfig(){
[ -z "$multiport" ] && multiport='22,53,80,123,143,194,443,465,587,853,993,995,5222,8080,8443' [ -z "$multiport" ] && multiport='22,53,80,123,143,194,443,465,587,853,993,995,5222,8080,8443'
[ "$common_ports" = "已开启" ] && ports="-m multiport --dports $multiport" [ "$common_ports" = "已开启" ] && ports="-m multiport --dports $multiport"
#yaml #yaml
[ -z "$yaml" ] && yaml=$clashdir/yamls/config.yaml [ -z "$yaml" ] && yaml=$CRASHDIR/yamls/config.yaml
} }
setconfig(){ setconfig(){
#参数1代表变量名参数2代表变量值,参数3即文件路径 #参数1代表变量名参数2代表变量值,参数3即文件路径
@ -55,15 +55,15 @@ compare(){
} }
logger(){ logger(){
#$1日志内容$2显示颜色$3是否推送 #$1日志内容$2显示颜色$3是否推送
[ -n "$2" ] && echo -e "\033[$2m$1\033[0m" [ -n "$2" -a "$2" != 0 ] && echo -e "\033[$2m$1\033[0m"
log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1" log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1"
echo $log_text >> $TMPDIR/ShellClash_log echo $log_text >> $TMPDIR/ShellCrash.log
[ "$(wc -l $TMPDIR/ShellClash_log | awk '{print $1}')" -gt 99 ] && sed -i '1,5d' $TMPDIR/ShellClash_log [ "$(wc -l $TMPDIR/ShellCrash.log | awk '{print $1}')" -gt 99 ] && sed -i '1,5d' $TMPDIR/ShellCrash.log
[ -z "$3" ] && { [ -z "$3" ] && {
getconfig getconfig
[ -n "$device_name" ] && log_text="$log_text($device_name)" [ -n "$device_name" ] && log_text="$log_text($device_name)"
[ -n "$(pidof clash)" ] && { [ -n "$(pidof clash)" ] && {
[ -n "$authentication" ] && auth="$authentication@" [ -n "$authentication" ] && auth="$authentication@"
export https_proxy="http://${auth}127.0.0.1:$mix_port" export https_proxy="http://${auth}127.0.0.1:$mix_port"
} }
[ -n "$push_TG" ] && { [ -n "$push_TG" ] && {
@ -143,7 +143,7 @@ getlanip(){
while [ "$i" -le "10" ];do while [ "$i" -le "10" ];do
host_ipv4=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'br' | grep -Ev 'iot' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/br.*$//g' | sed 's/metric.*$//g' ) #ipv4局域网网段 host_ipv4=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'br' | grep -Ev 'iot' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/br.*$//g' | sed 's/metric.*$//g' ) #ipv4局域网网段
[ "$ipv6_redir" = "已开启" ] && host_ipv6=$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g' ) #ipv6公网地址段 [ "$ipv6_redir" = "已开启" ] && host_ipv6=$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g' ) #ipv6公网地址段
[ -f $TMPDIR/ShellClash_log ] && break [ -f $TMPDIR/ShellCrash.log ] && break
[ -n "$host_ipv4" -a -n "$host_ipv6" ] && break [ -n "$host_ipv4" -a -n "$host_ipv6" ] && break
sleep 2 && i=$((i+1)) sleep 2 && i=$((i+1))
done done
@ -163,10 +163,10 @@ getlanip(){
getyaml(){ getyaml(){
[ -z "$rule_link" ] && rule_link=1 [ -z "$rule_link" ] && rule_link=1
[ -z "$server_link" ] && server_link=1 [ -z "$server_link" ] && server_link=1
Server=$(grep -aE '^3|^4' $clashdir/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}') Server=$(grep -aE '^3|^4' $CRASHDIR/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}')
[ -n "$(echo $Url | grep -oE 'vless:|hysteria:')" ] && Server=$(grep -aE '^4' $clashdir/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}') [ -n "$(echo $Url | grep -oE 'vless:|hysteria:')" ] && Server=$(grep -aE '^4' $CRASHDIR/configs/servers.list | sed -n ""$server_link"p" | awk '{print $3}')
[ "$retry" = 4 ] && Server=$(grep -aE '^497' $clashdir/configs/servers.list | awk '{print $3}') [ "$retry" = 4 ] && Server=$(grep -aE '^497' $CRASHDIR/configs/servers.list | awk '{print $3}')
Config=$(grep -aE '^5' $clashdir/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $3}') Config=$(grep -aE '^5' $CRASHDIR/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $3}')
#如果传来的是Url链接则合成Https链接否则直接使用Https链接 #如果传来的是Url链接则合成Https链接否则直接使用Https链接
if [ -z "$Https" ];then if [ -z "$Https" ];then
Https="$Server/sub?target=clash&insert=true&new_name=true&scv=true&udp=true&exclude=$exclude&include=$include&url=$Url&config=$Config" Https="$Server/sub?target=clash&insert=true&new_name=true&scv=true&udp=true&exclude=$exclude&include=$include&url=$Url&config=$Config"
@ -191,7 +191,7 @@ getyaml(){
else else
if [ "$retry" = 4 ];then if [ "$retry" = 4 ];then
logger "无法获取配置文件,请检查链接格式以及网络连接状态!" 31 logger "无法获取配置文件,请检查链接格式以及网络连接状态!" 31
echo -e "\033[32m你也可以尝试使用浏览器下载配置文件后使用WinSCP手动上传到$TMPDIR目录\033[0m" echo -e "\033[32m也可用浏览器下载以上链接后使用WinSCP手动上传到/tmp目录后执行clash命令\033[0m"
exit 1 exit 1
elif [ "$retry" = 3 ];then elif [ "$retry" = 3 ];then
retry=4 retry=4
@ -257,7 +257,7 @@ getyaml(){
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
logger "配置文件加载失败!请查看报错信息!" 31 logger "配置文件加载失败!请查看报错信息!" 31
$bindir/clash -t -d $bindir -f $yamlnew $bindir/clash -t -d $bindir -f $yamlnew
echo "$($bindir/clash -t -d $bindir -f $yamlnew)" >> $TMPDIR/ShellClash_log echo "$($bindir/clash -t -d $bindir -f $yamlnew)" >> $TMPDIR/ShellCrash.log
exit 1 exit 1
fi fi
fi fi
@ -280,19 +280,19 @@ modify_yaml(){
[ "$ipv6_dns" = "已开启" ] && dns_v6='true' || dns_v6='false' [ "$ipv6_dns" = "已开启" ] && dns_v6='true' || dns_v6='false'
external="external-controller: 0.0.0.0:$db_port" external="external-controller: 0.0.0.0:$db_port"
if [ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ];then if [ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ];then
[ "$clashcore" = 'clash.meta' ] && tun_meta=', device: utun, auto-route: false' [ "$clashcore" = 'meta' ] && tun_meta=', device: utun, auto-route: false'
tun="tun: {enable: true, stack: system$tun_meta}" tun="tun: {enable: true, stack: system$tun_meta}"
else else
tun='tun: {enable: false}' tun='tun: {enable: false}'
fi fi
exper='experimental: {ignore-resolve-fail: true, interface-name: en0}' exper='experimental: {ignore-resolve-fail: true, interface-name: en0}'
#Meta内核专属配置 #Meta内核专属配置
[ "$clashcore" = 'clash.meta' ] && { [ "$clashcore" = 'meta' ] && {
[ "$redir_mod" != "纯净模式" ] && find_process='find-process-mode: "off"' [ "$redir_mod" != "纯净模式" ] && find_process='find-process-mode: "off"'
} }
#dns配置 #dns配置
[ -z "$(cat $clashdir/yamls/user.yaml 2>/dev/null | grep '^dns:')" ] && { [ -z "$(cat $CRASHDIR/yamls/user.yaml 2>/dev/null | grep '^dns:')" ] && {
[ "$clashcore" = 'clash.meta' ] && dns_default_meta='- https://223.5.5.5/dns-query' [ "$clashcore" = 'meta' ] && dns_default_meta='- https://223.5.5.5/dns-query'
cat > $TMPDIR/dns.yaml <<EOF cat > $TMPDIR/dns.yaml <<EOF
dns: dns:
enable: true enable: true
@ -308,7 +308,7 @@ dns:
fake-ip-filter: fake-ip-filter:
EOF EOF
if [ "$dns_mod" = "fake-ip" ];then if [ "$dns_mod" = "fake-ip" ];then
cat $clashdir/configs/fake_ip_filter $clashdir/configs/fake_ip_filter.list 2>/dev/null | grep '\.' | sed "s/^/ - '/" | sed "s/$/'/" >> $TMPDIR/dns.yaml cat $CRASHDIR/configs/fake_ip_filter $CRASHDIR/configs/fake_ip_filter.list 2>/dev/null | grep '\.' | sed "s/^/ - '/" | sed "s/$/'/" >> $TMPDIR/dns.yaml
else else
echo " - '+.*'" >> $TMPDIR/dns.yaml echo " - '+.*'" >> $TMPDIR/dns.yaml
fi fi
@ -318,13 +318,13 @@ EOF
fallback-filter: fallback-filter:
geoip: true geoip: true
EOF EOF
[ -s $clashdir/configs/fallback_filter.list ] && { [ -s $CRASHDIR/configs/fallback_filter.list ] && {
echo " domain:" >> $TMPDIR/dns.yaml echo " domain:" >> $TMPDIR/dns.yaml
cat $clashdir/configs/fallback_filter.list | grep '\.' | sed "s/^/ - '/" | sed "s/$/'/" >> $TMPDIR/dns.yaml cat $CRASHDIR/configs/fallback_filter.list | grep '\.' | sed "s/^/ - '/" | sed "s/$/'/" >> $TMPDIR/dns.yaml
} }
} }
#域名嗅探配置 #域名嗅探配置
[ "$sniffer" = "已启用" ] && [ "$clashcore" = "clash.meta" ] && sniffer_set="sniffer: {enable: true, skip-domain: [Mijia Cloud], sniff: {tls: {ports: [443, 8443]}, http: {ports: [80, 8080-8880]}}}" [ "$sniffer" = "已启用" ] && [ "$clashcore" = "meta" ] && sniffer_set="sniffer: {enable: true, skip-domain: [Mijia Cloud], sniff: {tls: {ports: [443, 8443]}, http: {ports: [80, 8080-8880]}}}"
[ "$clashcore" = "clashpre" ] && [ "$dns_mod" = "redir_host" ] && exper="experimental: {ignore-resolve-fail: true, interface-name: en0, sniff-tls-sni: true}" [ "$clashcore" = "clashpre" ] && [ "$dns_mod" = "redir_host" ] && exper="experimental: {ignore-resolve-fail: true, interface-name: en0, sniff-tls-sni: true}"
#生成set.yaml #生成set.yaml
cat > $TMPDIR/set.yaml <<EOF cat > $TMPDIR/set.yaml <<EOF
@ -346,7 +346,7 @@ store-selected: $restore
$find_process $find_process
EOF EOF
#读取本机hosts并生成配置文件 #读取本机hosts并生成配置文件
if [ "$hosts_opt" != "未启用" ] && [ -z "$(grep -aE '^hosts:' $clashdir/yamls/user.yaml 2>/dev/null)" ];then if [ "$hosts_opt" != "未启用" ] && [ -z "$(grep -aE '^hosts:' $CRASHDIR/yamls/user.yaml 2>/dev/null)" ];then
#NTP劫持 #NTP劫持
cat >> $TMPDIR/hosts.yaml <<EOF cat >> $TMPDIR/hosts.yaml <<EOF
hosts: hosts:
@ -376,16 +376,16 @@ EOF
#插入自定义策略组 #插入自定义策略组
sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $TMPDIR/proxy-groups.yaml sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $TMPDIR/proxy-groups.yaml
sed -i "/#自定义策略组/d" $TMPDIR/proxy-groups.yaml sed -i "/#自定义策略组/d" $TMPDIR/proxy-groups.yaml
[ -n "$(grep -Ev '^#' $clashdir/yamls/proxy-groups.yaml 2>/dev/null)" ] && { [ -n "$(grep -Ev '^#' $CRASHDIR/yamls/proxy-groups.yaml 2>/dev/null)" ] && {
#获取空格数 #获取空格数
space_name=$(grep -aE '^ *- name: ' $TMPDIR/proxy-groups.yaml | head -n 1 | grep -oE '^ *') space_name=$(grep -aE '^ *- name: ' $TMPDIR/proxy-groups.yaml | head -n 1 | grep -oE '^ *')
space_proxy=$(grep -A 1 'proxies:$' $TMPDIR/proxy-groups.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *') space_proxy=$(grep -A 1 'proxies:$' $TMPDIR/proxy-groups.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *')
#合并自定义策略组到proxy-groups.yaml #合并自定义策略组到proxy-groups.yaml
cat $clashdir/yamls/proxy-groups.yaml | sed "/^#/d" | sed "s/#.*//g" | sed '1i\ #自定义策略组开始' | sed '$a\ #自定义策略组结束' | sed "s/^ */${space_name} /g" | sed "s/^ *- /${space_proxy}- /g" | sed "s/^ *- name: /${space_name}- name: /g" > $TMPDIR/proxy-groups_add.yaml cat $CRASHDIR/yamls/proxy-groups.yaml | sed "/^#/d" | sed "s/#.*//g" | sed '1i\ #自定义策略组开始' | sed '$a\ #自定义策略组结束' | sed "s/^ */${space_name} /g" | sed "s/^ *- /${space_proxy}- /g" | sed "s/^ *- name: /${space_name}- name: /g" > $TMPDIR/proxy-groups_add.yaml
cat $TMPDIR/proxy-groups.yaml >> $TMPDIR/proxy-groups_add.yaml cat $TMPDIR/proxy-groups.yaml >> $TMPDIR/proxy-groups_add.yaml
mv -f $TMPDIR/proxy-groups_add.yaml $TMPDIR/proxy-groups.yaml mv -f $TMPDIR/proxy-groups_add.yaml $TMPDIR/proxy-groups.yaml
oldIFS="$IFS" oldIFS="$IFS"
grep "\- name: " $clashdir/yamls/proxy-groups.yaml | sed "/^#/d" | while read line;do #将自定义策略组插入现有的proxy-group grep "\- name: " $CRASHDIR/yamls/proxy-groups.yaml | sed "/^#/d" | while read line;do #将自定义策略组插入现有的proxy-group
new_group=$(echo $line | grep -Eo '^ *- name:.*#' | cut -d'#' -f1 | sed 's/.*name: //g') new_group=$(echo $line | grep -Eo '^ *- name:.*#' | cut -d'#' -f1 | sed 's/.*name: //g')
proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" ) proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" )
IFS="#" IFS="#"
@ -404,11 +404,11 @@ EOF
#插入自定义代理 #插入自定义代理
sed -i "/#自定义代理/d" $TMPDIR/proxies.yaml sed -i "/#自定义代理/d" $TMPDIR/proxies.yaml
sed -i "/#自定义代理/d" $TMPDIR/proxy-groups.yaml sed -i "/#自定义代理/d" $TMPDIR/proxy-groups.yaml
[ -n "$(grep -Ev '^#' $clashdir/yamls/proxies.yaml 2>/dev/null)" ] && { [ -n "$(grep -Ev '^#' $CRASHDIR/yamls/proxies.yaml 2>/dev/null)" ] && {
space_proxy=$(cat $TMPDIR/proxies.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *') #获取空格数 space_proxy=$(cat $TMPDIR/proxies.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *') #获取空格数
cat $clashdir/yamls/proxies.yaml | sed "s/^ *- /${space_proxy}- /g" | sed "/^#/d" | sed "/^ *$/d" | sed 's/#.*/ #自定义代理/g' >> $TMPDIR/proxies.yaml #插入节点 cat $CRASHDIR/yamls/proxies.yaml | sed "s/^ *- /${space_proxy}- /g" | sed "/^#/d" | sed "/^ *$/d" | sed 's/#.*/ #自定义代理/g' >> $TMPDIR/proxies.yaml #插入节点
oldIFS="$IFS" oldIFS="$IFS"
cat $clashdir/yamls/proxies.yaml | sed "/^#/d" | while read line;do #将节点插入proxy-group cat $CRASHDIR/yamls/proxies.yaml | sed "/^#/d" | while read line;do #将节点插入proxy-group
proxy_name=$(echo $line | grep -Eo 'name: .+, ' | cut -d',' -f1 | sed 's/name: //g') proxy_name=$(echo $line | grep -Eo 'name: .+, ' | cut -d',' -f1 | sed 's/name: //g')
proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" ) proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" )
IFS="#" IFS="#"
@ -427,23 +427,23 @@ EOF
#节点绕过功能支持 #节点绕过功能支持
sed -i "/#节点绕过/d" $TMPDIR/rules.yaml sed -i "/#节点绕过/d" $TMPDIR/rules.yaml
[ "$proxies_bypass" = "已启用" ] && { [ "$proxies_bypass" = "已启用" ] && {
cat $TMPDIR/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '!a[$0]++' | sed 's/^/\ -\ IP-CIDR,/g' | sed 's|$|/32,DIRECT #节点绕过|g' >> $TMPDIR/proxies_bypass cat $TMPDIR/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '!a[$0]++' | sed 's/^/\ -\ IP-CIDR,/g' | sed 's|$|/32,DIRECT,no-resolve #节点绕过|g' >> $TMPDIR/proxies_bypass
cat $TMPDIR/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -vE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?'| awk '!a[$0]++' | sed 's/^/\ -\ DOMAIN,/g' | sed 's/$/,DIRECT #节点绕过/g' >> $TMPDIR/proxies_bypass cat $TMPDIR/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -vE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?'| awk '!a[$0]++' | sed 's/^/\ -\ DOMAIN,/g' | sed 's/$/,DIRECT #节点绕过/g' >> $TMPDIR/proxies_bypass
cat $TMPDIR/rules.yaml >> $TMPDIR/proxies_bypass cat $TMPDIR/rules.yaml >> $TMPDIR/proxies_bypass
mv -f $TMPDIR/proxies_bypass $TMPDIR/rules.yaml mv -f $TMPDIR/proxies_bypass $TMPDIR/rules.yaml
} }
#插入自定义规则 #插入自定义规则
sed -i "/#自定义规则/d" $TMPDIR/rules.yaml sed -i "/#自定义规则/d" $TMPDIR/rules.yaml
[ -f $clashdir/yamls/rules.yaml ] && { [ -f $CRASHDIR/yamls/rules.yaml ] && {
cat $clashdir/yamls/rules.yaml | sed "/^#/d" | sed '$a\' | sed 's/$/ #自定义规则/g' > $TMPDIR/rules.add cat $CRASHDIR/yamls/rules.yaml | sed "/^#/d" | sed '$a\' | sed 's/$/ #自定义规则/g' > $TMPDIR/rules.add
cat $TMPDIR/rules.yaml >> $TMPDIR/rules.add cat $TMPDIR/rules.yaml >> $TMPDIR/rules.add
mv -f $TMPDIR/rules.add $TMPDIR/rules.yaml mv -f $TMPDIR/rules.add $TMPDIR/rules.yaml
} }
#对齐rules中的空格 #对齐rules中的空格
sed -i 's/^ *-/ -/g' $TMPDIR/rules.yaml sed -i 's/^ *-/ -/g' $TMPDIR/rules.yaml
#合并文件 #合并文件
[ -s $clashdir/yamls/user.yaml ] && { [ -s $CRASHDIR/yamls/user.yaml ] && {
yaml_user=$clashdir/yamls/user.yaml yaml_user=$CRASHDIR/yamls/user.yaml
#set和user去重,且优先使用user.yaml #set和user去重,且优先使用user.yaml
cp -f $TMPDIR/set.yaml $TMPDIR/set_bak.yaml cp -f $TMPDIR/set.yaml $TMPDIR/set_bak.yaml
for char in mode allow-lan log-level tun experimental interface-name dns store-selected;do for char in mode allow-lan log-level tun experimental interface-name dns store-selected;do
@ -452,7 +452,7 @@ EOF
} }
[ -s $TMPDIR/dns.yaml ] && yaml_dns=$TMPDIR/dns.yaml [ -s $TMPDIR/dns.yaml ] && yaml_dns=$TMPDIR/dns.yaml
[ -s $TMPDIR/hosts.yaml ] && yaml_hosts=$TMPDIR/hosts.yaml [ -s $TMPDIR/hosts.yaml ] && yaml_hosts=$TMPDIR/hosts.yaml
[ -s $clashdir/yamls/others.yaml ] && yaml_others=$clashdir/yamls/others.yaml [ -s $CRASHDIR/yamls/others.yaml ] && yaml_others=$CRASHDIR/yamls/others.yaml
yaml_add= yaml_add=
for char in $yaml_char;do #将额外配置文件合并 for char in $yaml_char;do #将额外配置文件合并
[ -s $TMPDIR/${char}.yaml ] && { [ -s $TMPDIR/${char}.yaml ] && {
@ -485,8 +485,8 @@ EOF
#设置路由规则 #设置路由规则
cn_ip_route(){ cn_ip_route(){
[ ! -f $bindir/cn_ip.txt ] && { [ ! -f $bindir/cn_ip.txt ] && {
if [ -f $clashdir/cn_ip.txt ];then if [ -f $CRASHDIR/cn_ip.txt ];then
mv $clashdir/cn_ip.txt $bindir/cn_ip.txt mv $CRASHDIR/cn_ip.txt $bindir/cn_ip.txt
else else
logger "未找到cn_ip列表正在下载" 33 logger "未找到cn_ip列表正在下载" 33
$0 webget $bindir/cn_ip.txt "$update_url/bin/geodata/china_ip_list.txt" $0 webget $bindir/cn_ip.txt "$update_url/bin/geodata/china_ip_list.txt"
@ -504,8 +504,8 @@ cn_ip_route(){
} }
cn_ipv6_route(){ cn_ipv6_route(){
[ ! -f $bindir/cn_ipv6.txt ] && { [ ! -f $bindir/cn_ipv6.txt ] && {
if [ -f $clashdir/cn_ipv6.txt ];then if [ -f $CRASHDIR/cn_ipv6.txt ];then
mv $clashdir/cn_ipv6.txt $bindir/cn_ipv6.txt mv $CRASHDIR/cn_ipv6.txt $bindir/cn_ipv6.txt
else else
logger "未找到cn_ipv6列表正在下载" 33 logger "未找到cn_ipv6列表正在下载" 33
$0 webget $bindir/cn_ipv6.txt "$update_url/bin/geodata/china_ipv6_list.txt" $0 webget $bindir/cn_ipv6.txt "$update_url/bin/geodata/china_ipv6_list.txt"
@ -534,12 +534,12 @@ start_redir(){
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && \ [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && \
iptables -t nat -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null iptables -t nat -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null
#局域网设备过滤 #局域网设备过滤
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单
iptables -t nat -A clash -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port iptables -t nat -A clash -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port
done done
else else
for mac in $(cat $clashdir/configs/mac); do #mac黑名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单
iptables -t nat -A clash -m mac --mac-source $mac -j RETURN iptables -t nat -A clash -m mac --mac-source $mac -j RETURN
done done
#仅代理本机局域网网段流量 #仅代理本机局域网网段流量
@ -560,12 +560,12 @@ start_redir(){
[ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && \ [ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && \
ip6tables -t nat -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null ip6tables -t nat -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null
#局域网设备过滤 #局域网设备过滤
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单
ip6tables -t nat -A clashv6 -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port ip6tables -t nat -A clashv6 -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port
done done
else else
for mac in $(cat $clashdir/configs/mac); do #mac黑名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单
ip6tables -t nat -A clashv6 -m mac --mac-source $mac -j RETURN ip6tables -t nat -A clashv6 -m mac --mac-source $mac -j RETURN
done done
#仅代理本机局域网网段流量 #仅代理本机局域网网段流量
@ -585,33 +585,37 @@ start_ipt_dns(){
} }
#设置dns转发 #设置dns转发
iptables -t nat -N clash_dns iptables -t nat -N clash_dns
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单
iptables -t nat -A clash_dns -p udp -m mac --mac-source $mac -j REDIRECT --to $dns_port iptables -t nat -A clash_dns -p udp -m mac --mac-source $mac -j REDIRECT --to $dns_port
done done
else else
for mac in $(cat $clashdir/configs/mac); do #mac黑名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单
iptables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN iptables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN
done done
iptables -t nat -A clash_dns -p tcp -j REDIRECT --to $dns_port
iptables -t nat -A clash_dns -p udp -j REDIRECT --to $dns_port iptables -t nat -A clash_dns -p udp -j REDIRECT --to $dns_port
fi fi
iptables -t nat -I PREROUTING -p tcp --dport 53 -j clash_dns
iptables -t nat -I PREROUTING -p udp --dport 53 -j clash_dns iptables -t nat -I PREROUTING -p udp --dport 53 -j clash_dns
#ipv6DNS #ipv6DNS
if [ -n "$(lsmod | grep 'ip6table_nat')" -a -n "$(lsmod | grep 'xt_nat')" ];then if [ -n "$(lsmod | grep 'ip6table_nat')" -a -n "$(lsmod | grep 'xt_nat')" ];then
ip6tables -t nat -N clashv6_dns > /dev/null 2>&1 ip6tables -t nat -N clashv6_dns > /dev/null 2>&1
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单
ip6tables -t nat -A clashv6_dns -p udp -m mac --mac-source $mac -j REDIRECT --to $dns_port ip6tables -t nat -A clashv6_dns -p udp -m mac --mac-source $mac -j REDIRECT --to $dns_port
done done
else else
for mac in $(cat $clashdir/configs/mac); do #mac黑名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单
ip6tables -t nat -A clashv6_dns -m mac --mac-source $mac -j RETURN ip6tables -t nat -A clashv6_dns -m mac --mac-source $mac -j RETURN
done done
ip6tables -t nat -A clashv6_dns -p tcp -j REDIRECT --to $dns_port
ip6tables -t nat -A clashv6_dns -p udp -j REDIRECT --to $dns_port ip6tables -t nat -A clashv6_dns -p udp -j REDIRECT --to $dns_port
fi fi
ip6tables -t nat -I PREROUTING -p tcp --dport 53 -j clashv6_dns
ip6tables -t nat -I PREROUTING -p udp --dport 53 -j clashv6_dns ip6tables -t nat -I PREROUTING -p udp --dport 53 -j clashv6_dns
else else
ip6tables -I INPUT -p udp --dport 53 -m comment --comment "ShellClash-IPV6_DNS-REJECT" -j REJECT 2>/dev/null ip6tables -I INPUT -p udp --dport 53 -m comment --comment "ShellCrash-IPV6_DNS-REJECT" -j REJECT 2>/dev/null
fi fi
return 0 return 0
@ -632,12 +636,12 @@ start_tproxy(){
iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null
#tcp&udp分别进代理链 #tcp&udp分别进代理链
tproxy_set(){ tproxy_set(){
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单
iptables -t mangle -A clash -p $1 -m mac --mac-source $mac -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark iptables -t mangle -A clash -p $1 -m mac --mac-source $mac -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark
done done
else else
for mac in $(cat $clashdir/configs/mac); do #mac黑名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单
iptables -t mangle -A clash -m mac --mac-source $mac -j RETURN iptables -t mangle -A clash -m mac --mac-source $mac -j RETURN
done done
#仅代理本机局域网网段流量 #仅代理本机局域网网段流量
@ -654,7 +658,7 @@ start_tproxy(){
#屏蔽QUIC #屏蔽QUIC
[ "$quic_rj" = 已启用 ] && { [ "$quic_rj" = 已启用 ] && {
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && set_cn_ip='-m set ! --match-set cn_ip dst' [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && set_cn_ip='-m set ! --match-set cn_ip dst'
iptables -I INPUT -p udp --dport 443 -m comment --comment "ShellClash-QUIC-REJECT" $set_cn_ip -j REJECT >/dev/null 2>&1 iptables -I INPUT -p udp --dport 443 -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip -j REJECT >/dev/null 2>&1
} }
#设置ipv6转发 #设置ipv6转发
[ "$ipv6_redir" = "已开启" ] && { [ "$ipv6_redir" = "已开启" ] && {
@ -670,14 +674,14 @@ start_tproxy(){
ip6tables -t mangle -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null ip6tables -t mangle -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null
#tcp&udp分别进代理链 #tcp&udp分别进代理链
tproxy_set6(){ tproxy_set6(){
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then
#mac白名单 #mac白名单
for mac in $(cat $clashdir/configs/mac); do for mac in $(cat $CRASHDIR/configs/mac); do
ip6tables -t mangle -A clashv6 -p $1 -m mac --mac-source $mac -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark ip6tables -t mangle -A clashv6 -p $1 -m mac --mac-source $mac -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark
done done
else else
#mac黑名单 #mac黑名单
for mac in $(cat $clashdir/configs/mac); do for mac in $(cat $CRASHDIR/configs/mac); do
ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j RETURN ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j RETURN
done done
#仅代理本机局域网网段流量 #仅代理本机局域网网段流量
@ -693,7 +697,7 @@ start_tproxy(){
#屏蔽QUIC #屏蔽QUIC
[ "$quic_rj" = 已启用 ] && { [ "$quic_rj" = 已启用 ] && {
[ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && set_cn_ip6='-m set ! --match-set cn_ip6 dst' [ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && set_cn_ip6='-m set ! --match-set cn_ip6 dst'
ip6tables -I INPUT -p udp --dport 443 -m comment --comment "ShellClash-QUIC-REJECT" $set_cn_ip6 -j REJECT 2>/dev/null ip6tables -I INPUT -p udp --dport 443 -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip6 -j REJECT 2>/dev/null
} }
} }
} }
@ -745,8 +749,8 @@ start_tun(){
set_cn_ip='-m set ! --match-set cn_ip dst' set_cn_ip='-m set ! --match-set cn_ip dst'
set_cn_ip6='-m set ! --match-set cn_ip6 dst' set_cn_ip6='-m set ! --match-set cn_ip6 dst'
} }
iptables -I FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellClash-QUIC-REJECT" $set_cn_ip -j REJECT >/dev/null 2>&1 iptables -I FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip -j REJECT >/dev/null 2>&1
ip6tables -I FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellClash-QUIC-REJECT" $set_cn_ip6 -j REJECT >/dev/null 2>&1 ip6tables -I FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip6 -j REJECT >/dev/null 2>&1
fi fi
modprobe xt_mark &>/dev/null && { modprobe xt_mark &>/dev/null && {
i=1 i=1
@ -769,12 +773,12 @@ start_tun(){
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && \ [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && \
iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null
#局域网设备过滤 #局域网设备过滤
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单
iptables -t mangle -A clash -m mac --mac-source $mac -j MARK --set-mark $fwmark iptables -t mangle -A clash -m mac --mac-source $mac -j MARK --set-mark $fwmark
done done
else else
for mac in $(cat $clashdir/configs/mac); do #mac黑名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单
iptables -t mangle -A clash -m mac --mac-source $mac -j RETURN iptables -t mangle -A clash -m mac --mac-source $mac -j RETURN
done done
#仅代理本机局域网网段流量 #仅代理本机局域网网段流量
@ -786,7 +790,7 @@ start_tun(){
[ "$1" = "all" ] && iptables -t mangle -A PREROUTING -p tcp $ports -j clash [ "$1" = "all" ] && iptables -t mangle -A PREROUTING -p tcp $ports -j clash
#设置ipv6转发 #设置ipv6转发
[ "$ipv6_redir" = "已开启" -a "$clashcore" = "clash.meta" ] && { [ "$ipv6_redir" = "已开启" -a "$clashcore" = "meta" ] && {
ip -6 route add default dev utun table 101 ip -6 route add default dev utun table 101
ip -6 rule add fwmark $fwmark table 101 ip -6 rule add fwmark $fwmark table 101
ip6tables -t mangle -N clashv6 ip6tables -t mangle -N clashv6
@ -798,12 +802,12 @@ start_tun(){
[ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && \ [ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && \
ip6tables -t mangle -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null ip6tables -t mangle -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null
#局域网设备过滤 #局域网设备过滤
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then if [ "$macfilter_type" = "白名单" -a -n "$(cat $CRASHDIR/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac白名单
ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j MARK --set-mark $fwmark ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j MARK --set-mark $fwmark
done done
else else
for mac in $(cat $clashdir/configs/mac); do #mac黑名单 for mac in $(cat $CRASHDIR/configs/mac); do #mac黑名单
ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j RETURN ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j RETURN
done done
#仅代理本机局域网网段流量 #仅代理本机局域网网段流量
@ -833,8 +837,8 @@ start_nft(){
} }
[ -n "$(echo $redir_mod|grep Nft)" ] && { [ -n "$(echo $redir_mod|grep Nft)" ] && {
#过滤局域网设备 #过滤局域网设备
[ -n "$(cat $clashdir/configs/mac)" ] && { [ -n "$(cat $CRASHDIR/configs/mac)" ] && {
MAC=$(awk '{printf "%s, ",$1}' $clashdir/configs/mac) MAC=$(awk '{printf "%s, ",$1}' $CRASHDIR/configs/mac)
[ "$macfilter_type" = "黑名单" ] && \ [ "$macfilter_type" = "黑名单" ] && \
nft add rule inet shellclash prerouting ether saddr {$MAC} return || \ nft add rule inet shellclash prerouting ether saddr {$MAC} return || \
nft add rule inet shellclash prerouting ether saddr != {$MAC} return nft add rule inet shellclash prerouting ether saddr != {$MAC} return
@ -877,13 +881,13 @@ start_nft(){
nft add chain inet shellclash input { type filter hook input priority 0 \; } nft add chain inet shellclash input { type filter hook input priority 0 \; }
[ -n "$CN_IP" ] && nft add rule inet shellclash input ip daddr {$CN_IP} return [ -n "$CN_IP" ] && nft add rule inet shellclash input ip daddr {$CN_IP} return
[ -n "$CN_IP6" ] && nft add rule inet shellclash input ip6 daddr {$CN_IP6} return [ -n "$CN_IP6" ] && nft add rule inet shellclash input ip6 daddr {$CN_IP6} return
nft add rule inet shellclash input udp dport 443 reject comment 'ShellClash-QUIC-REJECT' nft add rule inet shellclash input udp dport 443 reject comment 'ShellCrash-QUIC-REJECT'
} }
#代理本机(仅TCP) #代理本机(仅TCP)
[ "$local_proxy" = "已开启" ] && [ "$local_type" = "nftables增强模式" ] && { [ "$local_proxy" = "已开启" ] && [ "$local_type" = "nftables增强模式" ] && {
#dns #dns
nft add chain inet shellclash dns_out { type nat hook output priority -100 \; } nft add chain inet shellclash dns_out { type nat hook output priority -100 \; }
nft add rule inet shellclash dns_out meta skgid {453,7890} return && \ nft add rule inet shellclash dns_out meta skgid { 453, 7890 } return && \
nft add rule inet shellclash dns_out udp dport 53 redirect to $dns_port nft add rule inet shellclash dns_out udp dport 53 redirect to $dns_port
#output #output
nft add chain inet shellclash output { type nat hook output priority -100 \; } nft add chain inet shellclash output { type nat hook output priority -100 \; }
@ -905,8 +909,8 @@ start_nft(){
start_nft_dns(){ start_nft_dns(){
nft add chain inet shellclash dns { type nat hook prerouting priority -100 \; } nft add chain inet shellclash dns { type nat hook prerouting priority -100 \; }
#过滤局域网设备 #过滤局域网设备
[ -n "$(cat $clashdir/configs/mac)" ] && { [ -n "$(cat $CRASHDIR/configs/mac)" ] && {
MAC=$(awk '{printf "%s, ",$1}' $clashdir/configs/mac) MAC=$(awk '{printf "%s, ",$1}' $CRASHDIR/configs/mac)
[ "$macfilter_type" = "黑名单" ] && \ [ "$macfilter_type" = "黑名单" ] && \
nft add rule inet shellclash dns ether saddr {$MAC} return || \ nft add rule inet shellclash dns ether saddr {$MAC} return || \
nft add rule inet shellclash dns ether saddr != {$MAC} return nft add rule inet shellclash dns ether saddr != {$MAC} return
@ -952,6 +956,7 @@ stop_firewall(){
iptables -t nat -F clash 2> /dev/null iptables -t nat -F clash 2> /dev/null
iptables -t nat -X clash 2> /dev/null iptables -t nat -X clash 2> /dev/null
#dns #dns
iptables -t nat -D PREROUTING -p tcp --dport 53 -j clash_dns 2> /dev/null
iptables -t nat -D PREROUTING -p udp --dport 53 -j clash_dns 2> /dev/null iptables -t nat -D PREROUTING -p udp --dport 53 -j clash_dns 2> /dev/null
iptables -t nat -F clash_dns 2> /dev/null iptables -t nat -F clash_dns 2> /dev/null
iptables -t nat -X clash_dns 2> /dev/null iptables -t nat -X clash_dns 2> /dev/null
@ -960,8 +965,8 @@ stop_firewall(){
iptables -D FORWARD -s 198.18.0.0/16 -o utun -j RETURN 2> /dev/null iptables -D FORWARD -s 198.18.0.0/16 -o utun -j RETURN 2> /dev/null
#屏蔽QUIC #屏蔽QUIC
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && set_cn_ip='-m set ! --match-set cn_ip dst' [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && set_cn_ip='-m set ! --match-set cn_ip dst'
iptables -D INPUT -p udp --dport 443 -m comment --comment "ShellClash-QUIC-REJECT" $set_cn_ip -j REJECT 2> /dev/null iptables -D INPUT -p udp --dport 443 -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip -j REJECT 2> /dev/null
iptables -D FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellClash-QUIC-REJECT" $set_cn_ip -j REJECT 2> /dev/null iptables -D FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip -j REJECT 2> /dev/null
#本机代理 #本机代理
iptables -t nat -D OUTPUT -p tcp $ports -j clash_out 2> /dev/null iptables -t nat -D OUTPUT -p tcp $ports -j clash_out 2> /dev/null
iptables -t nat -F clash_out 2> /dev/null iptables -t nat -F clash_out 2> /dev/null
@ -996,20 +1001,21 @@ stop_firewall(){
ckcmd ip6tables && { ckcmd ip6tables && {
#redir #redir
ip6tables -t nat -D PREROUTING -p tcp $ports -j clashv6 2> /dev/null ip6tables -t nat -D PREROUTING -p tcp $ports -j clashv6 2> /dev/null
ip6tables -D INPUT -p udp --dport 53 -m comment --comment "ShellClash-IPV6_DNS-REJECT" -j REJECT 2> /dev/null ip6tables -D INPUT -p udp --dport 53 -m comment --comment "ShellCrash-IPV6_DNS-REJECT" -j REJECT 2> /dev/null
ip6tables -t nat -F clashv6 2> /dev/null ip6tables -t nat -F clashv6 2> /dev/null
ip6tables -t nat -X clashv6 2> /dev/null ip6tables -t nat -X clashv6 2> /dev/null
#dns #dns
ip6tables -t nat -D PREROUTING -p tcp --dport 53 -j clashv6_dns 2>/dev/null
ip6tables -t nat -D PREROUTING -p udp --dport 53 -j clashv6_dns 2>/dev/null ip6tables -t nat -D PREROUTING -p udp --dport 53 -j clashv6_dns 2>/dev/null
ip6tables -t nat -F clashv6_dns 2> /dev/null ip6tables -t nat -F clashv6_dns 2> /dev/null
ip6tables -t nat -X clashv6_dns 2> /dev/null ip6tables -t nat -X clashv6_dns 2> /dev/null
#tun #tun
ip6tables -D FORWARD -o utun -j ACCEPT 2> /dev/null ip6tables -D FORWARD -o utun -j ACCEPT 2> /dev/null
ip6tables -D FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellClash-QUIC-REJECT" -j REJECT >/dev/null 2>&1 ip6tables -D FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellCrash-QUIC-REJECT" -j REJECT >/dev/null 2>&1
#屏蔽QUIC #屏蔽QUIC
[ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && set_cn_ip6='-m set ! --match-set cn_ip6 dst' [ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && set_cn_ip6='-m set ! --match-set cn_ip6 dst'
iptables -D INPUT -p udp --dport 443 -m comment --comment "ShellClash-QUIC-REJECT" $set_cn_ip6 -j REJECT 2> /dev/null iptables -D INPUT -p udp --dport 443 -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip6 -j REJECT 2> /dev/null
iptables -D FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellClash-QUIC-REJECT" $set_cn_ip6 -j REJECT 2> /dev/null iptables -D FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip6 -j REJECT 2> /dev/null
#公网访问 #公网访问
ip6tables -D INPUT -p tcp --dport $mix_port -j REJECT 2> /dev/null ip6tables -D INPUT -p tcp --dport $mix_port -j REJECT 2> /dev/null
ip6tables -D INPUT -p tcp --dport $mix_port -j ACCEPT 2> /dev/null ip6tables -D INPUT -p tcp --dport $mix_port -j ACCEPT 2> /dev/null
@ -1020,7 +1026,7 @@ stop_firewall(){
ip6tables -t mangle -D PREROUTING -p udp $ports -j clashv6 2> /dev/null ip6tables -t mangle -D PREROUTING -p udp $ports -j clashv6 2> /dev/null
ip6tables -t mangle -F clashv6 2> /dev/null ip6tables -t mangle -F clashv6 2> /dev/null
ip6tables -t mangle -X clashv6 2> /dev/null ip6tables -t mangle -X clashv6 2> /dev/null
ip6tables -D INPUT -p udp --dport 443 -m comment --comment "ShellClash-QUIC-REJECT" $set_cn_ip -j REJECT 2> /dev/null ip6tables -D INPUT -p udp --dport 443 -m comment --comment "ShellCrash-QUIC-REJECT" $set_cn_ip -j REJECT 2> /dev/null
} }
#清理ipset规则 #清理ipset规则
ipset destroy cn_ip >/dev/null 2>&1 ipset destroy cn_ip >/dev/null 2>&1
@ -1042,6 +1048,8 @@ stop_firewall(){
nft flush table inet shellclash >/dev/null 2>&1 nft flush table inet shellclash >/dev/null 2>&1
nft delete table inet shellclash >/dev/null 2>&1 nft delete table inet shellclash >/dev/null 2>&1
} }
#还原防火墙文件
[ -s /etc/init.d/firewall.bak ] && mv -f /etc/init.d/firewall.bak /etc/init.d/firewall
} }
#面板配置保存相关 #面板配置保存相关
web_save(){ web_save(){
@ -1055,10 +1063,10 @@ web_save(){
rm -rf $TMPDIR/clash_web_check_$USER rm -rf $TMPDIR/clash_web_check_$USER
#对比文件,如果有变动且不为空则写入磁盘,否则清除缓存 #对比文件,如果有变动且不为空则写入磁盘,否则清除缓存
if [ -s $TMPDIR/clash_web_save_$USER ];then if [ -s $TMPDIR/clash_web_save_$USER ];then
compare $TMPDIR/clash_web_save_$USER $clashdir/configs/web_save compare $TMPDIR/clash_web_save_$USER $CRASHDIR/configs/web_save
[ "$?" = 0 ] && rm -rf $TMPDIR/clash_web_save_$USER || mv -f $TMPDIR/clash_web_save_$USER $clashdir/configs/web_save [ "$?" = 0 ] && rm -rf $TMPDIR/clash_web_save_$USER || mv -f $TMPDIR/clash_web_save_$USER $CRASHDIR/configs/web_save
else else
echo > $clashdir/configs/web_save echo > $CRASHDIR/configs/web_save
fi fi
} }
web_restore(){ web_restore(){
@ -1075,11 +1083,11 @@ web_restore(){
i=$((i+1)) i=$((i+1))
done done
#发送数据 #发送数据
num=$(cat $clashdir/configs/web_save | wc -l) num=$(cat $CRASHDIR/configs/web_save | wc -l)
i=1 i=1
while [ "$i" -le "$num" ];do while [ "$i" -le "$num" ];do
group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' $clashdir/configs/web_save | sed 's/ /%20/g') group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' $CRASHDIR/configs/web_save | sed 's/ /%20/g')
now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' $clashdir/configs/web_save) now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' $CRASHDIR/configs/web_save)
put_save http://127.0.0.1:${db_port}/proxies/${group_name} "{\"name\":\"${now_name}\"}" put_save http://127.0.0.1:${db_port}/proxies/${group_name} "{\"name\":\"${now_name}\"}"
i=$((i+1)) i=$((i+1))
done done
@ -1116,7 +1124,7 @@ bfstart(){
#读取配置文件 #读取配置文件
getconfig getconfig
[ ! -d $bindir/ui ] && mkdir -p $bindir/ui [ ! -d $bindir/ui ] && mkdir -p $bindir/ui
[ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellClash@master [ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master
#检查yaml配置文件 #检查yaml配置文件
if [ ! -f $yaml ];then if [ ! -f $yaml ];then
if [ -n "$Url" -o -n "$Https" ];then if [ -n "$Url" -o -n "$Https" ];then
@ -1129,35 +1137,35 @@ bfstart(){
fi fi
fi fi
#检测vless/hysteria协议 #检测vless/hysteria协议
if [ -n "$(cat $yaml | grep -oE 'type: vless|type: hysteria')" ] && [ "$clashcore" != "clash.meta" ];then if [ -n "$(cat $yaml | grep -oE 'type: vless|type: hysteria')" ] && [ "$clashcore" != "meta" ];then
echo ----------------------------------------------- echo -----------------------------------------------
logger "检测到vless/hysteria协议将改为使用clash.meta核心启动" 33 logger "检测到vless/hysteria协议将改为使用meta核心启动" 33
rm -rf $bindir/clash rm -rf $bindir/clash
clashcore=clash.meta clashcore=meta
setconfig clashcore clash.meta setconfig clashcore meta
echo ----------------------------------------------- echo -----------------------------------------------
fi fi
#检测是否存在高级版规则 #检测是否存在高级版规则
if [ "$clashcore" = "clash" -a -n "$(cat $yaml | grep -aE '^script:|proxy-providers|rule-providers|rule-set')" ];then if [ "$clashcore" = "clash" -a -n "$(cat $yaml | grep -aE '^script:|proxy-providers|rule-providers|rule-set')" ];then
echo ----------------------------------------------- echo -----------------------------------------------
logger "检测到高级规则!将改为使用clash.meta核心启动" 33 logger "检测到高级规则!将改为使用meta核心启动" 33
rm -rf $bindir/clash rm -rf $bindir/clash
clashcore=clash.meta clashcore=meta
setconfig clashcore clash.meta setconfig clashcore meta
echo ----------------------------------------------- echo -----------------------------------------------
fi fi
#检查clash核心 #检查clash核心
if [ ! -f $bindir/clash ];then if [ ! -f $bindir/clash ];then
if [ -f $clashdir/clash ];then if [ -f $CRASHDIR/clash ];then
mv $clashdir/clash $bindir/clash mv $CRASHDIR/clash $bindir/clash
else else
logger "未找到clash核心正在下载" 33 logger "未找到clash核心正在下载" 33
if [ -z "$clashcore" ];then if [ -z "$clashcore" ];then
[ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ] && clashcore=clashpre || clashcore=clash [ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ] && clashcore=clashpre || clashcore=clash
fi fi
[ -z "$cpucore" ] && source $clashdir/getdate.sh && getcpucore [ -z "$cpucore" ] && source $CRASHDIR/getdate.sh && getcpucore
[ -z "$cpucore" ] && logger 找不到设备的CPU信息请手动指定处理器架构类型 31 && setcpucore [ -z "$cpucore" ] && logger 找不到设备的CPU信息请手动指定处理器架构类型 31 && setcpucore
[ "$update_url" = "https://jwsc.eu.org:8888" ] && [ "$clashcore" != 'clash' ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellClash@master [ "$update_url" = "https://jwsc.eu.org:8888" ] && [ "$clashcore" != 'clash' ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master
$0 webget $bindir/clash "$update_url/bin/$clashcore/clash-linux-$cpucore" $0 webget $bindir/clash "$update_url/bin/$clashcore/clash-linux-$cpucore"
#校验内核 #校验内核
chmod +x $bindir/clash 2>/dev/null chmod +x $bindir/clash 2>/dev/null
@ -1175,8 +1183,8 @@ bfstart(){
[ ! -x $bindir/clash ] && chmod +x $bindir/clash #检测可执行权限 [ ! -x $bindir/clash ] && chmod +x $bindir/clash #检测可执行权限
#检查数据库文件 #检查数据库文件
if [ ! -f $bindir/Country.mmdb ];then if [ ! -f $bindir/Country.mmdb ];then
if [ -f $clashdir/Country.mmdb ];then if [ -f $CRASHDIR/Country.mmdb ];then
mv $clashdir/Country.mmdb $bindir/Country.mmdb mv $CRASHDIR/Country.mmdb $bindir/Country.mmdb
else else
logger "未找到GeoIP数据库正在下载" 33 logger "未找到GeoIP数据库正在下载" 33
$0 webget $bindir/Country.mmdb $update_url/bin/geodata/cn_mini.mmdb $0 webget $bindir/Country.mmdb $update_url/bin/geodata/cn_mini.mmdb
@ -1186,8 +1194,8 @@ bfstart(){
fi fi
fi fi
#检查dashboard文件 #检查dashboard文件
if [ -f $clashdir/ui/index.html -a ! -f $bindir/ui/index.html ];then if [ -f $CRASHDIR/ui/index.html -a ! -f $bindir/ui/index.html ];then
cp -rf $clashdir/ui $bindir cp -rf $CRASHDIR/ui $bindir
fi fi
#检查curl或wget支持 #检查curl或wget支持
curl --version > /dev/null 2>&1 curl --version > /dev/null 2>&1
@ -1196,10 +1204,10 @@ bfstart(){
#生成pac文件 #生成pac文件
catpac catpac
#预下载GeoSite数据库 #预下载GeoSite数据库
if [ "$clashcore" = "clash.meta" ] && [ ! -f $bindir/GeoSite.dat ] && [ -n "$(cat $yaml|grep -Ei 'geosite')" ];then if [ "$clashcore" = "meta" ] && [ ! -f $bindir/GeoSite.dat ] && [ -n "$(cat $yaml|grep -Ei 'geosite')" ];then
[ -f $clashdir/geosite.dat ] && mv -f $clashdir/geosite.dat $clashdir/GeoSite.dat [ -f $CRASHDIR/geosite.dat ] && mv -f $CRASHDIR/geosite.dat $CRASHDIR/GeoSite.dat
if [ -f $clashdir/GeoSite.dat ];then if [ -f $CRASHDIR/GeoSite.dat ];then
mv -f $clashdir/GeoSite.dat $bindir/GeoSite.dat mv -f $CRASHDIR/GeoSite.dat $bindir/GeoSite.dat
else else
logger "未找到geosite数据库正在下载" 33 logger "未找到geosite数据库正在下载" 33
$0 webget $bindir/GeoSite.dat $update_url/bin/geodata/geosite.dat $0 webget $bindir/GeoSite.dat $update_url/bin/geodata/geosite.dat
@ -1232,6 +1240,8 @@ bfstart(){
fi fi
#生成配置文件 #生成配置文件
[ "$disoverride" != "1" ] && modify_yaml || ln -sf $yaml $bindir/config.yaml [ "$disoverride" != "1" ] && modify_yaml || ln -sf $yaml $bindir/config.yaml
#执行条件任务
[ -s $CRASHDIR/task/bfstart ] && source $CRASHDIR/task/bfstart
} }
afstart(){ afstart(){
@ -1281,18 +1291,20 @@ afstart(){
[ "$local_type" = "iptables增强模式" ] && start_output [ "$local_type" = "iptables增强模式" ] && start_output
[ "$local_type" = "nftables增强模式" ] && [ "$redir_mod" = "纯净模式" ] && start_nft [ "$local_type" = "nftables增强模式" ] && [ "$redir_mod" = "纯净模式" ] && start_nft
} }
ckcmd iptables && start_wan ckcmd iptables && start_wan #本地防火墙
#标记启动时间 mark_time #标记启动时间
mark_time [ -s $CRASHDIR/task/cron ] && croncmd $CRASHDIR/task/cron #加载定时任务
#加载定时任务 [ -s $CRASHDIR/configs/web_save ] && web_restore & #后台还原面板配置
[ -f $clashdir/tools/cron ] && croncmd $clashdir/tools/cron { sleep 5;logger Clash服务已启动;} & #推送日志
#启用面板配置自动保存 #执行条件任务
cronset '#每10分钟保存节点配置' "*/10 * * * * test -n \"\$(pidof clash)\" && $clashdir/start.sh web_save #每10分钟保存节点配置" [ -s $CRASHDIR/task/afstart ] && { source $CRASHDIR/task/afstart ;} &
[ -f $clashdir/configs/web_save ] && web_restore & #后台还原面板配置 [ -s $CRASHDIR/task/affirewall -a -s /etc/init.d/firewall -a ! -f /etc/init.d/firewall.bak ] && {
#推送日志 #注入防火墙
{ sleep 5;logger Clash服务已启动;} & line=$(grep -En "fw3 restart" /etc/init.d/firewall | cut -d ":" -f 1)
#同步本机时间 sed -i.bak "${line}a\\source $CRASHDIR/task/affirewall" /etc/init.d/firewall
{ ckcmd ntpd && ntpd -n -q -p 203.107.6.88 &>/dev/null;exit 0 ;} & line=$(grep -En "fw3 .* start" /etc/init.d/firewall | cut -d ":" -f 1)
sed -i "${line}a\\source $CRASHDIR/task/affirewall" /etc/init.d/firewall
}
else else
logger "Clash服务启动失败请查看报错信息" 33 logger "Clash服务启动失败请查看报错信息" 33
logger "$($bindir/clash -t -d $bindir | grep -Eo 'error.*=.*')" 31 logger "$($bindir/clash -t -d $bindir | grep -Eo 'error.*=.*')" 31
@ -1301,6 +1313,7 @@ afstart(){
fi fi
} }
start_old(){ start_old(){
bfstart
#使用传统后台执行二进制文件的方式执行 #使用传统后台执行二进制文件的方式执行
if [ "$local_proxy" = "已开启" -a -n "$(echo $local_type | grep '增强模式')" ];then if [ "$local_proxy" = "已开启" -a -n "$(echo $local_type | grep '增强模式')" ];then
ckcmd su && su=su ckcmd su && su=su
@ -1324,10 +1337,8 @@ afstart)
start) start)
[ -n "$(pidof clash)" ] && $0 stop #禁止多实例 [ -n "$(pidof clash)" ] && $0 stop #禁止多实例
getconfig getconfig
#检测必须文件并下载
bfstart
stop_firewall #清理路由策略 stop_firewall #清理路由策略
#使用不同方式启动clash服务 #使用不同方式启动服务
if [ "$start_old" = "已开启" ];then if [ "$start_old" = "已开启" ];then
start_old start_old
elif [ -f /etc/rc.common ];then elif [ -f /etc/rc.common ];then
@ -1344,7 +1355,7 @@ stop)
[ -n "$(pidof clash)" ] && web_save #保存面板配置 [ -n "$(pidof clash)" ] && web_save #保存面板配置
#删除守护进程&面板配置自动保存 #删除守护进程&面板配置自动保存
cronset "clash保守模式守护进程" cronset "clash保守模式守护进程"
cronset "保存节点配置" cronset "保存面板配置"
cronset "流媒体预解析" cronset "流媒体预解析"
#多种方式结束进程 #多种方式结束进程
if [ -f /etc/rc.common ];then if [ -f /etc/rc.common ];then
@ -1361,10 +1372,10 @@ restart)
$0 start $0 start
;; ;;
init) init)
clashdir=$(cd $(dirname $0);pwd) CRASHDIR=$(cd $(dirname $0);pwd)
profile=/etc/profile profile=/etc/profile
if [ -d "/etc/storage/clash" ];then if [ -d "/etc/storage/clash" ];then
clashdir=/etc/storage/clash CRASHDIR=/etc/storage/clash
i=1 i=1
while [ ! -w /etc/profile -a "$i" -lt 10 ];do while [ ! -w /etc/profile -a "$i" -lt 10 ];do
sleep 5 && i=$((i+1)) sleep 5 && i=$((i+1))
@ -1380,25 +1391,28 @@ init)
fi fi
fi fi
sed -i "/alias clash/d" $profile sed -i "/alias clash/d" $profile
sed -i "/export clashdir/d" $profile sed -i "/export CRASHDIR/d" $profile
echo "alias clash=\"$clashdir/clash.sh\"" >> $profile echo "alias clash=\"$CRASHDIR/clash.sh\"" >> $profile
echo "export clashdir=\"$clashdir\"" >> $profile echo "export CRASHDIR=\"$CRASHDIR\"" >> $profile
[ -f $clashdir/.dis_startup ] && cronset "clash保守模式守护进程" || $0 start [ -f $CRASHDIR/.dis_startup ] && cronset "clash保守模式守护进程" || $0 start
;; ;;
getyaml) getyaml)
getconfig getconfig
getyaml && \ getyaml && \
logger ShellClash配置文件更新成功 logger "任务:【更新订阅并重启服务】配置文件已更新!"
;; ;;
updateyaml) updateyaml)
getconfig getconfig
getyaml && \ getyaml && \
modify_yaml && \ modify_yaml && \
put_save http://127.0.0.1:${db_port}/configs "{\"path\":\"${clashdir}/config.yaml\"}" && \ put_save http://127.0.0.1:${db_port}/configs "{\"path\":\"${CRASHDIR}/config.yaml\"}" && \
logger ShellClash配置文件更新成功 logger "任务:【热更新订阅】配置文件已更新!"
;;
ntp)
{ ckcmd ntpd && ntpd -n -q -p 203.107.6.88 &>/dev/null;exit 0 ;} &
;; ;;
logger) logger)
logger $2 $3 logger $2 $3 $4
;; ;;
webget) webget)
#设置临时代理 #设置临时代理
@ -1406,9 +1420,9 @@ webget)
getconfig getconfig
[ -n "$authentication" ] && auth="$authentication@" [ -n "$authentication" ] && auth="$authentication@"
export all_proxy="http://${auth}127.0.0.1:$mix_port" export all_proxy="http://${auth}127.0.0.1:$mix_port"
url=$(echo $3 | sed 's#https://fastly.jsdelivr.net/gh/juewuy/ShellClash[@|/]#https://raw.githubusercontent.com/juewuy/ShellClash/#' | sed 's#https://gh.jwsc.eu.org/#https://raw.githubusercontent.com/juewuy/ShellClash/#') url=$(echo $3 | sed 's#https://fastly.jsdelivr.net/gh/juewuy/ShellCrash[@|/]#https://raw.githubusercontent.com/juewuy/ShellCrash/#' | sed 's#https://gh.jwsc.eu.org/#https://raw.githubusercontent.com/juewuy/ShellCrash/#')
else else
url=$(echo $3 | sed 's#https://raw.githubusercontent.com/juewuy/ShellClash/#https://fastly.jsdelivr.net/gh/juewuy/ShellClash@#') url=$(echo $3 | sed 's#https://raw.githubusercontent.com/juewuy/ShellCrash/#https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@#')
fi fi
#参数【$2】代表下载目录【$3】代表在线地址 #参数【$2】代表下载目录【$3】代表在线地址
#参数【$4】代表输出显示【$4】不启用重定向 #参数【$4】代表输出显示【$4】不启用重定向
@ -1451,7 +1465,7 @@ web_restore)
;; ;;
daemon) daemon)
getconfig getconfig
cronset '#clash保守模式守护进程' "*/1 * * * * test -z \"\$(pidof clash)\" && $clashdir/start.sh restart #clash保守模式守护进程" cronset '#clash保守模式守护进程' "*/1 * * * * test -z \"\$(pidof clash)\" && $CRASHDIR/start.sh restart #clash保守模式守护进程"
;; ;;
cronset) cronset)
cronset $2 $3 cronset $2 $3

486
scripts/task.sh Normal file
View File

@ -0,0 +1,486 @@
#!/bin/sh
# Copyright (C) Juewuy
#加载全局变量
[ -d "/etc/storage/clash" ] && CRASHDIR=/etc/storage/clash
[ -d "/jffs/clash" ] && CRASHDIR=/jffs/clash
[ -z "$CRASHDIR" ] && CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}')
[ -z "$CRASHDIR" ] && CRASHDIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}')
[ -z "$bindir" ] && bindir=$CRASHDIR
CFG_PATH=$CRASHDIR/configs/ShellCrash.cfg
TMPDIR=/tmp/ShellCrash && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR
source $CFG_PATH &> /dev/null
setconfig(){
#参数1代表变量名参数2代表变量值,参数3即文件路径
[ -z "$3" ] && configpath=$CFG_PATH || configpath=$3
[ -n "$(grep ${1} $configpath)" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath
}
#任务命令
check_update(){ #检查更新工具
$CRASHDIR/start.sh webget $TMPDIR/clashversion "$update_url/bin/version" echooff
[ "$?" = "0" ] && source $TMPDIR/clashversion 2>/dev/null
rm -rf $TMPDIR/clashversion
}
update_core(){ #自动更新内核
#检查版本
check_update
clash_v_new=$(eval echo \$${clashcore}_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
logger "任务:【自动更新内核】中止-未检测到版本更新"
exit 1
else
#更新内核
$CRASHDIR/start.sh webget $TMPDIR/clash.new "$update_url/bin/$clashcore/clash-linux-$cpucore"
if [ "$?" != "0" ];then
logger "任务:【自动更新内核】出错-下载失败!"
rm -rf $TMPDIR/clash.new
return 1
else
chmod +x $TMPDIR/clash.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
[ $clashcore = meta ] && $CRASHDIR/start.sh start
return 1
else
mv -f $TMPDIR/clash.new $bindir/clash
logger "任务:【自动更新内核】下载完成,正在重启服务!"
$CRASHDIR/start.sh start
return 0
fi
fi
fi
}
update_shellclash(){ #自动更新脚本
#检查版本
check_update
if [ -z "$versionsh" -o "$versionsh" = "versionsh_l" ];then
logger "任务:【自动更新脚本】中止-未检测到版本更新"
exit 1
else
$CRASHDIR/start.sh webget $TMPDIR/clashfm.tar.gz "$update_url/bin/clashfm.tar.gz"
if [ "$?" != "0" ];then
rm -rf $TMPDIR/clashfm.tar.gz
logger "任务:【自动更新内核】出错-下载失败!"
return 1
else
#解压
tar -zxvf "$TMPDIR/clashfm.tar.gz" -C $CRASHDIR/
if [ $? -ne 0 ];then
rm -rf $TMPDIR/clashfm.tar.gz
logger "任务:【自动更新内核】出错-解压失败!"
return 1
else
source $CRASHDIR/init.sh >/dev/null
return 0
fi
fi
fi
}
update_mmdb(){ #自动更新数据库
getgeo(){
#检查版本
check_update
geo_v="$(echo $2 | awk -F "." '{print $1}')_v" #获取版本号类型比如Country_v
geo_v_new=$GeoIP_v
geo_v_now=$(eval echo \$$geo_v)
if [ -z "$geo_v_new" -o "$geo_v_new" = "$geo_v_now" ];then
logger "任务:【自动更新数据库文件】跳过-未检测到$2版本更新"
else
#更新文件
$CRASHDIR/start.sh webget $TMPDIR/$1 "$update_url/bin/geodata/$2"
if [ "$?" != "0" ];then
logger "任务:【自动更新数据库文件】更新【$2】下载失败!"
rm -rf $TMPDIR/$1
return 1
else
mv -f $TMPDIR/$1 $bindir/$1
setconfig $geo_v $GeoIP_v
logger "任务:【自动更新数据库文件】更新【$2】成功!"
return 0
fi
fi
}
[ -n "${Country_v}" ] && getgeo Country.mmdb Country.mmdb
[ -n "${cn_mini_v}" ] && getgeo Country.mmdb cn_mini.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
}
reset_firewall(){ #重设透明路由防火墙
$CRASHDIR/start.sh stop_firewall
$CRASHDIR/start.sh afstart
}
#任务工具
logger(){
[ "$task_push" = 1 ] && push= || push=off
[ -n "$2" -a "$2" != 0 ] && echo -e "\033[$2m$1\033[0m"
[ "$3" = 'off' ] && push=off
$CRASHDIR/start.sh logger $1 0 $push
}
croncmd(){
if [ -n "$(crontab -h 2>&1 | grep '\-l')" ];then
crontab $1
else
crondir="$(crond -h 2>&1 | grep -oE 'Default:.*' | awk -F ":" '{print $2}')"
[ ! -w "$crondir" ] && crondir="/etc/storage/cron/crontabs"
[ ! -w "$crondir" ] && crondir="/var/spool/cron/crontabs"
[ ! -w "$crondir" ] && crondir="/var/spool/cron"
[ ! -w "$crondir" ] && echo "你的设备不支持定时任务配置,脚本大量功能无法启用,请前往 https://t.me/ShellCrash 申请适配!"
[ "$1" = "-l" ] && cat $crondir/$USER 2>/dev/null
[ -f "$1" ] && cat $1 > $crondir/$USER
fi
}
cronset(){
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
tmpcron=$TMPDIR/cron_$USER
croncmd -l > $tmpcron
sed -i "/$1/d" $tmpcron
sed -i '/^$/d' $tmpcron
echo "$2" >> $tmpcron
croncmd $tmpcron
rm -f $tmpcron
#华硕/Padavan固件存档在本地,其他则删除
[ "$CRASHDIR" = "/jffs/clash" -o "$CRASHDIR" = "/etc/storage/clash" ] && mv -f $tmpcron $CRASHDIR/task/cron || rm -f $tmpcron
echo -e "任务:【$1】\033[32m添加成功\033[0m"
}
set_cron(){
[ -z $week ] && week=*
[ -z $hour ] && hour=*
[ -z $min ] && min=0
echo -----------------------------------------------
echo -e "\033[33m$cron_time\033[0m执行任务:\033[36m$task_name\033[0m"
read -p "是否确认添加定时任务?(1/0) > " res
if [ "$res" = '1' ]; then
task_txt="$min $hour * * $week $CRASHDIR/task/task.sh $task_id $cron_time$task_name"
cronset "$cron_time$task_name" "$task_txt"
fi
unset week hour min
sleep 1
}
set_service(){
# 参数1代表要任务类型,参数2代表任务ID参数3代表任务描述
task_file=$CRASHDIR/task/$1
[ -s $task_file ] && sed -i "/$3/d" $task_file
echo "$CRASHDIR/task/task.sh $2 $3" >> $task_file
echo -e "任务:【$3】\033[32m添加成功\033[0m"
sleep 1
}
#任务界面
task_user_add(){ #自定义命令添加
echo -----------------------------------------------
echo -e "\033[33m命令可包含空格请确保命令可执行\033[0m"
echo -e "也可以手动编辑\033[32m$CRASHDIR/task/task.user\033[0m添加"
read -p "请输入命令语句 > " script
if [ -n "$script" ];then
task_command=$script
echo -e "请检查输入:\033[32m$task_command\033[0m"
#获取本任务ID
task_max_id=$(awk -F'#' '{print $1}' $CRASHDIR/task/task.user | sort -n | tail -n 1)
[ -z "$task_max_id" ] && task_max_id=200
task_id=$((task_max_id + 1))
read -p "请输入任务备注 > " txt
[ -n "$txt" ] && task_name=$txt || task_name=自定义任务$task_id
echo "$task_id#$task_command#$task_name" >> $CRASHDIR/task/task.user
echo -e "\033[32m自定义任务已添加\033[0m"
sleep 1
else
echo -e "\033[31m输入错误请重新输入\033[0m"
sleep 1
fi
}
task_user_del(){ #自定义命令删除
echo -----------------------------------------------
echo -e "请输入对应ID移除对应自定义任务(不会影响内置任务)"
echo -e "也可以手动编辑\033[32m$CRASHDIR/task/task.user\033[0m"
echo -----------------------------------------------
cat $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^#' | awk -F '#' '{print $1" "$3}'
echo -----------------------------------------------
echo 0 返回上级菜单
echo -----------------------------------------------
read -p "请输入对应数字 > " num
if [ -n "$num" ];then
sed -i "/^$num#/d" $CRASHDIR/task/task.user 2>/dev/null
[ "$num" != 0 ] && task_user_del
else
echo -e "\033[31m输入错误请重新输入\033[0m"
sleep 1
fi
}
task_add(){ #任务添加
echo -----------------------------------------------
echo -e "\033[36m请选择需要添加的任务\033[0m"
echo -----------------------------------------------
#检测并创建自定义任务文件
[ -f $CRASHDIR/task/task.user ] || echo '#任务ID(必须>200并顺序排列)#任务命令#任务说明(#号隔开,任务命令和说明中都不允许包含#号)' > $CRASHDIR/task/task.user
#输出任务列表
cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | awk -F '#' '{print " "NR" "$3}'
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
case "$num" in
0)
;;
[1-9]|[1-9][0-9])
if [ "$num" -le "$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | wc -l)" ];then
task_id=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | sed -n "$num p" | awk -F '#' '{print $1}')
task_name=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | sed -n "$num p" | awk -F '#' '{print $3}')
task_type
else
errornum
fi
;;
*)
errornum
;;
esac
}
task_del(){ #任务删除
#删除定时任务
croncmd -l > $TMPDIR/cron && sed -i "/$1/d" $TMPDIR/cron && croncmd $TMPDIR/cron
sed -i "/$1/d" $CRASHDIR/task/cron 2>/dev/null
rm -f $TMPDIR/cron
#删除条件任务
sed -i "/$1/d" $CRASHDIR/task/bfstart 2>/dev/null
sed -i "/$1/d" $CRASHDIR/task/afstart 2>/dev/null
sed -i "/$1/d" $CRASHDIR/task/affirewall 2>/dev/null
}
task_type(){ #任务条件选择菜单
echo -----------------------------------------------
echo -e "请选择任务\033[36m【$task_name】\033[0m执行条件"
echo -----------------------------------------------
echo -e " 1 定时任务\033[32m每周执行\033[0m"
echo -e " 2 定时任务\033[32m每日执行\033[0m"
echo -e " 3 定时任务\033[32m每小时执行\033[0m"
echo -e " 4 定时任务\033[32m每分钟执行\033[0m"
echo -e " 5 服务\033[33m启动前执行\033[0m"
echo -e " 6 服务\033[33m启动后执行\033[0m"
echo -e " 7 防火墙服务\033[33m重启后执行\033[0m"
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
case "$num" in
0)
;;
1)
echo -----------------------------------------------
echo -e " 输入 1~7 对应\033[33m每周的指定某天\033[0m运行"
echo -e " 输入 1,3,6 代表\033[36m每周1,3,6\033[0m运行"
echo -e " 输入 1-5 代表\033[36m周一至周五\033[0m运行"
read -p "请在每周哪天执行? > " week
echo -----------------------------------------------
read -p "想在该日的具体哪个小时执行0-23 > " hour
cron_time="在每周$week的$hour点整"
set_cron
;;
2)
echo -----------------------------------------------
echo -e " 输入 1,7,15 代表\033[36m每到1,7,15点\033[0m运行"
echo -e " 输入 6-18 代表\033[36m早6点至晚18点间每小时\033[0m运行"
read -p "想在每日的具体哪个小时执行0-23 > " hour
echo -----------------------------------------------
read -p "想在具体哪分钟执行1-59的整数 > " min
cron_time="在每日的$hour点$min分"
set_cron
;;
3)
echo -----------------------------------------------
read -p "想每隔多少小时执行一次1-23的整数 > " num
hour="*/$num"
cron_time="每隔$num小时"
set_cron
;;
4)
echo -----------------------------------------------
read -p "想每隔多少分钟执行一次1-59的整数 > " num
min="*/$num"
cron_time="每隔$num分钟"
set_cron
;;
5)
set_service bfstart "$task_id" "服务启动前$task_name"
;;
6)
set_service afstart "$task_id" "服务启动后$task_name"
;;
7)
echo -e "该功能会将相关启动代码注入到/etc/init.d/firewall中"
read -p "是否继续?(1/0) > " res
[ "$res" = 1 ] && set_service affirewall "$task_id" "防火墙重启后$task_name"
;;
*)
errornum
;;
esac
}
task_manager(){ #任务管理列表
echo -----------------------------------------------
#抽取并生成临时列表
croncmd -l | grep -oE "$CRASHDIR/task/task.sh .*" | awk -F ' ' '{print $2" "$3}' > $TMPDIR/task_list
cat $CRASHDIR/task/bfstart $CRASHDIR/task/afstart $CRASHDIR/task/affirewall 2>/dev/null | awk -F ' ' '{print $2" "$3}' >> $TMPDIR/task_list
#判断为空则返回
if [ ! -s $TMPDIR/task_list ];then
echo -e "\033[31m当前没有可供管理的任务\033[36m"
sleep 1
else
echo -e "\033[33m已添加的任务:\033[0m"
echo -----------------------------------------------
cat $TMPDIR/task_list | awk '{print " " NR " " $2}'
echo -----------------------------------------------
echo -e " d 清空任务列表"
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
case "$num" in
0)
;;
d)
task_del "$CRASHDIR\/task\/task.sh"
echo -e "\033[31m全部任务已清空\033[36m"
sleep 1
;;
[1-9]|[1-9][0-9])
task_txt=$(sed -n "$num p" $TMPDIR/task_list)
task_id=$(echo $task_txt | awk '{print $1}')
task_des=$(echo $task_txt | awk '{print $2}')
task_name=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$task_id" | awk -F '#' '{print $3}')
echo -----------------------------------------------
echo -e "当前任务为:\033[36m $task_des\033[0m"
echo -e " 1 \033[33m修改\033[0m当前任务"
echo -e " 2 \033[31m删除\033[0m当前任务"
echo -e " 3 \033[32m立即执行\033[0m一次"
echo -e " 4 查看\033[33m执行记录\033[0m"
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请选择需要执行的操作 > " num
case "$num" in
0)
;;
1)
task_type && task_del $task_des
;;
2)
task_del $task_des
;;
3)
task_command=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$task_id" | awk -F '#' '{print $2}')
eval $task_command && task_res='执行成功!' || task_res='执行失败!'
logger "任务:【$task_des$task_res" 33 off
sleep 1
;;
4)
echo -----------------------------------------------
if [ -n "$(cat $TMPDIR/ShellCrash.log | grep "$task_name")" ];then
cat $TMPDIR/ShellCrash.log | grep "$task_name"
else
echo -e "\033[31m未找到相关执行记录\033[0m"
fi
sleep 1
;;
*)
errornum
;;
esac
task_manager
;;
*)
errornum
;;
esac
fi
}
task_recom(){ #任务推荐
echo -----------------------------------------------
echo -e "\033[32m启用推荐的自动任务配置这包括\033[0m"
echo -----------------------------------------------
echo -e "每隔10分钟自动保存面板配置"
echo -e "服务启动后自动同步ntp时间"
echo -e "在每周3的3点整更新订阅并重启服务"
echo -----------------------------------------------
read -p "是否启用?(1/0) > " res
[ "$res" = 1 ] && {
cronset "每隔10分钟自动保存面板配置" "*/10 * * * * $CRASHDIR/task/task.sh 106 每隔10分钟自动保存面板配置"
cronset "在每周3的3点整更新订阅并重启服务" "0 3 * * 3 /data/clash/task/task.sh 104 在每周3的3点整更新订阅并重启服务"
set_service afstart "107" "服务启动后自动同步ntp时间"
}
}
task_menu(){ #任务菜单
echo -----------------------------------------------
echo -e "\033[30;47m欢迎使用自动任务功能\033[0m"
echo -----------------------------------------------
echo -e " 1 添加\033[32m自动任务\033[0m"
echo -e " 2 管理\033[33m任务列表\033[0m"
echo -e " 3 查看\033[36m任务日志\033[0m"
echo -e " 4 配置\033[36m日志推送\033[0m"
echo -e " 5 添加\033[33m自定义任务\033[0m"
echo -e " 6 删除\033[33m自定义任务\033[0m"
echo -e " 7 使用\033[32m推荐设置\033[0m"
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
case "$num" in
0)
;;
1)
task_add
task_menu
;;
2)
task_manager
rm -rf $TMPDIR/task_list
task_menu
;;
3)
echo -----------------------------------------------
cat $TMPDIR/ShellCrash.log | grep '任务:'
task_menu
;;
4)
echo -----------------------------------------------
echo -e "\033[36m请在日志工具中配置相关推送通道及推送开关\033[0m"
log_pusher
task_menu
;;
5)
task_user_add
task_menu
;;
6)
task_user_del
task_menu
;;
7)
task_recom
task_menu
;;
*)
errornum
;;
esac
}
case "$1" in
menu)
task_menu
;;
[1-9][0-9][0-9])
task_command=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $2}')
task_name=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $3}')
#logger "任务:$task_name 开始执行"
eval $task_command && task_res=成功 || task_res=失败
logger "任务【$2】执行$task_res"
;;
*)
$1
;;
esac