diff --git a/bin/ShellClash.tar.gz b/bin/ShellClash.tar.gz index e402ba0..92918cd 100644 Binary files a/bin/ShellClash.tar.gz and b/bin/ShellClash.tar.gz differ diff --git a/bin/clashfm.tar.gz b/bin/clashfm.tar.gz index c69bb8a..71d722c 100644 Binary files a/bin/clashfm.tar.gz and b/bin/clashfm.tar.gz differ diff --git a/bin/version b/bin/version index 91b194c..10904dc 100644 --- a/bin/version +++ b/bin/version @@ -2,5 +2,5 @@ clashnet_v=v1.7.6 clashpre_v=2022.11.25 clash_v=v1.7.1 meta_v=v1.14.4 -versionsh=1.7.8 GeoIP_v=20230527 +versionsh=1.7.9b diff --git a/scripts/clash.sh b/scripts/clash.sh index fec8cc0..66cbb03 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -2,7 +2,7 @@ # Copyright (C) Juewuy CFG_PATH=$clashdir/mark - +tmpdir=/tmp/clash_$USER && [ ! -f $tmpdir ] && mkdir -p $tmpdir #读取配置相关 setconfig(){ #参数1代表变量名,参数2代表变量值,参数3即文件路径 @@ -21,7 +21,7 @@ ckstatus(){ #检查重复行并去除 [ -n "$(awk 'a[$0]++' $CFG_PATH)" ] && awk '!a[$0]++' $CFG_PATH > $CFG_PATH #检查时间戳 - touch /tmp/clash_start_time + touch $tmpdir/clash_start_time #使用source加载配置文件 source $CFG_PATH > /dev/null versionsh=$(cat $clashdir/init.sh | grep -E ^version= | head -n 1 | sed 's/version=//') @@ -68,8 +68,8 @@ ckstatus(){ run="\033[32m正在运行($redir_mod)\033[0m" VmRSS=`cat /proc/$PID/status|grep -w VmRSS|awk '{print $2,$3}'` #获取运行时长 - touch /tmp/clash_start_time #用于延迟启动的校验 - start_time=$(cat /tmp/clash_start_time) + touch $tmpdir/clash_start_time #用于延迟启动的校验 + start_time=$(cat $tmpdir/clash_start_time) if [ -n "$start_time" ]; then time=$((`date +%s`-start_time)) day=$((time/86400)) @@ -213,7 +213,7 @@ log_pusher(){ case $num in 1) echo ----------------------------------------------- - cat /tmp/ShellClash_log + cat $tmpdir/ShellClash_log exit ;; 2) @@ -541,7 +541,6 @@ setdns(){ else echo -e "\033[31m当前设备未安装OpenSSL,无法启用加密DNS,Linux系统请自行搜索安装方式!\033[0m" fi - rm -rf /tmp/ssl_test sleep 2 setdns @@ -1593,9 +1592,9 @@ tools(){ echo ----------------------------------------------- if [ ! -f $clashdir/ShellDDNS.sh ];then echo -e "正在获取在线脚本……" - $clashdir/start.sh webget /tmp/ShellDDNS.sh $update_url/tools/ShellDDNS.sh + $clashdir/start.sh webget $tmpdir/ShellDDNS.sh $update_url/tools/ShellDDNS.sh if [ "$?" = "0" ];then - mv -f /tmp/ShellDDNS.sh $clashdir/ShellDDNS.sh + mv -f $tmpdir/ShellDDNS.sh $clashdir/ShellDDNS.sh source $clashdir/ShellDDNS.sh else echo -e "\033[31m文件下载失败!\033[0m" @@ -1646,9 +1645,9 @@ tools(){ tunfixlink="${update_url}/bin/fix/tun.ko" echo ----------------------------------------------- echo 正在连接服务器获取Tun模块补丁文件………… - $clashdir/start.sh webget /tmp/tun.ko $tunfixlink + $clashdir/start.sh webget $tmpdir/tun.ko $tunfixlink if [ "$?" = "0" ];then - mv -f /tmp/tun.ko $clashdir && \ + mv -f $tmpdir/tun.ko $clashdir && \ $clashdir/misnap_init.sh tunfix && \ echo -e "\033[32m设置成功!请重启clash服务!\033[0m" else @@ -1706,7 +1705,7 @@ clashcron(){ read -p "是否确认添加定时任务?(1/0) > " res if [ "$res" = '1' ]; then cronwords="$min $hour * * $week $cronset #$week1的$hour点$min分$cronname" - tmpcron=/tmp/cron_$USER + tmpcron=$tmpdir/cron_$USER croncmd -l > $tmpcron sed -i "/$cronname/d" $tmpcron sed -i '/^$/d' $tmpcron @@ -1736,9 +1735,9 @@ clashcron(){ elif [ "$num" = 0 ]; then i= elif [ "$num" = 9 ]; then - croncmd -l > /tmp/conf && sed -i "/$cronname/d" /tmp/conf && croncmd /tmp/conf + croncmd -l > $tmpdir/conf && sed -i "/$cronname/d" $tmpdir/conf && croncmd $tmpdir/conf sed -i "/$cronname/d" $clashdir/cron 2>/dev/null - rm -f /tmp/conf + rm -f $tmpdir/conf echo ----------------------------------------------- echo -e "\033[31m定时任务:$cronname已删除!\033[0m" elif [ "$num" = 8 ]; then @@ -1820,9 +1819,9 @@ clashcron(){ read -p "请输入备注的关键词 > " txt [ -n "$txt" ] && { cronname=$txt - croncmd -l > /tmp/conf && sed -i "/$cronname/d" /tmp/conf && croncmd /tmp/conf + croncmd -l > $tmpdir/conf && sed -i "/$cronname/d" $tmpdir/conf && croncmd $tmpdir/conf sed -i "/$cronname/d" $clashdir/cron 2>/dev/null - rm -f /tmp/conf + rm -f $tmpdir/conf echo ----------------------------------------------- echo -e "所有关键词\033[32m$cronname\033[0m匹配的定时任务均已删除!\033[0m" sleep 1 diff --git a/scripts/getdate.sh b/scripts/getdate.sh index fa862ec..926bc19 100644 --- a/scripts/getdate.sh +++ b/scripts/getdate.sh @@ -711,7 +711,7 @@ clashlink(){ } #下载更新相关 gettar(){ - $clashdir/start.sh webget /tmp/clashfm.tar.gz $tarurl + $clashdir/start.sh webget $tmpdir/clashfm.tar.gz $tarurl if [ "$?" != "0" ];then echo -e "\033[33m文件下载失败!\033[0m" error_down @@ -721,9 +721,9 @@ gettar(){ echo ----------------------------------------------- echo 开始解压文件! mkdir -p $clashdir > /dev/null - tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/ + tar -zxvf '$tmpdir/clashfm.tar.gz' -C $clashdir/ if [ $? -ne 0 ];then - rm -rf /tmp/clashfm.tar.gz + rm -rf $tmpdir/clashfm.tar.gz echo -e "\033[33m文件解压失败!\033[0m" error_down else @@ -792,21 +792,21 @@ getcore(){ #获取在线clash核心文件 echo ----------------------------------------------- echo 正在在线获取clash核心文件…… - $clashdir/start.sh webget /tmp/clash.new $corelink + $clashdir/start.sh webget $tmpdir/clash.new $corelink if [ "$?" = "1" ];then echo -e "\033[31m核心文件下载失败!\033[0m" - rm -rf /tmp/clash.new + rm -rf $tmpdir/clash.new [ -z "$custcorelink" ] && error_down else - chmod +x /tmp/clash.new - clashv=$(/tmp/clash.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //') + chmod +x $tmpdir/clash.new + clashv=$($tmpdir/clash.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //') if [ -z "$clashv" ];then echo -e "\033[31m核心文件下载成功但校验失败!请尝试手动指定CPU版本\033[0m" - rm -rf /tmp/clash.new + rm -rf $tmpdir/clash.new setcpucore else echo -e "\033[32m$clashcore核心下载成功!\033[0m" - mv -f /tmp/clash.new $bindir/clash + mv -f $tmpdir/clash.new $bindir/clash chmod +x $bindir/clash setconfig clashcore $clashcore setconfig clashv $version @@ -912,13 +912,13 @@ setcore(){ getgeo(){ echo ----------------------------------------------- echo 正在从服务器获取数据库文件………… - $clashdir/start.sh webget /tmp/$geoname $update_url/bin/geodata/$geotype + $clashdir/start.sh webget $tmpdir/$geoname $update_url/bin/geodata/$geotype if [ "$?" = "1" ];then echo ----------------------------------------------- echo -e "\033[31m文件下载失败!\033[0m" error_down else - mv -f /tmp/$geoname $bindir/$geoname + mv -f $tmpdir/$geoname $bindir/$geoname echo ----------------------------------------------- echo -e "\033[32mGeoIP/CN_IP数据库文件下载成功!\033[0m" Geo_v=$GeoIP_v @@ -996,7 +996,7 @@ getdb(){ dblink="${update_url}/bin/dashboard/${db_type}.tar.gz" echo ----------------------------------------------- echo 正在连接服务器获取安装文件………… - $clashdir/start.sh webget /tmp/clashdb.tar.gz $dblink + $clashdir/start.sh webget $tmpdir/clashdb.tar.gz $dblink if [ "$?" = "1" ];then echo ----------------------------------------------- echo -e "\033[31m文件下载失败!\033[0m" @@ -1006,10 +1006,10 @@ getdb(){ else echo -e "\033[33m下载成功,正在解压文件!\033[0m" mkdir -p $dbdir > /dev/null - tar -zxvf "/tmp/clashdb.tar.gz" -C $dbdir > /dev/null + tar -zxvf "$tmpdir/clashdb.tar.gz" -C $dbdir > /dev/null if [ $? -ne 0 ];then - tar -zxvf "/tmp/clashdb.tar.gz" --no-same-permissions -C $dbdir > /dev/null - [ $? -ne 0 ] && echo "文件解压失败!" && rm -rf /tmp/clashfm.tar.gz && exit 1 + tar -zxvf "$tmpdir/clashdb.tar.gz" --no-same-permissions -C $dbdir > /dev/null + [ $? -ne 0 ] && echo "文件解压失败!" && rm -rf $tmpdir/clashfm.tar.gz && exit 1 fi #修改默认host和端口 if [ "$db_type" = "clashdb" -o "$db_type" = "meta_db" ];then @@ -1023,7 +1023,7 @@ getdb(){ setconfig hostdir \'$hostdir\' echo ----------------------------------------------- echo -e "\033[32m面板安装成功!\033[0m" - rm -rf /tmp/clashdb.tar.gz + rm -rf $tmpdir/clashdb.tar.gz sleep 1 fi } @@ -1103,20 +1103,20 @@ getcrt(){ crtlink="${update_url}/bin/fix/ca-certificates.crt" echo ----------------------------------------------- echo 正在连接服务器获取安装文件………… - $clashdir/start.sh webget /tmp/ca-certificates.crt $crtlink + $clashdir/start.sh webget $tmpdir/ca-certificates.crt $crtlink if [ "$?" = "1" ];then echo ----------------------------------------------- echo -e "\033[31m文件下载失败!\033[0m" error_down else echo ----------------------------------------------- - mv -f /tmp/ca-certificates.crt $crtdir - $clashdir/start.sh webget /tmp/ssl_test https://baidu.com echooff rediron skipceroff + mv -f $tmpdir/ca-certificates.crt $crtdir + $clashdir/start.sh webget $tmpdir/ssl_test https://baidu.com echooff rediron skipceroff if [ "$?" = "1" ];then export CURL_CA_BUNDLE=$crtdir echo "export CURL_CA_BUNDLE=$crtdir" >> /etc/profile fi - rm -rf /tmp/ssl_test + rm -rf $tmpdir/ssl_test echo -e "\033[32m证书安装成功!\033[0m" sleep 1 fi @@ -1214,15 +1214,15 @@ setserver(){ elif [ "$num" = 9 ]; then echo ----------------------------------------------- echo -e "\033[33m如无法连接,请务必先启用clash服务!!!\033[0m" - $clashdir/start.sh webget /tmp/clashrelease https://raw.githubusercontent.com/juewuy/ShellClash/master/bin/release_version echooff rediroff 2>/tmp/clashrelease + $clashdir/start.sh webget $tmpdir/clashrelease https://raw.githubusercontent.com/juewuy/ShellClash/master/bin/release_version echooff rediroff 2>$tmpdir/clashrelease echo -e "\033[31m请选择想要回退至的release版本:\033[0m" - cat /tmp/clashrelease | awk '{print " "NR" "$1}' + cat $tmpdir/clashrelease | awk '{print " "NR" "$1}' echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" -o "$num" = 0 ]; then setserver - elif [ $num -le $(cat /tmp/clashrelease 2>/dev/null | awk 'END{print NR}') ]; then - release_version=$(cat /tmp/clashrelease | awk '{print $1}' | sed -n "$num"p) + 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) update_url="https://raw.githubusercontent.com/juewuy/ShellClash/$release_version" saveserver release_url='' @@ -1230,7 +1230,7 @@ setserver(){ echo ----------------------------------------------- echo -e "\033[31m输入有误,请重新输入!\033[0m" fi - rm -rf /tmp/clashrelease + rm -rf $tmpdir/clashrelease else errornum fi @@ -1240,25 +1240,25 @@ checkupdate(){ if [ -z "$release_new" ];then if [ -n "$release_url" ];then [ -n "$(echo $release_url|grep 'jsdelivr')" ] && check_url=$release_url@master || check_url=$release_url/master - $clashdir/start.sh webget /tmp/clashversion $check_url/bin/release_version echoon rediroff 2>/tmp/clashversion - release_new=$(cat /tmp/clashversion | head -1) + $clashdir/start.sh webget $tmpdir/clashversion $check_url/bin/release_version echoon rediroff 2>$tmpdir/clashversion + 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 setconfig update_url \'$update_url\' release_type=正式版 else release_type=测试版 fi - $clashdir/start.sh webget /tmp/clashversion $update_url/bin/version echooff - [ "$?" = "0" ] && release_new=$(cat /tmp/clashversion | grep -oE 'versionsh=.*' | awk -F'=' '{ print $2 }') + $clashdir/start.sh webget $tmpdir/clashversion $update_url/bin/version echooff + [ "$?" = "0" ] && release_new=$(cat $tmpdir/clashversion | grep -oE 'versionsh=.*' | awk -F'=' '{ print $2 }') if [ -n "$release_new" ];then - source /tmp/clashversion 2>/dev/null + source $tmpdir/clashversion 2>/dev/null else echo -e "\033[31m检查更新失败!请切换其他安装源!\033[0m" echo -e "\033[36m如全部安装源都无法使用,请先运行clash服务后再使用更新功能!\033[0m" sleep 1 setserver fi - rm -rf /tmp/clashversion + rm -rf $tmpdir/clashversion fi } update(){ @@ -1425,14 +1425,14 @@ userguide(){ [ "$res" = 1 ] && checkupdate && getcrt fi #设置加密DNS - $clashdir/start.sh webget /tmp/ssl_test https://doh.pub echooff rediron + $clashdir/start.sh webget $tmpdir/ssl_test https://doh.pub echooff rediron if [ "$?" = "0" ];then 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' setconfig dns_nameserver \'"$dns_nameserver"\' setconfig dns_fallback \'"$dns_fallback"\' fi - rm -rf /tmp/ssl_test + rm -rf $tmpdir/ssl_test #开启公网访问 sethost(){ read -p "请输入你的公网IP地址 > " host diff --git a/scripts/init.sh b/scripts/init.sh index d69c5be..4df8c58 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,7 +1,7 @@ #!/bin/sh # Copyright (C) Juewuy -version=1.7.8 +version=1.7.9b setdir(){ dir_avail(){ diff --git a/scripts/start.sh b/scripts/start.sh index f0e7e77..31a63e8 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,13 +1,15 @@ #!/bin/sh # Copyright (C) Juewuy +#初始化目录 +[ -d "/etc/storage/clash" ] && clashdir=/etc/storage/clash +[ -d "/jffs/clash" ] && clashdir=/jffs/clash +[ -z "$clashdir" ] && clashdir=$(cat /etc/profile | grep clashdir | awk -F "\"" '{print $2}') +[ -z "$clashdir" ] && clashdir=$(cat ~/.bashrc | grep clashdir | awk -F "\"" '{print $2}') +tmpdir=/tmp/clash_$USER && [ ! -f $tmpdir ] && mkdir -p $tmpdir #脚本内部工具 getconfig(){ #加载配置文件 - [ -d "/etc/storage/clash" ] && clashdir=/etc/storage/clash - [ -d "/jffs/clash" ] && clashdir=/jffs/clash - [ -z "$clashdir" ] && clashdir=$(cat /etc/profile | grep clashdir | awk -F "\"" '{print $2}') - [ -z "$clashdir" ] && clashdir=$(cat ~/.bashrc | grep clashdir | awk -F "\"" '{print $2}') source $clashdir/mark &> /dev/null #默认设置 [ -z "$bindir" ] && bindir=$clashdir @@ -52,8 +54,8 @@ logger(){ #$1日志内容$2显示颜色$3是否推送 [ -n "$2" ] && echo -e "\033[$2m$1\033[0m" log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1" - echo $log_text >> /tmp/ShellClash_log - [ "$(wc -l /tmp/ShellClash_log | awk '{print $1}')" -gt 99 ] && sed -i '1,5d' /tmp/ShellClash_log + echo $log_text >> $tmpdir/ShellClash_log + [ "$(wc -l $tmpdir/ShellClash_log | awk '{print $1}')" -gt 99 ] && sed -i '1,5d' $tmpdir/ShellClash_log [ -z "$3" ] && { getconfig [ -n "$device_name" ] && log_text="$log_text($device_name)" @@ -108,7 +110,7 @@ croncmd(){ } cronset(){ # 参数1代表要移除的关键字,参数2代表要添加的任务语句 - tmpcron=/tmp/cron_$USER + tmpcron=$tmpdir/cron_$USER croncmd -l > $tmpcron sed -i "/$1/d" $tmpcron sed -i '/^$/d' $tmpcron @@ -131,7 +133,7 @@ put_save(){ fi } mark_time(){ - echo `date +%s` > /tmp/clash_start_time + echo `date +%s` > $tmpdir/clash_start_time } getlanip(){ i=1 @@ -139,7 +141,7 @@ getlanip(){ host_ipv4=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'br' | grep -v 'iot' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/br.*$//g' ) #ipv4局域网网段 host_ipv6=$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g' ) #ipv6公网地址段 [ -n "$host_ipv4" -a -n "$host_ipv6" ] && break - [ -f /tmp/ShellClash_log ] && break + [ -f $tmpdir/ShellClash_log ] && break sleep 2 && i=$((i+1)) done #添加自定义ipv4局域网网段 @@ -193,7 +195,7 @@ EOF` echo 可以手动复制该链接到浏览器打开并查看数据是否正常! #获取在线yaml文件 yaml=$clashdir/config.yaml - yamlnew=/tmp/clash_config_$USER.yaml + yamlnew=$tmpdir/clash_config_$USER.yaml rm -rf $yamlnew $0 webget $yamlnew $Https if [ "$?" = "1" ];then @@ -206,7 +208,7 @@ EOF` else if [ "$retry" = 4 ];then logger "无法获取配置文件,请检查链接格式以及网络连接状态!" 31 - echo -e "\033[32m你也可以尝试使用浏览器下载配置文件后,使用WinSCP手动上传到/tmp目录!\033[0m" + echo -e "\033[32m你也可以尝试使用浏览器下载配置文件后,使用WinSCP手动上传到$tmpdir目录!\033[0m" exit 1 elif [ "$retry" = 3 ];then retry=4 @@ -260,12 +262,12 @@ EOF` fi #检测并去除无效节点组 [ -n "$url_type" ] && ckcmd xargs && { - cat $yamlnew | sed '/^rules:/,$d' | grep -A 15 "\- name:" | xargs | sed 's/- name: /\n/g' | sed 's/ type: .*proxies: /#/g' | sed 's/- //g' | grep -E '#DIRECT $|#DIRECT$' | awk -F '#' '{print $1}' > /tmp/clash_proxies_$USER + cat $yamlnew | sed '/^rules:/,$d' | grep -A 15 "\- name:" | xargs | sed 's/- name: /\n/g' | sed 's/ type: .*proxies: /#/g' | sed 's/- //g' | grep -E '#DIRECT $|#DIRECT$' | awk -F '#' '{print $1}' > $tmpdir/clash_proxies_$USER while read line ;do sed -i "/- $line/d" $yamlnew sed -i "/- name: $line/,/- DIRECT/d" $yamlnew - done < /tmp/clash_proxies_$USER - rm -rf /tmp/clash_proxies_$USER + done < $tmpdir/clash_proxies_$USER + rm -rf $tmpdir/clash_proxies_$USER } #使用核心内置test功能检测 if [ -x $bindir/clash ];then @@ -332,12 +334,10 @@ modify_yaml(){ #设置目录 yaml=$clashdir/config.yaml - tmpdir=/tmp/clash_$USER #预读取变量 mode=$(grep "^mode" $yaml | head -1 | awk '{print $2}') [ -z "$mode" ] && mode='Rule' #分割配置文件 - mkdir -p $tmpdir > /dev/null yaml_char='proxies proxy-groups proxy-providers rules rule-providers' for char in $yaml_char;do sed -n "/^$char:/,/^[a-z]/ { /^[a-z]/d; p; }" $yaml > $tmpdir/${char}.yaml @@ -356,7 +356,7 @@ modify_yaml(){ cat $tmpdir/proxy-groups.yaml >> $tmpdir/proxy-groups_add.yaml mv -f $tmpdir/proxy-groups_add.yaml $tmpdir/proxy-groups.yaml oldIFS="$IFS" - while read line;do #将自定义策略组插入现有的proxy-group + grep "\- name: " $clashdir/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') proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" ) IFS="#" @@ -368,7 +368,7 @@ modify_yaml(){ sed -i "${line_c}a\\${space}- ${new_group}#自定义策略组" $tmpdir/proxy-groups.yaml done IFS="$oldIFS" - done <<< $(grep "\- name: " $clashdir/proxy-groups.yaml) + done } #插入自定义代理 sed -i "/#自定义代理/d" $tmpdir/proxies.yaml @@ -376,7 +376,7 @@ modify_yaml(){ space_proxy=$(cat $tmpdir/proxies.yaml | grep -E '^ *- ' | head -n 1 | grep -oE '^ *') #获取空格数 cat $clashdir/proxies.yaml | sed "s/^ *- /${space_proxy}- /g" | sed "/^#/d" | sed '$a\' | sed 's/#.*/ #自定义代理/g' >> $tmpdir/proxies.yaml #插入节点 oldIFS="$IFS" - while read line;do #将节点插入proxy-group + cat $clashdir/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_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" ) IFS="#" @@ -388,13 +388,13 @@ modify_yaml(){ sed -i "${line_c}a\\${space}- ${proxy_name}#自定义代理" $tmpdir/proxy-groups.yaml done IFS="$oldIFS" - done <<< $(sed "/^#/d" $clashdir/proxies.yaml) + done } #节点绕过功能支持 sed -i "/#节点绕过/d" $tmpdir/rules.yaml [ "$proxies_bypass" = "已启用" ] && { - cat /tmp/clash_$USER/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | 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 /tmp/clash_$USER/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | 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/clash_$USER/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | 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/clash_$USER/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | 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 mv -f $tmpdir/proxies_bypass $tmpdir/rules.yaml } @@ -488,10 +488,10 @@ cn_ip_route(){ fi } [ -f $bindir/cn_ip.txt -a -z "$(echo $redir_mod|grep 'Nft')" ] && { - echo "create cn_ip hash:net family inet hashsize 1024 maxelem 65536" > /tmp/cn_$USER.ipset - awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' $bindir/cn_ip.txt >> /tmp/cn_$USER.ipset + echo "create cn_ip hash:net family inet hashsize 1024 maxelem 65536" > $tmpdir/cn_$USER.ipset + awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' $bindir/cn_ip.txt >> $tmpdir/cn_$USER.ipset ipset -! flush cn_ip 2>/dev/null - ipset -! restore < /tmp/cn_$USER.ipset + ipset -! restore < $tmpdir/cn_$USER.ipset rm -rf cn_$USER.ipset } } @@ -507,10 +507,10 @@ cn_ipv6_route(){ } [ -f $bindir/cn_ipv6.txt -a -z "$(echo $redir_mod|grep 'Nft')" ] && { #ipv6 - echo "create cn_ip6 hash:net family inet6 hashsize 1024 maxelem 65536" > /tmp/cn6_$USER.ipset - awk '!/^$/&&!/^#/{printf("add cn_ip6 %s'" "'\n",$0)}' $bindir/cn_ipv6.txt >> /tmp/cn6_$USER.ipset + echo "create cn_ip6 hash:net family inet6 hashsize 1024 maxelem 65536" > $tmpdir/cn6_$USER.ipset + awk '!/^$/&&!/^#/{printf("add cn_ip6 %s'" "'\n",$0)}' $bindir/cn_ipv6.txt >> $tmpdir/cn6_$USER.ipset ipset -! flush cn_ip6 2>/dev/null - ipset -! restore < /tmp/cn6_$USER.ipset + ipset -! restore < $tmpdir/cn6_$USER.ipset rm -rf cn6_$USER.ipset } } @@ -1033,17 +1033,17 @@ stop_firewall(){ #面板配置保存相关 web_save(){ #使用get_save获取面板节点设置 - get_save http://127.0.0.1:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' > /tmp/clash_web_check_$USER + get_save http://127.0.0.1:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' > $tmpdir/clash_web_check_$USER while read line ;do def=$(echo $line | awk -F "[[,]" '{print $2}') now=$(echo $line | grep -oE '"now".*",' | sed 's/"now"://g' | sed 's/"type":.*//g' | sed 's/,//g') - [ "$def" != "$now" ] && echo $line | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g' | sed 's/"type":.*//g' | sed 's/"//g' >> /tmp/clash_web_save_$USER - done < /tmp/clash_web_check_$USER - rm -rf /tmp/clash_web_check_$USER + [ "$def" != "$now" ] && echo $line | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g' | sed 's/"type":.*//g' | sed 's/"//g' >> $tmpdir/clash_web_save_$USER + done < $tmpdir/clash_web_check_$USER + rm -rf $tmpdir/clash_web_check_$USER #对比文件,如果有变动且不为空则写入磁盘,否则清除缓存 - if [ -s /tmp/clash_web_save_$USER ];then - compare /tmp/clash_web_save_$USER $clashdir/web_save - [ "$?" = 0 ] && rm -rf /tmp/clash_web_save_$USER || mv -f /tmp/clash_web_save_$USER $clashdir/web_save + if [ -s $tmpdir/clash_web_save_$USER ];then + compare $tmpdir/clash_web_save_$USER $clashdir/web_save + [ "$?" = 0 ] && rm -rf $tmpdir/clash_web_save_$USER || mv -f $tmpdir/clash_web_save_$USER $clashdir/web_save else echo > $clashdir/web_save fi @@ -1077,7 +1077,7 @@ catpac(){ [ -n "$host" ] && host_pac=$host [ -z "$host_pac" ] && host_pac=$(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_pac" ] && host_pac=$(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) - cat > /tmp/clash_pac < $tmpdir/clash_pac <