From: Philip Prindeville <philipp@xxxxxxxxxxxxxxxxxxxxx> Adjust the download script to only unpack the minimum set of files, and to delete the unversioned ZIP file, but to retain the dated/versioned directories it contains. Similarly, have the build script find the newest directory. Signed-off-by: Philip Prindeville <philipp@xxxxxxxxxxxxxxxxxxxxx> --- geoip/xt_geoip_build | 21 +++++++++++++++++++++ geoip/xt_geoip_dl | 10 +++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/geoip/xt_geoip_build b/geoip/xt_geoip_build index 07778ab4a5f2b76c3a5c1b9a977b9a7a724ab6fe..ab875939c5c7a700b1fb0abfec5332105a954ee3 100755 --- a/geoip/xt_geoip_build +++ b/geoip/xt_geoip_build @@ -29,6 +29,7 @@ if (!-d $source_dir) { print STDERR "Source directory \"$source_dir\" does not exist.\n"; exit 1; } + if (!-d $target_dir) { print STDERR "Target directory \"$target_dir\" does not exist.\n"; exit 1; @@ -39,11 +40,31 @@ if (!-d "$target_dir/cc" && !mkdir "$target_dir/cc") { exit 1; } +my $sub_dir = &locateSubdir($source_dir); + +if (! $sub_dir) { + print STDERR "Couldn't find unpacked directory.\n"; + exit 1; +} + +$source_dir = $sub_dir; + my %countryId; my %countryName; &loadCountries(); &dump(&collect()); +sub locateSubdir() +{ + my $topdir = shift; + + my $pattern = $topdir . '/GeoLite2-Country-CSV_20[0-9][0-9]{0[1-9],1[012]}{[0-2][0-9],3[01]}'; + + my @dirs = sort glob($pattern); + + return (@dirs > 0 ? $dirs[$#dirs] : undef); +} + sub loadCountries { sub id; sub cc; sub long; sub ct; sub cn; diff --git a/geoip/xt_geoip_dl b/geoip/xt_geoip_dl index 1de60442a8040f55d775d134d7a8ea707582d71e..35488bf38c61d5bd0c690373b5cc5aa51bd969c9 100755 --- a/geoip/xt_geoip_dl +++ b/geoip/xt_geoip_dl @@ -1,7 +1,11 @@ #!/bin/sh -rm -rf GeoLite2-Country-CSV_* +rm -f GeoIPv6.csv GeoIPv6.csv.gz GeoIPCountryCSV.zip GeoIPCountryWhois.csv +wget -q https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip +unzip -q GeoLite2-Country-CSV.zip \ + \*/GeoLite2-Country-Locations-en.csv \ + \*/GeoLite2-Country-Blocks-IPv6.csv \ + \*/GeoLite2-Country-Blocks-IPv4.csv \ + \*/COPYRIGHT.txt \*/README.txt \*/LICENSE.txt -wget -q http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip -unzip -q GeoLite2-Country-CSV.zip rm -f GeoLite2-Country-CSV.zip -- 2.17.2