v1.0.0beta16.9
~新增更新切换版本到其他release版本的功能 ~调整release版本更新检测机制 ~修复部分设备提示缺少cmb的问题 ~修复使用自定义规则时,每次启动clash规则都会被重复导入的问题 ~进一步优化面板保存机制
This commit is contained in:
@@ -40,8 +40,8 @@ if [ "$test" -gt 0 ];then
|
|||||||
[ "$test" -eq 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi"
|
[ "$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"
|
[ "$test" -eq 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi"
|
||||||
else
|
else
|
||||||
webget /tmp/clashrelease https://github.com.cnpmjs.org/juewuy/ShellClash/releases/latest echoon rediroff 2>/tmp/clashrelease
|
webget /tmp/clashrelease $url@master/bin/release_version echoon rediroff 2>/tmp/clashrelease
|
||||||
release_new=$( cat /tmp/clashrelease | grep -aoE "releases/tag/.*" | awk -F '[/" ]' '{print $3}')
|
release_new=$(cat /tmp/clashrelease | head -1)
|
||||||
[ -z "$release_new" ] && release_new=master
|
[ -z "$release_new" ] && release_new=master
|
||||||
url=$url@$release_new
|
url=$url@$release_new
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -679,6 +679,7 @@ setserver(){
|
|||||||
echo -e " 3 Github源(test版本,需开启clash服务)"
|
echo -e " 3 Github源(test版本,需开启clash服务)"
|
||||||
echo -e " 4 Gitee源(release版本,可能滞后)"
|
echo -e " 4 Gitee源(release版本,可能滞后)"
|
||||||
echo -e " 5 自定义输入(请务必确保路径正确)"
|
echo -e " 5 自定义输入(请务必确保路径正确)"
|
||||||
|
echo -e " 6 切换版本(仅支持切换至release分支)"
|
||||||
echo -e " 0 返回上级菜单"
|
echo -e " 0 返回上级菜单"
|
||||||
read -p "请输入对应数字 > " num
|
read -p "请输入对应数字 > " num
|
||||||
if [ -z "$num" ]; then
|
if [ -z "$num" ]; then
|
||||||
@@ -700,6 +701,24 @@ setserver(){
|
|||||||
echo -e "\033[31m取消输入,返回上级菜单\033[0m"
|
echo -e "\033[31m取消输入,返回上级菜单\033[0m"
|
||||||
update
|
update
|
||||||
fi
|
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
|
elif [ "$num" = 9 ]; then
|
||||||
update_url='http://192.168.31.30:8080/clash-for-Miwifi'
|
update_url='http://192.168.31.30:8080/clash-for-Miwifi'
|
||||||
else
|
else
|
||||||
@@ -716,8 +735,8 @@ setserver(){
|
|||||||
checkupdate(){
|
checkupdate(){
|
||||||
if [ -z "$release_new" ];then
|
if [ -z "$release_new" ];then
|
||||||
if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ];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
|
webget /tmp/clashrelease $update_url@master/bin/release_version echoon rediroff 2>/tmp/clashrelease
|
||||||
release_new=$( cat /tmp/clashrelease | grep -aoE "releases/tag/.*" | awk -F '[/" ]' '{print $3}')
|
release_new=$(cat /tmp/clashrelease | head -1)
|
||||||
[ -z "$release_new" ] && release_new=master
|
[ -z "$release_new" ] && release_new=master
|
||||||
update_url=$update_url@$release_new
|
update_url=$update_url@$release_new
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -35,6 +35,13 @@ setconfig(){
|
|||||||
sed -i "/${1}*/"d $configpath
|
sed -i "/${1}*/"d $configpath
|
||||||
echo "${1}=${2}" >> $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(){
|
webget(){
|
||||||
[ -n "$(pidof clash)" ] && export all_proxy="http://$authentication@127.0.0.1:$mix_port" #设置临时http代理
|
[ -n "$(pidof clash)" ] && export all_proxy="http://$authentication@127.0.0.1:$mix_port" #设置临时http代理
|
||||||
#参数【$1】代表下载目录,【$2】代表在线地址
|
#参数【$1】代表下载目录,【$2】代表在线地址
|
||||||
@@ -169,7 +176,7 @@ EOF`
|
|||||||
fi
|
fi
|
||||||
#如果不同则备份并替换文件
|
#如果不同则备份并替换文件
|
||||||
if [ -f $yaml ];then
|
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
|
[ "$?" = 0 ] && rm -f $yamlnew || mv -f $yaml $yaml.bak && mv -f $yamlnew $yaml
|
||||||
else
|
else
|
||||||
mv -f $yamlnew $yaml
|
mv -f $yamlnew $yaml
|
||||||
@@ -243,12 +250,15 @@ EOF
|
|||||||
#插入自定义规则
|
#插入自定义规则
|
||||||
if [ -f $clashdir/rules.yaml ];then
|
if [ -f $clashdir/rules.yaml ];then
|
||||||
while read line;do
|
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
|
done < $clashdir/rules.yaml
|
||||||
fi
|
fi
|
||||||
#如果没有使用小闪存模式
|
#如果没有使用小闪存模式
|
||||||
if [ "$tmpdir" != "$bindir" ];then
|
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
|
[ "$?" != 0 ] && mv -f $tmpdir/config.yaml $yaml || rm -f $tmpdir/config.yaml
|
||||||
fi
|
fi
|
||||||
rm -f $tmpdir/set.yaml
|
rm -f $tmpdir/set.yaml
|
||||||
@@ -413,8 +423,8 @@ web_save(){
|
|||||||
}
|
}
|
||||||
#使用get_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
|
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
|
[ "$?" = 0 ] && rm -rf /tmp/clash_web_save_$USER || mv -f /tmp/clash_web_save_$USER $clashdir/web_save
|
||||||
}
|
}
|
||||||
web_restore(){
|
web_restore(){
|
||||||
@@ -445,7 +455,6 @@ web_restore(){
|
|||||||
now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' $clashdir/web_save)
|
now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' $clashdir/web_save)
|
||||||
put_save http://localhost:${db_port}/proxies/${group_name} "{\"name\":\"${now_name}\"}"
|
put_save http://localhost:${db_port}/proxies/${group_name} "{\"name\":\"${now_name}\"}"
|
||||||
done
|
done
|
||||||
exit 0
|
|
||||||
}
|
}
|
||||||
#启动相关
|
#启动相关
|
||||||
catpac(){
|
catpac(){
|
||||||
@@ -469,7 +478,7 @@ function FindProxyForURL(url, host) {
|
|||||||
return "SOCKS5 $host:$mix_port; PROXY $host:$mix_port; DIRECT;"
|
return "SOCKS5 $host:$mix_port; PROXY $host:$mix_port; DIRECT;"
|
||||||
}
|
}
|
||||||
EOF
|
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
|
[ "$?" = 0 ] && rm -rf /tmp/clash_pac || mv -f /tmp/clash_pac $bindir/ui/pac
|
||||||
}
|
}
|
||||||
bfstart(){
|
bfstart(){
|
||||||
|
|||||||
Reference in New Issue
Block a user