Skip to content

Commit 93d550a

Browse files
committed
fix sb dns
1 parent a6c3763 commit 93d550a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

sing-box.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
args=$@
4-
is_sh_ver=v1.11
4+
is_sh_ver=v1.12
55

66
. /etc/sing-box/sh/src/init.sh

src/dns.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ is_dns_list=(
88
none
99
)
1010
dns_set() {
11+
if [[ $(echo -e "1.11.99\n$is_core_ver" | sort -V | head -n1) == '1.11.99' ]]; then
12+
is_dns_new=1
13+
fi
1114
if [[ $1 ]]; then
1215
case ${1,,} in
1316
11 | 1111)
@@ -46,11 +49,34 @@ dns_set() {
4649
ask string is_dns_use "请输入 DNS: "
4750
fi
4851
fi
52+
is_dns_use_bak=$is_dns_use
4953
if [[ $is_dns_use == "none" ]]; then
5054
cat <<<$(jq '.dns={}' $is_config_json) >$is_config_json
5155
else
52-
cat <<<$(jq '.dns.servers=[{address:"'$is_dns_use'",address_resolver:"local"},{tag:"local",address:"local"}]' $is_config_json) >$is_config_json
56+
if [[ $is_dns_new ]]; then
57+
dns_set_server $is_dns_use
58+
cat <<<$(jq '.dns.servers=[{type:"'$is_dns_type'",server:"'$is_dns_use'",domain_resolver:"local"},{tag:"local",type:"local"}]' $is_config_json) >$is_config_json
59+
else
60+
cat <<<$(jq '.dns.servers=[{address:"'$is_dns_use'",address_resolver:"local"},{tag:"local",address:"local"}]' $is_config_json) >$is_config_json
61+
fi
5362
fi
5463
manage restart &
55-
msg "\n已更新 DNS 为: $(_green $is_dns_use)\n"
64+
msg "\n已更新 DNS 为: $(_green $is_dns_use_bak)\n"
65+
}
66+
dns_set_server() {
67+
if [[ $(grep '://' <<<$1) ]]; then
68+
is_tmp_dns_set=($(awk -F '://|/' '{print $1, $2}' <<<${1,,}))
69+
case ${is_tmp_dns_set[0]} in
70+
tcp | udp | tls | https | quic | h3)
71+
is_dns_use=${is_tmp_dns_set[1]}
72+
is_dns_type=${is_tmp_dns_set[0]}
73+
;;
74+
*)
75+
err "无法识别 DNS 类型!"
76+
;;
77+
esac
78+
else
79+
is_dns_use=$1
80+
is_dns_type=udp
81+
fi
5682
}

0 commit comments

Comments
 (0)