From 200c8f81ddf6a0a64d595af01341cbd17a83a375 Mon Sep 17 00:00:00 2001 From: juewuy Date: Fri, 31 Jul 2020 00:36:08 +0800 Subject: [PATCH] =?UTF-8?q?1.=E9=A1=B9=E7=9B=AE=E8=B7=AF=E5=BE=84=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E5=8F=98=E9=87=8F=E5=8C=96=EF=BC=8C=E5=8F=AA=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E4=BF=AE=E6=94=B9=E8=84=9A=E6=9C=AC=E5=BC=80=E5=A4=B4?= =?UTF-8?q?=E7=9A=84clash=E7=9B=AE=E5=BD=95=E5=8D=B3=E5=8F=AF=E9=80=82?= =?UTF-8?q?=E9=85=8D=E4=BB=BB=E6=84=8F=E7=9B=AE=E5=BD=95=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=202=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BA=86redir=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?tun=E7=BD=91=E5=8D=A1=E4=BE=9D=E7=84=B6=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clash/clashservice | 13 ++++---- clash/clashsh | 75 +++++++++++++++++++++++++++------------------- 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/clash/clashservice b/clash/clashservice index a771a3d..ab3d59f 100644 --- a/clash/clashservice +++ b/clash/clashservice @@ -6,8 +6,8 @@ USE_PROCD=1 START=99 getconfig(){ -ccfg=/etc/clash/mark -csh=/bin/clash +cpath=/etc/clash +ccfg=$cpath/mark if [ ! -f "$ccfg" ]; then echo mark文件不存在,默认以Redir模式运行! cat >$ccfg< /dev/null 2>&1 iptables -t nat -X clash > /dev/null 2>&1 iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1 - ip6tables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1 + ip6tables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1 } start_tun(){ #修改iptables规则使流量进入clash iptables -I FORWARD -o utun -j ACCEPT - iptables -t nat -I PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 + iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 } stop_tun(){ @@ -58,15 +57,15 @@ stop_tun(){ ip6tables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1 } start_service() { + getconfig #创建clash后台进程 procd_open_instance procd_set_param respawn procd_set_param stderr 1 procd_set_param stdout 1 - procd_set_param command /etc/clash/clash -d /etc/clash + procd_set_param command $cpath/clash -d $cpath procd_close_instance #修改iptables规则使流量进入clash - getconfig if [[ "$redir_mod" = "Tun模式" ]];then stop_tun start_tun diff --git a/clash/clashsh b/clash/clashsh index 69d5136..739d06c 100644 --- a/clash/clashsh +++ b/clash/clashsh @@ -9,9 +9,10 @@ echo "***********************************************" getconfig(){ #文件路径 -ccfg=/etc/clash/mark -csh=/bin/clash -yaml=/etc/clash/config.yaml +cpath=/etc/clash #clash目录地址,如有变动只需要修改此处 +sed -i "/^cpath\=*/ccpath\=$cpath" /etc/init.d/clash #同步service文件中的clash路径 +ccfg=$cpath/mark +yaml=$cpath/config.yaml #检查标识文件 if [ ! -f "$ccfg" ]; then echo mark文件不存在,正在创建! @@ -23,8 +24,10 @@ source $ccfg #获取自启状态 if [ $auto_start = true ] > /dev/null 2>&1; then auto="\033[32m已设置开机启动!\033[0m" +auto1="禁用clash开机启动" else auto="\033[31m未设置开机启动!\033[0m" +auto1="允许clash开机启动" fi #获取运行模式 if [ ! -n "$redir_mod" ]; then @@ -60,7 +63,7 @@ fi getyaml(){ source $ccfg -#前后端订阅服务器地址索引 +#前后端订阅服务器地址索引,可在此处添加! Server=`sed -n ""$server_link"p"< 0 ];then + sleep 1 + uid=`ps |grep -w 'clash -d'|grep -v grep|awk '{print $1}'` + if [ $uid > 0 ];then echo ----------------------------------------------- echo -e "\033[32mclash服务已启动!\033[0m" echo 可以使用 http://clash.razord.top (IP为网关IP,端口为9999)管理clash内置规则 @@ -357,15 +361,16 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then if [[ $redir_mod = "Redir模式" ]]; then sed -i '/redir_mod*/'d $ccfg sed -i "2i\redir_mod=Tun模式" $ccfg #修改redir_mod标记 - sed -i '1,40s/tun: {enable: false/tun: {enable: true/' $yaml #修改配置文件 + sed -i '5,20s/tun: {enable: false/tun: {enable: true/' $yaml #修改配置文件 if [ $uid > 0 ];then > /dev/null 2>&1 echo ----------------------------------------------- echo -e "\033[33m正在重启clash进程……\033[0m" /etc/init.d/clash stop > /dev/null 2>&1 fi /etc/init.d/clash start - Num=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` - if [ $Num > 0 ];then + sleep 1 + uid=`ps |grep -w 'clash -d'|grep -v grep|awk '{print $1}'` + if [ $uid > 0 ];then echo ----------------------------------------------- echo -e "\033[32mclash服务已启动!\033[0m" echo -e "\033[33mclash已成功切换为:\033[47;34m Tun模式! \033[0m" @@ -386,15 +391,16 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then if [[ $redir_mod = "Tun模式" ]]; then sed -i '/redir_mod*/'d $ccfg sed -i "2i\redir_mod=Redir模式" $ccfg #修改redir_mod标记 - sed -i '1,40s/tun: {enable: false/tun: {enable: true/' $yaml #修改配置文件 + sed -i '5,20s/tun: {enable: true/tun: {enable: false/' $yaml #修改配置文件 if [ $uid > 0 ];then echo ----------------------------------------------- echo -e "\033[33m正在重启clash进程……\033[0m" /etc/init.d/clash stop > /dev/null 2>&1 fi /etc/init.d/clash start - Num=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` - if [ $Num > 0 ];then + sleep 1 + uid=`ps |grep -w 'clash -d'|grep -v grep|awk '{print $1}'` + if [ $uid > 0 ];then echo ----------------------------------------------- echo -e "\033[32mclash服务已启动!\033[0m" echo -e "\033[33mclash已成功切换为:\033[47;34m Redir模式! \033[0m" @@ -420,7 +426,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then if [ "$res" = '1' ]; then /etc/init.d/clash disable /etc/init.d/clash stop - rm -rf /etc/clash + rm -rf $cpath rm /etc/init.d/clash rm $csh echo 已卸载clash相关文件! @@ -443,8 +449,8 @@ getconfig echo 1 启动/重启clash服务 echo 2 测试代理服务器连通性 echo 3 停止clash服务 -echo 4 允许clash开机启动 -echo 5 禁止clash开机启动 +echo 4 $auto1 +echo 5 设置定时任务(施工中) echo 6 使用链接导入节点/订阅 echo 7 高级设置 echo 0 退出脚本 @@ -458,11 +464,11 @@ if [[ $num -le 7 ]] > /dev/null 2>&1; then echo ----------------------------------------------- /etc/init.d/clash stop > /dev/null 2>&1 echo -e "\033[31mClash服务已停止!\033[0m" - sleep 1 fi /etc/init.d/clash start - Num=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` - if [ $Num > 0 ];then + sleep 1 + uid=`ps |grep -w 'clash -d'|grep -v grep|awk '{print $1}'` + if [ $uid > 0 ];then echo ----------------------------------------------- echo -e "\033[32mclash服务已启动!\033[0m" echo 可以使用 http://clash.razord.top (IP为网关IP,端口为9999)管理clash内置规则 @@ -493,19 +499,28 @@ if [[ $num -le 7 ]] > /dev/null 2>&1; then exit; elif [[ $num == 4 ]]; then - /etc/init.d/clash enable - sed -i '/auto_start*/'d $ccfg - sed -i "1i\auto_start=true" $ccfg - echo ----------------------------------------------- - echo -e "\033[32m已设置Clash开机启动!\033[0m" - clashsh + sed -i '/auto_start*/'d $ccfg + echo ----------------------------------------------- + if [ $auto_start = true ] > /dev/null 2>&1; then + /etc/init.d/clash disable + sed -i "1i\auto_start=false" $ccfg + echo -e "\033[33m已禁止Clash开机启动!\033[0m" + else + /etc/init.d/clash enable + sed -i "1i\auto_start=true" $ccfg + echo -e "\033[32m已设置Clash开机启动!\033[0m" + fi + clashsh elif [[ $num == 5 ]]; then - /etc/init.d/clash disable - sed -i '/auto_start*/'d $ccfg - sed -i "1i\auto_start=false" $ccfg - echo ----------------------------------------------- - echo -e "\033[33m已禁止Clash开机启动!\033[0m" +echo ----------------------------------------------- +echo -e "\033[31m正在施工中,敬请期待!\033[0m" +echo -e "\033[32m正在施工中,敬请期待!\033[0m" +echo -e "\033[33m正在施工中,敬请期待!\033[0m" +echo -e "\033[34m正在施工中,敬请期待!\033[0m" +echo -e "\033[35m正在施工中,敬请期待!\033[0m" +echo -e "\033[36m正在施工中,敬请期待!\033[0m" + clashsh elif [[ $num == 6 ]]; then