mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-04 07:06:36 +08:00
refactor(agent): stop embedding GeoIP MMDB in agent binary
Agent ships without City/Country MMDB in the binary; Docker images COPY databases into data_dir, bare installs seed via download on first start. Server keeps Country-only embed for optional MaxMind control-plane use. Also harden fetch script nonempty check and reject non-file MMDB paths.
This commit is contained in:
@@ -1,25 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# Download MaxMind GeoLite2 Country/City databases for packaging (Docker image COPY),
|
||||
# not for go:embed into the agent binary.
|
||||
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}"
|
||||
OUT_DIR="${GEOIP_OUT_DIR:-${ROOT}/dist/geoip}"
|
||||
COUNTRY_URL="${GEOIP_MMDB_URL:-https://github.com/FyraLabs/geolite2/releases/latest/download/GeoLite2-Country.mmdb}"
|
||||
CITY_URL="${GEOIP_CITY_MMDB_URL:-https://github.com/FyraLabs/geolite2/releases/latest/download/GeoLite2-City.mmdb}"
|
||||
|
||||
mkdir -p "$(dirname "$TARGET")"
|
||||
mkdir -p "${OUT_DIR}"
|
||||
|
||||
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
|
||||
download_one() {
|
||||
local url="$1"
|
||||
local dest="$2"
|
||||
local name="$3"
|
||||
if curl -fsSL -o "${dest}.tmp" "$url" && [ -s "${dest}.tmp" ]; then
|
||||
mv "${dest}.tmp" "$dest"
|
||||
echo "GeoIP ${name} downloaded: $dest ($(wc -c <"$dest" | tr -d ' ') bytes)"
|
||||
return 0
|
||||
fi
|
||||
rm -f "${dest}.tmp"
|
||||
if [ -s "$dest" ]; then
|
||||
echo "GeoIP ${name} download failed, keeping existing: $dest" >&2
|
||||
return 0
|
||||
fi
|
||||
echo "GeoIP ${name} missing and download failed: $url" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ ! -s "$TARGET" ]; then
|
||||
echo "GeoIP database is empty: $TARGET" >&2
|
||||
exit 1
|
||||
fi
|
||||
download_one "$COUNTRY_URL" "${OUT_DIR}/GeoLite2-Country.mmdb" "Country"
|
||||
download_one "$CITY_URL" "${OUT_DIR}/GeoLite2-City.mmdb" "City"
|
||||
|
||||
Reference in New Issue
Block a user