11#! /usr/bin/env bash
22
33# 当前脚本版本号
4- VERSION=' v1.2.17 (2025.07.12 )'
4+ VERSION=' v1.2.17 (2025.07.16 )'
55
66# 各变量默认值
77GH_PROXY=' gh-proxy.com/'
@@ -989,10 +989,30 @@ sing-box_variables() {
989989 [ -z " $SERVER_IP " ] && error " $( text 47) "
990990
991991 # 根据服务 IP,使用不同的 warp 配置
992- if [[ " $SERVER_IP " =~ : ]]; then
992+ [ -x " $( type -p ping) " ] && for i in {1..3}; do
993+ ping -c 1 -W 1 " 8.8.8.8" & > /dev/null && local IS_IPV4=is_ipv4 && break
994+ done
995+
996+ if [ -x " $( type -p ping6) " ]; then
997+ for i in {1..3}; do
998+ ping6 -c 1 -W 1 " 2001:4860:4860::8888" & > /dev/null && local IS_IPV6=is_ipv6 && break
999+ done
1000+ elif [ -x " $( type -p ping) " ]; then
1001+ for i in {1..3}; do
1002+ ping -6 -c 1 -W 1 " 2001:4860:4860::8888" & > /dev/null && local IS_IPV6=is_ipv6 && break
1003+ done
1004+ fi
1005+
1006+ if [[ " $SERVER_IP " =~ : && -n " $IS_IPV4 " ]]; then
9931007 STRATEGY=prefer_ipv6
1008+ elif [[ " $SERVER_IP " =~ : && -z " $IS_IPV4 " ]]; then
1009+ STRATEGY=ipv6_only
9941010 else
995- STRATEGY=ipv4_only
1011+ if [[ -n " $IS_IPV6 " ]]; then
1012+ STRATEGY=prefer_ipv4
1013+ elif [[ -z " $IS_IPV6 " ]]; then
1014+ STRATEGY=ipv4_only
1015+ fi
9961016 fi
9971017
9981018 # 检测是否解锁 chatGPT
@@ -1075,8 +1095,9 @@ check_dependencies() {
10751095 fi
10761096
10771097 # 检测 Linux 系统的依赖,升级库并重新安装依赖
1078- local DEPS_CHECK=(" wget" " tar" " ip" " bash" " openssl" )
1079- local DEPS_INSTALL=(" wget" " tar" " iproute2" " bash" " openssl" )
1098+ local DEPS_INSTALL=(" wget" " tar" " iproute2" " iproute2" " bash" " openssl" " ping" )
1099+ local DEPS_CHECK=(" wget" " tar" " ss" " ip" " bash" " openssl" " iputils-ping" )
1100+
10801101 [ " $SYSTEM " != ' Alpine' ] && DEPS_CHECK+=(" systemctl" ) && DEPS_INSTALL+=(" systemctl" )
10811102 for g in " ${! DEPS_CHECK[@]} " ; do
10821103 [ ! -x " $( type -p ${DEPS_CHECK[g]} ) " ] && DEPS+=(${DEPS_INSTALL[g]} )
@@ -1092,7 +1113,8 @@ check_dependencies() {
10921113 [ ! -x " $( type -p ip6tables) " ] && DEPS+=(ip6tables)
10931114 fi
10941115
1095- # 如需要安装的依赖大于0,就更新库并安装
1116+ # 先 DEPS 去重,如需要安装的依赖大于0,就更新库并安装
1117+ DEPS=($( echo " ${DEPS[@]} " | tr ' ' ' \n' | awk ' !a[$0]++' ) )
10961118 if [[ " ${# DEPS[@]} " > 0 ]]; then
10971119 [[ ! " $SYSTEM " =~ Alpine| CentOS ]] && ${PACKAGE_UPDATE[int]} > /dev/null 2>&1
10981120 ${PACKAGE_INSTALL[int]} ${DEPS[@]} > /dev/null 2>&1
@@ -3584,4 +3606,4 @@ if [ "$NONINTERACTIVE_INSTALL" = 'noninteractive_install' ]; then
35843606else
35853607 menu_setting
35863608 menu
3587- fi
3609+ fi
0 commit comments