From ed30acdd7a7087ddc90b4965cde9d5cef8c2a39f Mon Sep 17 00:00:00 2001 From: juewuy Date: Sat, 7 Nov 2020 12:08:31 +0800 Subject: [PATCH] =?UTF-8?q?v1.0.0beta16.9=20~=E6=96=B0=E5=A2=9E=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=88=87=E6=8D=A2=E7=89=88=E6=9C=AC=E5=88=B0=E5=85=B6?= =?UTF-8?q?=E4=BB=96release=E7=89=88=E6=9C=AC=E7=9A=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20~=E8=B0=83=E6=95=B4release=E7=89=88=E6=9C=AC=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=A3=80=E6=B5=8B=E6=9C=BA=E5=88=B6=20~=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=83=A8=E5=88=86=E8=AE=BE=E5=A4=87=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E7=BC=BA=E5=B0=91cmb=E7=9A=84=E9=97=AE=E9=A2=98=20~=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BD=BF=E7=94=A8=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=97=B6=EF=BC=8C=E6=AF=8F=E6=AC=A1=E5=90=AF=E5=8A=A8?= =?UTF-8?q?clash=E8=A7=84=E5=88=99=E9=83=BD=E4=BC=9A=E8=A2=AB=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=AF=BC=E5=85=A5=E7=9A=84=E9=97=AE=E9=A2=98=20~?= =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E4=BC=98=E5=8C=96=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 4 ++-- scripts/getdate.sh | 23 +++++++++++++++++++++-- scripts/start.sh | 23 ++++++++++++++++------- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/install.sh b/install.sh index 7a60c52..3517f45 100644 --- a/install.sh +++ b/install.sh @@ -40,8 +40,8 @@ if [ "$test" -gt 0 ];then [ "$test" -eq 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi" [ "$test" -eq 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi" else - webget /tmp/clashrelease https://github.com.cnpmjs.org/juewuy/ShellClash/releases/latest echoon rediroff 2>/tmp/clashrelease - release_new=$( cat /tmp/clashrelease | grep -aoE "releases/tag/.*" | awk -F '[/" ]' '{print $3}') + webget /tmp/clashrelease $url@master/bin/release_version echoon rediroff 2>/tmp/clashrelease + release_new=$(cat /tmp/clashrelease | head -1) [ -z "$release_new" ] && release_new=master url=$url@$release_new fi diff --git a/scripts/getdate.sh b/scripts/getdate.sh index 4d38497..006c7ee 100644 --- a/scripts/getdate.sh +++ b/scripts/getdate.sh @@ -679,6 +679,7 @@ setserver(){ echo -e " 3 Github源(test版本,需开启clash服务)" echo -e " 4 Gitee源(release版本,可能滞后)" echo -e " 5 自定义输入(请务必确保路径正确)" + echo -e " 6 切换版本(仅支持切换至release分支)" echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" ]; then @@ -700,6 +701,24 @@ setserver(){ echo -e "\033[31m取消输入,返回上级菜单\033[0m" update fi + elif [ "$num" = 6 ]; then + echo ----------------------------------------------- + webget /tmp/clashrelease https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/bin/release_version echooff rediroff 2>/tmp/clashrelease + echo -e "\033[32m请选择想要更新至的版本:\033[0m" + cat /tmp/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 | awk 'END{print NR}') 2>/dev/null ]; then + release_version=$(cat /tmp/clashrelease | awk '{print $1}' | sed -n "$num"p) + update_url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash@$release_version" + echo -e "\033[32m设置成功!\033[0m" + else + echo ----------------------------------------------- + echo -e "\033[31m输入有误,请重新输入!\033[0m" + fi + elif [ "$num" = 9 ]; then update_url='http://192.168.31.30:8080/clash-for-Miwifi' else @@ -716,8 +735,8 @@ setserver(){ checkupdate(){ if [ -z "$release_new" ];then if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ];then - webget /tmp/clashrelease https://github.com.cnpmjs.org/juewuy/ShellClash/releases/latest echoon rediroff 2>/tmp/clashrelease - release_new=$( cat /tmp/clashrelease | grep -aoE "releases/tag/.*" | awk -F '[/" ]' '{print $3}') + webget /tmp/clashrelease $update_url@master/bin/release_version echoon rediroff 2>/tmp/clashrelease + release_new=$(cat /tmp/clashrelease | head -1) [ -z "$release_new" ] && release_new=master update_url=$update_url@$release_new fi diff --git a/scripts/start.sh b/scripts/start.sh index d72cdf3..c9cc6c9 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -35,6 +35,13 @@ setconfig(){ sed -i "/${1}*/"d $configpath echo "${1}=${2}" >> $configpath } +compare(){ + if command -v cmp >/dev/null 2>&1; then + cmp -s $1 $2 + else + [ "$(cat $1)" = "$(cat $2)" ] && return 0 || return 1 + fi +} webget(){ [ -n "$(pidof clash)" ] && export all_proxy="http://$authentication@127.0.0.1:$mix_port" #设置临时http代理 #参数【$1】代表下载目录,【$2】代表在线地址 @@ -169,7 +176,7 @@ EOF` fi #如果不同则备份并替换文件 if [ -f $yaml ];then - cmp -s $yamlnew $yaml 2>/dev/null + compare $yamlnew $yaml [ "$?" = 0 ] && rm -f $yamlnew || mv -f $yaml $yaml.bak && mv -f $yamlnew $yaml else mv -f $yamlnew $yaml @@ -243,12 +250,15 @@ EOF #插入自定义规则 if [ -f $clashdir/rules.yaml ];then while read line;do - [ -z "$(echo "$line" | grep '#')" ] && [ -n "$(echo "$line" | grep '\-\ ')" ] && sed -i "/^rules:/a\ $line" $tmpdir/config.yaml + [ -z "$(echo "$line" | grep '#')" ] && \ + [ -n "$(echo "$line" | grep '\-\ ')" ] && \ + sed -i "/$line/d" $tmpdir/config.yaml && \ + sed -i "/^rules:/a\ $line" $tmpdir/config.yaml done < $clashdir/rules.yaml fi #如果没有使用小闪存模式 if [ "$tmpdir" != "$bindir" ];then - cmp -s $tmpdir/config.yaml $yaml 2>/dev/null + compare $tmpdir/config.yaml $yaml [ "$?" != 0 ] && mv -f $tmpdir/config.yaml $yaml || rm -f $tmpdir/config.yaml fi rm -f $tmpdir/set.yaml @@ -413,8 +423,8 @@ web_save(){ } #使用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 - #对比文件,如果有变动则写入磁盘,否则清除缓存 - cmp -s /tmp/clash_web_save_$USER $clashdir/web_save 2>/dev/null + #对比文件,如果有变动且不为空则写入磁盘,否则清除缓存 + [ ! -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 } web_restore(){ @@ -445,7 +455,6 @@ web_restore(){ now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' $clashdir/web_save) put_save http://localhost:${db_port}/proxies/${group_name} "{\"name\":\"${now_name}\"}" done - exit 0 } #启动相关 catpac(){ @@ -469,7 +478,7 @@ function FindProxyForURL(url, host) { return "SOCKS5 $host:$mix_port; PROXY $host:$mix_port; DIRECT;" } EOF - cmp -s /tmp/clash_pac $bindir/ui/pac 2>/dev/null + compare /tmp/clash_pac $bindir/ui/pac [ "$?" = 0 ] && rm -rf /tmp/clash_pac || mv -f /tmp/clash_pac $bindir/ui/pac } bfstart(){