-
Notifications
You must be signed in to change notification settings - Fork 0
/
geoipdownload.bash
executable file
·78 lines (45 loc) · 1.67 KB
/
geoipdownload.bash
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
cd .
# Analog for geoipupdate
# https://dev.maxmind.com/geoip/geoipupdate/
GeoIPConfName="GeoIP.conf"
# Getting the License Key
LicenseKeyVar=$(cat $GeoIPConfName | grep -oP '^LicenseKey\s+\K\S+')
LicenseKey=$LicenseKeyVar
# Getting the EditionIDs GeoIP Bases
# Making List of GeoIP Bases
#declare -a EditionIDs=(
# "GeoLite2-ASN"
# "GeoLite2-City"
# "GeoLite2-Country"
#)
EditionIDsVar=$(cat $GeoIPConfName | grep -Po "(?<=EditionIDs\s).*")
read -ra EditionIDs <<< $EditionIDsVar;
declare -a EditionIDs
# Permanent link for downloading files
DownloadLink="https://download.maxmind.com/app/geoip_download?edition_id=EDITION_ID&license_key=LICENSE_KEY&suffix=tar.gz"
# Walking through the array
# And downloading database in current directory
for EditionID in "${EditionIDs[@]}"
do
echo $EditionID
EditionIDArchive=$EditionID.mmdb.gz
EditionIDBase=$EditionID.mmdb
# Replacing tags to real variables
EditionDownloadLink=$DownloadLink
EditionDownloadLink="${EditionDownloadLink/EDITION_ID/$EditionID}"
EditionDownloadLink="${EditionDownloadLink/LICENSE_KEY/$LicenseKey}"
echo $EditionDownloadLink
# Downloading Bases
curl $EditionDownloadLink --output $EditionIDArchive
# Getting the path to the Destination file
EditionIDTargetPath=$(tar -tf $EditionIDArchive | grep $EditionIDBase)
# Extracting the final file from the archive
tar -zxf $EditionIDArchive $EditionIDTargetPath
# Moving the destination file to the current directory
mv $EditionIDTargetPath $EditionIDBase
# Delete temporary Extractiong directory
rm -rf $(dirname $EditionIDTargetPath)
# Delete temporary downloading Archives
rm $EditionIDArchive
done