Merging bug fix from rel-1-2
[koha.git] / buildrelease
1 #!/usr/bin/perl
2
3 my $kohadir=`pwd`;
4 chomp $kohadir;
5 my $kohahtmldir="/koha/koha/koha-html/";
6
7 if (-e "/root/.kohaautobuild.conf") {
8     open C, "/root/.kohaautobuild.conf";
9     while (<C>) {
10         chomp;
11         if (/kohadir=(.*)/) {
12             $kohadir=$1;
13         }
14         if (/kohahtmldir=(.*)/) {
15             $kohahtmldir=$1;
16         }
17     }
18 }
19
20 my $input;
21
22 print qq |
23 ***************************************
24 * Welcome to the Koha Release Builder *
25 ***************************************
26
27 This script will automatically build a release tarball.
28
29 The script assumes that you already have the koha and koha-html modules checked
30 out for the release that you want to build, although it will update the modules
31 before building.
32
33 |;
34 print "\nWhere is the 'koha' cvs module located [$kohadir]: ";
35 chomp($input = <STDIN>);
36 if ($input) {
37     $kohadir=$input;
38 }
39
40
41 print "\nWhere is the 'koha-html' cvs module located [$kohahtmldir]: ";
42 chomp($input = <STDIN>);
43 if ($input) {
44     $kohahtmldir=$input;
45 }
46
47 open (C, ">/root/.kohaautobuild.conf");
48 print C qq|
49 kohadir=$kohadir
50 kohahtmldir=$kohahtmldir
51 |;
52
53 print "\n\nGuessing at next release version.  You may need to enter your SourceForge password...\n";
54 chdir $kohadir;
55 open (CVSLOG, "cvs log buildrelease|");
56 my $symbolicnamessection=0;
57 my $symbolicnames;
58 my $highestversion;
59 my $highestrc;
60 my $released;
61 while (<CVSLOG>) {
62     if (/^symbolic names:/) {
63         $symbolicnamessection=1;
64     }
65     if ($symbolicnamessection && (/^\s+([^:]*):/)) {
66         my $tag=$1;
67         if ($tag=~/R_(.*)/) {
68             my $version='';
69             my $rc=0;
70             my $id=$1;
71             $id=~s/-/\./g;
72             if ($id =~/(.*)RC(.*)/) {
73                 $version=$1;
74                 $rc=$2;
75                 if (versioncompare($version, $highestversion)) {
76                     $highestversion=$version;
77                     $released=0;
78                     $highestrc=$rc;
79                 }
80             } else {
81                 $version=$id;
82                 if (versioncompare($version, $highestversion)) {
83                     $highestversion=$version;
84                     $released=1;
85                     $highestrc=0;
86                 }
87             }
88             $symbolicnames->{$version}->{$rc}=1;
89         }
90     }
91 }
92
93
94 my $releaseversion='';
95 my $currentversion='';
96
97 if ($released) {
98     $releaseversion=($highestversion+1)."RC1";
99     $currentversion=$highestversion;
100 } else {
101     $releaseversion="$highestversion\RC".($highestrc+1);
102     $currentversion="$highestversion\RC$highestrc";
103 }
104
105 print "Current release tag is $currentversion.\n";
106 print "\nWould you like to bump that up to $releaseversion?  [Y]/N: ";
107 chomp($input = <STDIN>);
108 if ($input =~ /^n/i) {
109     print "\nWould you like to rebuild the $currentversion tarball?  Y/[N]: ";
110     chomp($input = <STDIN>);
111     if ($input =~ /^y/i) {
112         $releaseversion=$currentversion;
113         print "\n\n";
114         print "Do not do this if you have released the tarball to anybody, as it will\n";
115         print "overwrite the tag marking the files that were in the tarball.\n\n";
116         print "Confirm that you want to overwrite the tag for $releaseversion? Y/[N]: ";
117         chomp($input = <STDIN>);
118         if ($input =~ /^n/i || $input eq '') {
119             print "\nStopping.  Please re-run buildrelease now.\n";
120             exit;
121         }
122     } else {
123         print "What should the new version be? [$releaseversion]: ";
124         chomp ($input=<STDIN>);
125         if ($input) {
126             $releaseversion=$input;
127         }
128     }
129 }
130
131
132 my $sfuserid='';
133 if ($cvsroot=$ENV{'CVSROOT'}) {
134     $cvsroot=~m#(.*)\@cvs#;
135     $sfuserid=$1;
136 } else {
137     $ENV{'CVS_RSH'}='ssh';
138     print "\nWhat is your userid at SourceForge: ";
139     chomp($input = <STDIN>);
140     if ($input) {
141         $sfuserid=$input;
142     }
143     $ENV{'CVSROOT'}="$sfuserid\@cvs.koha.sourceforge.net:/cvsroot/koha";
144 }
145 my $tagname=$releaseversion;
146 $tagname=~s/\./-/g;
147
148 print qq|
149 Updating the 'koha' CVS files.  You may need to enter your SourceForge password.
150 Using $kohadir.
151 |;
152 chdir($kohadir);
153 system("cvs update");
154 print qq|
155 Tagging koha with tag R_$tagname
156 |;
157 system("cvs tag -F R_$tagname");
158 print qq|
159 Updating the 'koha-html' CVS files.  You may need to enter your SourceForge password.
160 Using $kohahtmldir.
161 |;
162 chdir($kohahtmldir);
163 system("cvs update");
164 print qq|
165 Tagging koha-html with tag R_$tagname
166 |;
167 system("cvs tag -F R_$tagname");
168
169
170
171
172 my $rootdir="/tmp/koha-".$releaseversion;
173 system("rm -rf $rootdir");
174 mkdir ($rootdir, 0700);
175 chdir($rootdir);
176
177 mkdir("intranet-cgi", 0755);
178 mkdir("intranet-html", 0755);
179 mkdir("opac-cgi", 0755);
180 mkdir("opac-html", 0755);
181 mkdir("scripts", 0755);
182 mkdir("scripts/z3950daemon", 0755);
183 mkdir("modules", 0755);
184 mkdir("docs", 0755);
185
186 # Create koha.versin file
187
188 open (KV, ">$rootdir/koha.version");
189 print KV "$releaseversion\n";
190 close KV;
191
192 # Copy all CVS files to intranet-cgi
193 system("cp -a $kohadir/* $rootdir/intranet-cgi");
194
195 # Move C4 to modules directory
196 system("mv $rootdir/intranet-cgi/C4 $rootdir/modules");
197
198 # Move files from intranet-cgi to root of tarball
199 system("mv $rootdir/intranet-cgi/INSTALL $rootdir");
200 system("mv $rootdir/intranet-cgi/ChangeLog* $rootdir");
201 system("mv $rootdir/intranet-cgi/Hints $rootdir");
202 system("mv $rootdir/intranet-cgi/LICENSE $rootdir");
203 system("mv $rootdir/intranet-cgi/News $rootdir");
204 system("mv $rootdir/intranet-cgi/README $rootdir");
205 system("mv $rootdir/intranet-cgi/TODO $rootdir");
206 system("mv $rootdir/intranet-cgi/databaseinstall.sh $rootdir");
207 system("mv $rootdir/intranet-cgi/installer.pl $rootdir"); 
208 system("mv $rootdir/intranet-cgi/koha.upgrade $rootdir"); 
209 chmod 0770, "$rootdir/installer.pl";
210 chmod 0770, "$rootdir/koha.upgrade";
211 system("mv $rootdir/intranet-cgi/koha.conf $rootdir");
212 system("mv $rootdir/intranet-cgi/koha.mysql $rootdir");
213 system("mv $rootdir/intranet-cgi/sampledata-1.2 $rootdir");
214 system("gzip -9 $rootdir/sampledata-1.2");
215
216 # Copy files from intranet-cgi to opac-cgi
217 system("cp $rootdir/intranet-cgi/detail.pl $rootdir/opac-cgi");
218 system("cp $rootdir/intranet-cgi/moredetail.pl $rootdir/opac-cgi");
219 system("cp $rootdir/intranet-cgi/search.pl $rootdir/opac-cgi");
220
221
222 # Move files from intranet-cgi to /scripts/ directory
223 system("mv $rootdir/intranet-cgi/telnet $rootdir/scripts");
224 system("mv $rootdir/intranet-cgi/tkperl $rootdir/scripts");
225 system("mv $rootdir/intranet-cgi/translator $rootdir/scripts");
226 system("mv $rootdir/intranet-cgi/updater $rootdir/scripts");
227 system("mv $rootdir/intranet-cgi/misc $rootdir/scripts");
228 system("mv $rootdir/intranet-cgi/acqui.simple/processz3950queue $rootdir/scripts/z3950daemon/");
229 system("mv $rootdir/intranet-cgi/acqui.simple/z3950-daemon-launch.sh $rootdir/scripts/z3950daemon/");
230 system("mv $rootdir/intranet-cgi/acqui.simple/z3950-daemon-shell.sh $rootdir/scripts/z3950daemon/");
231
232
233 # Remove extraneous files from intranet-cgi
234 system("rm -f $rootdir/intranet-cgi/ChangeLog.bak");
235 system("rm -f $rootdir/intranet-cgi/ChangeLog.bak");
236 system("rm -f $rootdir/intranet-cgi/SendMessages");
237 system("rm -f $rootdir/intranet-cgi/buildrelease");
238 system("rm -f $rootdir/intranet-cgi/database.mysql");
239 system("rm -f $rootdir/intranet-cgi/installer-lite.pl");
240 system("rm -f $rootdir/intranet-cgi/koha-1.2.0.tar.gz");
241 system("rm -f $rootdir/intranet-cgi/rel-1-2");
242 system("rm -f $rootdir/intranet-cgi/testKoha.pl");
243 system("rm -rf $rootdir/intranet-cgi/html-template");
244 system("rm -rf $rootdir/intranet-cgi/t");
245
246 # Copy all CVS files to intranet-html and opac-html
247 system("cp -a $kohahtmldir/intranet-html/* $rootdir/intranet-html");
248 system("cp -a $kohahtmldir/opac-html/* $rootdir/opac-html");
249
250 # Remove extraneous files from opac-html
251 system("rm -f $rootdir/opac-html/koha.mo");
252 system("rm -f $rootdir/opac-html/koha.pot");
253 system("rm -f $rootdir/opac-html/test");
254
255 # Remove extraneous files from intranet-html
256 system("rm -f $rootdir/intranet-html/koha.pot");
257 system("rm -f $rootdir/intranet-html/results.html");
258 system("rm -f $rootdir/intranet-html/test");
259
260 # Remove junk from directory
261 system("find $rootdir -name CVS -exec rm -rf \\{\\} \\; 2>/dev/null");
262 system("find $rootdir -name *~ -exec rm -rf \\{\\} \\; 2>/dev/null");
263 system("find $rootdir -name .#* -exec rm -rf \\{\\} \\; 2>/dev/null");
264
265 if (-e "/root/docs") {
266     print "Copying docs folder from /root/docs...";
267     system("cp -r /root/docs/* $rootdir/docs/");
268 } else {
269     print "I would have copied the docs from from /root/docs, but I couldn't find it.\n";
270     print "Press <ENTER> to continue...\n";
271     <STDIN>;
272 }
273
274 chdir("/tmp");
275 system("tar czf /tmp/koha-$releaseversion.tar.gz koha-".$releaseversion);
276 system("rm -rf $rootdir");
277
278 print qq|
279 ============
280 = ALL DONE =
281 ============
282
283 Your new tarball is located in /tmp/koha-$releaseversion.tar.gz
284
285 |;
286
287
288 sub versioncompare {
289     my $v1=shift;
290     my $v2=shift;
291     my @v1=split(/\./, $v1);
292     my @v2=split(/\./, $v2);
293     my $count=$#v1;
294     ($#v2>$count) && ($count=$#v2);
295     for (my $index=0; $index<$count; $index++) {
296         if ($v1[$index]>$v2[$index]) {
297             return 1;
298         }
299     }
300     return 0;
301 }