1
18.7 Legacy Series / Re: ntopng: geolocation
« on: January 07, 2019, 07:41:56 am »
Here ya go
Code: [Select]
#!/bin/sh
set -eu
mkdir -p "/usr/local/share/ntopng/httpdocs/geoip"
# arguments:
# $1 URL
# $2 output file name
_fetch() {
url="$1"
out="$2"
TEMPFILE="$(mktemp "/usr/local/share/ntopng/httpdocs/geoip/GeoIP.dat-XXXXXX")"
trap 'rc=$? ; set +e ; rm -f "'"$TEMPFILE"'" ; exit $rc' 0
if fetch -o - "$url" | tar -x --strip-components 1 -f - "*/$out" >> "$TEMPFILE" ; then
chmod 444 "$TEMPFILE"
if ! mv -f "$TEMPFILE" "/usr/local/share/ntopng/httpdocs/geoip/$2" ; then
echo "Unable to replace /usr/local/share/ntopng/httpdocs/geoip/$2"
return 2
fi
else
echo "$2 download failed"
return 1
fi
rm -f "$TEMPFILE"
trap - 0
return 0
}
echo Fetching GeoLite2-City.tar.gz...
_fetch "https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz" GeoLite2-City.mmdb
echo GeoLite2-ASN.tar.gz...
_fetch "https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz" GeoLite2-ASN.mmdb