2010-04-05 03:07:37 +04:00
|
|
|
#!/usr/bin/perl
|
2014-02-09 09:45:40 +04:00
|
|
|
# vim: set ts=4 sts=4 sw=4 tw=99 noet:
|
2010-04-05 03:07:37 +04:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Cwd;
|
|
|
|
use File::Basename;
|
2018-08-27 16:06:59 +03:00
|
|
|
use File::stat;
|
2018-09-14 21:21:47 +03:00
|
|
|
use File::Temp qw/ tempfile :seekable/;
|
2010-04-05 03:07:37 +04:00
|
|
|
use Net::FTP;
|
2019-10-17 16:42:27 +03:00
|
|
|
use Archive::Tar;
|
2018-08-27 16:06:59 +03:00
|
|
|
use Time::localtime;
|
2010-04-05 03:07:37 +04:00
|
|
|
|
|
|
|
my ($ftp_file, $ftp_host, $ftp_user, $ftp_pass, $ftp_path);
|
|
|
|
|
|
|
|
$ftp_file = shift;
|
|
|
|
|
|
|
|
open(FTP, $ftp_file) or die "Unable to read FTP config file $ftp_file: $!\n";
|
|
|
|
$ftp_host = <FTP>;
|
|
|
|
$ftp_user = <FTP>;
|
|
|
|
$ftp_pass = <FTP>;
|
|
|
|
$ftp_path = <FTP>;
|
|
|
|
close(FTP);
|
|
|
|
|
|
|
|
chomp $ftp_host;
|
|
|
|
chomp $ftp_user;
|
|
|
|
chomp $ftp_pass;
|
|
|
|
chomp $ftp_path;
|
|
|
|
|
|
|
|
my ($myself, $path) = fileparse($0);
|
|
|
|
chdir($path);
|
|
|
|
|
|
|
|
require 'helpers.pm';
|
|
|
|
|
|
|
|
my ($version);
|
2010-04-05 05:10:35 +04:00
|
|
|
$version = Build::ProductVersion(Build::PathFormat('../../product.version'));
|
2014-02-09 09:45:40 +04:00
|
|
|
$version .= '-git' . Build::GitRevNum('.');
|
2010-04-05 03:07:37 +04:00
|
|
|
|
2010-04-05 05:10:35 +04:00
|
|
|
#Switch to the output folder.
|
|
|
|
chdir(Build::PathFormat('../../../OUTPUT'));
|
2010-04-05 03:07:37 +04:00
|
|
|
|
2018-08-27 16:06:59 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-10-17 16:42:27 +03:00
|
|
|
my $next = Archive::Tar->iter('../GeoLite2-Country.tar.gz', 1, {filter => qr/\.mmdb$/});
|
|
|
|
while (my $file = $next->()) {
|
|
|
|
$file->extract($geoIPfile) or warn "Extraction failed";
|
|
|
|
}
|
2018-08-27 16:06:59 +03:00
|
|
|
|
2013-02-13 11:22:40 +04:00
|
|
|
my (@packages,@mac_exclude);
|
2010-04-05 05:10:35 +04:00
|
|
|
@packages = ('base', 'cstrike', 'dod', 'esf', 'ns', 'tfc', 'ts');
|
2013-02-13 11:22:40 +04:00
|
|
|
@mac_exclude = ('esf', 'ns', 'ts');
|
2010-04-05 03:07:37 +04:00
|
|
|
|
|
|
|
my ($major,$minor) = ($version =~ /^(\d+)\.(\d+)/);
|
2014-02-09 09:45:40 +04:00
|
|
|
|
|
|
|
my ($i);
|
|
|
|
for ($i = 0; $i <= $#packages; $i++) {
|
|
|
|
my ($filename);
|
|
|
|
next if (($^O eq "darwin") && ($packages[$i] ~~ @mac_exclude));
|
|
|
|
|
|
|
|
if ($^O eq "linux") {
|
|
|
|
$filename = "amxmodx-$version-" . $packages[$i] . "-linux.tar.gz";
|
|
|
|
} elsif ($^O eq "darwin") {
|
|
|
|
$filename = "amxmodx-$version-" . $packages[$i] . "-mac.zip";
|
|
|
|
} else {
|
|
|
|
$filename = "amxmodx-$version-" . $packages[$i] . "-windows.zip";
|
|
|
|
}
|
|
|
|
unlink($filename);
|
|
|
|
|
|
|
|
chdir(Build::PathFormat("packages/" . $packages[$i]));
|
|
|
|
if ($^O eq "linux") {
|
|
|
|
Build::Command("tar zcvf $filename addons");
|
|
|
|
} else {
|
|
|
|
Build::Command("zip -r $filename addons");
|
|
|
|
}
|
|
|
|
Build::Move($filename, Build::PathFormat('../../'));
|
|
|
|
chdir(Build::PathFormat('../..'));
|
|
|
|
}
|
2010-04-05 03:07:37 +04:00
|
|
|
|
|
|
|
my ($ftp);
|
2014-02-09 09:45:40 +04:00
|
|
|
$ftp_path .= "/$major.$minor";
|
2010-04-05 03:07:37 +04:00
|
|
|
|
2014-03-12 06:54:37 +04:00
|
|
|
$ftp = Net::FTP->new($ftp_host, Debug => 0, Passive => 1)
|
2010-04-05 03:07:37 +04:00
|
|
|
or die "Cannot connect to host $ftp_host: $@";
|
|
|
|
|
|
|
|
$ftp->login($ftp_user, $ftp_pass)
|
|
|
|
or die "Cannot connect to host $ftp_host as $ftp_user: " . $ftp->message . "\n";
|
|
|
|
|
|
|
|
if ($ftp_path ne '')
|
|
|
|
{
|
|
|
|
$ftp->cwd($ftp_path)
|
2014-02-09 09:45:40 +04:00
|
|
|
or die "Cannot change to folder $ftp_path: " . $ftp->message . "\n";
|
2010-04-05 03:07:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$ftp->binary();
|
2010-04-05 05:10:35 +04:00
|
|
|
for ($i = 0; $i <= $#packages; $i++) {
|
|
|
|
my ($filename);
|
2018-09-14 21:21:47 +03:00
|
|
|
my ($latest);
|
2010-04-05 05:10:35 +04:00
|
|
|
if ($^O eq "linux") {
|
2013-02-13 11:22:40 +04:00
|
|
|
$filename = "amxmodx-$version-" . $packages[$i] . "-linux.tar.gz";
|
2018-09-14 21:21:47 +03:00
|
|
|
$latest = "amxmodx-latest-" . $packages[$i] . "-linux";
|
2013-02-13 11:22:40 +04:00
|
|
|
} elsif ($^O eq "darwin") {
|
|
|
|
next if ($packages[$i] ~~ @mac_exclude);
|
|
|
|
$filename = "amxmodx-$version-" . $packages[$i] . "-mac.zip";
|
2018-09-14 21:21:47 +03:00
|
|
|
$latest = "amxmodx-latest-" . $packages[$i] . "-mac";
|
2010-04-05 05:10:35 +04:00
|
|
|
} else {
|
2013-02-13 11:22:40 +04:00
|
|
|
$filename = "amxmodx-$version-" . $packages[$i] . "-windows.zip";
|
2018-09-14 21:21:47 +03:00
|
|
|
$latest = "amxmodx-latest-" . $packages[$i] . "-windows";
|
2010-04-05 05:10:35 +04:00
|
|
|
}
|
2018-09-14 21:21:47 +03:00
|
|
|
|
|
|
|
my ($tmpfh, $tmpfile) = tempfile();
|
|
|
|
print $tmpfh $filename;
|
|
|
|
$tmpfh->seek( 0, SEEK_END );
|
|
|
|
|
2010-04-05 05:10:35 +04:00
|
|
|
print "Uploading $filename...\n";
|
|
|
|
$ftp->put($filename)
|
|
|
|
or die "Cannot drop file $filename ($ftp_path): " . $ftp->message . "\n";
|
2018-09-14 21:21:47 +03:00
|
|
|
|
|
|
|
print "Uploading $latest...\n";
|
|
|
|
$ftp->put($tmpfile, $latest)
|
|
|
|
or die "Cannot drop file $latest ($ftp_path): " . $ftp->message . "\n";
|
2010-04-05 05:10:35 +04:00
|
|
|
}
|
2010-04-05 03:07:37 +04:00
|
|
|
|
|
|
|
$ftp->close();
|
|
|
|
|
2010-04-05 05:10:35 +04:00
|
|
|
print "Files sent to drop site -- build succeeded.\n";
|
2010-04-05 03:07:37 +04:00
|
|
|
|
2014-03-12 06:54:37 +04:00
|
|
|
exit(0);
|