road to 1.3.2
[koha.git] / buildrelease
1 #!/usr/bin/perl
2
3 sub guess_kohahtmldir ($;$);
4
5 my $kohadir=`pwd`;
6 chomp $kohadir;
7 my $kohahtmldir=guess_kohahtmldir($kohadir, "/koha/koha/koha-html/");
8 my $roothomedir=(getpwuid(0))[7];       # ~root is traditionally just /
9 $roothomedir='/root' unless defined $roothomedir;
10
11 my $has_kohaautobuild_conf = 0;
12
13 if (-e "$roothomedir/.kohaautobuild.conf") {
14     open C, "<$roothomedir/.kohaautobuild.conf";
15     while (<C>) {
16         chomp;
17         if (/kohadir=(.*)/) {
18             $kohadir=$1;
19         }
20         if (/kohahtmldir=(.*)/) {
21             $kohahtmldir=$1;
22         }
23     }
24     $has_kohaautobuild_conf = 1;
25 }
26
27 my $input;
28
29 print qq |
30 ***************************************
31 * Welcome to the Koha Release Builder *
32 ***************************************
33
34 This script will automatically build a release tarball.
35
36 The script assumes that you already have the koha and koha-html modules checked
37 out for the release that you want to build, although it will update the modules
38 before building.
39
40 |;
41 print "\nWhere is the 'koha' cvs module located [$kohadir]: ";
42 chomp($input = <STDIN>);
43 if ($input) {
44     $kohadir=$input;
45     $kohahtmldir=guess_kohahtmldir($kohadir, $kohahtmldir) unless $has_kohaautobuild_conf;
46 }
47
48
49 print "\nWhere is the 'koha-html' cvs module located [$kohahtmldir]: ";
50 chomp($input = <STDIN>);
51 if ($input) {
52     $kohahtmldir=$input;
53 }
54
55 open (C, ">$roothomedir/.kohaautobuild.conf");
56 print C qq|
57 kohadir=$kohadir
58 kohahtmldir=$kohahtmldir
59 |;
60
61 print "\n\nGuessing at next release version.  You may need to enter your SourceForge password...\n";
62 open (CVSLOG, "cvs log buildrelease|");
63 my $symbolicnamessection=0;
64 my $symbolicnames;
65 my $highestversion;
66 my $highestrc;
67 my $released;
68 my $majorversion;
69 my $majorversionrc;
70 while (<CVSLOG>) {
71     if (/^symbolic names:/) {
72         $symbolicnamessection=1;
73     }
74     if ($symbolicnamessection && (/^\s+([^:]*):/)) {
75         my $tag=$1;
76         if ($tag=~/R_(.*)/) {
77             my $version='';
78             my $rc=0;
79             my $id=$1;
80             $id=~s/-/\./g;
81             if ($id =~/(.*)RC(.*)/) {
82                 $version=$1;
83                 $rc=$2;
84                 $version=~m#(\d+\.\d+)\.#;
85                 if (versioncompare($version, $majorversion->{$1})) {
86                     $majorversion->{$1}=$version;
87                     $majorversionrc->{$1}=$rc;
88                 }
89                 if (versioncompare($version, $highestversion)) {
90                     $highestversion=$version;
91                     $released=0;
92                     $highestrc=$rc;
93                 }
94             } else {
95                 $version=$id;
96                 $version=~m#(\d+\.\d+)\.#;
97                 if (versioncompare($version, $majorversion->{$1})) {
98                     $majorversion->{$1}=$version;
99                     $majorversionrc->{$1}=0;
100                 }
101                 if (versioncompare($version, $highestversion)) {
102                     $highestversion=$version;
103                     $released=1;
104                     $highestrc=0;
105                 }
106             }
107             $symbolicnames->{$version}->{$rc}=1;
108         }
109     }
110 }
111
112
113 my $releaseversion='';
114 my $currentversion='';
115
116 my $branchdata=`grep buildrelease CVS/Entries`;
117 chomp $branchdata;
118 my $branch=(split(m#/#, $branchdata))[5];
119
120 if ($branch eq 'Trel-1-2') {
121     $highestversion=$majorversion->{'1.2'};
122     $highestrc=$majorversionrc->{'1.2'};
123     ($highestrc) ? ($released=0) : ($released=1);
124 }
125
126 if ($released) {
127     my @components=split(/\./, $highestversion);
128     $components[$#components]++;
129     $nexthighestversion=join '.', @components;
130     my $minornumber=(split(/\./, $highestversion))[1];
131     if ($minornumber/2 == int($minornumber/2)) {
132         $releaseversion=$nexthighestversion."RC1";
133     } else {
134         $releaseversion=$nexthighestversion;
135     }
136     $currentversion=$highestversion;
137 } else {
138     $releaseversion=$highestversion."RC".($highestrc+1);
139     $currentversion=$highestversion."RC$highestrc";
140 }
141
142
143 print "Current release tag is $currentversion.\n";
144 print "\nWould you like to bump that up to $releaseversion (or manually enter version)?  [Y]/N: ";
145 chomp($input = <STDIN>);
146 my $tagging_needs_confirmation = 0;
147 if ($input =~ /^n/i) {
148     print "\nWould you like to rebuild the $currentversion tarball?  Y/[N]: ";
149     chomp($input = <STDIN>);
150     print STDERR "releaseversion=($releaseversion), currentversion=($currentversion)\n";#XXXZZZ
151     if ($input =~ /^y/i) {
152         $releaseversion=$currentversion;
153         $tagging_needs_confirmation = 1;
154     } else {
155         print "What should the new version be? [$releaseversion]: ";
156         chomp ($input=<STDIN>);
157         if ($input) {
158             $releaseversion=$input;
159         }
160     }
161 } else {
162     print "What should the new version be? [$releaseversion]: ";
163     chomp ($input=<STDIN>);
164     if ($input) {
165         $releaseversion=$input;
166     }
167 }
168
169
170 print "\nWould you like to tag the CVS repository?\n(answer yes if releasing tarball)  Y/[N]: ";
171 chomp ($input=<STDIN>);
172 my $cvstag=0;
173 # FIXME: This means anything other than n will tag; too dangerous?
174 if ($input=~/^y/i) {
175     $cvstag=1;
176 }
177
178
179 if ($cvstag && $tagging_needs_confirmation) {
180         print "\n\n";
181         print "Do not do this if you have released the tarball to anybody, as it will\n";
182         print "overwrite the tag marking the files that were in the tarball:\n\n";
183         print "Confirm that you want to overwrite the tag for $releaseversion? Y/[N]: ";
184         chomp($input = <STDIN>);
185         if ($input =~ /^n/i || $input !~ /\S/) {
186             print "\nStopping.  Please re-run buildrelease now.\n";
187             exit;
188         }
189 }
190
191
192 my $sfuserid='';
193 if ($cvsroot=$ENV{'CVSROOT'}) {
194     $cvsroot=~m#(.*)\@cvs#;
195     $sfuserid=$1;
196 } else {
197     $ENV{'CVS_RSH'}='ssh';
198     print "\nWhat is your userid at SourceForge: ";
199     chomp($input = <STDIN>);
200     if ($input) {
201         $sfuserid=$input;
202     }
203     $ENV{'CVSROOT'}="$sfuserid\@cvs.koha.sourceforge.net:/cvsroot/koha";
204 }
205 my $tagname=$releaseversion;
206 $tagname=~s/\./-/g;
207
208 print qq|
209 Updating your checked-out copy of the 'koha' CVS files.
210 You may need to enter your SourceForge password.
211 Using $kohadir.
212 |;
213 chdir($kohadir);
214 system("cvs update");
215 if ($cvstag) {
216     print qq|
217 Tagging koha with tag R_$tagname
218 |;
219     system("cvs tag -F R_$tagname");
220 }
221 print qq|
222 Updating your checked-out copy of the 'koha-html' CVS files.
223 You may need to enter your SourceForge password.
224 Using $kohahtmldir.
225 |;
226 chdir($kohahtmldir) || die "$kohahtmldir: $!\n";
227 system("cvs update");
228
229 if ($cvstag) {
230     print qq|
231 Tagging koha-html with tag R_$tagname
232 |;
233     system("cvs tag -F R_$tagname");
234 }
235
236
237
238
239 my $rootdir="/tmp/koha-".$releaseversion;
240 system("rm -rf $rootdir");
241 mkdir ($rootdir, 0700);
242 chdir($rootdir) || die "$rootdir: $!\n";
243
244 mkdir("intranet-cgi", 0755);
245 mkdir("intranet-html", 0755);
246 mkdir("opac-cgi", 0755);
247 mkdir("opac-html", 0755);
248 mkdir("scripts", 0755);
249 mkdir("scripts/z3950daemon", 0755);
250 mkdir("modules", 0755);
251 mkdir("docs", 0755);
252
253 # Create koha.versin file
254
255 open (KV, ">$rootdir/koha.version");
256 print KV "$releaseversion\n";
257 close KV;
258
259 # Copy all CVS files to intranet-cgi
260 system("cp -a $kohadir/* $rootdir/intranet-cgi");
261
262 # Move C4 to modules directory
263 system("mv $rootdir/intranet-cgi/C4 $rootdir/modules");
264
265 # Move files from intranet-cgi to root of tarball
266 system("mv $rootdir/intranet-cgi/INSTALL $rootdir");
267 system("mv $rootdir/intranet-cgi/ChangeLog* $rootdir");
268 system("mv $rootdir/intranet-cgi/Hints $rootdir");
269 system("mv $rootdir/intranet-cgi/LICENSE $rootdir");
270 system("mv $rootdir/intranet-cgi/News $rootdir");
271 system("mv $rootdir/intranet-cgi/README $rootdir");
272 system("mv $rootdir/intranet-cgi/TODO $rootdir");
273 system("mv $rootdir/intranet-cgi/installer.pl $rootdir"); 
274 system("mv $rootdir/intranet-cgi/koha.upgrade $rootdir"); 
275 system("mv $rootdir/intranet-cgi/Install.pm $rootdir"); 
276 system("mv $rootdir/intranet-cgi/kohareporter $rootdir"); 
277 chmod 0770, "$rootdir/installer.pl";
278 chmod 0770, "$rootdir/koha.upgrade";
279 system("mv $rootdir/intranet-cgi/koha.conf $rootdir");
280 system("mv $rootdir/intranet-cgi/koha.mysql $rootdir");
281 system("mv $rootdir/intranet-cgi/sampledata-1.2 $rootdir");
282 system("gzip -9 $rootdir/sampledata-1.2");
283
284 # Copy files from intranet-cgi to opac-cgi
285 system("cp $rootdir/intranet-cgi/detail.pl $rootdir/opac-cgi");
286 system("cp $rootdir/intranet-cgi/moredetail.pl $rootdir/opac-cgi");
287 system("cp $rootdir/intranet-cgi/search.pl $rootdir/opac-cgi");
288 system("cp $rootdir/intranet-cgi/subjectsearch.pl $rootdir/opac-cgi");
289 system("cp $rootdir/intranet-cgi/logout.pl $rootdir/opac-cgi");
290 system("mv $rootdir/intranet-cgi/opac/* $rootdir/opac-cgi");
291 system("rmdir $rootdir/intranet-cgi/opac");
292
293
294 # Move files from intranet-cgi to /scripts/ directory
295 system("mv $rootdir/intranet-cgi/telnet $rootdir/scripts");
296 system("mv $rootdir/intranet-cgi/tkperl $rootdir/scripts");
297 system("mv $rootdir/intranet-cgi/translator $rootdir/scripts");
298 system("mv $rootdir/intranet-cgi/updater $rootdir/scripts");
299 system("mv $rootdir/intranet-cgi/misc $rootdir/scripts");
300 system("mv $rootdir/intranet-cgi/marc $rootdir/scripts");
301 system("mv $rootdir/intranet-cgi/acqui.simple/bulkmarcimport.pl $rootdir/scripts/z3950daemon/");
302 system("mv $rootdir/intranet-cgi/acqui.simple/processz3950queue $rootdir/scripts/z3950daemon/");
303 system("mv $rootdir/intranet-cgi/acqui.simple/z3950-daemon-launch.sh $rootdir/scripts/z3950daemon/");
304 system("mv $rootdir/intranet-cgi/acqui.simple/z3950-daemon-shell.sh $rootdir/scripts/z3950daemon/");
305
306
307 # Remove extraneous files from intranet-cgi
308 system("rm -f $rootdir/intranet-cgi/ChangeLog.bak");
309 system("rm -f $rootdir/intranet-cgi/SendMessages");
310 system("rm -f $rootdir/intranet-cgi/buildrelease");
311 system("rm -f $rootdir/intranet-cgi/database.mysql");
312 system("rm -f $rootdir/intranet-cgi/installer-lite.pl");
313 # FIXME: The following two lines look suspicious
314 #system("rm -f $rootdir/intranet-cgi/koha-1.2.0.tar.gz");
315 #system("rm -f $rootdir/intranet-cgi/rel-1-2");
316 system("rm -f $rootdir/intranet-cgi/testKoha.pl");
317 system("rm -rf $rootdir/intranet-cgi/html-template");
318 system("rm -rf $rootdir/intranet-cgi/t");
319
320 # Set all .pl scripts executable
321 system("find $rootdir/intranet-cgi -name '*.pl' -exec chmod a+x \\{\\} \\;"); 
322 # Copy all CVS files to intranet-html and opac-html
323 system("cp -a $kohahtmldir/intranet-html/* $rootdir/intranet-html");
324 system("cp -a $kohahtmldir/opac-html/* $rootdir/opac-html");
325
326 # Move koha-tmpl files
327 system("mv $rootdir/intranet-cgi/koha-tmpl/opac-tmpl/* $rootdir/opac-html");
328 system("mv $rootdir/intranet-cgi/koha-tmpl/intranet-tmpl/* $rootdir/intranet-html");
329 system("rm -rf $rootdir/intranet-cgi/koha-tmpl");
330
331 # Remove extraneous files from opac-html
332 system("rm -f $rootdir/opac-html/koha.mo");
333 system("rm -f $rootdir/opac-html/koha.pot");
334 system("rm -f $rootdir/opac-html/test");
335
336 # Remove extraneous files from intranet-html
337 system("rm -f $rootdir/intranet-html/koha.pot");
338 system("rm -f $rootdir/intranet-html/results.html");
339 system("rm -f $rootdir/intranet-html/test");
340
341 # Remove junk from directory
342 system("find $rootdir -name CVS -exec rm -rf \\{\\} \\; 2>/dev/null");
343 system("find $rootdir -name *~ -exec rm -rf \\{\\} \\; 2>/dev/null");
344 system("find $rootdir -name .#* -exec rm -rf \\{\\} \\; 2>/dev/null");
345
346   
347 if (-e "$roothomedir/docs") {
348     print "Copying docs folder from $roothomedir/docs...";
349     system("cp -r $roothomedir/docs/* $rootdir/docs/");
350 } else {
351     print "I would have copied the docs from from $roothomedir/docs, but I couldn't find it.\n";
352     print "Press <ENTER> to continue...\n";
353     <STDIN>;
354 }
355
356 chdir("/tmp");
357 system("tar czf /tmp/koha-$releaseversion.tar.gz koha-".$releaseversion);
358 system("rm -rf $rootdir");
359
360 print qq|
361 ============
362 = ALL DONE =
363 ============
364
365 Your new tarball is located in /tmp/koha-$releaseversion.tar.gz
366
367 |;
368
369
370 sub versioncompare {
371     my $v1=shift;
372     my $v2=shift;
373     my @v1=split(/\./, $v1);
374     my @v2=split(/\./, $v2);
375     my $count=$#v1;
376     ($#v2>$count) && ($count=$#v2);
377     for (my $index=0; $index<$count; $index++) {
378         if ($v1[$index]>$v2[$index]) {
379             return 1;
380         }
381     }
382     return 0;
383 }
384
385 sub guess_kohahtmldir ($;$) {
386     my($kohadir, $default) = @_;
387     my $kohahtmldir;
388     # It probably makes sense to assume that the 'koha' and 'koha-html'
389     # modules are checked out within the same parent directory
390     if (-d $kohadir && $kohadir =~ /^(.*)\/[^\/]+$/) {
391         $kohahtmldir = "$1/koha-html"
392     } else {
393         $kohahtmldir = $default;
394     }
395     return $kohahtmldir;
396 }