-
-
Notifications
You must be signed in to change notification settings - Fork 420
/
package.pl
executable file
·184 lines (152 loc) · 4.41 KB
/
package.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/perl
use strict;
use Cwd;
use File::Basename;
use File::stat;
use File::Temp qw/ tempfile :seekable/;
use Net::FTP;
use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
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>;
$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);
use FindBin;
use lib $FindBin::Bin;
require 'helpers.pm';
#Switch to the output folder.
chdir(Build::PathFormat('../../../OUTPUT/package'));
print "Downloading languages.cfg...\n";
# Don't check certificate. It will fail on the slaves and we're resolving to internal addressing anyway
system('wget --no-check-certificate -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";
# Don't check certificate. It will fail on the slaves and we're resolving to internal addressing anyway
system("wget --no-check-certificate -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/");
unlink("$abbr.zip");
}
}
close($fh);
my $needNewGeoIP = 1;
if (-e '../GeoIP.dat.gz')
{
my $stats = stat('../GeoIP.dat.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 GeoIP.dat...\n";
# Don't check certificate. It will fail on the slaves and we're resolving to internal addressing anyway
system('wget --no-check-certificate -q -O ../GeoIP.dat.gz https://sm.alliedmods.net/GeoIP.dat.gz');
}
else
{
print "Reusing existing GeoIP.dat\n";
}
my $geoIPfile = 'addons/sourcemod/configs/geoip/GeoIP.dat';
if (-e $geoIPfile) {
unlink($geoIPfile);
}
open(my $fh, ">", $geoIPfile)
or die "cannot open $geoIPfile for writing: $!";
binmode($fh);
gunzip '../GeoIP.dat.gz' => $fh
or die "gunzip failed: $GunzipError\n";
close($fh);
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 ($tmpfh, $tmpfile) = tempfile();
print $tmpfh $filename;
$tmpfh->seek( 0, SEEK_END );
my $latest = "sourcemod-latest-";
if ($^O eq "darwin") {
$latest .= "mac";
}
elsif ($^O =~ /MSWin/) {
$latest .= "windows";
}
else {
$latest .= $^O;
}
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->put($tmpfile, $latest)
or die "Cannot drop file $latest ($ftp_path): " . $ftp->message . "\n";
$ftp->close();
print "File sent to drop site as $filename -- build succeeded.\n";
exit(0);