Created
May 17, 2023 02:43
-
-
Save unex/c50d0bb532e108fce77cf823525721df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
API_KEY="" | |
set -eu | |
mkdir -p "/usr/local/share/ntopng/httpdocs/geoip" | |
TEMPDIR="$(mktemp -d "/usr/local/share/ntopng/httpdocs/geoip/MMDB-XXXXXX")" | |
trap 'rc=$? ; set +e ; rm -rf "'"$TEMPDIR"'" ; exit $rc' 0 | |
cd "${TEMPDIR}" | |
# arguments: | |
# $1 URL | |
# $2 filename | |
_fetchextract() { | |
url="$1" | |
file="$(basename "${url}")" | |
if fetch "${url}"; then | |
tar xzvf "${file}" | |
mv **/*.mmdb /usr/local/share/ntopng/httpdocs/geoip | |
else | |
echo "${file} download failed" | |
return 1 | |
fi | |
return 0 | |
} | |
echo Fetching GeoLite2-City | |
_fetchextract "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=${API_KEY}&suffix=tar.gz" | |
echo Fetching GeoLite2-ASN | |
_fetchextract "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${API_KEY}&suffix=tar.gz" | |
echo Fetching GeoLite2-Country | |
_fetchextract "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${API_KEY}&suffix=tar.gz" | |
cd /usr/local/share/ntopng/httpdocs/geoip | |
rm -rf "${TEMPDIR}" | |
chown root:wheel *.mmdb | |
chmod 444 *.mmdb | |
trap - 0 | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment