-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
50 lines (34 loc) · 1.35 KB
/
init.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
47
48
49
50
#!/bin/sh
# Source your free maxmind licence key first
. ./license_key
WGET="wget -N --no-if-modified-since"
# Only download if modified since previous
# touch .last-modified
curl --head "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=$license_key&suffix=tar.gz" 2>/dev/null |
grep last-modified > tmpmod
curl --head "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=$license_key&suffix=tar.gz" 2>/dev/null |
grep last-modified >> tmpmod
if cmp --silent -- "tmpmod" ".last-modified"; then
rm tmpmod
echo "No fresh updates !"
exit
fi
mkdir tmp data 2>/dev/null
$WGET -q "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=$license_key&suffix=tar.gz" -O tmp/GeoLite2-Country.tar.gz
$WGET -q "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=$license_key&suffix=tar.gz" -O tmp/GeoLite2-ASN.tar.gz
cd tmp
tar zxf GeoLite2-Country.tar.gz
tar zxf GeoLite2-ASN.tar.gz
ls *.gz | xargs -n 1 tar zxf
rm *.gz
find . -name \*.mmdb | xargs -I[] cp [] ../data/
COUNTRYFILE=`ls -d GeoLite2-Country_*`
ASNFILE=`ls -d GeoLite2-ASN*`
echo COUNTRYFILE : $COUNTRYFILE
echo ASNFILE : $ASNFILE
cd ..
cat init.tpl |\
sed "s+%COUNTRYFILE%+$COUNTRYFILE+g" |\
sed "s+%ASNFILE%+$ASNFILE+g" > init.go
mv tmpmod .last-modified
rm -fr tmp