File geoipupdate-legacy of Package geoipupdate.29493
#!/bin/bash
geoip_conf='/etc/GeoIP.conf'
function conf_value()
{
key=$1
value=$(grep $key $geoip_conf | sed -e 's:#.*::' -e "s:$key::")
if [ -z $value ]; then
echo $key not configured in $geoip_conf
exit 1
fi
echo $value
}
function download_geodata_csv()
{
csv_product=$1
echo ">>> Downloading $csv_product.zip"
curl "https://download.maxmind.com/app/geoip_download?edition_id=$csv_product&license_key=$license_key&suffix=zip" \
-o $database_directory/$csv_product.zip
}
function geolite_to_legacy()
{
csv_product=$1
echo ">>> Converting $csv_product.zip to legacy format"
if ! which geolite2legacy >/dev/null 2>&1; then
echo 'geolite2legacy program required'
return
fi
pushd $database_directory
if [ ! -f $csv_product.zip ]; then
echo $database_directory/$csv_product.zip not found
return
fi
geolite2legacy -i $csv_product.zip
geolite2legacy -i $csv_product.zip -6
popd
}
license_key=$(conf_value 'LicenseKey')
database_directory=$(conf_value 'DatabaseDirectory')
download_geodata_csv GeoLite2-ASN-CSV
geolite_to_legacy GeoLite2-ASN-CSV
download_geodata_csv GeoLite2-City-CSV
geolite_to_legacy GeoLite2-City-CSV
download_geodata_csv GeoLite2-Country-CSV
geolite_to_legacy GeoLite2-Country-CSV