-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.sh
executable file
·46 lines (38 loc) · 1.2 KB
/
generate.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
set -e
# This script is more of an outline than a super reliable production-ready
# process, but it should serve as a reasonable starting point from which you
# can tweak things to your exact needs.
#
# Free for non-comercial uses
CITY=GeoLite2-City
ASN=GeoLite2-ASN
# Full versions
#CITY=GeoIP2-City
#ISP=GeoIP2-ISP
if [ -z "$MAXMIND_LICENSE_KEY" ]; then
echo "MAXMIND_LICENSE_KEY env var required to download databases, even the free ones" >&2
exit 1
fi
# A temporary place to download
TMP="tmp"
mkdir -p $TMP
for edition_id in $CITY $ASN $ISP; do
tar_gz="${TMP}/${edition_id}.tar.gz"
if [ ! -e "$tar_gz" ]; then
# We need to download it
curl -sS --max-time 10 "https://download.maxmind.com/app/geoip_download?license_key=$MAXMIND_LICENSE_KEY&edition_id=$edition_id&suffix=tar.gz" > "$tar_gz"
tar xvzf "$tar_gz" -C "$TMP" || (rm "$tar_gz" && false)
(cd $TMP && ln -s "${edition_id}"*"/${edition_id}.mmdb" "${edition_id}.mmdb")
fi
done
OUT="out"
mkdir -p $OUT
if [ -n "$ISP" ]; then
args="-isp-db ${TMP}/${ISP}.mmdb"
else
args="-asn-db ${TMP}/${ASN}.mmdb"
fi
haproxy-mapper -outdir $OUT -all -city-db "${TMP}/GeoLite2-City.mmdb" $args
echo "Maps in $OUT"
wc -l $OUT/*