Add GeoIP data update to the automatic build system (#524)

* Add GeoIP data update to the automatic build system

* Apply few fixes
This commit is contained in:
Vincent Herbet 2018-08-27 15:06:59 +02:00 committed by GitHub
parent 1ddf199e71
commit c820db4dc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,10 @@
use strict; use strict;
use Cwd; use Cwd;
use File::Basename; use File::Basename;
use File::stat;
use Net::FTP; use Net::FTP;
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
use Time::localtime;
my ($ftp_file, $ftp_host, $ftp_user, $ftp_pass, $ftp_path); my ($ftp_file, $ftp_host, $ftp_user, $ftp_pass, $ftp_path);
@ -34,6 +37,47 @@ $version .= '-git' . Build::GitRevNum('.');
#Switch to the output folder. #Switch to the output folder.
chdir(Build::PathFormat('../../../OUTPUT')); chdir(Build::PathFormat('../../../OUTPUT'));
my $needNewGeoIP = 1;
if (-e '../GeoLite2-Country.tar.gz')
{
my $stats = stat('../GeoLite2-Country.tar.gz');
if ($stats->size != 0)
{
my $fileModifiedTime = $stats->mtime;
my $fileModifiedMonth = localtime($fileModifiedTime)->mon;
my $currentMonth = localtime->mon;
my $thirtyOneDays = 60 * 60 * 24 * 31;
# GeoIP file only updates once per month
if ($currentMonth == $fileModifiedMonth || (time() - $fileModifiedTime) < $thirtyOneDays)
{
$needNewGeoIP = 0;
}
}
}
if ($needNewGeoIP)
{
print "Downloading GeoLite2-Country.mmdb...\n";
system('wget -q -O ../GeoLite2-Country.tar.gz https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz');
}
else
{
print "Reusing existing GeoLite2-Country.mmdb\n";
}
my $geoIPfile = 'packages/base/addons/amxmodx/data/GeoLite2-Country.mmdb';
if (-e $geoIPfile) {
unlink($geoIPfile);
}
open(my $fh, ">", $geoIPfile)
or die "cannot open $geoIPfile for writing: $!";
binmode($fh);
gunzip '../GeoLite2-Country.tar.gz' => $fh
or die "gunzip failed: $GunzipError\n";
close($fh);
my (@packages,@mac_exclude); my (@packages,@mac_exclude);
@packages = ('base', 'cstrike', 'dod', 'esf', 'ns', 'tfc', 'ts'); @packages = ('base', 'cstrike', 'dod', 'esf', 'ns', 'tfc', 'ts');
@mac_exclude = ('esf', 'ns', 'ts'); @mac_exclude = ('esf', 'ns', 'ts');