From 29b94a19d74568ad47b1210491abdbc1e3e03b98 Mon Sep 17 00:00:00 2001 From: juewuy Date: Fri, 21 Jul 2023 20:39:10 +0800 Subject: [PATCH] =?UTF-8?q?v1.7.10=20~=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=A6=86=E5=86=99=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=20~?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E9=85=8D=E7=BD=AE=E7=94=9F=E6=88=90=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E9=83=A8=E5=88=86=E5=9C=B0=E5=9D=80=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=20~=E6=96=B0=E6=89=8B=E5=BC=95=E5=AF=BC=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=85=8D=E7=BD=AEipv6=E8=B7=AF=E7=94=B1=20~?= =?UTF-8?q?=E5=B1=8F=E8=94=BDQUIC=E5=8A=9F=E8=83=BD=E5=A2=9E=E5=8A=A0ipv6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20~=E4=BF=AE=E5=A4=8Dothers.yaml=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E8=A2=AB=E6=AD=A3=E7=A1=AE=E8=AF=BB=E5=8F=96=E7=9A=84?= =?UTF-8?q?bug=20~=E4=BF=AE=E5=A4=8D=E5=B1=80=E5=9F=9F=E7=BD=91=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=8A=9F=E8=83=BD=E4=B8=8D=E4=BC=9A=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/clash.service | 2 +- scripts/clash.sh | 8 ++++++-- scripts/clashservice | 5 +++-- scripts/getdate.sh | 40 ++++++++++++++++++++++--------------- scripts/init.sh | 4 +++- scripts/start.sh | 46 +++++++++++++++++++++++-------------------- 6 files changed, 62 insertions(+), 43 deletions(-) diff --git a/scripts/clash.service b/scripts/clash.service index 267cc7a..0c27197 100644 --- a/scripts/clash.service +++ b/scripts/clash.service @@ -5,7 +5,7 @@ After=network.target [Service] Type=simple User=root -ExecStart=/etc/clash/clash -d /etc/clash >/dev/null +ExecStart=/etc/clash/clash -d /etc/clash -f /tmp/clash_$USER/config.yaml >/dev/null ExecStartPost=/etc/clash/start.sh afstart Restart=on-failure RestartSec=3s diff --git a/scripts/clash.sh b/scripts/clash.sh index b27a219..37f0cb6 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -961,13 +961,12 @@ setboot(){ 2) if [ "$start_old" = "未开启" ] > /dev/null 2>&1; then echo -e "\033[33m改为使用保守模式启动clash服务!!\033[0m" - echo -e "\033[31m注意:部分设备保守模式可能无法禁用开机启动!!\033[0m" start_old=已开启 setconfig start_old $start_old $clashdir/start.sh stop else 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改为使用系统守护进程启动clash服务!!\033[0m" $clashdir/start.sh cronset "ShellClash初始化" start_old=未开启 setconfig start_old $start_old @@ -1316,7 +1315,12 @@ clashcfg(){ clashcfg elif [ "$num" = 5 ]; then + checkcfg_mac=$(cat $clashdir/mac) macfilter + if [ -n "$PID" ];then + checkcfg_mac_new=$(cat $clashdir/mac) + [ "$checkcfg_mac" != "$checkcfg_mac_new" ] && checkrestart + fi clashcfg elif [ "$num" = 6 ]; then diff --git a/scripts/clashservice b/scripts/clashservice index 91f4c17..59d6cd7 100644 --- a/scripts/clashservice +++ b/scripts/clashservice @@ -10,6 +10,7 @@ DIR=$(cat /etc/profile | grep clashdir | awk -F "\"" '{print $2}') [ -z "$DIR" ] && DIR=$(cat ~/.bashrc | grep clashdir | awk -F "\"" '{print $2}') BINDIR=$(cat $DIR/mark | grep bindir | awk -F "=" '{print $2}') [ -z "$BINDIR" ] && BINDIR=$DIR +TMPDIR=/tmp/clash_$USER start_service() { #检测必须文件 @@ -20,7 +21,7 @@ start_service() { procd_set_param respawn procd_set_param stderr 0 procd_set_param stdout 0 - procd_set_param command $BINDIR/clash -d $BINDIR + procd_set_param command $BINDIR/clash -d $BINDIR -f $TMPDIR/config.yaml procd_close_instance #其他设置 $DIR/start.sh afstart @@ -33,7 +34,7 @@ start() { $DIR/start.sh bfstart if [ "$?" = "0" ];then #创建后台进程 - service_start $BINDIR/clash -d $BINDIR + service_start $BINDIR/clash -d $BINDIR -f $TMPDIR/config.yaml #其他设置 $DIR/start.sh afstart #设置守护进程 diff --git a/scripts/getdate.sh b/scripts/getdate.sh index 3c02b4b..f448041 100644 --- a/scripts/getdate.sh +++ b/scripts/getdate.sh @@ -539,7 +539,6 @@ setproxies(){ ;; esac } - override(){ [ -z "$rule_link" ] && rule_link=1 [ -z "$server_link" ] && server_link=1 @@ -547,11 +546,10 @@ override(){ echo -e "\033[30;47m 欢迎使用配置文件覆写功能!\033[0m" echo ----------------------------------------------- echo -e " 1 自定义\033[32m端口及秘钥\033[0m" - echo -e " 2 配置\033[33m内置DNS服务\033[0m" - echo -e " 3 管理\033[36m自定义规则\033[0m" - echo -e " 4 管理\033[33m自定义节点\033[0m" - echo -e " 5 管理\033[36m自定义策略组\033[0m" - echo -e " 6 \033[32m自定义\033[0m其他功能" + echo -e " 2 管理\033[36m自定义规则\033[0m" + echo -e " 3 管理\033[33m自定义节点\033[0m" + echo -e " 4 管理\033[36m自定义策略组\033[0m" + echo -e " 5 \033[32m自定义\033[0m高级功能" [ "$disoverride" != 1 ] && echo -e " 9 \033[33m禁用\033[0m配置文件覆写" echo ----------------------------------------------- [ "$inuserguide" = 1 ] || echo -e " 0 返回上级菜单" @@ -573,24 +571,21 @@ override(){ override ;; 2) - setdns - override - ;; - 3) setrules override ;; - 4) + 3) setproxies override ;; - 5) + 4) setgroups override ;; - 6) + 5) [ ! -f $clashdir/user.yaml ] && cat > $clashdir/user.yaml < $clashdir/others.yaml < /dev/null && redir_mod="Nft混合" + modprobe nft_tproxy &> /dev/null && redir_mod="Nft混合" setconfig redir_mod "$redir_mod" + #自动识别IPV6 + [ -n "$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g')" ] && { + setconfig ipv6_redir 已开启 + setconfig ipv6_support 已开启 + setconfig ipv6_dns 已开启 + } #设置开机启动 [ -f /etc/rc.common ] && /etc/init.d/clash enable ckcmd systemctl && systemctl enable clash.service > /dev/null 2>&1 @@ -1549,7 +1556,8 @@ testcommand(){ $clashdir/start.sh stop echo ----------------------------------------------- if $clashdir/clash -v &>/dev/null;then - $clashdir/clash -t -d $clashdir + clash -s modify_yaml &>/dev/null + $clashdir/clash -t -d $clashdir -f $tmpdir/config.yaml [ "$?" = 0 ] && testover=32m测试通过!|| testover=31m出现错误!请截图后到TG群询问!!! echo -e "\033[$testover\033[0m" else diff --git a/scripts/init.sh b/scripts/init.sh index 7577d78..10cc339 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -229,6 +229,8 @@ fi #删除临时文件 rm -rf /tmp/*lash*gz rm -rf /tmp/SC_tmp - +#转换&清理旧版本文件 +mkdir -p $clashdir/configs +mkdir -p $clashdir/tools sleep 1 echo -e "\033[32m脚本初始化完成,请输入\033[30;47m clash \033[0;33m命令开始使用!\033[0m" diff --git a/scripts/start.sh b/scripts/start.sh index 23a4a87..e757d91 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -163,7 +163,7 @@ getyaml(){ #前后端订阅服务器地址索引,可在此处添加! Server=`sed -n ""$server_link"p"< $tmpdir/config.yaml + cut -c 1- $tmpdir/set.yaml $yaml_hosts $yaml_user $yaml_others $yaml_add > $tmpdir/config.yaml #测试自定义配置文件 $bindir/clash -t -d $bindir -f $tmpdir/config.yaml >/dev/null if [ "$?" != 0 ];then logger "$($bindir/clash -t -d $bindir -f $tmpdir/config.yaml | grep -Eo 'error.*=.*')" 31 logger "自定义配置文件校验失败!将使用基础配置文件启动!" 33 - sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $tmpdir/config.yaml - sed -i "/#自定义/d" $tmpdir/config.yaml + sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $tmpdir/proxy-groups.yaml + cut -c 1- $tmpdir/set.yaml $yaml_add > $tmpdir/config.yaml + sed -i "/#自定义/d" $tmpdir/config.yaml fi #存档 - if [ "$clashdir" = "$bindir" ];then - cmp -s $tmpdir/config.yaml $yaml >/dev/null 2>&1 - [ "$?" != 0 ] && mv -f $tmpdir/config.yaml $yaml || rm -f $tmpdir/config.yaml - elif [ "$tmpdir" != "$bindir" ];then - mv -f $tmpdir/config.yaml $bindir/config.yaml - fi + # if [ "$clashdir" = "$bindir" ];then + # cmp -s $tmpdir/config.yaml $yaml >/dev/null 2>&1 + # [ "$?" != 0 ] && mv -f $tmpdir/config.yaml $yaml || rm -f $tmpdir/config.yaml + # elif [ "$tmpdir" != "$bindir" ];then + # mv -f $tmpdir/config.yaml $bindir/config.yaml + # fi #清理缓存 for char in $yaml_char set hosts;do rm -f $tmpdir/${char}.yaml @@ -740,9 +741,12 @@ start_tun(){ ip6tables -I FORWARD -o utun -j ACCEPT > /dev/null 2>&1 #屏蔽QUIC if [ "$quic_rj" = 已启用 ];then - [ "$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' + 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 - #ip6tables -I FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellClash-QUIC-REJECT" -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 fi modprobe xt_mark &>/dev/null && { i=1 @@ -1220,7 +1224,7 @@ bfstart(){ [ -z "$(grep 'procd_set_param user shellclash' /etc/init.d/clash)" ] && \ sed -i '/procd_close_instance/i\\t\tprocd_set_param user shellclash' /etc/init.d/clash elif [ -w "$servdir" ]; then - setconfig ExecStart "/bin/su shellclash -c \"$bindir/clash -d $bindir >/dev/null\"" $servdir + setconfig ExecStart "/bin/su shellclash -c \"$bindir/clash -d $bindir -f $tmpdir/config.yaml >/dev/null\"" $servdir systemctl daemon-reload >/dev/null fi fi @@ -1297,10 +1301,10 @@ start_old(){ #使用传统后台执行二进制文件的方式执行 if [ "$local_proxy" = "已开启" -a -n "$(echo $local_type | grep '增强模式')" ];then ckcmd su && su=su - $su shellclash -c "$bindir/clash -d $bindir >/dev/null" & + $su shellclash -c "$bindir/clash -d $bindir -f $tmpdir/config.yaml >/dev/null" & else ckcmd nohup && nohup=nohup - $nohup $bindir/clash -d $bindir >/dev/null 2>&1 & + $nohup $bindir/clash -d $bindir -f $tmpdir/config.yaml >/dev/null 2>&1 & fi afstart $0 daemon @@ -1321,7 +1325,7 @@ start) bfstart stop_firewall #清理路由策略 #使用内置规则强行覆盖config配置文件 - [ "$disoverride" != "1" ] && modify_yaml + [ "$disoverride" != "1" ] && modify_yaml || ln -s $clashdir/config.yaml $tmpdir/config.yaml #使用不同方式启动clash服务 if [ "$start_old" = "已开启" ];then start_old