ansibleguy / infra_haproxy

Ansible Role to provision HAProxy Community (with ACME, GeoIP and some WAF-Features)
Other
3 stars 2 forks source link

GeoIP Update with MaxMind DBs #2

Open NiceRath opened 2 months ago

NiceRath commented 2 months ago

Has some issues:

NiceRath commented 2 months ago

This is a working example of the script:

TOKEN="<SECRET>"
DST_ASN="/var/local/lib/geoip/asn.mmdb"
DST_COUNTRY="/var/local/lib/geoip/country.mmdb"

TMP_DIR="/tmp/geoip_$(date +'%s')"
mkdir -p "$TMP_DIR"
cd "$TMP_DIR"

echo 'Downloading..'
curl -s -L -u "$TOKEN" "https://download.maxmind.com/geoip/databases/GeoLite2-ASN/download?suffix=tar.gz" -o "${TMP_DIR}/asn.mmdb.tar.gz"
curl -s -L -u "$TOKEN" "https://download.maxmind.com/geoip/databases/GeoLite2-Country/download?suffix=tar.gz" -o "${TMP_DIR}/country.mmdb.tar.gz"

echo 'Extracting..'
tar -xvf 'asn.mmdb.tar.gz' --strip-components=1
mv 'GeoLite2-ASN.mmdb' "$DST_ASN"
tar -xvf 'country.mmdb.tar.gz' --strip-components=1
mv 'GeoLite2-Country.mmdb' "$DST_COUNTRY"

cd /tmp
rm -rf "$TMP_DIR"