Files
OpenFlare/scripts/fetch-agent-geoip-mmdb.sh
T
ryan 570b639e07 fix(agent): commit GeoLite2 mmdb as build fallback
Vendor GeoLite2-Country.mmdb in the repository so agent builds still
work when the remote download is unavailable. Update the fetch script
and agent Dockerfile to prefer a fresh download and fall back to the
committed database file.
2026-06-20 14:04:42 +08:00

25 lines
734 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TARGET="${ROOT}/internal/apps/agent/geoipdata/GeoLite2-Country.mmdb"
URL="${GEOIP_MMDB_URL:-https://raw.githubusercontent.com/Loyalsoldier/geoip/release/GeoLite2-Country.mmdb}"
mkdir -p "$(dirname "$TARGET")"
if curl -fsSL -o "${TARGET}.tmp" "$URL"; then
mv "${TARGET}.tmp" "$TARGET"
echo "GeoIP database downloaded: $TARGET"
elif [ -s "$TARGET" ]; then
rm -f "${TARGET}.tmp"
echo "GeoIP download failed, using committed database: $TARGET"
else
rm -f "${TARGET}.tmp"
echo "GeoIP database missing and download failed: $URL" >&2
exit 1
fi
if [ ! -s "$TARGET" ]; then
echo "GeoIP database is empty: $TARGET" >&2
exit 1
fi