#!/usr/bin/perl 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, $tag); $ftp_file = shift; $tag = shift; open(FTP, $ftp_file) or die "Unable to read FTP config file $ftp_file: $!\n"; $ftp_host = ; $ftp_user = ; $ftp_pass = ; $ftp_path = ; close(FTP); chomp $ftp_host; chomp $ftp_user; chomp $ftp_pass; chomp $ftp_path; my ($myself, $path) = fileparse($0); chdir($path); require 'helpers.pm'; #Switch to the output folder. chdir(Build::PathFormat('../../../OUTPUT/package')); print "Downloading languages.cfg...\n"; system('wget -q -O addons/sourcemod/configs/languages.cfg "https://sm.alliedmods.net/translator/index.php?go=translate&op=export_langs"'); open(my $fh, '<', 'addons/sourcemod/configs/languages.cfg') or die "Could not open languages.cfg' $!"; while (my $ln = <$fh>) { if ($ln =~ /"([^"]+)"\s*"[^"]+.*\((\d+)\) /) { my $abbr = $1; my $id = $2; print "Downloading language pack $abbr.zip...\n"; system("wget -q -O $abbr.zip \"https://sm.alliedmods.net/translator/index.php?go=translate&op=export&lang_id=$id\""); system("unzip -qo $abbr.zip -d addons/sourcemod/translations/"); system("rm $abbr.zip"); } } close($fh); my $needNewGeoIP = 1; if (-e '../GeoIP.dat.gz') { my $fileModifiedTime = stat('../GeoIP.dat.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 GeoIP.dat...\n"; system('wget -q -O ../GeoIP.dat.gz http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz'); } else { print "Reusing existing GeoIP.dat\n"; } system('gunzip -c ../GeoIP.dat.gz > addons/sourcemod/configs/geoip/GeoIP.dat'); my ($version); $version = Build::ProductVersion(Build::PathFormat('../../build/product.version')); $version =~ s/-dev//g; $version .= '-git' . Build::GitRevNum('../../build'); # Append OS to package version if ($^O eq "darwin") { $version .= '-mac'; } elsif ($^O =~ /MSWin/) { $version .= '-windows'; } else { $version .= '-' . $^O; } if (defined $tag) { $version .= '-' . $tag; } my ($filename); $filename = 'sourcemod-' . $version; if ($^O eq "linux") { $filename .= '.tar.gz'; print "tar zcvf $filename addons cfg\n"; system("tar zcvf $filename addons cfg"); } else { $filename .= '.zip'; print "zip -r $filename addons cfg\n"; system("zip -r $filename addons cfg"); } my ($major,$minor) = ($version =~ /^(\d+)\.(\d+)/); $ftp_path .= "/$major.$minor"; my ($ftp); $ftp = Net::FTP->new($ftp_host, Debug => 0, Passive => 1) 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) or die "Cannot change to folder $ftp_path: " . $ftp->message . "\n"; } $ftp->binary(); $ftp->put($filename) or die "Cannot drop file $filename ($ftp_path): " . $ftp->message . "\n"; $ftp->close(); print "File sent to drop site as $filename -- build succeeded.\n"; exit(0);