forked from dvv/luvit-geoip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·148 lines (124 loc) · 2.38 KB
/
install
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/sh
countries() {
awk '
BEGIN {
arr = ""
buf = ""
print "return {"
}
/^const char (\* )?GeoIP_country_/ {
arr = $0
i = index(arr, "_country_")
if (i) {
arr = substr(arr, i+9)
i = index(arr, "[")
arr = substr(arr, 1, i-1)
}
buf = ""
}
/\}\;$/ {
buf = buf $0
gsub(/.*{/, "", buf)
gsub(/};/, "", buf)
gsub(/ /, "", buf)
if (arr) {
print " " arr " = {" buf "},"
}
arr = ""
}
{
if (arr) {
buf = buf $0
}
}
END {
print "}"
}
'
}
timezones() {
awk '
BEGIN {
country = ""
region = ""
print "return {"
}
/strcmp \(country\, "([A-Z]+)"\)/ {
if (country) s = $6; else s = $5
country = substr(s,2,2)
region = ""
}
/strcmp \(region\, \"([A-Z0-9]+)\"\)/ {
if (region) s = $6; else s = $5
region = substr(s,2,2)
}
/timezone = "/ {
print " [\"" country region "\"] = \"" substr($3,2,length($3)-3) "\","
}
END {
print "}"
}
'
}
currencies() {
awk '
BEGIN {
done = 0
code = ""
num = ""
name = ""
print "return {"
}
/ letter_code="([A-Z]+)"/ {
code = substr($1,14,3)
}
/ numeric_code="([0-9]+)"/ {
num = substr($1,15,3)
}
/ currency_name="([^"]+)"/ {
name = substr($0,18)
i = index(name, "\"")
name = substr(name,1,i-1)
if (!done) {
print " [\"" code "\"] = { id = \"" code "\", code = \"" num "\", name = \"" name "\" },"
}
}
/historic_iso_4217_entry/ {
if (code) done = 1
}
END {
print "}"
}
'
}
(
if ! test -f GeoLiteCity.dat; then
wget -qct3 http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz -O GeoLiteCity.dat.part && mv GeoLiteCity.dat.part GeoLiteCity.dat.gz && gunzip GeoLiteCity.dat.gz
fi
mkdir -p build
cd build
# fetch libGeoIP sources
V=1.4.8
if ! test -f GeoIP-$V/libGeoIP/GeoIP.c; then
wget -qct3 http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$V.tar.gz
tar -xzpf GeoIP-$V.tar.gz
fi
# fetch currencies
if ! test -f iso4217.xml; then
wget -qct3 https://bitbucket.org/victorlin/correct_pycountry/raw/a144b415d051/src/pycountry/databases/iso4217.xml
fi
cd ..
# extract info
countries <build/GeoIP-$V/libGeoIP/GeoIP.c >lib/country.lua
timezones <build/GeoIP-$V/libGeoIP/timeZone.c >lib/timezone.lua
# TODO: parse also regionName.c
# TODO: bind languages?, currencies?
# ...
#
currencies <build/iso4217.xml >lib/currency.lua
# make the first run to get geo.json
luvit lib/geoip.lua
)
#
# ftp://elsie.nci.nih.gov/pub/tz{code,data}2011b.tar.gz
#