| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# geoip-lite-update -- update geoip lite database(s). |
| 4 |
# (c) 2008,2009,2010,2011,2012,2013,2014 [email protected] |
| 5 |
# Distribute under GPLv2 if it proves worthy. |
| 6 |
|
| 7 |
# With added support for: |
| 8 |
# - GeoLiteCityv6 |
| 9 |
# - GeoIPASNum |
| 10 |
# - GeoIPASNumv6 |
| 11 |
# by Ludovic Fauvet <[email protected]> |
| 12 |
|
| 13 |
|
| 14 |
for i in curl wget ftp; do |
| 15 |
if which $i &>/dev/null; then |
| 16 |
prg=$i |
| 17 |
break |
| 18 |
fi |
| 19 |
done |
| 20 |
|
| 21 |
if [ -z "$prg" ]; then |
| 22 |
echo cannot find a tool to download, like curl or wget >&2 |
| 23 |
exit 1 |
| 24 |
fi |
| 25 |
|
| 26 |
case $prg in |
| 27 |
curl) |
| 28 |
prg="curl -s -O" |
| 29 |
;; |
| 30 |
wget) |
| 31 |
prg="wget --quiet" |
| 32 |
;; |
| 33 |
esac |
| 34 |
|
| 35 |
|
| 36 |
set -e |
| 37 |
|
| 38 |
# GeoIP data used to be in /usr/share/GeoIP in the openSUSE package, and was moved later. |
| 39 |
# try the old location first - if it's present, it means that the user had his own |
| 40 |
# updated database there |
| 41 |
cd /usr/share/GeoIP/ 2>/dev/null || cd /var/lib/GeoIP |
| 42 |
|
| 43 |
rm -f GeoIP.dat.gz |
| 44 |
$prg https://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz |
| 45 |
gunzip -c GeoIP.dat.gz > GeoIP.dat.updated.new |
| 46 |
mv GeoIP.dat.updated.new GeoIP.dat.updated |
| 47 |
|
| 48 |
rm -f GeoLiteCity.dat.gz |
| 49 |
$prg https://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz |
| 50 |
gunzip -c GeoLiteCity.dat.gz > GeoLiteCity.dat.updated.new |
| 51 |
mv GeoLiteCity.dat.updated.new GeoLiteCity.dat.updated |
| 52 |
|
| 53 |
rm -f GeoLiteCityv6.dat.gz |
| 54 |
$prg https://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz |
| 55 |
gunzip -c GeoLiteCityv6.dat.gz > GeoLiteCityv6.dat.updated.new |
| 56 |
mv GeoLiteCityv6.dat.updated.new GeoLiteCityv6.dat.updated |
| 57 |
|
| 58 |
rm -f GeoIPv6.dat.gz |
| 59 |
$prg https://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz |
| 60 |
gunzip -c GeoIPv6.dat.gz > GeoIPv6.dat.updated.new |
| 61 |
mv GeoIPv6.dat.updated.new GeoIPv6.dat.updated |
| 62 |
|
| 63 |
rm -f GeoIPASNum.dat.gz |
| 64 |
$prg https://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz |
| 65 |
gunzip -c GeoIPASNum.dat.gz > GeoIPASNum.dat.updated.new |
| 66 |
mv GeoIPASNum.dat.updated.new GeoIPASNum.dat.updated |
| 67 |
|
| 68 |
rm -f GeoIPASNumv6.dat.gz |
| 69 |
$prg https://download.maxmind.com/download/geoip/database/asnum/GeoIPASNumv6.dat.gz |
| 70 |
gunzip -c GeoIPASNumv6.dat.gz > GeoIPASNumv6.dat.updated.new |
| 71 |
mv GeoIPASNumv6.dat.updated.new GeoIPASNumv6.dat.updated |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
set +e |
| 76 |
|
| 77 |
if [ "$1" = "--no-reload" ]; then |
| 78 |
exit 0 |
| 79 |
fi |
| 80 |
|
| 81 |
if [ -x /etc/init.d/apache2 ]; then |
| 82 |
/etc/init.d/apache2 reload |
| 83 |
elif [ -x /etc/init.d/httpd ]; then |
| 84 |
/etc/init.d/httpd reload |
| 85 |
elif [ -x /usr/bin/systemctl ]; then |
| 86 |
/usr/bin/systemctl reload httpd >/dev/null 2>&1 || : |
| 87 |
elif [ -x /bin/systemctl ]; then |
| 88 |
/bin/systemctl reload httpd >/dev/null 2>&1 || : |
| 89 |
fi |
| 90 |
|