|
Lines 1-16
Link Here
|
| 1 |
#!/bin/sh |
1 |
#!/bin/sh |
| 2 |
|
2 |
|
| 3 |
set -eu |
3 |
set -u |
| 4 |
echo Fetching GeoIP.dat and GeoIPv6.dat... |
4 |
echo Fetching GeoIP.dat and GeoIPv6.dat... |
| 5 |
|
5 |
|
|
|
6 |
MAXMIND_HOST_MAIN="geolite.maxmind.com" |
| 7 |
MAXMIND_HOST_ALT="geoip.maxmind.com" |
| 8 |
|
| 6 |
# arguments: |
9 |
# arguments: |
| 7 |
# $1 URL |
10 |
# $1 URL |
| 8 |
# $2 output file name |
11 |
# $2 output file name |
| 9 |
_fetch() { |
12 |
_fetch() { |
| 10 |
url="$1" |
13 |
local url="$1" |
| 11 |
out="$2" |
14 |
local out="$2" |
| 12 |
TEMPDIR="$(mktemp -d '%%DATADIR%%/GeoIPupdate.XXXXXX')" |
15 |
local TEMPDIR="$(mktemp -d '%%DATADIR%%/GeoIPupdate.XXXXXX')" |
| 13 |
trap 'rc=$? ; set +e ; rm -rf "'"$TEMPDIR"'" ; exit $rc' 0 |
16 |
trap 'rc=$? ; rm -rf "'"$TEMPDIR"'" ; exit $rc' 0 |
| 14 |
if fetch -o "$TEMPDIR/$out.gz" "$url"; then |
17 |
if fetch -o "$TEMPDIR/$out.gz" "$url"; then |
| 15 |
gunzip "$TEMPDIR/$out.gz" |
18 |
gunzip "$TEMPDIR/$out.gz" |
| 16 |
chmod 444 "$TEMPDIR/$out" |
19 |
chmod 444 "$TEMPDIR/$out" |
|
Lines 27-32
Link Here
|
| 27 |
return 0 |
30 |
return 0 |
| 28 |
} |
31 |
} |
| 29 |
|
32 |
|
| 30 |
_fetch "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz" GeoIP.dat |
33 |
_fetch2() { |
|
|
34 |
local url="$1" |
| 35 |
local out="$2" |
| 36 |
_fetch "http://${MAXMIND_HOST_MAIN}/${url}" "${out}" || |
| 37 |
! echo "Download of ${out} from ${MAXMIND_HOST_MAIN} failed, trying an alternative server ${MAXMIND_HOST_ALT}" || |
| 38 |
_fetch "http://${MAXMIND_HOST_ALT}/${url}" "${out}" |
| 39 |
} |
| 31 |
|
40 |
|
| 32 |
_fetch "http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz" GeoIPv6.dat |
41 |
(_fetch2 "/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz" GeoIP.dat && |
|
|
42 |
_fetch2 "/download/geoip/database/GeoIPv6.dat.gz" GeoIPv6.dat |
| 43 |
) || exit 1 |
| 44 |
|