Skip to content

Commit 0799c94

Browse files
committed
解决编译时会因为被墙卡在GeoIP数据库下载的问题
1 parent 7c7591d commit 0799c94

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

fetch-geoip.sh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,32 @@ set -o errexit || exit $?
1212
HERE=$(dirname "$0")
1313
cd "${HERE}"
1414

15+
GEOIP_FILE="IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP"
16+
GEOIP_URL="https://github.com/OpenRA/GeoIP-Database/releases/download/monthly/IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP"
17+
TIMEOUT_SECONDS=30
18+
1519
# Database does not exist or is older than 30 days.
16-
if [ -z "$(find . -path ./IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP -mtime -30 -print)" ]; then
17-
rm -f IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP || :
18-
echo "Downloading IP2Location GeoIP database."
20+
if [ -z "$(find . -path ./${GEOIP_FILE} -mtime -30 -print)" ]; then
21+
rm -f "${GEOIP_FILE}" || :
22+
echo "Downloading IP2Location GeoIP database (timeout: ${TIMEOUT_SECONDS}s)..."
23+
24+
DOWNLOAD_SUCCESS=0
25+
1926
if command -v curl >/dev/null 2>&1; then
20-
curl -s -L -O https://github.com/OpenRA/GeoIP-Database/releases/download/monthly/IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP || echo "Warning: Download failed"
21-
else
22-
wget -cq https://github.com/OpenRA/GeoIP-Database/releases/download/monthly/IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP || echo "Warning: Download failed"
27+
if curl --connect-timeout ${TIMEOUT_SECONDS} --max-time $((TIMEOUT_SECONDS * 2)) -s -L -o "${GEOIP_FILE}" "${GEOIP_URL}" 2>/dev/null; then
28+
DOWNLOAD_SUCCESS=1
29+
fi
30+
elif command -v wget >/dev/null 2>&1; then
31+
if wget --timeout=${TIMEOUT_SECONDS} -q -O "${GEOIP_FILE}" "${GEOIP_URL}" 2>/dev/null; then
32+
DOWNLOAD_SUCCESS=1
33+
fi
34+
fi
35+
36+
if [ "${DOWNLOAD_SUCCESS}" -eq 0 ]; then
37+
echo "Warning: GeoIP database download failed or timed out."
38+
echo " Server will run without GeoIP country lookup."
39+
echo " You can manually download from: ${GEOIP_URL}"
40+
rm -f "${GEOIP_FILE}" || :
2341
fi
2442
fi
2543
# changeCR2LF

0 commit comments

Comments
 (0)