Make Digital Beautiful.

und schnell

Update geolocation databases for Crowdsec WordPress

Bash Script:

#!/bin/bash

# Set the path to the directory where the database is stored
DATABASE_DIR='PATH/TO/YOUR_WPCONTAINER/wp-content/plugins/crowdsec/geolocation'

export GEOIP_EDITION='GeoLite2-Country'
export GEOIP_LICENCE_KEY='YOUR KEY'
export GEOIP_TMP_FILE=geoip.tar.gz

curl -sS "https://download.maxmind.com/app/geoip_download?edition_id=${GEOIP_EDITION}&license_key=${GEOIP_LICENCE_KEY}&suffix=tar.gz" > $GEOIP_TMP_FILE && \
tar -xzf $GEOIP_TMP_FILE --wildcards "*/${GEOIP_EDITION}.mmdb" --strip=1                                                                                && \
rm $GEOIP_TMP_FILE
mv GeoLite2-Country.mmdb $DATABASE_DIR/GeoLite2-Country.mmdb

Make the script executable:

chmod +x geoupdate.sh

Let Cron run it twice a week

0 6 * * 3,6 /path/to/geoupdate.sh >> /path/to/geo.log 2>&1

This runs the script “At 06:00 on Wednesday and Saturday.
For people like me, there is a nice tool to generate the right time here ⇾ https://crontab.guru/

Maxmind relating Updates:

GeoLite2 databases are free IP geolocation databases comparable to, but less accurate than, MaxMind’s GeoIP2 databases. The GeoLite2 Country, City, and ASN databases are updated twice weekly, every Tuesday and Friday. GeoLite2 data is also available as a web service in the GeoLite2 Country and GeoLite2 City web services. Users of the GeoLite2 web services are limited to 1000 IP address lookups per service per day.

GeoLite2 Free Geolocation Data | MaxMind Developer Portal