Skip to content

Commit c37baf7

Browse files
committed
fix bug when upgrading sing-box to the latest core version.
1 parent 5dc6bc2 commit c37baf7

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

docker_init.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# 脚本更新日期 2025.04.05
3+
# 脚本更新日期 2025.05.19
44
WORK_DIR=/sing-box
55
PORT=$START_PORT
66
SUBSCRIBE_TEMPLATE="https://raw.githubusercontent.com/fscarmen/client_template/main"
@@ -34,7 +34,7 @@ check_latest_sing-box() {
3434

3535
# 获取最终版本号
3636
local VERSION=$(wget --no-check-certificate --tries=2 --timeout=3 -qO- https://api.github.com/repos/SagerNet/sing-box/releases | awk -F '["v]' -v var="tag_name.*$FORCE_VERSION" '$0 ~ var {print $5; exit}')
37-
VERSION=${VERSION:-'1.12.0-beta.1'}
37+
VERSION=${VERSION:-'v1.12.0-beta.15'}
3838

3939
echo "$VERSION"
4040
}

sing-box.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# 当前脚本版本号
4-
VERSION='v1.2.17 (2025.05.11)'
4+
VERSION='v1.2.17 (2025.05.19)'
55

66
# 各变量默认值
77
GH_PROXY='https://ghfast.top/'
@@ -18,7 +18,7 @@ NODE_TAG=("xtls-reality" "hysteria2" "tuic" "ShadowTLS" "shadowsocks" "trojan" "
1818
CONSECUTIVE_PORTS=${#PROTOCOL_LIST[@]}
1919
CDN_DOMAIN=("skk.moe" "ip.sb" "time.is" "cfip.xxxxxxxx.tk" "bestcf.top" "cdn.2020111.xyz" "xn--b6gac.eu.org")
2020
SUBSCRIBE_TEMPLATE="https://raw.githubusercontent.com/fscarmen/client_template/main"
21-
DEFAULT_NEWEST_VERSION='1.12.0-beta.11'
21+
DEFAULT_NEWEST_VERSION='1.12.0-beta.15'
2222

2323
export DEBIAN_FRONTEND=noninteractive
2424

@@ -640,7 +640,7 @@ check_install() {
640640
if [ "${STATUS[0]}" = "$(text 26)" ] && [ ! -s ${WORK_DIR}/sing-box ]; then
641641
{
642642
# 获取需要下载的 sing-box 版本
643-
ONLINE=$(get_sing_box_version)
643+
local ONLINE=$(get_sing_box_version)
644644
wget --no-check-certificate --continue ${GH_PROXY}https://github.com/SagerNet/sing-box/releases/download/v$ONLINE/sing-box-$ONLINE-linux-$SING_BOX_ARCH.tar.gz -qO- | tar xz -C $TEMP_DIR sing-box-$ONLINE-linux-$SING_BOX_ARCH/sing-box >/dev/null 2>&1
645645
[ -s $TEMP_DIR/sing-box-$ONLINE-linux-$SING_BOX_ARCH/sing-box ] && mv $TEMP_DIR/sing-box-$ONLINE-linux-$SING_BOX_ARCH/sing-box $TEMP_DIR
646646
wget --no-check-certificate --continue -qO $TEMP_DIR/jq ${GH_PROXY}https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-$JQ_ARCH >/dev/null 2>&1 && chmod +x $TEMP_DIR/jq >/dev/null 2>&1
@@ -789,22 +789,6 @@ check_system_info() {
789789
fi
790790
}
791791

792-
# 删除端口跳跃
793-
del_port_hopping_nat(){
794-
check_port_hopping_nat
795-
if [ "$SYSTEM" = 'Alpine' ]; then
796-
iptables --table nat -D PREROUTING -p udp --dport ${PORT_HOPPING_START}:${PORT_HOPPING_END} -m comment --comment "NAT ${PORT_HOPPING_START}:${PORT_HOPPING_END} to ${PORT_HOPPING_TARGET} (Sing-box Family Bucket)" -j DNAT --to-destination :${PORT_HOPPING_TARGET} 2>/dev/null
797-
ip6tables --table nat -D PREROUTING -p udp --dport ${PORT_HOPPING_START}:${PORT_HOPPING_END} -m comment --comment "NAT ${PORT_HOPPING_START}:${PORT_HOPPING_END} to ${PORT_HOPPING_TARGET} (Sing-box Family Bucket)" -j DNAT --to-destination :${PORT_HOPPING_TARGET} 2>/dev/null
798-
elif [ "$(systemctl is-active firewalld)" = 'active' ]; then
799-
firewall-cmd --permanent --remove-forward-port=port=${PORT_HOPPING_START}-${PORT_HOPPING_END}:proto=udp:toport=${PORT_HOPPING_TARGET} >/dev/null 2>&1
800-
firewall-cmd --reload >/dev/null 2>&1
801-
else
802-
iptables --table nat -D PREROUTING -p udp --dport ${PORT_HOPPING_START}:${PORT_HOPPING_END} -m comment --comment "NAT ${PORT_HOPPING_START}:${PORT_HOPPING_END} to ${PORT_HOPPING_TARGET} (Sing-box Family Bucket)" -j DNAT --to-destination :${PORT_HOPPING_TARGET} 2>/dev/null
803-
ip6tables --table nat -D PREROUTING -p udp --dport ${PORT_HOPPING_START}:${PORT_HOPPING_END} -m comment --comment "NAT ${PORT_HOPPING_START}:${PORT_HOPPING_END} to ${PORT_HOPPING_TARGET} (Sing-box Family Bucket)" -j DNAT --to-destination :${PORT_HOPPING_TARGET} 2>/dev/null
804-
[ "$(systemctl is-active netfilter-persistent)" = 'active' ] && netfilter-persistent save 2>/dev/null
805-
fi
806-
}
807-
808792
# 获取 sing-box 最新版本
809793
get_sing_box_version() {
810794
# FORCE_VERSION 用于在 sing-box 某个主程序出现 bug 时,强制为指定版本,以防止运行出错
@@ -814,7 +798,7 @@ get_sing_box_version() {
814798
else
815799
# 先判断 github api 返回 http 状态码是否为 200,有时候 IP 会被限制,导致获取不到最新版本
816800
local API_RESPONSE=$(wget --no-check-certificate --server-response --tries=2 --timeout=3 -qO- "${GH_PROXY}https://api.github.com/repos/SagerNet/sing-box/releases" 2>&1 | grep -E '^[ ]+HTTP/|tag_name')
817-
if ! grep -q 'HTTP.* 200' <<< "$API_RESPONSE"; then
801+
if grep -q 'HTTP.* 200' <<< "$API_RESPONSE"; then
818802
local VERSION_LATEST=$(awk -F '["v-]' '/tag_name/{print $5}' <<< "$API_RESPONSE" | sort -Vr | sed -n '1p')
819803
local RESULT_VERSION=$(wget --no-check-certificate --tries=2 --timeout=3 -qO- ${GH_PROXY}https://api.github.com/repos/SagerNet/sing-box/releases | awk -F '["v]' -v var="tag_name.*$VERSION_LATEST" '$0 ~ var {print $5; exit}')
820804
else
@@ -873,6 +857,22 @@ add_port_hopping_nat() {
873857
fi
874858
}
875859

860+
# 删除端口跳跃
861+
del_port_hopping_nat(){
862+
check_port_hopping_nat
863+
if [ "$SYSTEM" = 'Alpine' ]; then
864+
iptables --table nat -D PREROUTING -p udp --dport ${PORT_HOPPING_START}:${PORT_HOPPING_END} -m comment --comment "NAT ${PORT_HOPPING_START}:${PORT_HOPPING_END} to ${PORT_HOPPING_TARGET} (Sing-box Family Bucket)" -j DNAT --to-destination :${PORT_HOPPING_TARGET} 2>/dev/null
865+
ip6tables --table nat -D PREROUTING -p udp --dport ${PORT_HOPPING_START}:${PORT_HOPPING_END} -m comment --comment "NAT ${PORT_HOPPING_START}:${PORT_HOPPING_END} to ${PORT_HOPPING_TARGET} (Sing-box Family Bucket)" -j DNAT --to-destination :${PORT_HOPPING_TARGET} 2>/dev/null
866+
elif [ "$(systemctl is-active firewalld)" = 'active' ]; then
867+
firewall-cmd --permanent --remove-forward-port=port=${PORT_HOPPING_START}-${PORT_HOPPING_END}:proto=udp:toport=${PORT_HOPPING_TARGET} >/dev/null 2>&1
868+
firewall-cmd --reload >/dev/null 2>&1
869+
else
870+
iptables --table nat -D PREROUTING -p udp --dport ${PORT_HOPPING_START}:${PORT_HOPPING_END} -m comment --comment "NAT ${PORT_HOPPING_START}:${PORT_HOPPING_END} to ${PORT_HOPPING_TARGET} (Sing-box Family Bucket)" -j DNAT --to-destination :${PORT_HOPPING_TARGET} 2>/dev/null
871+
ip6tables --table nat -D PREROUTING -p udp --dport ${PORT_HOPPING_START}:${PORT_HOPPING_END} -m comment --comment "NAT ${PORT_HOPPING_START}:${PORT_HOPPING_END} to ${PORT_HOPPING_TARGET} (Sing-box Family Bucket)" -j DNAT --to-destination :${PORT_HOPPING_TARGET} 2>/dev/null
872+
[ "$(systemctl is-active netfilter-persistent)" = 'active' ] && netfilter-persistent save 2>/dev/null
873+
fi
874+
}
875+
876876
# 查端口跳跃的 dnat 端口
877877
check_port_hopping_nat() {
878878
PORT_HOPPING_TARGET=$(awk -F [:,] '/"listen_port"/{print $2}' ${WORK_DIR}/conf/*${NODE_TAG[1]}_inbounds.json)
@@ -3265,7 +3265,7 @@ uninstall() {
32653265
# Sing-box 的最新版本
32663266
version() {
32673267
# 获取需要下载的 sing-box 版本
3268-
ONLINE=$(get_sing_box_version)
3268+
local ONLINE=$(get_sing_box_version)
32693269

32703270
grep -q '.' <<< "$ONLINE" || error " $(text 100) \n"
32713271
local LOCAL=$(${WORK_DIR}/sing-box version | awk '/version/{print $NF}')
@@ -3584,4 +3584,4 @@ if [ "$NONINTERACTIVE_INSTALL" = 'noninteractive_install' ]; then
35843584
else
35853585
menu_setting
35863586
menu
3587-
fi
3587+
fi

0 commit comments

Comments
 (0)