From 9a1e686e3cece084e864bdb972a4f29ff0213ade Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 27 Aug 2018 12:13:41 +0200 Subject: [PATCH 1/2] Add GeoIP data update to the automatic build system --- support/buildbot/package.pl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/support/buildbot/package.pl b/support/buildbot/package.pl index 753404ecb8..340944e36f 100755 --- a/support/buildbot/package.pl +++ b/support/buildbot/package.pl @@ -4,7 +4,9 @@ use strict; use Cwd; use File::Basename; +use File::stat; use Net::FTP; +use Time::localtime; my ($ftp_file, $ftp_host, $ftp_user, $ftp_pass, $ftp_path); @@ -34,6 +36,34 @@ #Switch to the output folder. chdir(Build::PathFormat('../../../OUTPUT')); +my $needNewGeoIP = 1; +if (-e '../GeoLite2-Country.tar.gz') +{ + my $fileModifiedTime = stat('../GeoLite2-Country.tar.gz')->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 http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz'); +} +else +{ + print "Reusing existing GeoLite2-Country.mmdb\n"; +} + +system('gunzip -c ../GeoLite2-Country.tar.gz > packages/base/addons/amxmodx/data/GeoLite2-Country.mmdb'); + + my (@packages,@mac_exclude); @packages = ('base', 'cstrike', 'dod', 'esf', 'ns', 'tfc', 'ts'); @mac_exclude = ('esf', 'ns', 'ts'); From 502d9129ce5b690eb20c4ee77f35974d65945d71 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 27 Aug 2018 14:56:59 +0200 Subject: [PATCH 2/2] Apply few fixes --- support/buildbot/package.pl | 38 +++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/support/buildbot/package.pl b/support/buildbot/package.pl index 340944e36f..ad8f7a1c36 100755 --- a/support/buildbot/package.pl +++ b/support/buildbot/package.pl @@ -6,6 +6,7 @@ use File::Basename; use File::stat; use Net::FTP; +use IO::Uncompress::Gunzip qw(gunzip $GunzipError); use Time::localtime; my ($ftp_file, $ftp_host, $ftp_user, $ftp_pass, $ftp_path); @@ -39,30 +40,43 @@ my $needNewGeoIP = 1; if (-e '../GeoLite2-Country.tar.gz') { - my $fileModifiedTime = stat('../GeoLite2-Country.tar.gz')->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; - } + 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 http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz'); + 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"; } -system('gunzip -c ../GeoLite2-Country.tar.gz > packages/base/addons/amxmodx/data/GeoLite2-Country.mmdb'); +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); @packages = ('base', 'cstrike', 'dod', 'esf', 'ns', 'tfc', 'ts');