From 66cc65f23937ccc74822378da79311d59f20d870 Mon Sep 17 00:00:00 2001 From: juewuy Date: Sun, 13 Dec 2020 21:22:41 +0800 Subject: [PATCH] =?UTF-8?q?v1.0.0beta17.8=20~=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=AF=B9padavan=E7=B3=BB=E7=BB=9F=E8=AF=BB=E5=8F=96=E5=B1=80?= =?UTF-8?q?=E5=9F=9F=E7=BD=91=E8=AE=BE=E5=A4=87=E8=BF=87=E6=BB=A4=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E6=94=AF=E6=8C=81=20~=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BA=86=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E5=87=8F=E5=B0=91=E9=97=AA=E5=AD=98?= =?UTF-8?q?=E6=B6=88=E8=80=97=20~=E4=BF=AE=E5=A4=8D=E4=BA=86=E9=83=A8?= =?UTF-8?q?=E5=88=86mipsle=E8=AE=BE=E5=A4=87=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E8=AF=86=E5=88=AB=E6=A0=B8=E5=BF=83=E7=9A=84bug=20~?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E9=83=A8=E5=88=86=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E8=AE=A2=E9=98=85=E9=93=BE=E6=8E=A5/=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=93=BE=E6=8E=A5=E4=B8=A2=E5=A4=B1=E7=9A=84bug=20~?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E9=83=A8=E5=88=86=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E4=BC=9A=E8=BF=9E=E7=BB=AD=E4=B8=8B=E8=BD=BD=E4=B8=A4?= =?UTF-8?q?=E6=AC=A1=E6=A0=B8=E5=BF=83=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/clash.sh | 43 ++++++++++++++++++++++++++++--------------- scripts/getdate.sh | 19 +++++++++---------- scripts/start.sh | 10 +++++----- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/scripts/clash.sh b/scripts/clash.sh index 77f0b9c..b2bb263 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -11,6 +11,9 @@ getconfig(){ yaml=$clashdir/config.yaml #检查/读取标识文件 [ ! -f $ccfg ] && echo '#标识clash运行状态的文件,不明勿动!' > $ccfg + #检查重复行并去除 + [ -n "$(awk 'a[$0]++' $ccfg)" ] && awk '!a[$0]++' $ccfg > $ccfg + #使用source加载配置文件 source $ccfg #设置默认核心资源目录 [ -z "$bindir" ] && bindir=$clashdir @@ -78,7 +81,7 @@ getconfig(){ echo ----------------------------------------------- #检查新手引导 if [ -z "$userguide" ];then - sed -i "1i\userguide=1" $ccfg + setconfig userguide 1 source $clashdir/getdate.sh && userguide fi #检查执行权限 @@ -87,8 +90,7 @@ getconfig(){ setconfig(){ #参数1代表变量名,参数2代表变量值,参数3即文件路径 [ -z "$3" ] && configpath=$clashdir/mark || configpath=$3 - sed -i "/${1}*/"d $configpath - echo "${1}=${2}" >> $configpath + [ -n "$(grep ${1} $configpath)" ] && sed -i "s/${1}=.*/${1}=${2}/g" $configpath || echo "${1}=${2}" >> $configpath } #启动相关 errornum(){ @@ -124,7 +126,7 @@ clashstart(){ } checkrestart(){ echo ----------------------------------------------- - echo -e "\033[32m检测到配置文件已变更,需要重启clash服务以生效!\033[0m" + echo -e "\033[32m检测到已变更的内容,请重启clash服务!\033[0m" echo ----------------------------------------------- read -p "是否现在重启clash服务?(1/0) > " res [ "$res" = 1 ] && clashstart @@ -178,7 +180,7 @@ setport(){ read -p "请输入Http/Sock5用户名及密码 > " input if [ "$input" = "0" ];then authentication="" - sed -i "/authentication*/"d $ccfg + setconfig authentication echo 密码已移除! else if [ "$local_proxy" = "已开启" ];then @@ -267,8 +269,8 @@ setdns(){ elif [ "$num" = 3 ]; then dns_nameserver="" dns_fallback="" - sed -i "/dns_nameserver*/"d $ccfg - sed -i "/dns_fallback*/"d $ccfg + setconfig dns_nameserver + setconfig dns_fallback echo -e "\033[33mDNS配置已重置!!!\033[0m" setdns elif [ "$num" = 4 ]; then @@ -364,9 +366,10 @@ macfilter(){ fi } echo ----------------------------------------------- - [ -f /var/lib/dhcp/dhcpd.leases ] && dhcpdir='/var/lib/dhcp/dhcpd.leases' - [ -f /var/lib/dhcpd/dhcpd.leases ] && dhcpdir='/var/lib/dhcpd/dhcpd.leases' - [ -f /tmp/dhcp.leases ] && dhcpdir='/tmp/dhcp.leases' + [ -z "$dhcpdir" ] && dhcpdir='/var/lib/dhcp/dhcpd.leases' + [ -z "$dhcpdir" ] && dhcpdir='/var/lib/dhcpd/dhcpd.leases' + [ -z "$dhcpdir" ] && dhcpdir='/tmp/dhcp.leases' + [ -z "$dhcpdir" ] && dhcpdir='/tmp/dnsmasq.leases' [ -z "$dhcpdir" ] && dhcpdir='/dev/null' [ -z "$macfilter_type" ] && macfilter_type='黑名单' [ "$macfilter_type" = "黑名单" ] && macfilter_over='白名单' || macfilter_over='黑名单' @@ -798,7 +801,7 @@ clashadv(){ if [ "$dns_no" = "已禁用" ];then read -p "检测到内置DNS已被禁用,是否启用内置DNS?(1/0) > " res if [ "$res" = "1" ];then - sed -i "/dns_no*/"d $ccfg + setconfig dns_no setdns fi else @@ -1008,8 +1011,10 @@ clashsh(){ elif [ "$num" = 2 ]; then checkcfg=$(cat $ccfg) clashcfg - checkcfg_new=$(cat $ccfg) - [ "$checkcfg" != "$checkcfg_new" ] && checkrestart + if [ -n "$PID" ];then + checkcfg_new=$(cat $ccfg) + [ "$checkcfg" != "$checkcfg_new" ] && checkrestart + fi clashsh elif [ "$num" = 3 ]; then @@ -1050,15 +1055,23 @@ clashsh(){ elif [ "$num" = 7 ]; then checkcfg=$(cat $ccfg) clashadv - checkcfg_new=$(cat $ccfg) - [ "$checkcfg" != "$checkcfg_new" ] && checkrestart + if [ -n "$PID" ];then + checkcfg_new=$(cat $ccfg) + [ "$checkcfg" != "$checkcfg_new" ] && checkrestart + fi clashsh elif [ "$num" = 8 ]; then source $clashdir/getdate.sh && testcommand elif [ "$num" = 9 ]; then + checkcfg=$(cat $ccfg) source $clashdir/getdate.sh && update + if [ -n "$PID" ];then + checkcfg_new=$(cat $ccfg) + [ "$checkcfg" != "$checkcfg_new" ] && checkrestart + fi + clashsh else errornum diff --git a/scripts/getdate.sh b/scripts/getdate.sh index ea5d731..ac14035 100644 --- a/scripts/getdate.sh +++ b/scripts/getdate.sh @@ -394,26 +394,28 @@ getcpucore(){ [ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386" [ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64" if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ];then - mipstype=$(echo -n I | hexdump -o | awk '{ print substr($2,6,1); exit}') #通过判断大小端判断mips或mipsle - [ "$mipstype" != "1" ] && cpucore="mips-softfloat" || cpucore="mipsle-softfloat" + mipstype=$(echo -n I | hexdump -o 2>/dev/null | awk '{ print substr($2,6,1); exit}') #通过判断大小端判断mips或mipsle + [ "$mipstype" = "0" ] && cpucore="mips-softfloat" || cpucore="mipsle-softfloat" fi [ -n "$cpucore" ] && setconfig cpucore $cpucore } setcpucore(){ - cpucore_list="armv5 armv7 armv8 386 amd64 \nmipsle-softfloat mipsle-hardfloat mips-softfloat" + cpucore_list="armv5 armv7 armv8 386 amd64 mipsle-softfloat mipsle-hardfloat mips-softfloat" echo ----------------------------------------------- echo -e "\033[31m仅适合脚本无法正确识别核心或核心无法正常运行时使用!\033[0m" echo -e "当前可供在线下载的处理器架构为:" - echo -e "\033[32m$cpucore_list\033[0m" + echo $cpucore_list | awk -F " " '{for(i=1;i<=NF;i++) {print i" "$i }}' echo -e "如果您的CPU架构未在以上列表中,请运行【uname -a】命令,并复制好返回信息" echo -e "之后前往 t.me/clashfm 群提交或 github.com/juewuy/ShellClash 提交issue" echo ----------------------------------------------- - read -p "请手动输入处理器架构 > " cpucore - if [ -z "$(echo $cpucore_list |grep "$cpucore")" ];then + read -p "请输入对应数字 > " num + setcpucore=$(echo $cpucore_list | awk '{print $"'"$num"'"}' ) + if [ -z "$setcpucore" ];then echo -e "\033[31m请输入正确的处理器架构!\033[0m" sleep 1 cpucore="" else + cpucore=$setcpucore setconfig cpucore $cpucore fi } @@ -770,9 +772,8 @@ update(){ read -p "请输入对应数字 > " num if [ -z "$num" ]; then errornum - clashsh elif [ "$num" = 0 ]; then - clashsh + i= elif [ "$num" = 1 ]; then getsh @@ -840,9 +841,7 @@ update(){ update else errornum - clashsh fi -exit; } #新手引导 userguide(){ diff --git a/scripts/start.sh b/scripts/start.sh index 191b9dd..91826cd 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -33,8 +33,7 @@ getconfig(){ setconfig(){ #参数1代表变量名,参数2代表变量值,参数3即文件路径 [ -z "$3" ] && configpath=$clashdir/mark || configpath=$3 - sed -i "/${1}*/"d $configpath - echo "${1}=${2}" >> $configpath + [ -n "$(grep ${1} $configpath)" ] && sed -i "s/${1}=.*/${1}=${2}/g" $configpath || echo "${1}=${2}" >> $configpath } compare(){ if [ ! -f $1 -o ! -f $2 ];then @@ -422,7 +421,6 @@ web_save(){ fi } #使用get_save获取面板节点设置 - #get_save http://localhost:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g'| sed 's/"//g' > /tmp/clash_web_save_$USER get_save http://localhost:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' > /tmp/clash_web_check_$USER while read line ;do def=$(echo $line | awk -F "[\[,]" '{print $2}') @@ -430,8 +428,10 @@ web_save(){ [ "$def" != "$now" ] && echo $line | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g'| sed 's/"//g' >> /tmp/clash_web_save_$USER done < /tmp/clash_web_check_$USER #对比文件,如果有变动且不为空则写入磁盘,否则清除缓存 - [ ! -s /tmp/clash_web_save_$USER ] && 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 /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 + fi } web_restore(){ put_save(){