47 lines
1.6 KiB
Bash
Executable File
47 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# update-geoip-db.sh — lädt die aktuelle DB-IP Lite Country MMDB (CC-BY-4.0) nach GEOIP_DB_PATH.
|
|
# Für die lokale, EU-konforme Land-Auflösung ohne externen Transfer (AD-22, EXT-12).
|
|
#
|
|
# Monatlich ausführen (z.B. Coolify Scheduled Task oder system-cron). Die MMDB ist ein
|
|
# Deploy-Artefakt und gehört NICHT ins Git.
|
|
#
|
|
# Monat überschreibbar: ./scripts/update-geoip-db.sh 2026-05 (falls die Monatsdatei noch nicht released ist)
|
|
#
|
|
set -euo pipefail
|
|
|
|
DEST="${GEOIP_DB_PATH:-./data/geoip/dbip-country-lite.mmdb}"
|
|
MONTH="${1:-$(date +%Y-%m)}"
|
|
URL="https://download.db-ip.com/free/dbip-country-lite-${MONTH}.mmdb.gz"
|
|
|
|
mkdir -p "$(dirname "$DEST")"
|
|
tmp="$(mktemp)"
|
|
trap 'rm -f "$tmp"' EXIT
|
|
|
|
echo "Lade GeoIP-DB: $URL"
|
|
if ! node - "$URL" "$tmp" <<'NODE'
|
|
const fs = require("node:fs");
|
|
const { pipeline } = require("node:stream/promises");
|
|
const { Readable } = require("node:stream");
|
|
|
|
(async () => {
|
|
const [, , url, destination] = process.argv;
|
|
const response = await fetch(url, { redirect: "follow", signal: AbortSignal.timeout(30_000) });
|
|
if (!response.ok || !response.body) {
|
|
throw new Error(`GeoIP download failed with HTTP ${response.status}`);
|
|
}
|
|
await pipeline(Readable.fromWeb(response.body), fs.createWriteStream(destination, { flags: "w" }));
|
|
})().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|
|
NODE
|
|
then
|
|
echo "FEHLER: Download fehlgeschlagen. Ist die Monatsdatei für ${MONTH} schon veröffentlicht?" >&2
|
|
echo " Versuche den Vormonat: ./scripts/update-geoip-db.sh JJJJ-MM" >&2
|
|
exit 1
|
|
fi
|
|
|
|
gunzip -c "$tmp" > "$DEST"
|
|
echo "GeoIP-DB aktualisiert: $DEST"
|