mirror of
https://github.com/juewuy/ShellCrash.git
synced 2024-11-16 11:42:18 +08:00
v1.7.9e
~优化了自定义配置文件功能的脚本显示 ~软固化功能代码优化,并重新加入新手引导 ~集中修复了自定义配置文件功能的若干bug ~修复首次启动时无法自动下载必须文件的bug ~修复无法正确还原yaml文件备份的bug
This commit is contained in:
parent
4c43100d6d
commit
4aa316b348
Binary file not shown.
Binary file not shown.
|
@ -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.9d
|
||||
GeoIP_v=20230610
|
||||
versionsh=1.7.9e
|
||||
|
|
|
@ -1480,6 +1480,27 @@ clashadv(){
|
|||
*) errornum ;;
|
||||
esac
|
||||
}
|
||||
#工具脚本
|
||||
autoSSH(){
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[33m本功能使用软件命令进行固化不保证100%成功!\033[0m"
|
||||
echo -e "\033[33m如有问题请加群反馈:\033[36;4mhttps://t.me/ShellClash\033[0m"
|
||||
read -p "请输入需要还原的SSH密码(不影响当前密码,回车可跳过) > " mi_autoSSH_pwd
|
||||
mi_autoSSH=已配置
|
||||
cp -f /etc/dropbear/dropbear_rsa_host_key $clashdir/dropbear_rsa_host_key 2>/dev/null
|
||||
cp -f /etc/dropbear/authorized_keys $clashdir/authorized_keys 2>/dev/null
|
||||
cwcmd nvram && {
|
||||
nvram set ssh_en=1
|
||||
nvram set telnet_en=1
|
||||
nvram set uart_en=1
|
||||
nvram set boot_wait=on
|
||||
nvram commit
|
||||
}
|
||||
echo -e "\033[32m设置成功!\033[0m"
|
||||
setconfig mi_autoSSH $mi_autoSSH
|
||||
setconfig mi_autoSSH_pwd $mi_autoSSH_pwd
|
||||
sleep 1
|
||||
}
|
||||
tools(){
|
||||
ssh_tools(){
|
||||
stop_iptables(){
|
||||
|
@ -1547,7 +1568,7 @@ tools(){
|
|||
}
|
||||
#获取设置默认显示
|
||||
[ -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/tun.ko ] && mi_tunfix=32m已启用 || mi_tunfix=31m未启用
|
||||
#
|
||||
echo -----------------------------------------------
|
||||
|
@ -1614,20 +1635,10 @@ tools(){
|
|||
|
||||
elif [ "$num" = 6 ]; then
|
||||
if [ "$systype" = "mi_snapshot" ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[33m本功能使用软件命令进行固化不保证100%成功!\033[0m"
|
||||
echo -e "\033[33m如有问题请加群反馈:\033[36;4mhttps://t.me/ShellClash\033[0m"
|
||||
read -p "请输入需要还原的SSH密码(不影响当前密码,回车可跳过) > " mi_autoSSH_pwd
|
||||
mi_autoSSH=已启用
|
||||
cp -f /etc/dropbear/dropbear_rsa_host_key $clashdir/dropbear_rsa_host_key 2>/dev/null
|
||||
cp -f /etc/dropbear/authorized_keys $clashdir/authorized_keys 2>/dev/null
|
||||
echo -e "\033[32m设置成功!\033[0m"
|
||||
sleep 1
|
||||
autoSSH
|
||||
else
|
||||
echo 不支持的设备!
|
||||
fi
|
||||
setconfig mi_autoSSH $mi_autoSSH
|
||||
setconfig mi_autoSSH_pwd $mi_autoSSH_pwd
|
||||
tools
|
||||
elif [ "$num" = 8 ]; then
|
||||
if [ -f $clashdir/tun.ko ];then
|
||||
|
|
|
@ -276,8 +276,8 @@ setrules(){
|
|||
esac
|
||||
}
|
||||
del_rule_type(){
|
||||
echo -----------------------------------------------
|
||||
echo -e "输入对应数字即可移除相应规则:"
|
||||
sed -i '/^ *$/d' $clashdir/rules.yaml
|
||||
cat $clashdir/rules.yaml | grep -Ev '^#' | awk -F "#" '{print " "NR" "$1$2$3}'
|
||||
echo -----------------------------------------------
|
||||
echo -e " 0 返回上级菜单"
|
||||
|
@ -286,7 +286,7 @@ setrules(){
|
|||
0) ;;
|
||||
'') ;;
|
||||
*)
|
||||
if [ $num -le $(cat $clashdir/rules.yaml | grep -Ev '^#' | wc -l) ];then
|
||||
if [ $num -le $(cat $clashdir/rules.yaml | grep -Ev '^#' | grep -Ev '^ *$' | wc -l) ];then
|
||||
sed -i "$num{/^\s*[^#]/d}" $clashdir/rules.yaml
|
||||
del_rule_type
|
||||
else
|
||||
|
@ -313,7 +313,13 @@ setrules(){
|
|||
setrules
|
||||
;;
|
||||
2)
|
||||
del_rule_type
|
||||
echo -----------------------------------------------
|
||||
if [ -s $clashdir/rules.yaml ];then
|
||||
del_rule_type
|
||||
else
|
||||
echo -e "请先添加自定义规则!"
|
||||
sleep 1
|
||||
fi
|
||||
setrules
|
||||
;;
|
||||
3)
|
||||
|
@ -346,7 +352,7 @@ setgroups(){
|
|||
echo -e "\033[33m注意策略组名称必须和【自定义规则】或【自定义节点】功能中指定的策略组一致!\033[0m"
|
||||
echo -e "\033[33m建议先创建策略组,之后可在【自定义规则】或【自定义节点】功能中自动指定\033[0m"
|
||||
echo -e "\033[33m如需在当前策略组下添加节点,请手动编辑$clashdir/proxy-groups.yaml\033[0m"
|
||||
read -p "请输入自定义策略组名称 > " new_group_name
|
||||
read -p "请输入自定义策略组名称(不支持纯数字) > " new_group_name
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[32m请选择策略组【$new_group_name】的类型!\033[0m"
|
||||
echo $group_type_cn | awk '{for(i=1;i<=NF;i++){print i" "$i}}'
|
||||
|
@ -370,6 +376,7 @@ setgroups(){
|
|||
proxies:
|
||||
- DIRECT
|
||||
EOF
|
||||
sed -i "/^ *$/d" $clashdir/proxy-groups.yaml
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[32m添加成功!\033[0m"
|
||||
|
||||
|
@ -378,7 +385,9 @@ EOF
|
|||
echo -----------------------------------------------
|
||||
echo -e "\033[36m请选择想要将本策略添加到的策略组\033[0m"
|
||||
echo -e "\033[32m如需添加到多个策略组,请一次性输入多个数字并用空格隔开\033[0m"
|
||||
echo -----------------------------------------------
|
||||
echo $proxy_group | awk -F '#' '{for(i=1;i<=NF;i++){print i" "$i}}'
|
||||
echo -----------------------------------------------
|
||||
echo -e " 0 跳过添加"
|
||||
read -p "请输入对应数字(多个用空格隔开) > " char
|
||||
case $char in
|
||||
|
@ -402,20 +411,26 @@ EOF
|
|||
echo -e "\033[36m如需修改或批量操作,请手动编辑:$clashdir/proxy-groups.yaml\033[0m"
|
||||
echo -----------------------------------------------
|
||||
echo -e " 1 添加自定义策略组"
|
||||
echo -e " 2 清空自定义策略组"
|
||||
echo -e " 2 查看自定义策略组"
|
||||
echo -e " 3 清空自定义策略组"
|
||||
echo -e " 0 返回上级菜单"
|
||||
read -p "请输入对应数字 > " num
|
||||
case $num in
|
||||
1)
|
||||
group_type="select url-test fallback load-balance"
|
||||
group_type_cn="手动选择 自动选择 故障转移 负载均衡"
|
||||
proxy_group="$(cat $clashdir/proxy-groups.yaml $clashdir/config.yaml | grep -Ev '^#' | grep -o '\- name:.*' | sed 's/- name: /#/g' | tr -d '\n' | sed 's/#//')"
|
||||
proxy_group="$(cat $clashdir/proxy-groups.yaml $clashdir/config.yaml | sed "/#自定义策略组开始/,/#自定义策略组结束/d" | grep -Ev '^#' | grep -o '\- name:.*' | sed 's/#.*//' | sed 's/- name: /#/g' | tr -d '\n' | sed 's/#//')"
|
||||
set_group_type
|
||||
setgroups
|
||||
;;
|
||||
2)
|
||||
echo -----------------------------------------------
|
||||
cat $clashdir/proxy-groups.yaml
|
||||
setgroups
|
||||
;;
|
||||
3)
|
||||
read -p "确认清空全部自定义策略组?(1/0) > " res
|
||||
[ "$res" = "1" ] && sed -i '/^\s*[^#]/d' $clashdir/proxy-groups.yaml
|
||||
[ "$res" = "1" ] && echo '#用于添加自定义策略组' > $clashdir/proxy-groups.yaml
|
||||
setgroups
|
||||
;;
|
||||
*)
|
||||
|
@ -437,7 +452,9 @@ setproxies(){
|
|||
echo -e "\033[36m请选择想要将节点添加到的策略组\033[0m"
|
||||
echo -e "\033[32m如需添加到多个策略组,请一次性输入多个数字并用空格隔开\033[0m"
|
||||
echo -e "\033[33m如需自定义策略组,请先使用【管理自定义策略组功能】添加\033[0m"
|
||||
echo -----------------------------------------------
|
||||
echo $proxy_group | awk -F '#' '{for(i=1;i<=NF;i++){print i" "$i}}'
|
||||
echo -----------------------------------------------
|
||||
echo -e " 0 返回上级菜单"
|
||||
read -p "请输入对应数字(多个用空格隔开) > " char
|
||||
case $char in
|
||||
|
@ -471,20 +488,27 @@ setproxies(){
|
|||
case $num in
|
||||
1)
|
||||
proxy_type="DOMAIN-SUFFIX DOMAIN-KEYWORD IP-CIDR SRC-IP-CIDR DST-PORT SRC-PORT GEOIP GEOSITE IP-CIDR6 DOMAIN MATCH"
|
||||
proxy_group="$(cat $clashdir/proxy-groups.yaml $clashdir/config.yaml | grep -Ev '^#' | grep -o '\- name:.*' | sed 's/- name: /#/g' | tr -d '\n' | sed 's/#//')"
|
||||
proxy_group="$(cat $clashdir/proxy-groups.yaml $clashdir/config.yaml | sed "/#自定义策略组开始/,/#自定义策略组结束/d" | grep -Ev '^#' | grep -o '\- name:.*' | sed 's/#.*//' | sed 's/- name: /#/g' | tr -d '\n' | sed 's/#//')"
|
||||
set_proxy_type
|
||||
setproxies
|
||||
;;
|
||||
2)
|
||||
echo -e "当前已添加的自定义节点为:"
|
||||
cat $clashdir/proxies.yaml | grep -Ev '^#' | awk -F '[,,}]' '{print NR, $1, $NF}' | sed 's/- {//g'
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[33m输入节点对应数字可以移除对应节点\033[0m"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ $num -le $(cat $clashdir/proxies.yaml | grep -Ev '^#' | wc -l) ];then
|
||||
sed -i "$num{/^\s*[^#]/d}" $clashdir/proxies.yaml
|
||||
2)
|
||||
echo -----------------------------------------------
|
||||
sed -i '/^ *$/d' $clashdir/proxies.yaml
|
||||
if [ -s $clashdir/proxies.yaml ];then
|
||||
echo -e "当前已添加的自定义节点为:"
|
||||
cat $clashdir/proxies.yaml | grep -Ev '^#' | awk -F '[,,}]' '{print NR, $1, $NF}' | sed 's/- {//g'
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[33m输入节点对应数字可以移除对应节点\033[0m"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ $num -le $(cat $clashdir/proxies.yaml | grep -Ev '^#' | wc -l) ];then
|
||||
sed -i "$num{/^\s*[^#]/d}" $clashdir/proxies.yaml
|
||||
else
|
||||
errornum
|
||||
fi
|
||||
else
|
||||
errornum
|
||||
echo -e "请先添加自定义节点!"
|
||||
sleep 1
|
||||
fi
|
||||
setproxies
|
||||
;;
|
||||
|
@ -521,10 +545,10 @@ override(){
|
|||
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[36m管理\033[0m自定义节点"
|
||||
echo -e " 5 \033[36m管理\033[0m自定义策略组"
|
||||
echo -e " 7 \033[32m自定义\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其他功能"
|
||||
[ "$disoverride" != 1 ] && echo -e " 9 \033[33m禁用\033[0m配置文件覆写"
|
||||
echo -----------------------------------------------
|
||||
[ "$inuserguide" = 1 ] || echo -e " 0 返回上级菜单"
|
||||
|
@ -583,7 +607,7 @@ EOF
|
|||
echo -e "\033[33m可用于编写自定义的锚点、入站、proxy-providers、sub-rules、rule-set、script等功能\033[0m"
|
||||
echo -e "Windows下请\n使用\033[33mWinSCP软件\033[0m进行编辑!\033[0m"
|
||||
echo -e "MacOS下请\n使用\033[33mSecureFX软件\033[0m进行编辑!\033[0m"
|
||||
echo -e "Linux本机请\n使用\033[33mVim\033[0m进行编辑(不支持路由设备)!\033[0m"
|
||||
echo -e "Linux本机可\n使用\033[33mvim\033[0m进行编辑(路由设备可能不显示中文请勿使用)!\033[0m"
|
||||
sleep 3
|
||||
override
|
||||
;;
|
||||
|
@ -616,7 +640,7 @@ clashlink(){
|
|||
echo -----------------------------------------------
|
||||
echo -e " 1 在线\033[32m生成Clash配置文件\033[0m"
|
||||
echo -e " 2 导入\033[33mClash配置文件链接\033[0m"
|
||||
echo -e " 3 \033[36m还原\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"
|
||||
|
@ -659,17 +683,16 @@ clashlink(){
|
|||
fi
|
||||
;;
|
||||
3)
|
||||
yamlbak=$yaml.bak
|
||||
if [ ! -f "$yaml".bak ];then
|
||||
if [ ! -f $clashdir/config.yaml.bak ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m没有找到配置文件的备份!\033[0m"
|
||||
clashlink
|
||||
else
|
||||
echo -----------------------------------------------
|
||||
echo -e 备份文件共有"\033[32m`wc -l < $yamlbak`\033[0m"行内容,当前文件共有"\033[32m`wc -l < $yaml`\033[0m"行内容
|
||||
echo -e 备份文件共有"\033[32m`wc -l < $clashdir/config.yaml.bak`\033[0m"行内容,当前文件共有"\033[32m`wc -l < $clashdir/config.yaml`\033[0m"行内容
|
||||
read -p "确认还原配置文件?此操作不可逆![1/0] > " res
|
||||
if [ "$res" = '1' ]; then
|
||||
mv $yamlbak $yaml
|
||||
mv $clashdir/config.yaml.bak $clashdir/config.yaml
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[32m配置文件已还原!请手动重启clash服务!\033[0m"
|
||||
sleep 1
|
||||
|
@ -1467,12 +1490,12 @@ userguide(){
|
|||
fi
|
||||
fi
|
||||
#小米设备软固化
|
||||
# if [ "$systype" = "mi_snapshot" ];then
|
||||
# echo -----------------------------------------------
|
||||
# echo -e "\033[33m检测到为小米路由设备,启用软固化可防止路由升级后丢失SSH\033[0m"
|
||||
# read -p "是否启用软固化功能?(1/0) > " res
|
||||
# [ "$res" = 1 ] && setconfig mi_autoSSH 已启用
|
||||
# fi
|
||||
if [ "$systype" = "mi_snapshot" ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[33m检测到为小米路由设备,启用软固化可防止路由升级后丢失SSH\033[0m"
|
||||
read -p "是否启用软固化功能?(1/0) > " res
|
||||
[ "$res" = 1 ] && autoSSH
|
||||
fi
|
||||
#提示导入订阅或者配置文件
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[32m是否导入配置文件?\033[0m(这是运行前的最后一步)"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) Juewuy
|
||||
|
||||
version=1.7.9d
|
||||
version=1.7.9e
|
||||
|
||||
setdir(){
|
||||
dir_avail(){
|
||||
|
|
|
@ -6,17 +6,20 @@ profile=/etc/profile
|
|||
|
||||
autoSSH(){
|
||||
#自动开启SSH
|
||||
[ "$(nvram get ssh_en)" = 0 ] && nvram set ssh_en=1 && nvram commit
|
||||
[ "`uci -c /usr/share/xiaoqiang get xiaoqiang_version.version.CHANNEL`" != 'stable' ] && {
|
||||
uci -c /usr/share/xiaoqiang set xiaoqiang_version.version.CHANNEL='stable'
|
||||
uci -c /usr/share/xiaoqiang commit xiaoqiang_version.version
|
||||
uci -c /usr/share/xiaoqiang set xiaoqiang_version.version.CHANNEL='stable'
|
||||
uci -c /usr/share/xiaoqiang commit xiaoqiang_version.version
|
||||
}
|
||||
[ -z "$(pidof dropbear)" -o -z "$(netstat -ntul | grep :22)" ] && {
|
||||
sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear
|
||||
/etc/init.d/dropbear restart
|
||||
mi_autoSSH_pwd=$(grep 'mi_autoSSH_pwd=' $clashdir/mark | awk -F "=" '{print $2}')
|
||||
[ -n "$mi_autoSSH_pwd" ] && echo -e "$mi_autoSSH_pwd\n$mi_autoSSH_pwd" | passwd root
|
||||
sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear
|
||||
/etc/init.d/dropbear restart
|
||||
mi_autoSSH_pwd=$(grep 'mi_autoSSH_pwd=' $clashdir/mark | awk -F "=" '{print $2}')
|
||||
[ -n "$mi_autoSSH_pwd" ] && echo -e "$mi_autoSSH_pwd\n$mi_autoSSH_pwd" | passwd root
|
||||
}
|
||||
#配置nvram
|
||||
[ "$(nvram get ssh_en)" = 0 ] && nvram set ssh_en=1
|
||||
[ "$(nvram get telnet_en)" = 0 ] && nvram set telnet_en=1
|
||||
nvram commit &> /dev/null
|
||||
#备份还原SSH秘钥
|
||||
[ -f $clashdir/dropbear_rsa_host_key ] && ln -sf $clashdir/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key
|
||||
[ -f $clashdir/authorized_keys ] && ln -sf $clashdir/authorized_keys /etc/dropbear/authorized_keys
|
||||
|
|
|
@ -347,12 +347,13 @@ modify_yaml(){
|
|||
sed -i 's/skip-cert-verify: true/skip-cert-verify: false/' $tmpdir/proxies.yaml
|
||||
#插入自定义策略组
|
||||
sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $tmpdir/proxy-groups.yaml
|
||||
[ -f $clashdir/proxy-groups.yaml ] && {
|
||||
sed -i "/#自定义策略组/d" $tmpdir/proxy-groups.yaml
|
||||
[ -n "$(grep -Ev '^#' $clashdir/proxy-groups.yaml 2>/dev/null)" ] && {
|
||||
#获取空格数
|
||||
space_name=$(grep -E '^ *- name: ' $tmpdir/proxy-groups.yaml | head -n 1 | grep -oE '^ *')
|
||||
space_proxy=$(grep -A 1 'proxies:$' $tmpdir/proxy-groups.yaml | grep -E '^ *- ' | head -n 1 | grep -oE '^ *')
|
||||
#合并自定义策略组到proxy-groups.yaml
|
||||
cat $clashdir/proxy-groups.yaml | sed "/^#/d" | 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 $clashdir/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
|
||||
mv -f $tmpdir/proxy-groups_add.yaml $tmpdir/proxy-groups.yaml
|
||||
oldIFS="$IFS"
|
||||
|
@ -362,19 +363,21 @@ modify_yaml(){
|
|||
IFS="#"
|
||||
for name in $proxy_groups; do
|
||||
line_a=$(grep -n "\- name: $name" $tmpdir/proxy-groups.yaml | awk -F: '{print $1}') #获取group行号
|
||||
line_b=$(grep -A 8 "\- name: $name" $tmpdir/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号
|
||||
line_c=$((line_a + line_b - 1)) #计算需要插入的行号
|
||||
space=$(sed -n "$((line_c + 1))p" $tmpdir/proxy-groups.yaml | grep -oE '^ *') #获取空格数
|
||||
sed -i "${line_c}a\\${space}- ${new_group}#自定义策略组" $tmpdir/proxy-groups.yaml
|
||||
[ -n "$line_a" ] && {
|
||||
line_b=$(grep -A 8 "\- name: $name" $tmpdir/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号
|
||||
line_c=$((line_a + line_b - 1)) #计算需要插入的行号
|
||||
space=$(sed -n "$((line_c + 1))p" $tmpdir/proxy-groups.yaml | grep -oE '^ *') #获取空格数
|
||||
[ "$line_c" -gt 2 ] && sed -i "${line_c}a\\${space}- ${new_group} #自定义策略组" $tmpdir/proxy-groups.yaml
|
||||
}
|
||||
done
|
||||
IFS="$oldIFS"
|
||||
done
|
||||
}
|
||||
#插入自定义代理
|
||||
sed -i "/#自定义代理/d" $tmpdir/proxies.yaml
|
||||
[ -f $clashdir/proxies.yaml ] && {
|
||||
[ -n "$(grep -Ev '^#' $clashdir/proxies.yaml 2>/dev/null)" ] && {
|
||||
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 #插入节点
|
||||
cat $clashdir/proxies.yaml | sed "s/^ *- /${space_proxy}- /g" | sed "/^#/d" | sed "/^ *$/d" | sed 's/#.*/ #自定义代理/g' >> $tmpdir/proxies.yaml #插入节点
|
||||
oldIFS="$IFS"
|
||||
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')
|
||||
|
@ -382,10 +385,12 @@ modify_yaml(){
|
|||
IFS="#"
|
||||
for name in $proxy_groups; do
|
||||
line_a=$(grep -n "\- name: $name" $tmpdir/proxy-groups.yaml | awk -F: '{print $1}') #获取group行号
|
||||
line_b=$(grep -A 8 "\- name: $name" $tmpdir/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号
|
||||
line_c=$((line_a + line_b - 1)) #计算需要插入的行号
|
||||
space=$(sed -n "$((line_c + 1))p" $tmpdir/proxy-groups.yaml | grep -oE '^ *') #获取空格数
|
||||
sed -i "${line_c}a\\${space}- ${proxy_name}#自定义代理" $tmpdir/proxy-groups.yaml
|
||||
[ -n "$line_a" ] && {
|
||||
line_b=$(grep -A 8 "\- name: $name" $tmpdir/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号
|
||||
line_c=$((line_a + line_b - 1)) #计算需要插入的行号
|
||||
space=$(sed -n "$((line_c + 1))p" $tmpdir/proxy-groups.yaml | grep -oE '^ *') #获取空格数
|
||||
[ "$line_c" -gt 2 ] && sed -i "${line_c}a\\${space}- ${proxy_name} #自定义代理" $tmpdir/proxy-groups.yaml
|
||||
}
|
||||
done
|
||||
IFS="$oldIFS"
|
||||
done
|
||||
|
@ -401,10 +406,12 @@ modify_yaml(){
|
|||
#插入自定义规则
|
||||
sed -i "/#自定义规则/d" $tmpdir/rules.yaml
|
||||
[ -f $clashdir/rules.yaml ] && {
|
||||
cat $clashdir/rules.yaml | sed 's/^ *-/ -/g' | sed "/^#/d" | sed '$a\' | sed 's/$/ #自定义规则/g' > $tmpdir/rules.add
|
||||
cat $clashdir/rules.yaml | sed "/^#/d" | sed '$a\' | sed 's/$/ #自定义规则/g' > $tmpdir/rules.add
|
||||
cat $tmpdir/rules.yaml >> $tmpdir/rules.add
|
||||
mv -f $tmpdir/rules.add $tmpdir/rules.yaml
|
||||
}
|
||||
#对齐rules中的空格
|
||||
sed -i 's/^ *-/ -/g' $tmpdir/rules.yaml
|
||||
#添加配置
|
||||
###################################
|
||||
cat > $tmpdir/set.yaml <<EOF
|
||||
|
@ -483,7 +490,7 @@ cn_ip_route(){
|
|||
mv $clashdir/cn_ip.txt $bindir/cn_ip.txt
|
||||
else
|
||||
logger "未找到cn_ip列表,正在下载!" 33
|
||||
$0 webget $bindir/cn_ip.txt "$update_url/bin/china_ip_list.txt"
|
||||
$0 webget $bindir/cn_ip.txt "$update_url/bin/geodata/china_ip_list.txt"
|
||||
[ "$?" = "1" ] && rm -rf $bindir/cn_ip.txt && logger "列表下载失败!" 31
|
||||
fi
|
||||
}
|
||||
|
@ -501,7 +508,7 @@ cn_ipv6_route(){
|
|||
mv $clashdir/cn_ipv6.txt $bindir/cn_ipv6.txt
|
||||
else
|
||||
logger "未找到cn_ipv6列表,正在下载!" 33
|
||||
$0 webget $bindir/cn_ipv6.txt "$update_url/bin/china_ipv6_list.txt"
|
||||
$0 webget $bindir/cn_ipv6.txt "$update_url/bin/geodata/china_ipv6_list.txt"
|
||||
[ "$?" = "1" ] && rm -rf $bindir/cn_ipv6.txt && logger "列表下载失败!" 31
|
||||
fi
|
||||
}
|
||||
|
@ -1166,8 +1173,8 @@ bfstart(){
|
|||
mv $clashdir/Country.mmdb $bindir/Country.mmdb
|
||||
else
|
||||
logger "未找到GeoIP数据库,正在下载!" 33
|
||||
$0 webget $bindir/Country.mmdb $update_url/bin/cn_mini.mmdb
|
||||
[ "$?" = "1" ] && rm -rf $bindir/Country.mmdb && logger "数据库下载失败,已退出!" 31 && exit 1
|
||||
$0 webget $bindir/Country.mmdb $update_url/bin/geodata/cn_mini.mmdb
|
||||
[ "$?" = "1" ] && rm -rf $bindir/Country.mmdb && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1
|
||||
Geo_v=$(date +"%Y%m%d")
|
||||
setconfig Geo_v $Geo_v
|
||||
fi
|
||||
|
@ -1189,8 +1196,8 @@ bfstart(){
|
|||
mv -f $clashdir/GeoSite.dat $bindir/GeoSite.dat
|
||||
else
|
||||
logger "未找到geosite数据库,正在下载!" 33
|
||||
$0 webget $bindir/GeoSite.dat $update_url/bin/geosite.dat
|
||||
[ "$?" = "1" ] && rm -rf $bindir/GeoSite.dat && logger "数据库下载失败,已退出!" 31 && exit 1
|
||||
$0 webget $bindir/GeoSite.dat $update_url/bin/geodata/geosite.dat
|
||||
[ "$?" = "1" ] && rm -rf $bindir/GeoSite.dat && logger "数据库下载失败,已退出,请前往更新界面尝试手动下载!" 31 && exit 1
|
||||
fi
|
||||
fi
|
||||
#本机代理准备
|
||||
|
|
Loading…
Reference in New Issue
Block a user