-
Notifications
You must be signed in to change notification settings - Fork 4
/
update_server.pl
126 lines (98 loc) · 3.07 KB
/
update_server.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
#!/usr/bin/perl -w
use warnings;
use strict;
use File::Copy;
if(@ARGV!=1){
die "Usage\trelease or test?";
}
my $release;
if($ARGV[0] eq 'release'){
$release=1;
}else{
$release=0;
}
`sh fix_carriage_return.sh`;
my $serverDir='/opt/server/download.glycoworkbench.org';
my $lastBuildNo="$serverDir/current_build_no";
my $packagesDir='packages';
`rm $packagesDir -rf`;
my $majorVersion=2;
my $minorVersion=1;
my $state="stable";
my $topLevelDir="$serverDir/$majorVersion/$minorVersion";
my $buildDir="$serverDir/build";
if(!-e $buildDir){
`mkdir $buildDir`;
}
my $currentReleaseLink="$serverDir/current_version";
my $currentReleaseLinkInfo="$serverDir/latest_version";
my $buildNo=0;
if(-f $lastBuildNo){
open(BUILD_NO,"$lastBuildNo") || die "Could not open the file $lastBuildNo for reading\n";
$buildNo=<BUILD_NO>; chomp($buildNo);
if(!$buildNo=~/^([0-9]+)$/){
die "Could not determine the last build number from file $lastBuildNo --$buildNo--\n";
}
close(BUILD_NO);
}
$buildNo++;
#Replace all macros with their corresponding values within the given list of files. (restored after build)
my @replaceInFiles=('winInstaller.nsi','src/html/about_gwb.html','README.txt','src/org/eurocarbdb/application/glycoworkbench/GlycoWorkbench.java');
foreach my $file(@replaceInFiles){
`sed 's/GWB_MAJOR/$majorVersion/g;s/GWB_MINOR/$minorVersion/g;s/GWB_STATE/$state/g;s/GWB_BUILD/$buildNo/g' $file > tmp.out`;
copy($file,"$file.bak") || onDie("Error copying file\n");
copy('tmp.out',$file) || onDie("Error copying file\n");
}
#Open readme file and create an in memory version of the file with \n replaced with \r\n
my $dosLineBrakedReadMeFile="";
open(README_FILE,"README.txt") || onDie("Could not open the file README.txt for reading");
while(<README_FILE>){
my $line=$_;
if(!($line=~/\r/)){
$line=~s/\n/\r\n/g;
}
$dosLineBrakedReadMeFile.=$line;
}
close(README_FILE);
#Write out \r\n readme to a file the build script knows about.
open(WIN_README,">WIN_README.txt") || onDie("Could not open the file WIN_README.txt for writing");
print WIN_README $dosLineBrakedReadMeFile;
close(WIN_README);
system('ant clean');
system('ant dist-all');
#`ant dist-lin`;
my $buildPublishDir="$buildDir/$buildNo";
my $versionLink="$topLevelDir/$buildNo";
if(!-f $buildPublishDir){
system("mkdir -p $buildPublishDir");
if($? >> 8 !=0){
onDie("Could not create the directory $topLevelDir\n");
}
}else{
`rm -rf $buildPublishDir/*`
}
system("cp -r $packagesDir/* $buildPublishDir");
`echo "$buildNo" > $lastBuildNo`;
if(!-e $versionLink){
system("ln -s $buildPublishDir $versionLink");
}
if($release){
print "About to release new version? (Ctrl+C in the next 10 seconds to quit)";
sleep(10);
if(-e $currentReleaseLink){
unlink($currentReleaseLink);
}
system("ln -s $buildPublishDir $currentReleaseLink");
`echo "$majorVersion $minorVersion $state $buildNo" > $currentReleaseLinkInfo`;
}
onExit();
sub onDie {
my @args=@_;
onExit();
die @args;
}
sub onExit {
foreach my $file(@replaceInFiles){
copy("$file.bak",$file) || print "Could not restore backup file $file, continuing with restore attempt\n";
}
}