summaryrefslogtreecommitdiff
blob: a85fa160627fede493a6887260ca9d9ee0c3df4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

GEOIP_MIRROR="http://geolite.maxmind.com/download/geoip/database"
GEOIPDIR=/usr/share/GeoIP
TMPDIR=

DATABASES="GeoLiteCity GeoLiteCountry/GeoIP asnum/GeoIPASNum GeoIPv6 GeoLiteCityv6-beta/GeoLiteCityv6"

if [ -d "${GEOIPDIR}" ]; then
	cd $GEOIPDIR
	if [ -n "${DATABASES}" ]; then
		TMPDIR=$(mktemp -d geoipupdate.XXXXXXXXXX)

		echo "Updating GeoIP databases..."

		for db in $DATABASES; do
			fname=$(basename $db)

			if [ -f ${GEOPDIR}/${fname} ]; then
				wget --no-verbose -t 3 -T 60 \
					"${GEOIP_MIRROR}/${db}.dat.gz" \
					-O "${TMPDIR}/${fname}.dat.gz"
				if [ $? -eq 0 ]; then
					gunzip -fdc "${TMPDIR}/${fname}.dat.gz" > "${TMPDIR}/${fname}.dat"
					mv "${TMPDIR}/${fname}.dat" "${GEOIPDIR}/${fname}.dat"
					chmod 0644 "${GEOIPDIR}/${fname}.dat"
				fi
			fi
		done
		[ -d "${TMPDIR}" ] && rm -rf $TMPDIR
	fi
fi