From 4d7bd92381252257b14598c61c99cd0d401bde44 Mon Sep 17 00:00:00 2001 From: juewuy Date: Fri, 19 Mar 2021 17:55:20 +0800 Subject: [PATCH] =?UTF-8?q?v1.1.6-test=20~=E6=96=B0=E5=A2=9E=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=9C=AC=E6=9C=BAhost=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=887-6-8=EF=BC=89=20~=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=83=A8=E5=88=86=E6=83=85=E5=86=B5=E4=B8=8B=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E6=9C=AC=E6=9C=BAhost=E5=A4=B1=E8=B4=A5=E7=9A=84bug?= =?UTF-8?q?=20~=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E5=AF=BC=E5=85=A5=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/clash.sh | 27 ++++++++++++++++++++++++--- scripts/start.sh | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/scripts/clash.sh b/scripts/clash.sh index f5fb218..d0cdb87 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -27,7 +27,7 @@ getconfig(){ #检查mac地址记录 [ ! -f $clashdir/mac ] && touch $clashdir/mac #获取本机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 -E '\ 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host" ] && host=127.0.0.1 #dashboard目录位置 @@ -93,7 +93,7 @@ getconfig(){ setconfig(){ #参数1代表变量名,参数2代表变量值,参数3即文件路径 [ -z "$3" ] && configpath=$clashdir/mark || configpath=$3 - [ -n "$(grep ${1} $configpath)" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath + [ -n "$(grep ${1} $configpath)" ] && sed -i "s#${1}=\(.*\)#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath } #启动相关 errornum(){ @@ -166,6 +166,7 @@ setport(){ echo -e " 5 修改面板访问端口: \033[36m$db_port\033[0m" echo -e " 6 设置面板访问密码: \033[36m$secret\033[0m" echo -e " 7 修改默认端口过滤: \033[36m$multiport\033[0m" + echo -e " 8 指定本机host地址: \033[36m$host\033[0m" echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" ]; then @@ -233,6 +234,26 @@ setport(){ echo -e "\033[32m设置成功!!!\033[0m" fi setport + elif [ "$num" = 8 ]; then + echo ----------------------------------------------- + echo -e "\033[33m此处可以更改脚本内置的host地址\033[0m" + echo -e "\033[31m设置后如本机host地址有变动,请务必手动修改!\033[0m" + echo ----------------------------------------------- + read -p "请输入自定义host地址(输入0移除自定义host) > " host + if [ "$host" = "0" ];then + host="" + setconfig host $host + echo -e "\033[32m已经移除自定义host地址,请重新运行脚本以自动获取host!!!\033[0m" + exit 0 + elif [ -n "$(echo $host | grep -Po '(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])(\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)){3}')" ]; then + setconfig host $host + echo -e "\033[32m设置成功!!!\033[0m" + else + host="" + echo -e "\033[31m输入错误,请仔细核对!!!\033[0m" + fi + sleep 1 + setport fi } setdns(){ @@ -719,7 +740,7 @@ clashadv(){ echo -e " 3 Redir模式udp转发: \033[36m$tproxy_mod\033[0m ————依赖iptables-mod-tproxy" echo -e " 4 启用小闪存模式: \033[36m$mini_clash\033[0m ————启动时方下载核心及数据库文件" echo -e " 5 配置内置DNS服务 \033[36m$dns_no\033[0m" - echo -e " 6 手动指定相关服务端口及秘钥" + echo -e " 6 手动指定相关端口、秘钥及本机host" echo -e " 7 使用自定义配置" echo ----------------------------------------------- echo -e " 8 \033[31m重置\033[0m配置文件" diff --git a/scripts/start.sh b/scripts/start.sh index 552ad3f..3abab90 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -90,7 +90,7 @@ mark_time(){ echo start_time=$start_time >> $clashdir/mark } gethost(){ - 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 -E '\ 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -n "$host" ] && lanhost="-s $(echo $host | grep -oE '^1(92|0|72)\.')0.0.0/8" }