Last active
May 13, 2019 07:44
-
-
Save anhtran/5d661216bacb30d473e0e47b308b9944 to your computer and use it in GitHub Desktop.
Script to update GeoLite2-City database for detect location by IP address
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
#!/usr/bin/env bash | |
#prg="wget --quiet" | |
prg="wget" | |
# currently it will create folder `geoip` in parent of this script path | |
# you could modify to absolute path to fix as your wish | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
geolite_path="$(dirname "$DIR")/geoip" | |
mkdir -p ${geolite_path} | |
download_path="${geolite_path}/download" | |
[[ -d ${download_path} ]] || mkdir ${download_path} | |
if [[ ! -e ${geolite_path} ]]; then | |
echo "Unable to find GeoIP directory: $geolite_path" | |
exit 1 | |
fi | |
cd ${download_path} | |
${prg} http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz | |
if [[ ! -e ${download_path}/GeoLite2-City.tar.gz ]]; then | |
echo "Unable to find GeoLite2-City.tar.gz!" | |
exit 1 | |
fi | |
tar -xzf ${download_path}/GeoLite2-City.tar.gz -C ${download_path}/ | |
mv -f ${download_path}/GeoLite2-City*/GeoLite2-City.mmdb ${geolite_path}/ | |
rm -rf ${download_path}/ | |
echo "OK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment